def _load_eggs(env, search_path, auto_enable=None): # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins(pkg_resources.Environment(search_path)) for dist in distributions: env.log.debug("Adding plugin %s from %s", dist, dist.location) working_set.add(dist) def _log_error(item, e): ue = exception_to_unicode(e) if isinstance(e, DistributionNotFound): env.log.debug('Skipping "%s": ("%s" not found)', item, ue) elif isinstance(e, VersionConflict): env.log.error('Skipping "%s": (version conflict "%s")', item, ue) elif isinstance(e, UnknownExtra): env.log.error('Skipping "%s": (unknown extra "%s")', item, ue) elif isinstance(e, ImportError): env.log.error('Skipping "%s": (can\'t import "%s")', item, ue) else: env.log.error('Skipping "%s": (error "%s")', item, ue) for dist, e in errors.iteritems(): _log_error(dist, e) for entry in working_set.iter_entry_points(entry_point_name): env.log.debug("Loading %s from %s", entry.name, entry.dist.location) try: entry.load(require=True) except (ImportError, DistributionNotFound, VersionConflict, UnknownExtra), e: _log_error(entry, e) else: if os.path.dirname(entry.dist.location) == auto_enable: _enable_plugin(env, entry.module_name)
def add_plugin_dir(plugin_dir): """ Find available plugins """ if not os.path.isdir(plugin_dir): LOG.debug("Adding plugin directory: %r", plugin_dir) env = Environment([plugin_dir]) dists, errors = working_set.find_plugins(env) for dist in dists: LOG.debug("Adding distribution: %r", dist) working_set.add(dist) if errors: for dist, error in list(errors.items()): errmsg = None if isinstance(error, DistributionNotFound): req, = error.args errmsg = "%r not found" % req.project_name elif isinstance(error, VersionConflict): dist, req = error.args errmsg = "Version Conflict. Requested %s Found %s" % (req, dist) else: errmsg = repr(error) LOG.error("Failed to load %s: %r", dist, errmsg) PLUGIN_DIRECTORIES.append(plugin_dir)
def _load_eggs(env): distributions, errors = working_set.find_plugins( pkg_resources.Environment()) for dist in distributions: if dist not in working_set: env.log.debug('Adding plugin %s from %s', dist, dist.location) working_set.add(dist) def _log_error(item, e): ue = exception_to_unicode(e) if isinstance(e, DistributionNotFound): env.log.debug('Skipping "%s": ("%s" not found)', item, ue) elif isinstance(e, VersionConflict): env.log.error('Skipping "%s": (version conflict "%s")', item, ue) elif isinstance(e, UnknownExtra): env.log.error('Skipping "%s": (unknown extra "%s")', item, ue) else: env.log.error('Skipping "%s": %s', item, exception_to_unicode(e, traceback=True)) for dist, e in errors.iteritems(): _log_error(dist, e) for entry in sorted(working_set.iter_entry_points(entry_point_name), key=lambda entry: entry.name): env.log.debug('Loading %s from %s', entry.name, entry.dist.location) try: entry.load(require=True) except Exception as exc: _log_error(entry, exc) else: _enable_plugin(env, entry.module_name)
def _load_eggs(env, search_path, auto_enable=None): # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path)) for dist in distributions: env.log.debug('Adding plugin %s from %s', dist, dist.location) working_set.add(dist) def _log_error(item, e): if isinstance(e, DistributionNotFound): env.log.debug('Skipping "%s": ("%s" not found)', item, e) elif isinstance(e, VersionConflict): env.log.error('Skipping "%s": (version conflict "%s")', item, e) elif isinstance(e, UnknownExtra): env.log.error('Skipping "%s": (unknown extra "%s")', item, e) elif isinstance(e, ImportError): env.log.error('Skipping "%s": (can\'t import "%s")', item, e) else: env.log.error('Skipping "%s": (error "%s")', item, e) for dist, e in errors.iteritems(): _log_error(dist, e) for entry in working_set.iter_entry_points(entry_point_name): env.log.debug('Loading %s from %s', entry.name, entry.dist.location) try: entry.load(require=True) except (ImportError, DistributionNotFound, VersionConflict, UnknownExtra), e: _log_error(entry, e) else: if os.path.dirname(entry.dist.location) == auto_enable: _enable_plugin(env, entry.module_name)
def _load_eggs(env, search_path, auto_enable=None): # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path) ) for dist in distributions: if dist not in working_set: env.log.debug('Adding plugin "%s" from "%s"', dist, dist.location) working_set.add(dist) def _log_error(item, e): ue = exception_to_unicode(e) if isinstance(e, DistributionNotFound): env.log.debug('Skipping "%s": %s', item, ue) elif isinstance(e, (ImportError, UnknownExtra, VersionConflict)): env.log.error('Skipping "%s": %s', item, ue) else: env.log.error('Skipping "%s": %s', item, exception_to_unicode(e, traceback=True)) for dist, e in errors.iteritems(): _log_error(dist, e) for entry in sorted(working_set.iter_entry_points(entry_point_name), key=lambda entry: entry.name): env.log.debug('Loading plugin "%s" from "%s"', entry.name, entry.dist.location) try: entry.load(require=True) except Exception as e: _log_error(entry, e) else: if os.path.dirname(entry.dist.location) == auto_enable: _enable_plugin(env, entry.module_name)
def activate_plugins(dirs, working_set=working_set): """ Add plugins from `dirs` to `working_set` """ plugin_env = pkg_resources.Environment(dirs) dists, errors = working_set.find_plugins(plugin_env, fallback=False) map(working_set.add, dists)
def load_eggs(self, search_path, auto_enable=None): # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path) ) for dist in distributions: if dist not in working_set: working_set.add(dist) def _log_error(item, e): log.error("[plugins] error loading %s %s", item, e) log.error('[plugins] %s', traceback.format_exc()) for dist, e in errors.iteritems(): # ignore version conflict of modules which are not OMS plugins if self.ENTRY_POINT_NAME in dist.get_entry_map(): _log_error(dist, e) for entry in sorted(working_set.iter_entry_points(self.ENTRY_POINT_NAME), key=lambda entry: entry.name): log.debug('[plugins] Loading %s from %s' % (entry.name, entry.dist.location)) try: entry.load(require=True) except Exception, e: _log_error(entry, e) else: yield entry
def add_plugin_dir(plugin_dir): if os.path.isdir(plugin_dir): return None LOGGER.debug("Adding plugin directory: %r", plugin_dir) env = Environment([plugin_dir]) dists, errors = working_set.find_plugins(env) for dist in dists: LOGGER.debug("Adding distribution: %r", dist) working_set.add(dist) if errors: for dist, error in list(errors.items()): errmsg = None if isinstance(error, DistributionNotFound): req, = error.args errmsg = "%r not found" % req.project_name elif isinstance(error, VersionConflict): dist, req = error.args errmsg = "Version Conflict. Requested %s Found %s" % (req, dist) else: # FIXME: Are there other types of failures? errmsg = repr(error) LOGGER.error("Failed to load %s: %r", dist, errmsg) global plugin_directories plugin_directories.append(plugin_dir)
def _load_eggs(ch, search_path): logger.debug("Loading eggs...") # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path) ) logger.debug("Found distributions: %s", str(distributions)) for dist in distributions: if dist not in working_set: logger.debug('Adding plugin %s from %s', dist, dist.location) working_set.add(dist) for dist, e in errors.iteritems(): logger.error("Error in distribution %s: %s", str(dist), str(e)) for entry in sorted(working_set.iter_entry_points(entry_point_name), key=lambda entry: entry.name): logger.debug('Loading %s from %s', entry.name, entry.dist.location) try: entry.load(require=True) except Exception, e: logger.exception("Error loading: %s", entry) else: logger.debug("Loaded module %s from %s:", entry.module_name, entry.dist.location)
def load_eggs(self, search_path, auto_enable=None): # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path)) for dist in distributions: if dist not in working_set: working_set.add(dist) def _log_error(item, e): log.error("[plugins] error loading %s %s", item, e) log.error('[plugins] %s', traceback.format_exc()) for dist, e in errors.iteritems(): # ignore version conflict of modules which are not OMS plugins if self.ENTRY_POINT_NAME in dist.get_entry_map(): _log_error(dist, e) for entry in sorted(working_set.iter_entry_points( self.ENTRY_POINT_NAME), key=lambda entry: entry.name): log.debug('[plugins] Loading %s from %s' % (entry.name, entry.dist.location)) try: entry.load(require=True) except Exception, e: _log_error(entry, e) else: yield entry
def search(apps_paths=None, installed_apps=None): """ Searches in the given apps directories for Django apps with the entry point ``'django.apps'`` and adds them to the python path, if necesary. Returns a tuple with all installed and reusable applications. """ if Environment is not None and apps_paths is not None: # find every "distributions" in the given paths for reusable apps and # add them to the "working_set", effectively setting PYTHONPATH distributions, errors = working_set.find_plugins( Environment(apps_paths)) for dist in distributions: working_set.add(dist) for dist, e in errors.iteritems(): if isinstance(e, DistributionNotFound): raise ReusableAppsError('"%s": ("%s" not found)', dist, e) elif isinstance(e, VersionConflict): raise ReusableAppsError('"%s": (version conflict "%s")', dist, e) elif isinstance(e, UnknownExtra): raise ReusableAppsError('"%s": (unknown extra "%s")', dist, e) elif isinstance(e, ImportError): raise ReusableAppsError('"%s": (can\'t import "%s")', dist, e) else: raise ReusableAppsError('"%s": (error "%s")', dist, e) # look for entry points in all distributions of the current working set # (on the PYTHONPATH) and add matching modules to INSTALLED_APPS for entry in working_set.iter_entry_points('django.apps'): app_name = entry.module_name if app_name not in installed_apps and app_name not in REUSEABLE_APPS: REUSEABLE_APPS.append(entry.module_name) return installed_apps + tuple(REUSEABLE_APPS)
def _load_eggs(ch, search_path): logger.debug("Loading eggs...") # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path)) logger.debug("Found distributions: %s", str(distributions)) for dist in distributions: if dist not in working_set: logger.debug('Adding plugin %s from %s', dist, dist.location) working_set.add(dist) for dist, e in errors.iteritems(): logger.error("Error in distribution %s: %s", str(dist), str(e)) for entry in sorted(working_set.iter_entry_points(entry_point_name), key=lambda entry: entry.name): logger.debug('Loading %s from %s', entry.name, entry.dist.location) try: entry.load(require=True) except Exception, e: logger.exception("Error loading: %s", entry) else: logger.debug("Loaded module %s from %s:", entry.module_name, entry.dist.location)
def activate_plugins(dirs, working_set=working_set): """ Add plugins from `dirs` to `working_set` """ plugin_env = pkg_resources.Environment(dirs) dists, errors = working_set.find_plugins(plugin_env, fallback=False) map(working_set.add, dists)
def load(self, env, search_path, disable_re, name_re): generate_debug_messages = __debug__ and env.log.isEnabledFor( logging.DEBUG) if not pkg_resources_avail: if generate_debug_messages: env.log.debug( 'The EggLoader service is terminating early because the pkg_resources package is not available on this machine.' ) return env.log.info('BEGIN - Loading plugins with an EggLoader service') distributions, errors = working_set.find_plugins( pkg_environment(search_path)) for dist in distributions: if name_re.match(str(dist)): if generate_debug_messages: env.log.debug('Adding plugin %r from %r', dist, dist.location) working_set.add(dist) else: if generate_debug_messages: env.log.debug('Ignoring plugin %r from %r', dist, dist.location) def _log_error(item, e): gen_debug = __debug__ and env.log.isEnabledFor(logging.DEBUG) if isinstance(e, DistributionNotFound): if gen_debug: env.log.debug('Skipping "%s": ("%s" not found)', item, e) elif isinstance(e, VersionConflict): if gen_debug: env.log.debug('Skipping "%s": (version conflict "%s")', item, e) elif isinstance(e, UnknownExtra): env.log.error('Skipping "%s": (unknown extra "%s")', item, e) elif isinstance(e, ImportError): env.log.error('Skipping "%s": (can\'t import "%s")', item, e) else: env.log.error('Skipping "%s": (error "%s")', item, e) for dist, e in errors.items(): _log_error(dist, e) for entry in working_set.iter_entry_points(self.entry_point_name): if generate_debug_messages: env.log.debug('Loading %r from %r', entry.name, entry.dist.location) try: entry.load(require=True) except (ImportError, DistributionNotFound, VersionConflict, UnknownExtra): e = sys.exc_info()[1] _log_error(entry, e) else: if not disable_re.match(os.path.dirname( entry.module_name)) is None: #_enable_plugin(env, entry.module_name) pass env.log.info('END - Loading plugins with an EggLoader service')
def search(apps_paths=None, installed_apps=None): """ Searches in the given apps directories for Django apps with the entry point ``'django.apps'`` and adds them to the python path, if necesary. Returns a tuple with all installed and reusable applications. """ if Environment is not None and apps_paths is not None: # find every "distributions" in the given paths for reusable apps and # add them to the "working_set", effectively setting PYTHONPATH distributions, errors = working_set.find_plugins(Environment(apps_paths)) for dist in distributions: working_set.add(dist) for dist, e in errors.iteritems(): if isinstance(e, DistributionNotFound): raise ReusableAppsError('"%s": ("%s" not found)', dist, e) elif isinstance(e, VersionConflict): raise ReusableAppsError('"%s": (version conflict "%s")', dist, e) elif isinstance(e, UnknownExtra): raise ReusableAppsError('"%s": (unknown extra "%s")', dist, e) elif isinstance(e, ImportError): raise ReusableAppsError('"%s": (can\'t import "%s")', dist, e) else: raise ReusableAppsError('"%s": (error "%s")', dist, e) # look for entry points in all distributions of the current working set # (on the PYTHONPATH) and add matching modules to INSTALLED_APPS for entry in working_set.iter_entry_points('django.apps'): app_name = entry.module_name if app_name not in installed_apps and app_name not in REUSEABLE_APPS: REUSEABLE_APPS.append(entry.module_name) return installed_apps + tuple(REUSEABLE_APPS)
def load(self, env, search_path, disable_re, name_re): generate_debug_messages = __debug__ and env.log.isEnabledFor( logging.DEBUG) if not pkg_resources_avail: if generate_debug_messages: env.log.debug( 'The EggLoader service is terminating early because the pkg_resources package is not available on this machine.') return env.log.info('BEGIN - Loading plugins with an EggLoader service') distributions, errors = working_set.find_plugins( pkg_environment(search_path)) for dist in distributions: if name_re.match(str(dist)): if generate_debug_messages: env.log.debug('Adding plugin %r from %r', dist, dist.location) working_set.add(dist) else: if generate_debug_messages: env.log.debug('Ignoring plugin %r from %r', dist, dist.location) def _log_error(item, e): gen_debug = __debug__ and env.log.isEnabledFor(logging.DEBUG) if isinstance(e, DistributionNotFound): if gen_debug: env.log.debug('Skipping "%s": ("%s" not found)', item, e) elif isinstance(e, VersionConflict): if gen_debug: env.log.debug('Skipping "%s": (version conflict "%s")', item, e) elif isinstance(e, UnknownExtra): env.log.error('Skipping "%s": (unknown extra "%s")', item, e) elif isinstance(e, ImportError): env.log.error('Skipping "%s": (can\'t import "%s")', item, e) else: env.log.error('Skipping "%s": (error "%s")', item, e) for dist, e in errors.items(): _log_error(dist, e) for entry in working_set.iter_entry_points(self.entry_point_name): if generate_debug_messages: env.log.debug('Loading %r from %r', entry.name, entry.dist.location) try: entry.load(require=True) except (ImportError, DistributionNotFound, VersionConflict, UnknownExtra): e = sys.exc_info()[1] _log_error(entry, e) else: if not disable_re.match(os.path.dirname( entry.module_name)) is None: #_enable_plugin(env, entry.module_name) pass env.log.info('END - Loading plugins with an EggLoader service')
def configure(self, section): env = Environment([]) self._eggs,errors = working_set.find_plugins(env) # load plugin eggs for p in self._eggs: working_set.add(p) for e in errors: logger.info("failed to load plugin egg '%s'" % e)
def load_eggs(search_path): distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path) ) map(working_set.add, distributions) if errors: import warnings warnings.warn("Error loading eggs: %s" % (errors,))
def main(): """ Run the application. """ # Find all additional eggs. environment = Environment(EGG_PATH) distributions, errors = working_set.find_plugins(environment) if len(errors) > 0: raise SystemError('cannot add eggs %s' % errors) logger.debug('added eggs %s' % distributions) # Add them to the working set. map(working_set.add, distributions) # Create and run the application. return run()
def main(): """ Run the application. """ # Find all additional eggs. environment = Environment(EGG_PATH) distributions, errors = working_set.find_plugins(environment) if len(errors) > 0: raise SystemError('cannot add eggs %s' % errors) logger.debug('added eggs %s' % distributions) # Add them to the working set. map(working_set.add, distributions) # Create and run the application. return run()
def load_eggs(ch, entry_point, search_path, only_enabled=True): """Loader that loads any eggs on the search path and `sys.path`.""" logger.debug("Loading eggs...") # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path)) logger.debug("Found distributions: %s", str(distributions)) for dist in distributions: if dist not in working_set: logger.debug('Adding plugin %s from %s', dist, dist.location) working_set.add(dist) for dist, e in errors.iteritems(): logger.error("Error in distribution %s: %s", str(dist), str(e)) for entry in sorted(working_set.iter_entry_points(entry_point), key=lambda entry: entry.name): logger.debug('Loading %s from %s', entry.name, entry.dist.location) # If we are only loading enabled components, consult the config and skip if # not found if only_enabled and not any( map(lambda x: x.startswith(entry.name), ch.config.get('components', {}))): logger.debug('Skipping component %s since it is not enabled' % entry.name) continue try: entry.load(require=True) except ImportError, e: ch.failed_components[entry.name] = e logger.warn( "Loading %s failed, probably because of unmet dependencies: %s", entry.name, str(e)) except Exception, e: ch.failed_components[entry.name] = e logger.exception("Error loading: %s", entry)
def _load_eggs(self, search_path): # Redefine where to search entry point. distributions, errors = working_set.find_plugins( Environment(search_path) ) if errors: logger.warn('could not load %s', errors) map(working_set.add, distributions) # Load each entry point one by one for entry in working_set.iter_entry_points('rdiffweb.plugins'): # Get unicode plugin name module_name = entry.name if isinstance(module_name, bytes): module_name = module_name.decode('ascii') # Plugin is enabled. Load it. logger.debug('loading module plugin [%s] from [%r]', module_name, entry.module_name) try: yield (module_name, entry.load(), entry.dist) except: logger.error('fail to load module plugin [%s] from [%r]', module_name, entry.module_name, exc_info=1)
def _load_eggs(search_path, auto_enable=None): # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path) ) for dist in distributions: if dist not in working_set: working_set.add(dist) def _log_error(item, e): log.error("[plugins] error loading %s %s", item, e) for dist, e in errors.iteritems(): # ignore version conflict of modules which are not OMS plugins if ENTRY_POINT_NAME in dist.get_entry_map(): _log_error(dist, e) for entry in sorted(working_set.iter_entry_points(ENTRY_POINT_NAME), key=lambda entry: entry.name): yield entry
def _load_eggs(env): distributions, errors = working_set.find_plugins( pkg_resources.Environment() ) for dist in distributions: if dist not in working_set: env.log.debug('Adding plugin %s from %s', dist, dist.location) working_set.add(dist) def _log_error(item, e): ue = exception_to_unicode(e) if isinstance(e, DistributionNotFound): env.log.debug('Skipping "%s": ("%s" not found)', item, ue) elif isinstance(e, VersionConflict): env.log.error('Skipping "%s": (version conflict "%s")', item, ue) elif isinstance(e, UnknownExtra): env.log.error('Skipping "%s": (unknown extra "%s")', item, ue) else: env.log.error('Skipping "%s": %s', item, exception_to_unicode(e, traceback=True)) for dist, e in errors.iteritems(): _log_error(dist, e) for entry in sorted(working_set.iter_entry_points(entry_point_name), key=lambda entry: entry.name): env.log.debug( 'Loading %s from %s', entry.name, entry.dist.location ) try: entry.load(require=True) except Exception as exc: _log_error(entry, exc) else: _enable_plugin(env, entry.module_name)
def add_plugin_dir(plugin_dir): LOGGER.debug("Adding plugin directory: %r", plugin_dir) env = Environment([plugin_dir]) dists, errors = working_set.find_plugins(env) for dist in dists: LOGGER.debug("Adding distribution: %r", dist) working_set.add(dist) if errors: for dist, error in errors.items(): errmsg = None if isinstance(error, DistributionNotFound): req, = error.args errmsg = "%r not found" % req.project_name elif isinstance(error, VersionConflict): dist, req = error.args errmsg = "Version Conflict. Requested %s Found %s" % (req, dist) else: # FIXME: Are there other types of failures? errmsg = repr(error) LOGGER.error("Failed to load %s: %r", dist, errmsg) global plugin_directories plugin_directories.append(plugin_dir)
def load_eggs(ch, entry_point, search_path, only_enabled=True): """Loader that loads any eggs on the search path and `sys.path`.""" logger.debug("Loading eggs...") # Note that the following doesn't seem to support unicode search_path distributions, errors = working_set.find_plugins( pkg_resources.Environment(search_path) ) logger.debug("Found distributions: %s", str(distributions)) for dist in distributions: if dist not in working_set: logger.debug('Adding plugin %s from %s', dist, dist.location) working_set.add(dist) for dist, e in errors.iteritems(): logger.error("Error in distribution %s: %s", str(dist), str(e)) for entry in sorted(working_set.iter_entry_points(entry_point), key=lambda entry: entry.name): logger.debug('Loading %s from %s', entry.name, entry.dist.location) # If we are only loading enabled components, consult the config and skip if # not found if only_enabled and not any(map(lambda x: x.startswith(entry.name), ch.config.get('components', {}))): logger.debug('Skipping component %s since it is not enabled' % entry.name) continue try: entry.load(require=True) except ImportError, e: ch.failed_components[entry.name] = e logger.warn("Loading %s failed, probably because of unmet dependencies: %s", entry.name, str(e)) except Exception, e: ch.failed_components[entry.name] = e logger.exception("Error loading: %s", entry)
def load_plugins(self, plugin_dirs=None, quiet=True): """ Load plugins in `sys.path` and `plugin_dirs` Args: plugin_dirs: a list of plugin directory path quiet: if True, print all error message """ from pkg_resources import working_set from pkg_resources import iter_entry_points from pkg_resources import Environment if plugin_dirs is None: plugin_dirs = [os.path.dirname(__file__)] plugin_dirs += settings['user']['plugin_dirs'] distributions, errors = working_set.find_plugins( Environment(plugin_dirs) ) map(working_set.add, distributions) if not quiet: # display error info for distribution, error in errors: print distrubution, error for entry_point in iter_entry_points(self.ENTRY_POINT): # load entry point plugin = entry_point.load() # if plugin is callable and `manually` is True, initialize manually if callable(plugin) and getattr(plugin, 'manually', False): # manually initialize plugin plugin(self) else: # automatically initialize plugin self.register(entry_point.name, plugin)
def __init__(self): self._plugins = {} plugins_dir = os.path.join(site_settings["HIGGINS_DIR"], "plugins") self.log_info("added '%s' to plugin search path" % plugins_dir) working_set.add_entry(plugins_dir) env = Environment([plugins_dir,]) self._eggs,errors = working_set.find_plugins(env) # load plugin eggs for p in self._eggs: working_set.add(p) self.log_info("loaded plugin egg '%s'" % p) for e in errors: self.log_error("failed to load plugin egg '%s'" % e) # load all discovered plugins for ep in working_set.iter_entry_points('higgins.plugin'): try: factory = ep.load() if issubclass(factory, Service): self.log_info("found service plugin '%s'" % ep.name) self._plugins[ep.name] = factory else: self.log_warning("ignoring plugin '%s': unknown plugin type" % ep.name) except Exception, e: self.log_error("failed to load plugin '%s': %s" % (ep.name, e))
def configure(self, settings): """ Finds all discoverable plugins and configures them. Plugins are discoverable if they are in the normal python module path, or in the path specified by 'plugin directory'. """ # load plugins section = settings.section('server') self.pluginsdir = os.path.join(section.getPath("plugin directory")) if self.pluginsdir: logger.debug("loading plugins from %s" % self.pluginsdir) working_set.add_entry(self.pluginsdir) env = Environment([ self.pluginsdir, ]) else: env = Environment([]) self._eggs, errors = working_set.find_plugins(env) # load plugin eggs for p in self._eggs: working_set.add(p) logger.info("loaded plugin egg '%s'" % p) for e in errors: logger.info("failed to load plugin egg '%s'" % e) # load all discovered plugins for each type for ep in working_set.iter_entry_points("terane.plugin"): # if no config section exists, then don't load the plugin if not settings.hasSection("plugin:%s" % ep.name): continue try: # load and configure the plugin _Plugin = ep.load() if not IPlugin.implementedBy(_Plugin): raise Exception("plugin '%s' doesn't implement IPlugin" % ep.name) plugin = _Plugin() plugin.setName(ep.name) plugin.setServiceParent(self) section = settings.section("plugin:%s" % ep.name) plugin.configure(section) logger.info("loaded plugin '%s'" % ep.name) # find all plugin components for impl, spec, name in plugin.listComponents(): if not ILoadable.implementedBy(impl): raise Exception( "component %s:%s in plugin %s doesn't implement ILoadable" % (spec.__name__, name, ep.name)) if not isinstance(spec, InterfaceClass): raise TypeError("spec must be an Interface") if (spec, name) in self._components: raise KeyError("component %s:%s already exists" % (spec.__name__, name)) # a little extra syntax here to make sure the lambda expression # passed as the factory function has the appropriate variables bound # in its scope def _makeTrampoline(impl=impl, plugin=plugin): def _trampoline(*args, **kwds): logger.trace("allocating new %s from plugin %s" % (impl.__name__, plugin.name)) return impl(plugin, *args, **kwds) return _trampoline self._components[(spec, name)] = _makeTrampoline(impl, plugin) logger.trace("added component %s:%s" % (spec.__name__, name)) except ConfigureError: raise except Exception, e: logger.exception(e) logger.warning("failed to load plugin '%s'" % ep.name)
def configure(self, settings): """ Finds all discoverable plugins and configures them. Plugins are discoverable if they are in the normal python module path, or in the path specified by 'plugin directory'. """ # load plugins section = settings.section('server') self.pluginsdir = os.path.join(section.getPath("plugin directory")) if self.pluginsdir: logger.debug("loading plugins from %s" % self.pluginsdir) working_set.add_entry(self.pluginsdir) env = Environment([self.pluginsdir,]) else: env = Environment([]) self._eggs,errors = working_set.find_plugins(env) # load plugin eggs for p in self._eggs: working_set.add(p) logger.info("loaded plugin egg '%s'" % p) for e in errors: logger.info("failed to load plugin egg '%s'" % e) # load all discovered plugins for each type for ep in working_set.iter_entry_points("terane.plugin"): # if no config section exists, then don't load the plugin if not settings.hasSection("plugin:%s" % ep.name): continue try: # load and configure the plugin _Plugin = ep.load() if not IPlugin.implementedBy(_Plugin): raise Exception("plugin '%s' doesn't implement IPlugin" % ep.name) plugin = _Plugin() plugin.setName(ep.name) plugin.setServiceParent(self) section = settings.section("plugin:%s" % ep.name) plugin.configure(section) logger.info("loaded plugin '%s'" % ep.name) # find all plugin components for impl,spec,name in plugin.listComponents(): if not ILoadable.implementedBy(impl): raise Exception("component %s:%s in plugin %s doesn't implement ILoadable" % (spec.__name__, name, ep.name)) if not isinstance(spec, InterfaceClass): raise TypeError("spec must be an Interface") if (spec,name) in self._components: raise KeyError("component %s:%s already exists" % (spec.__name__,name)) # a little extra syntax here to make sure the lambda expression # passed as the factory function has the appropriate variables bound # in its scope def _makeTrampoline(impl=impl, plugin=plugin): def _trampoline(*args, **kwds): logger.trace("allocating new %s from plugin %s" % (impl.__name__,plugin.name)) return impl(plugin, *args, **kwds) return _trampoline self._components[(spec,name)] = _makeTrampoline(impl, plugin) logger.trace("added component %s:%s" % (spec.__name__, name)) except ConfigureError: raise except Exception, e: logger.exception(e) logger.warning("failed to load plugin '%s'" % ep.name)
def run(plugins=[], use_eggs=True, egg_path=[], image_path=[], template_path=[], startup_task="", application_name="Omnivore", debug_log=False, document_class=None): """Start the application :param plugins: list of user plugins :param use_eggs Boolean: search for setuptools plugins and plugins in local eggs? :param egg_path: list of user-specified paths to search for more plugins :param startup_task string: task factory identifier for task shown in initial window :param application_name string: change application name instead of default Omnivore """ EnthoughtWxApp.mac_menubar_app_name = application_name _app = EnthoughtWxApp(redirect=False) if False: # enable this to use FilterEvent _app.FilterEvent = _app.FilterEventMouseWheel # Enthought library imports. from envisage.api import PluginManager from envisage.core_plugin import CorePlugin # Local imports. from omnivore.framework.application import FrameworkApplication from omnivore.framework.plugin import OmnivoreTasksPlugin, OmnivoreMainPlugin from omnivore.file_type.plugin import FileTypePlugin from omnivore import get_image_path from omnivore.utils.jobs import get_global_job_manager # Include standard plugins core_plugins = [ CorePlugin(), OmnivoreTasksPlugin(), OmnivoreMainPlugin(), FileTypePlugin() ] if sys.platform == "darwin": from omnivore.framework.osx_plugin import OSXMenuBarPlugin core_plugins.append(OSXMenuBarPlugin()) import omnivore.file_type.recognizers core_plugins.extend(omnivore.file_type.recognizers.plugins) import omnivore.plugins core_plugins.extend(omnivore.plugins.plugins) # Add the user's plugins core_plugins.extend(plugins) # Check basic command line args default_parser = argparse.ArgumentParser(description="Default Parser") default_parser.add_argument("--no-eggs", dest="use_eggs", action="store_false", default=True, help="Do not load plugins from python eggs") options, extra_args = default_parser.parse_known_args() # The default is to use the specified plugins as well as any found # through setuptools and any local eggs (if an egg_path is specified). # Egg/setuptool plugin searching is turned off by the use_eggs parameter. default = PluginManager( plugins = core_plugins, ) if use_eggs and options.use_eggs: from pkg_resources import Environment, working_set from envisage.api import EggPluginManager from envisage.composite_plugin_manager import CompositePluginManager # Find all additional eggs and add them to the working set environment = Environment(egg_path) distributions, errors = working_set.find_plugins(environment) if len(errors) > 0: raise SystemError('cannot add eggs %s' % errors) logger = logging.getLogger() logger.debug('added eggs %s' % distributions) map(working_set.add, distributions) # The plugin manager specifies which eggs to include and ignores all others egg = EggPluginManager( include = [ 'omnivore.tasks', ] ) plugin_manager = CompositePluginManager( plugin_managers=[default, egg] ) else: plugin_manager = default # Add omnivore icons after all image paths to allow user icon themes to take # precidence from pyface.resource_manager import resource_manager import os image_paths = image_path[:] image_paths.append(get_image_path("icons")) image_paths.append(get_image_path("../omnivore8bit/icons")) resource_manager.extra_paths.extend(image_paths) from omnivore.templates import template_subdirs template_subdirs.extend(template_path) kwargs = {} if startup_task: kwargs['startup_task'] = startup_task if application_name: kwargs['name'] = application_name if document_class: kwargs['document_class'] = document_class # Create a debugging log if debug_log: filename = app.get_log_file_name("debug") handler = logging.FileHandler(filename) logger = logging.getLogger('') logger.addHandler(handler) logger.setLevel(logging.DEBUG) # Turn off omnivore log debug messages by default log = logging.getLogger("omnivore") log.setLevel(logging.INFO) # check for logging stuff again to pick up any new loggers loaded since # startup import omnivore.utils.wx.error_logger as error_logger if "-d" in extra_args: i = extra_args.index("-d") error_logger.enable_loggers(extra_args[i+1]) app = FrameworkApplication(plugin_manager=plugin_manager, command_line_args=extra_args, **kwargs) app.run() job_manager = get_global_job_manager() if job_manager is not None: job_manager.shutdown()