mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added --groups to list; more tests.
This commit is contained in:
parent
8f4483bd6e
commit
a54e5a6477
@ -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):
|
||||
"""<group>
|
||||
"""[--groups] <group>
|
||||
|
||||
Returns the configuration variables available under the given
|
||||
configuration <group>.
|
||||
configuration <group>. If --groups is given, return the subgroups of
|
||||
the <group>.
|
||||
"""
|
||||
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):
|
||||
"""<name>
|
||||
@ -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):
|
||||
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user