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 | |
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
-rw-r--r-- | config.py | 4 | ||||
-rw-r--r-- | plugin.py | 4 | ||||
-rw-r--r-- | supybotconfig.py | 72 |
3 files changed, 80 insertions, 0 deletions
@@ -44,6 +44,10 @@ MeetBot = conf.registerPlugin('MeetBot') # This is where your configuration variables (if any) should go. For example: # conf.registerGlobalValue(MeetBot, 'someConfigVariableName', # registry.Boolean(False, """Help for someConfigVariableName.""")) +conf.registerGlobalValue(MeetBot, 'enableSupybotBasedConfig', + registry.Boolean(False, """Enable configuration via the supybot config """ + """mechanism.""")) + # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: @@ -38,6 +38,8 @@ import supybot.ircmsgs as ircmsgs import time import meeting meeting = reload(meeting) +import supybotconfig +supybotconfig = reload(supybotconfig) # By doing this, we can not lose all of our meetings across plugin # reloads. But, of course, you can't change the source too @@ -97,6 +99,8 @@ class MeetBot(callbacks.Plugin): irc.sendMsg(ircmsgs.privmsg(channel, x)) M._setTopic = _setTopic M._sendReply = _sendReply + # callback to get supybot registry values. + M._registryValue = self.registryValue # If there is no meeting going on, then we quit if M is None: return # Add line to our meeting buffer. 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), {}) |