channels.py
author Tero Marttila <terom@fixme.fi>
Mon, 09 Feb 2009 01:11:05 +0200
changeset 51 07ca28f3a9f2
parent 50 f13cf27a360b
child 73 5a7188bf2894
permissions -rw-r--r--
use improved URLConfig/URLType
"""
    Our list of LogChannels
"""

import pytz

# for relpath
import os.path

from log_channel import LogChannel
from log_source import LogDirectory
from log_parser import IrssiParser

relpath = lambda path : os.path.join(os.path.dirname(__file__), path)

class ChannelList (object) :
    """
        The list of channels, and related methods
    """

    # timezone to use
    TIMEZONE = pytz.timezone('Europe/Helsinki')

    # the parser that we use
    PARSER = IrssiParser(TIMEZONE, "%H:%M:%S")
    
    # the statically defined channel list
    CHANNELS = {
        'tycoon':   LogChannel('tycoon', "OFTC", "#tycoon", 
            LogDirectory(relpath('logs/tycoon'), TIMEZONE, PARSER)
        ),
        'openttd':   LogChannel('openttd', "OFTC", "#openttd", 
            LogDirectory(relpath('logs/openttd'), TIMEZONE, PARSER)
        ),
    }

    def __init__ (self, channels) :
        """
            Initialize with the given channel dict
        """

        self.channels = channels

    def lookup (self, channel_name) :
        """
            Looks up the LogChannel for the given name
        """

        return self.channels[channel_name]
    
    def dict (self) :
        """
            Returns a { name: LogChannel } dict
        """
        return self.channels

    def __iter__ (self) :
        """
            Iterate over our defined LogChannel objects
        """

        return self.channels.itervalues()

# the global singletone ChannelList...
channel_list = ChannelList(ChannelList.CHANNELS)