예제 #1
0
################################################################################
import simpleapi as _simpleapi
from kernel import plugins as _plugins


_plugins_key = 'python.plugins.directories'
_user_key = 'user.%s' % _plugins_key
plugin_dirs = _plugins.get_plugin_paths_as_set(_plugins_key)
plugin_dirs.update(_plugins.get_plugin_paths_as_set(_user_key))

# Load
plugin_files = []
alg_files = []
for directory in plugin_dirs:
    try:
        all_plugins, algs = _plugins.find_plugins(directory)
        plugin_files += all_plugins
        alg_files += algs
    except ValueError, exc:
        logger.warning(str(exc))
        continue

# Mockup the full API first so that any Python algorithm module has something to import
_simpleapi._mockup(alg_files)
# Load the plugins
plugin_modules = _plugins.load(plugin_files)
# Create the proper algorithm definitions in the module
new_attrs = _simpleapi._translate()
# Finally, overwrite the mocked function definitions in the loaded modules with the real ones 
_plugins.sync_attrs(_simpleapi, new_attrs, plugin_modules)
예제 #2
0
# loaded the correction translation is applied to create the "real" simple
# API functions.
#
# Although this seems odd it is necessary so that any PythonAlgorithm 
# can call any other PythonAlgorithm through the simple API mechanism. If left 
# to the simple import mechanism then plugins that are loaded later cannot
# be seen by the earlier ones (chicken & the egg essentially). 
################################################################################
import simpleapi as _simpleapi
from kernel import plugins as _plugins

plugin_dirs = kernel.config['pythonalgorithms.directories'].split(";")
plugin_files = []
for directory in plugin_dirs:
    try:
        if directory != '':
            plugin_files += _plugins.find_plugins(directory)
    except ValueError, exc:
        logger.warning(str(exc))
        continue

# Mockup the full API first so that any Python algorithm module has something to import
_simpleapi.mockup(plugin_files)
# Now actually load the Python plugins
plugin_modules = _plugins.load(plugin_files)
# Create the proper definitions in the module
new_attrs = _simpleapi.translate()
# Finally, overwrite the mocked function definitions in the loaded modules with the real ones 
_plugins.sync_attrs(_simpleapi, new_attrs, plugin_modules)
################################################################################