From b94a7a3b4e38021c8744ad0fa219d316eaf05407 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sun, 25 Jan 2004 08:22:50 +0000 Subject: [PATCH] Made defaultplugin use the registry. --- scripts/supybot | 15 ++++++-- scripts/supybot-wizard | 2 +- src/Config.py | 17 +++++---- src/Owner.py | 81 +++++++++++++----------------------------- src/conf.py | 4 +-- src/registry.py | 3 +- 6 files changed, 51 insertions(+), 71 deletions(-) diff --git a/scripts/supybot b/scripts/supybot index 5331c977d..91823ef82 100755 --- a/scripts/supybot +++ b/scripts/supybot @@ -223,16 +223,25 @@ if __name__ == '__main__': registry.open(registryFilename) except registry.InvalidRegistryFile, e: sys.stderr.write(str(e)) - sys.stderr.write('\n') + sys.stderr.write(os.linesep) + sys.exit(-1) + except EnvironmentError, e: + sys.stderr.write(str(e)) + sys.stderr.write(os.linesep) sys.exit(-1) import log import conf + import world def closeRegistry(): - log.info('Writing registry file to %s', registryFilename) + # We only print if world.dying so we don't see these messages during + # upkeep. + if world.dying: + log.info('Writing registry file to %s', registryFilename) registry.close(conf.supybot, registryFilename, annotated=True) - log.info('Finished writing registry file.') + if world.dying: + log.info('Finished writing registry file.') world.flushers.append(closeRegistry) nick = options.nick or conf.supybot.nick() diff --git a/scripts/supybot-wizard b/scripts/supybot-wizard index 936604502..bde4196ea 100755 --- a/scripts/supybot-wizard +++ b/scripts/supybot-wizard @@ -653,7 +653,7 @@ def main(): # Done! output("""All done! Your new bot configuration is %s. If you're running a *nix based OS, you can probably start your bot with the command line - "supybot ./%s". If you're not running a *nix or similar machine, you'll + "supybot %s". If you're not running a *nix or similar machine, you'll just have to start it like you start all your other Python scripts.""" % \ (filename, filename)) diff --git a/src/Config.py b/src/Config.py index 0e5326910..117f49983 100644 --- a/src/Config.py +++ b/src/Config.py @@ -59,7 +59,7 @@ def getWrapper(name): parts.pop(0) while parts: try: - group = getattr(group, parts.pop(0)) + group = group.get(parts.pop(0)) except registry.NonExistentRegistryEntry: raise InvalidRegistryName, name return group @@ -144,15 +144,18 @@ class Config(callbacks.Privmsg): wrapper = getWrapper(name) irc.reply(wrapper.default) - def flush(self, irc, msg, args): - """ + def reload(self, irc, msg, args): + """takes no arguments - Flushes the current registry to the file given. + Reloads the various configuration files (user database, channel + database, registry, etc.). """ - filename = privmsgs.getArgs(args) - registry.close(conf.supybot, filename) + # TODO: Reload registry. + ircdb.users.reload() + ircdb.channels.reload() irc.replySuccess() - flush = privmsgs.checkCapability(flush, 'owner') + reload = privmsgs.checkCapability(reload, 'owner') + Class = Config diff --git a/src/Owner.py b/src/Owner.py index b9b7c3b8e..063f88b7d 100644 --- a/src/Owner.py +++ b/src/Owner.py @@ -94,6 +94,24 @@ def loadPluginClass(irc, module): assert not irc.getCallback(callback.name()) irc.addCallback(callback) +conf.registerGroup(conf.supybot, 'commands') +conf.registerGroup(conf.supybot.commands, 'defaultPlugins', + registry.GroupWithDefault(registry.String('', """ + Determines what commands have default plugins set, and which + plugins are set to be the default for each of those + commands."""))) +conf.registerGlobalValue(conf.supybot.commands.defaultPlugins, + 'list', registry.String('Misc', '')) +conf.registerGlobalValue(conf.supybot.commands.defaultPlugins, + 'help', registry.String('Misc', '')) +conf.registerGlobalValue(conf.supybot.commands.defaultPlugins, + 'capabilities', registry.String('User', '')) +conf.registerGlobalValue(conf.supybot.commands.defaultPlugins, + 'addcapability', registry.String('Admin', '')) +conf.registerGlobalValue(conf.supybot.commands.defaultPlugins, + 'removecapability', registry.String('Admin', '')) +conf.registerGlobalValue(conf.supybot.commands.defaultPlugins, + 'reload', registry.String('Misc', '')) class Owner(privmsgs.CapabilityCheckingPrivmsg): # This plugin must be first; its priority must be lowest; otherwise odd @@ -104,11 +122,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg): def __init__(self): callbacks.Privmsg.__init__(self) setattr(self.__class__, 'exec', self.__class__._exec) - self.defaultPlugins = {'list': 'Misc', - 'help': 'Misc', - 'capabilities': 'User', - 'addcapability': 'Admin', - 'removecapability': 'Admin',} for (name, s) in registry._cache.iteritems(): if name.startswith('supybot.plugins'): try: @@ -142,9 +155,13 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg): ambiguousCommands = {} if tokens: command = callbacks.canonicalName(tokens[0]) - if command in self.defaultPlugins: - tokens.insert(0, self.defaultPlugins[command]) - else: + try: + plugin = conf.supybot.commands.defaultPlugins.get(command)() + if plugin: + tokens.insert(0, plugin) + else: + raise registry.NonExistentRegistryEntry + except registry.NonExistentRegistryEntry: cbs = callbacks.findCallbackForCommand(irc, command) if len(cbs) > 1: names = [cb.name() for cb in cbs] @@ -200,44 +217,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg): else: callbacks.IrcObjectProxy(irc, msg, tokens) - def defaultplugin(self, irc, msg, args): - """ [] [--remove] - - Calls from by default, rather than complaining about - multiple plugins providing it. If is not provided, shows the - current default plugin for . If --remove is given, removes - the current default plugin for . - """ - if '--remove' in args: - while '--remove' in args: - args.remove('--remove') - remove = True - else: - remove = False - (command, plugin) = privmsgs.getArgs(args, optional=1) - command = callbacks.canonicalName(command) - cbs = callbacks.findCallbackForCommand(irc, command) - if not cbs: - irc.error('That\'t not a valid command.') - return - if plugin: - self.defaultPlugins[command] = plugin - else: - try: - if remove: - del self.defaultPlugins[command] - else: - L = [command] - d = self.disambiguate(irc, L) - if d: - raise KeyError - assert len(L) == 2, 'Not disambiguated!' - irc.reply(L[0]) - except KeyError: - irc.error('I have no default plugin for that command.') - return - irc.replySuccess() - if conf.allowEval: def eval(self, irc, msg, args): """ @@ -402,16 +381,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg): else: irc.error('There was no callback %s' % name) - def reconf(self, irc, msg, args): - """takes no arguments - - Reloads the configuration files for the user and channel databases: - conf/users.conf and conf/channels.conf, by default. - """ - ircdb.users.reload() - ircdb.channels.reload() - irc.replySuccess() - Class = Owner diff --git a/src/conf.py b/src/conf.py index d778b7792..b71f3716a 100644 --- a/src/conf.py +++ b/src/conf.py @@ -71,8 +71,8 @@ def registerChannelValue(group, name, value): def registerGlobalValue(group, name, value): group.register(name, value) -def registerGroup(group, name): - group.registerGroup(name) +def registerGroup(group, name, Group=None): + group.registerGroup(name, Group) class ValidNick(registry.String): def setValue(self, v): diff --git a/src/registry.py b/src/registry.py index 501251ac3..ddfa1a5a4 100644 --- a/src/registry.py +++ b/src/registry.py @@ -122,8 +122,7 @@ class Value(object): # TODO: Check _lastModified to see if stuff needs to be reloaded from # the _cache. return self.value - - + class Boolean(Value): def set(self, s): s = s.lower()