forked from openlp/openlp
Change the importing of plugins to use the "imp" module in an effort to get around the UNO import errors.
This commit is contained in:
parent
203eb315b7
commit
230c06c83c
@ -32,6 +32,7 @@ Provide plugin management
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
import imp
|
||||||
|
|
||||||
from openlp.core.lib import Plugin, PluginStatus, Registry
|
from openlp.core.lib import Plugin, PluginStatus, Registry
|
||||||
|
|
||||||
@ -55,11 +56,8 @@ class PluginManager(object):
|
|||||||
"""
|
"""
|
||||||
log.info(u'Plugin manager Initialising')
|
log.info(u'Plugin manager Initialising')
|
||||||
Registry().register(u'plugin_manager', self)
|
Registry().register(u'plugin_manager', self)
|
||||||
if not plugin_dir in sys.path:
|
self.base_path = os.path.abspath(plugin_dir)
|
||||||
log.debug(u'Inserting %s into sys.path', plugin_dir)
|
log.debug(u'Base path %s ', self.base_path)
|
||||||
sys.path.insert(0, plugin_dir)
|
|
||||||
self.basepath = os.path.abspath(plugin_dir)
|
|
||||||
log.debug(u'Base path %s ', self.basepath)
|
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
log.info(u'Plugin manager Initialised')
|
log.info(u'Plugin manager Initialised')
|
||||||
|
|
||||||
@ -73,9 +71,8 @@ class PluginManager(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
log.info(u'Finding plugins')
|
log.info(u'Finding plugins')
|
||||||
startdepth = len(os.path.abspath(plugin_dir).split(os.sep))
|
start_depth = len(os.path.abspath(plugin_dir).split(os.sep))
|
||||||
log.debug(u'finding plugins in %s at depth %d',
|
log.debug(u'finding plugins in %s at depth %d', unicode(plugin_dir), start_depth)
|
||||||
unicode(plugin_dir), startdepth)
|
|
||||||
for root, dirs, files in os.walk(plugin_dir):
|
for root, dirs, files in os.walk(plugin_dir):
|
||||||
# TODO Presentation plugin is not yet working on Mac OS X.
|
# TODO Presentation plugin is not yet working on Mac OS X.
|
||||||
# For now just ignore it. The following code will hide it
|
# For now just ignore it. The following code will hide it
|
||||||
@ -88,22 +85,20 @@ class PluginManager(object):
|
|||||||
for name in files:
|
for name in files:
|
||||||
if name.endswith(u'.py') and not name.startswith(u'__'):
|
if name.endswith(u'.py') and not name.startswith(u'__'):
|
||||||
path = os.path.abspath(os.path.join(root, name))
|
path = os.path.abspath(os.path.join(root, name))
|
||||||
thisdepth = len(path.split(os.sep))
|
this_depth = len(path.split(os.sep))
|
||||||
if thisdepth - startdepth > 2:
|
if this_depth - start_depth > 2:
|
||||||
# skip anything lower down
|
# skip anything lower down
|
||||||
break
|
break
|
||||||
modulename = os.path.splitext(path)[0]
|
module_name = name[:-3]
|
||||||
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
|
# import the modules
|
||||||
log.debug(u'Importing %s from %s. Depth %d', modulename, path, thisdepth)
|
log.debug(u'Importing %s from %s. Depth %d', module_name, root, this_depth)
|
||||||
try:
|
try:
|
||||||
__import__(modulename, globals(), locals(), [])
|
fp, path_name, description = imp.find_module(module_name, [root])
|
||||||
|
imp.load_module(module_name, fp, path_name, description)
|
||||||
|
#__import__(module_name, globals(), locals(), [])
|
||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
log.exception(u'Failed to import module %s on path %s for reason %s',
|
log.exception(u'Failed to import module %s on path %s for reason %s',
|
||||||
modulename, path, e.args[0])
|
module_name, path, e.args[0])
|
||||||
plugin_classes = Plugin.__subclasses__()
|
plugin_classes = Plugin.__subclasses__()
|
||||||
plugin_objects = []
|
plugin_objects = []
|
||||||
for p in plugin_classes:
|
for p in plugin_classes:
|
||||||
|
Loading…
Reference in New Issue
Block a user