channels.py
changeset 46 185504387370
parent 42 5a72c00c4ae4
child 50 f13cf27a360b
equal deleted inserted replaced
45:e94ab812c0c8 46:185504387370
       
     1 """
       
     2     Our list of LogChannels
       
     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 
       
    13 relpath = lambda path : os.path.join(os.path.dirname(__file__), path)
       
    14 
       
    15 class ChannelList (object) :
       
    16     """
       
    17         The list of channels, and related methods
       
    18     """
       
    19     
       
    20     # the statically defined channel list
       
    21     CHANNELS = {
       
    22         'tycoon':   LogChannel('tycoon', "OFTC", "#tycoon", 
       
    23             LogDirectory(relpath('logs/tycoon'), pytz.timezone('Europe/Helsinki'))
       
    24         ),
       
    25         'openttd':   LogChannel('openttd', "OFTC", "#openttd", 
       
    26             LogDirectory(relpath('logs/openttd'), pytz.timezone('Europe/Helsinki'))
       
    27         ),
       
    28     }
       
    29 
       
    30     def __init__ (self, channels) :
       
    31         """
       
    32             Initialize with the given channel dict
       
    33         """
       
    34 
       
    35         self.channels = channels
       
    36 
       
    37     def lookup (self, channel_name) :
       
    38         """
       
    39             Looks up the LogChannel for the given name
       
    40         """
       
    41 
       
    42         return self.channels[channel_name]
       
    43 
       
    44     def __iter__ (self) :
       
    45         """
       
    46             Iterate over our defined LogChannel objects
       
    47         """
       
    48 
       
    49         return self.channels.itervalues()
       
    50 
       
    51 # the global singletone ChannelList...
       
    52 channel_list = ChannelList(ChannelList.CHANNELS)
       
    53