def get_plugins(plugintype, module = None):
""" Discover the plugin classes contained in Python files.
Return a list of plugin classes.
"""
dir = os.path.join(os.getcwd(), "plugins", plugintype.id)
loaded = 0
plugins = []
for filename in os.listdir(dir):
modname, ext = os.path.splitext(filename)
if ext == '.py':
file, path, descr = imp.find_module(modname, [dir])
if file:
if module == modname:
# Loading the module registers the plugin in
# the corresponding base classes
mod = imp.load_module(modname, file, path, descr)
loaded += 1
elif not module:
plugins.append(modname)
loaded += 1
if plugins:
return plugins
else:
return plugintype.registry
评论列表
文章目录