channels.py
changeset 46 185504387370
parent 42 5a72c00c4ae4
child 50 f13cf27a360b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/channels.py	Sun Feb 08 03:23:25 2009 +0200
@@ -0,0 +1,53 @@
+"""
+    Our list of LogChannels
+"""
+
+import pytz
+
+# for relpath
+import os.path
+
+from log_channel import LogChannel
+from log_source import LogDirectory
+
+relpath = lambda path : os.path.join(os.path.dirname(__file__), path)
+
+class ChannelList (object) :
+    """
+        The list of channels, and related methods
+    """
+    
+    # the statically defined channel list
+    CHANNELS = {
+        'tycoon':   LogChannel('tycoon', "OFTC", "#tycoon", 
+            LogDirectory(relpath('logs/tycoon'), pytz.timezone('Europe/Helsinki'))
+        ),
+        'openttd':   LogChannel('openttd', "OFTC", "#openttd", 
+            LogDirectory(relpath('logs/openttd'), pytz.timezone('Europe/Helsinki'))
+        ),
+    }
+
+    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 __iter__ (self) :
+        """
+            Iterate over our defined LogChannel objects
+        """
+
+        return self.channels.itervalues()
+
+# the global singletone ChannelList...
+channel_list = ChannelList(ChannelList.CHANNELS)
+