1 """ |
1 """ |
2 Our list of LogChannels |
2 Our list of LogChannels |
3 """ |
3 """ |
4 |
|
5 import pytz |
|
6 |
|
7 # for relpath |
|
8 import os.path |
|
9 |
|
10 from log_channel import LogChannel |
|
11 from log_source import LogDirectory |
|
12 from log_parser import IrssiParser |
|
13 |
|
14 relpath = lambda path : os.path.join(os.path.dirname(__file__), path) |
|
15 |
4 |
16 class ChannelList (object) : |
5 class ChannelList (object) : |
17 """ |
6 """ |
18 The list of channels, and related methods |
7 The list of channels, and related methods |
19 """ |
8 """ |
20 |
9 |
21 # timezone to use |
|
22 TIMEZONE = pytz.timezone('Europe/Helsinki') |
|
23 |
10 |
24 # the parser that we use |
11 def __init__ (self, channel_list) : |
25 PARSER = IrssiParser(TIMEZONE, "%H:%M:%S") |
|
26 |
|
27 # the statically defined channel list |
|
28 CHANNELS = { |
|
29 'tycoon': LogChannel('tycoon', "OFTC", "#tycoon", |
|
30 LogDirectory(relpath('logs/tycoon'), TIMEZONE, PARSER) |
|
31 ), |
|
32 'openttd': LogChannel('openttd', "OFTC", "#openttd", |
|
33 LogDirectory(relpath('logs/openttd'), TIMEZONE, PARSER) |
|
34 ), |
|
35 } |
|
36 |
|
37 def __init__ (self, channels) : |
|
38 """ |
12 """ |
39 Initialize with the given channel dict |
13 Initialize with the given channel dict |
40 """ |
14 """ |
41 |
15 |
42 self.channels = channels |
16 self.channel_list = channel_list |
|
17 self.channel_dict = dict((channel.id, channel) for channel in channel_list) |
43 |
18 |
44 def lookup (self, channel_name) : |
19 def lookup (self, channel_name) : |
45 """ |
20 """ |
46 Looks up the LogChannel for the given name |
21 Looks up the LogChannel for the given name |
47 """ |
22 """ |
48 |
23 |
49 return self.channels[channel_name] |
24 return self.channel_dict[channel_name] |
50 |
25 |
51 def dict (self) : |
26 def dict (self) : |
52 """ |
27 """ |
53 Returns a { name: LogChannel } dict |
28 Returns a { name: LogChannel } dict |
54 """ |
29 """ |
55 return self.channels |
30 return self.channel_dict |
56 |
31 |
57 def __iter__ (self) : |
32 def __iter__ (self) : |
58 """ |
33 """ |
59 Iterate over our defined LogChannel objects |
34 Iterate over our defined LogChannel objects |
60 """ |
35 """ |
61 |
36 |
62 return self.channels.itervalues() |
37 return iter(self.channel_list) |
63 |
38 |
64 # the global singletone ChannelList... |
|
65 channel_list = ChannelList(ChannelList.CHANNELS) |
|
66 |
|