From a765308cbdf7a58d5159db40b080923a5254435f Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 18 Sep 2003 05:47:42 +0000 Subject: [PATCH] Extracted loadPlugin{Module,Class} behavior into separate functions that can be exported to all modules. --- src/OwnerCommands.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/OwnerCommands.py b/src/OwnerCommands.py index 17f4ea53b..21e606300 100644 --- a/src/OwnerCommands.py +++ b/src/OwnerCommands.py @@ -52,6 +52,18 @@ import drivers import privmsgs import callbacks +def loadPluginModule(name): + moduleInfo = imp.find_module(name, conf.pluginDirs) + module = imp.load_module(name, *moduleInfo) + linecache.checkcache() + return module + +def loadPluginClass(irc, module): + callback = module.Class() + irc.addCallback(callback) + if hasattr(callback, 'configure'): + callback.configure(irc) + class OwnerCommands(privmsgs.CapabilityCheckingPrivmsg): priority = ~sys.maxint # This must be first! capability = 'owner' @@ -208,16 +220,11 @@ class OwnerCommands(privmsgs.CapabilityCheckingPrivmsg): irc.error(msg, 'That module is already loaded.') return try: - moduleInfo = imp.find_module(name, conf.pluginDirs) + module = loadPluginModule(name) except ImportError: irc.error(msg, 'No plugin %s exists.' % name) return - module = imp.load_module(name, *moduleInfo) - linecache.checkcache() - callback = module.Class() - irc.addCallback(callback) - if hasattr(callback, 'configure'): - callback.configure(irc) + loadPluginClass(irc, module) irc.reply(msg, conf.replySuccess) '''