forked from openlp/openlp
Only searches down one directory level for Plugin-subclasses
bzr-revno: 288
This commit is contained in:
parent
cb5407c9d3
commit
4efdc4e274
@ -51,18 +51,23 @@ class PluginManager(object):
|
||||
"""
|
||||
Scan the directory dir for objects inheriting from openlp.plugin
|
||||
"""
|
||||
log.debug("find plugins " + str(dir))
|
||||
startdepth=len(os.path.abspath(dir).split(os.sep))
|
||||
log.debug("find plugins %s at depth %d" %( str(dir), startdepth))
|
||||
|
||||
for root, dirs, files in os.walk(dir):
|
||||
for name in files:
|
||||
if name.endswith(".py") and not name.startswith("__"):
|
||||
path = os.path.abspath(os.path.join(root, name))
|
||||
thisdepth=len(path.split(os.sep))
|
||||
if thisdepth-startdepth > 2: # skip anything lower down
|
||||
continue
|
||||
modulename, pyext = os.path.splitext(path)
|
||||
prefix = os.path.commonprefix([self.basepath, path])
|
||||
# hack off the plugin base path
|
||||
modulename = modulename[len(prefix) + 1:]
|
||||
modulename = modulename.replace(os.path.sep, '.')
|
||||
# import the modules
|
||||
log.debug("Importing %s from %s." % (modulename, path))
|
||||
log.debug("Importing %s from %s. Depth %d" % (modulename, path, thisdepth))
|
||||
try:
|
||||
__import__(modulename, globals(), locals(), [])
|
||||
except ImportError, e:
|
||||
|
@ -30,7 +30,7 @@ class TestPluginManager:
|
||||
# see which ones we've got
|
||||
assert ("testplugin1" in names)
|
||||
assert ("testplugin2" in names)
|
||||
# and not got!
|
||||
# and not got - it's too deep in the hierarchy!
|
||||
assert ("testplugin3" not in names)
|
||||
# test that the weighting is done right
|
||||
assert p.plugins[0].name=="testplugin2"
|
||||
|
1
openlp/core/test/testplugins/deeper/__init__.py
Normal file
1
openlp/core/test/testplugins/deeper/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
|
1
openlp/core/test/testplugins/deeper/toodeep/__init__.py
Normal file
1
openlp/core/test/testplugins/deeper/toodeep/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,13 @@
|
||||
from openlp.core.lib import Plugin
|
||||
import logging
|
||||
|
||||
class testplugin3toodeep(Plugin):
|
||||
name="testplugin3"
|
||||
version=0
|
||||
global log
|
||||
log=logging.getLogger("testplugin1")
|
||||
log.info("Started")
|
||||
weight=10
|
||||
def __init__(self):
|
||||
pass
|
||||
|
@ -7,7 +7,7 @@ class testplugin1(Plugin):
|
||||
global log
|
||||
log=logging.getLogger("testplugin1")
|
||||
log.info("Started")
|
||||
Weight=10
|
||||
weight=10
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
@ -3,6 +3,6 @@ from openlp.core.lib import Plugin
|
||||
class testplugin2(Plugin):
|
||||
name="testplugin2"
|
||||
version=1
|
||||
Weight=1
|
||||
weight=1
|
||||
def __init__(self):
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user