From a54e5a647700df9a54dd2a486f6b8b01cd802237 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 26 Jan 2004 17:54:07 +0000 Subject: [PATCH] Added --groups to list; more tests. --- src/Config.py | 42 +++++++++++++++++++++++++++++++----------- test/test_Config.py | 15 +++++++++++++++ 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/Config.py b/src/Config.py index 117f49983..58a871d19 100644 --- a/src/Config.py +++ b/src/Config.py @@ -33,14 +33,15 @@ Handles configuration of the bot while it's running. """ -import plugins +import getopt import conf import utils import ircdb +import plugins import ircutils -import registry import privmsgs +import registry import callbacks ### @@ -87,21 +88,35 @@ class Config(callbacks.Privmsg): irc.error(str(e)) def list(self, irc, msg, args): - """ + """[--groups] Returns the configuration variables available under the given - configuration . + configuration . If --groups is given, return the subgroups of + the . """ - name = privmsgs.getArgs(args) + (optlist, rest) = getopt.getopt(args, '', ['groups']) + groups = False + for (name, arg) in optlist: + if name == '--groups': + groups = True + name = privmsgs.getArgs(rest) group = getWrapper(name) - if hasattr(group, 'getValues'): - try: - L = zip(*group.getValues(fullNames=False))[0] + if groups: + L = group.children.keys() + if L: + utils.sortBy(str.lower, L) irc.reply(utils.commaAndify(L)) - except TypeError: - irc.error('There don\'t seem to be any values in %r' % name) + else: + irc.reply('%s has no subgroups.' % name) else: - irc.error('%r is not a valid configuration group.' % name) + if hasattr(group, 'getValues'): + try: + L = zip(*group.getValues(fullNames=False))[0] + irc.reply(utils.commaAndify(L)) + except TypeError: + irc.error('There don\'t seem to be any values in %s'%name) + else: + irc.error('%r is not a valid configuration group.' % name) def get(self, irc, msg, args): """ @@ -110,6 +125,11 @@ class Config(callbacks.Privmsg): """ name = privmsgs.getArgs(args) wrapper = getWrapper(name) + if wrapper.__class__ is registry.Group: + irc.error(msg, 'That\'s not a value, it\'s a group. Use the list ' + 'command in this plugin to see what values are ' + 'available in this group.') + return irc.reply(str(wrapper)) def set(self, irc, msg, args): diff --git a/test/test_Config.py b/test/test_Config.py index abe5b7b28..ad63f1f15 100644 --- a/test/test_Config.py +++ b/test/test_Config.py @@ -36,6 +36,21 @@ class ConfigTestCase(ChannelPluginTestCase): def testGet(self): self.assertNotRegexp('config get supybot.reply', r'registry\.Group') + def testList(self): + self.assertError('config list asldfkj') + self.assertError('config list supybot.asdfkjsldf') + self.assertNotError('config list supybot') + self.assertNotError('config list supybot.replies') + self.assertRegexp('config list --groups supybot', + r'plugins.*replies.*reply') + + def testHelp(self): + self.assertError('config help alsdkfj') + self.assertError('config help supybot') + self.assertError('config help supybot.plugins') + self.assertError('config help supybot.alsdkfj') + self.assertNotError('config help supybot.replies.success') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: