diff --git a/src/OwnerCommands.py b/src/OwnerCommands.py index c6878e75a..607c98748 100644 --- a/src/OwnerCommands.py +++ b/src/OwnerCommands.py @@ -37,6 +37,7 @@ their caller to have the 'owner' capability. This plugin is loaded by default. import fix import gc +import os import imp import sys import linecache @@ -54,6 +55,15 @@ import callbacks def loadPluginModule(name): """Loads (and returns) the module for the plugin with the given name.""" + files = [] + for dir in conf.pluginDirs: + files.extend(os.listdir(dir)) + loweredFiles = map(str.lower, files) + try: + index = map(str.lower, files).index(name.lower()+'.py') + name = os.path.splitext(files[index])[0] + except ValueError: # We'd rather raise the ImportError, so we'll let go... + pass moduleInfo = imp.find_module(name, conf.pluginDirs) module = imp.load_module(name, *moduleInfo) linecache.checkcache() @@ -244,7 +254,8 @@ class OwnerCommands(privmsgs.CapabilityCheckingPrivmsg): Loads the plugin from any of the directories in conf.pluginDirs; usually this includes the main installed directory - and 'plugins' in the current directory. + and 'plugins' in the current directory. Be sure not to have ".py" at + the end. """ name = privmsgs.getArgs(args) for cb in irc.callbacks: diff --git a/test/test_OwnerCommands.py b/test/test_OwnerCommands.py index ace59545a..d66c1edb4 100644 --- a/test/test_OwnerCommands.py +++ b/test/test_OwnerCommands.py @@ -32,6 +32,7 @@ from test import * import conf +import OwnerCommands class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation): plugins = ('OwnerCommands',) @@ -129,7 +130,13 @@ class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation): conf.replyWhenNotCommand = originalReplyWhenNotCommand finally: conf.allowEval = originalConfAllowEval + +class FunctionsTestCase(unittest.TestCase): + def testLoadPluginModule(self): + self.assertRaises(ImportError, OwnerCommands.loadPluginModule, 'asldj') + self.failUnless(OwnerCommands.loadPluginModule('OwnerCommands')) + self.failUnless(OwnerCommands.loadPluginModule('ownercommands')) # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: