def load_plugins(logger, plugins, pluginpath):
def load_plugin(name):
logger.debug('Loading plugin %s' % name)
fp, pathname, description = imp.find_module(name, [pluginpath])
try:
return imp.load_module(name, fp, pathname, description)
finally:
if fp:
fp.close()
logger.debug('Loading plugins from %s...' % pluginpath)
expanded = (glob.glob(os.path.join(pluginpath, '*' + ext))
for ext in python_extensions)
files = itertools.chain.from_iterable(expanded)
names = set(os.path.splitext(os.path.basename(fn))[0] for fn in files)
for name in names:
if name != '__init__':
plugin = load_plugin(name)
if hasattr(plugin, 'plugin_init'):
obj = plugin.plugin_init(plugins)
plugins.append(obj or plugin)
else:
plugins.append(plugin)
评论列表
文章目录