diff options
author | Richard Darst <rkd@zgib.net> | 2009-06-26 18:40:17 (GMT) |
---|---|---|
committer | Richard Darst <rkd@zgib.net> | 2009-06-26 18:40:17 (GMT) |
commit | 0a49a92f37b93ecb91457dd0bfeb782e8d5633fe (patch) | |
tree | 001843e190ce9ebfcf53237b9e829ecf28d75fd8 /supybotconfig.py | |
parent | aac4ff07f0e90afca6ee1a5001f91d63dc1d3fa9 (diff) |
Initial checkin of supybot-based config method
- this simply proxies all string attributes of the Config class to the
supybot config namespace supybot.plugins.MeetBot.* When you adjust them
in supybot, the MeetBot methods see the changes.
- To enable, you must set supybot.plugins.MeetBot.enableSupybotBasedConfig
to True, and then reload MeetBot.
Then "config list supybot.plugins.MeetBot" and you'll see a bunch of
variables for you to change.
- To-do: think about supybot config stomping changes to defaults, and
implement channel-based config.
darcs-hash:20090626184017-82ea9-c24fcb02c54fd848de6ce5b212b1a48fcf42d970.gz
Diffstat (limited to 'supybotconfig.py')
-rw-r--r-- | supybotconfig.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/supybotconfig.py b/supybotconfig.py new file mode 100644 index 0000000..3052915 --- /dev/null +++ b/supybotconfig.py @@ -0,0 +1,72 @@ +# Richard Darst, June 2009 + +import supybot.conf as conf +import supybot.registry as registry + +import meeting +OriginalConfig = meeting.Config + +# The plugin group for configuration +MeetBotConfigGroup = conf.registerPlugin('MeetBot') + +class SupybotConfig(object): + def __init__(self, M): + """Do the regular default configuration, and sta""" + self.__C = OriginalConfig(M) + + def __getattr__(self, attrname): + """Try to get the value from the supybot registry. If it's in + the registry, return it. If it's not, then proxy it to th. + """ + if attrname in settable_attributes: + value = self.__C.M._registryValue(attrname, + #channel=self.__C.M.channel + ) + if value != '.': + value = value.replace('\\n', '\n') + return value + # We don't have this value in the registry. So, proxy it to + # the normal config object. This is also the path that all + # functions take. + return getattr(self.__C, attrname) + + #def __getattribute__(self, attrname): + # print attrname + # + # from fitz import interact ; interact.interact() + # if attrname in settable_attributes: + # "getting from registry" + # #self.registryValue('enable', channel) + # return "blah blah blah" + # + # raise AttributeError + + +#conf.registerGlobalValue(MeetBot +use_supybot_config = conf.registerGlobalValue(MeetBotConfigGroup, + 'enableSupybotBasedConfig', + registry.Boolean(False, '')) +#from fitz import interactnow +if (use_supybot_config.value and + not getattr(OriginalConfig, 'dontBotConfig', False)): + # Set all string variables in the default Config class as supybot + # registry variables. + settable_attributes = [ ] + for attrname in dir(OriginalConfig): + # Don't configure attributs starting with '_' + if attrname[0] == '_': + continue + attr = getattr(OriginalConfig, attrname) + # Don't configure attributes that aren't strings. + if not isinstance(attr, (str, unicode)): + continue + attr = attr.replace('\n', '\\n') + # Use this instead: conf.registerChannelValue + conf.registerGlobalValue(MeetBotConfigGroup, attrname, + registry.String(attr,"")) + settable_attributes.append(attrname) + + # Here is where the real proxying occurs. + meeting.Config = SupybotConfig + meeting.ConfigOriginal = OriginalConfig + #meeting.Config = type('Config', (Config, meeting.Config), {}) |