Made loadPluginModule case-insensitive.

This commit is contained in:
Jeremy Fincher 2003-10-14 03:34:47 +00:00
parent 56016de47c
commit 8e37d2ae88
2 changed files with 19 additions and 1 deletions

View File

@ -37,6 +37,7 @@ their caller to have the 'owner' capability. This plugin is loaded by default.
import fix import fix
import gc import gc
import os
import imp import imp
import sys import sys
import linecache import linecache
@ -54,6 +55,15 @@ import callbacks
def loadPluginModule(name): def loadPluginModule(name):
"""Loads (and returns) the module for the plugin with the given 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) moduleInfo = imp.find_module(name, conf.pluginDirs)
module = imp.load_module(name, *moduleInfo) module = imp.load_module(name, *moduleInfo)
linecache.checkcache() linecache.checkcache()
@ -244,7 +254,8 @@ class OwnerCommands(privmsgs.CapabilityCheckingPrivmsg):
Loads the plugin <plugin> from any of the directories in Loads the plugin <plugin> from any of the directories in
conf.pluginDirs; usually this includes the main installed directory 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) name = privmsgs.getArgs(args)
for cb in irc.callbacks: for cb in irc.callbacks:

View File

@ -32,6 +32,7 @@
from test import * from test import *
import conf import conf
import OwnerCommands
class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation): class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
plugins = ('OwnerCommands',) plugins = ('OwnerCommands',)
@ -131,6 +132,12 @@ class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
conf.allowEval = originalConfAllowEval 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: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: