def get_service_instance(class_, env='microdrop.managed'): e = PluginGlobals.env(env) for service in e.services: if isinstance(service, class_): # A plugin of this type is registered return service return None
def get_service_instance_by_name(name, env='microdrop.managed'): e = PluginGlobals.env(env) plugins = [p for i, p in enumerate(e.services) if name == p.name] if plugins: return plugins[0] else: raise KeyError, 'No plugin registered with name: %s' % name
def get_service_names(env='microdrop.managed'): e = PluginGlobals.env(env) service_names = [] for name in get_plugin_names(env): plugin_class = e.plugin_registry[name] service = get_service_instance(plugin_class, env=env) service_names.append(service.name) return service_names
def get_service_instance_by_package_name(name, env='microdrop.managed'): e = PluginGlobals.env(env) plugins = [p for i, p in enumerate(e.services) \ if name == get_plugin_package_name(p.__class__.__module__)] if plugins: return plugins[0] else: raise KeyError, 'No plugin registered with package name: %s' % name
def get_service_class(name, env='microdrop.managed'): e = PluginGlobals.env(env) if name not in e.plugin_registry: raise KeyError, 'No plugin registered with name: %s' % name return e.plugin_registry[name]
def get_plugin_names(env=None): if env is None: env = 'pca' e = PluginGlobals.env(env) return list(e.plugin_registry.keys())
if plugins_dir.parent.abspath() not in sys.path: sys.path.insert(0, plugins_dir.parent.abspath()) for package in plugins_dir.dirs(): try: logging.info('\t %s' % package.abspath()) import_statement = 'import %s.%s' % \ (plugins_dir.name, package.name) logging.debug(import_statement) exec(import_statement) except Exception, why: logging.info(''.join(traceback.format_exc())) logging.error('Error loading %s plugin.' % package.name) # Create an instance of each of the plugins, but set it to disabled e = PluginGlobals.env('microdrop.managed') for class_ in e.plugin_registry.values(): service = class_() service.disable() def post_install(install_path): # __NB__ The `cwd` directory ["is not considered when searching the # executable, so you can't specify the program's path relative to # `cwd`."][cwd]. Therefore, we manually change to the directory # containing the hook script and change back to the original working # directory when we're done. # # [cwd]: https://docs.python.org/2/library/subprocess.html#popen-constructor cwd = os.getcwd() if platform.system() in ('Linux', 'Darwin'):