From 944c6eded08ca7c6ba76fe1e9511a3a702347577 Mon Sep 17 00:00:00 2001 From: Richard Darst Date: Sat, 27 Jun 2009 22:49:26 +0000 Subject: 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 --- (limited to 'supybotconfig.py') 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 -- cgit v0.9.1