Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/supybotconfig.py
diff options
context:
space:
mode:
authorRichard Darst <rkd@zgib.net>2009-06-27 22:49:26 (GMT)
committer Richard Darst <rkd@zgib.net>2009-06-27 22:49:26 (GMT)
commit944c6eded08ca7c6ba76fe1e9511a3a702347577 (patch)
tree5c2b956b566f005be2b13107279a880350c5282f /supybotconfig.py
parent4416e68aa3b99c3a612c6471196693bf0ecd81aa (diff)
add support for setting writer_map via supybot
- we define our own WriterMap class to translate the config to/from a string. This is the Right Way to integrate with the supybot registry. darcs-hash:20090627224926-82ea9-c1dfa4da4724e29d660382082a7ced0da1d4b5c1.gz
Diffstat (limited to 'supybotconfig.py')
-rw-r--r--supybotconfig.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/supybotconfig.py b/supybotconfig.py
index a989eaf..195dab9 100644
--- a/supybotconfig.py
+++ b/supybotconfig.py
@@ -4,11 +4,45 @@ import supybot.conf as conf
import supybot.registry as registry
import meeting
+import writers
+
OriginalConfig = meeting.Config
# The plugin group for configuration
MeetBotConfigGroup = conf.registerPlugin('MeetBot')
+class WriterMap(registry.String):
+ """List of output formats to write. This is a space-separated
+ list of 'WriterName:.ext' pairs. WriterName must be from the
+ writers.py module, '.ext' must be a extension ending in a .
+ """
+ def set(self, s):
+ s = s.split()
+ writer_map = { }
+ for writer in s:
+ #from fitz import interact ; interact.interact()
+ writer, ext = writer.split(':')
+ if not hasattr(writers, writer):
+ raise ValueError("Writer name not found: %s"%writer)
+ if len(ext) < 2 or ext[0] != '.':
+ raise ValueError("Extension must start with '.' and have "
+ "at least one more character.")
+ writer_map[ext] = getattr(writers, writer)
+ self.setValue(writer_map)
+ def setValue(self, writer_map):
+ for e, w in writer_map.iteritems():
+ if not hasattr(w, "format"):
+ raise ValueError("Writer %s must have method .format()"%
+ w.__class__.__name__)
+ self.value = writer_map
+ def __str__(self):
+ writers_string = [ ]
+ for ext, w in self.value.iteritems():
+ name = w.__class__.__name__
+ writers_string.append("%s:%s"%(name, ext))
+ return " ".join(writers_string)
+
+
class SupybotConfig(object):
def __init__(self, M):
"""Do the regular default configuration, and sta"""
@@ -21,6 +55,8 @@ class SupybotConfig(object):
if attrname in settable_attributes:
value = self.__C.M._registryValue(attrname,
channel=self.__C.M.channel)
+ if not isinstance(value, (str, unicode)):
+ return value
if value != '.':
value = value.replace('\\n', '\n')
return value
@@ -66,6 +102,14 @@ if (use_supybot_config.value and
registry.String(attr,""))
settable_attributes.append(attrname)
+ # writer_map
+ if 'writer_map' in MeetBotConfigGroup._children:
+ MeetBotConfigGroup.unregister('writer_map')
+ conf.registerChannelValue(MeetBotConfigGroup, 'writer_map',
+ WriterMap(OriginalConfig.writer_map, ""))
+ settable_attributes.append('writer_map')
+
+
# Here is where the real proxying occurs.
meeting.Config = SupybotConfig
meeting.ConfigOriginal = OriginalConfig