mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +01:00
Made loadPluginModule case-insensitive.
This commit is contained in:
parent
56016de47c
commit
8e37d2ae88
@ -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 <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:
|
||||
|
@ -32,6 +32,7 @@
|
||||
from test import *
|
||||
|
||||
import conf
|
||||
import OwnerCommands
|
||||
|
||||
class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('OwnerCommands',)
|
||||
@ -131,6 +132,12 @@ class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
|
||||
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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user