Skip to content

Commit

Permalink
Convert plugin utils to a Command
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Jul 24, 2011
1 parent ddf6078 commit a0cbeb2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions hamper/plugins/plugin_utils.py
Expand Up @@ -3,31 +3,32 @@
from zope.interface import implements from zope.interface import implements
from bravo import plugin from bravo import plugin


from hamper.interfaces import IPlugin from hamper.interfaces import Command, IPlugin




class PluginUtils(object): class PluginUtils(Command):
implements(IPlugin)


name = 'plugins' name = 'plugins'
priority = 0 priority = 0
regex = r'^plugins?\W+(.*)$'


def process(self, bot, comm): def command(self, bot, comm, groups):
match = re.match('^plugins?\w+(.*)$', comm['message']) args = groups[0].split(' ')
if not match:
return

args = match.groups()[0].split(' ')
args = [a.strip() for a in args] args = [a.strip() for a in args]
args = [a for a in args if a] args = [a for a in args if a]


dispatch = { dispatch = {
'list': self.listPlugins, 'list': self.listPlugins,
'reload': self.reloadPlugin, 'reload': self.reloadPlugin,
} }
print args

if len(args) == 0:
self.listPlugins(bot, *args)
return True


if args[0] in dispatch: if args[0] in dispatch:
dispatch[args[0]](bot, *args[1:]) dispatch[args[0]](bot, *args)
return True return True


def listPlugins(self, bot, *args): def listPlugins(self, bot, *args):
Expand All @@ -37,7 +38,7 @@ def listPlugins(self, bot, *args):


def reloadPlugin(self, bot, *args): def reloadPlugin(self, bot, *args):
"""Reload a named plugin.""" """Reload a named plugin."""
name = ' '.join(args) name = ' '.join(args[1:])


ps = bot.factory.plugins ps = bot.factory.plugins


Expand All @@ -53,7 +54,7 @@ def reloadPlugin(self, bot, *args):


bot.removePlugin(target_plugin) bot.removePlugin(target_plugin)
bot.addPlugin(new_plugin) bot.addPlugin(new_plugin)
bot.say('Request reload of {0}.'.format(new_plugin)) bot.say('Reloading {0}.'.format(new_plugin))




plugin_utils = PluginUtils() plugin_utils = PluginUtils()

0 comments on commit a0cbeb2

Please sign in to comment.