def _list(self, *args, **options): print('Installed Apps') for entry in working_set.iter_entry_points(powerplug.ENTRY_POINT_APP): print('\t', entry.module_name) print('Installed APIs') for entry in working_set.iter_entry_points(powerplug.ENTRY_POINT_API): print('\t', entry.module_name)
def init_parser(parser: argparse.ArgumentParser, namespace: str, group_description: str = 'Available Commands') -> None: if len(list(working_set.iter_entry_points(namespace))): subparser = parser.add_subparsers(help=group_description) for entry_point in working_set.iter_entry_points(namespace): if "hook" not in entry_point.name: # load can raise exception due to missing imports or error in # object creation subcommand = entry_point.load() command_parser = subparser.add_parser( entry_point.name, help=subcommand.help_description(), parents=subcommand.register_subparsers()) action = None if not getattr(subcommand.action, '__isnotrunnable__', False): action = getattr(subcommand, "action", None) if callable(action): command_parser.set_defaults(action=subcommand, help=command_parser.print_help, namespace=namespace + "." + entry_point.name) else: command_parser.set_defaults(help=command_parser.print_help, namespace=namespace + "." + entry_point.name) group_description = subcommand.group_description() if group_description: init_parser(command_parser, namespace + "." + entry_point.name, group_description) else: init_parser(command_parser, namespace + "." + entry_point.name)
def list(self): """ Get all applications from configuration, and fill the L{applications} variable. """ for entry in working_set.iter_entry_points( "vigilo.vigiconf.applications"): appclass = entry.load() app = appclass() if app.name != entry.name: msg = _("Incoherent configuration: application %(app)s has an " "entry point named %(epname)s in package %(eppkg)s") LOGGER.warning(msg % {"app": app.name, "epname": entry.name, "eppkg": entry.dist}) if app.name not in conf.apps: LOGGER.info(_("Application %s is installed but disabled " "(see conf.d/general/apps.py)") % app.name) continue if app.name in [ a.name for a in self.applications ]: msg = _("application %s is not unique. " "Providing modules: %s") % ( app.name, ", ".join(list(working_set.iter_entry_points( "vigilo.vigiconf.applications", entry.name))) ) raise DispatchatorError(msg) self.applications.append(app) # Vérification : a-t-on déclaré une application non installée ? for listed_app in set(conf.apps): if listed_app not in [a.name for a in self.applications]: LOGGER.warning(_("Application %s has been added to " "conf.d/general/apps.py, but is not installed") % listed_app) self.applications.sort(reverse=True, key=lambda a: a.priority)
def iter_plugins(group, name=None): """ Iterate over all unique distributions defining entrypoints with the given group and name """ for ep in working_set.iter_entry_points(group, name): yield ep.name, dist_metainfo_dict(ep.dist)
def cli(): """Entry point.""" if len(sys.argv) > 2: try: args = docopt(__doc__, help=False, version=__version__) except DocoptExit: args = { "<command>": " ".join(sys.argv[1:2]), } elif len(sys.argv) > 1: try: args = docopt(__doc__, help=False, version=__version__) except DocoptExit: args = {"<command>": sys.argv[1]} else: print(__doc__) if args["<command>"]: args.update({"<tool>": os.path.basename(sys.argv[0])}) # load <command> from entry_points for entry_point in working_set.iter_entry_points("%s.subcmd" % args["<tool>"]): if entry_point.name == args["<command>"]: subcommand = entry_point.load() sys.exit(subcommand()) LOGGER.error("'%s %s' is not a valid command", args["<tool>"], args["<command>"]) sys.exit(1) raise DocoptExit
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 __init__(self, *args, **kwargs): """ Initialise le contrôleur en lui ajoutant dynamiquement des attributs (sous-contrôleurs), en fonction des points d'entrée définis dans le groupe "<application>.controllers". """ app_name = str(config.get('app_name')).lower() group = '%s.controllers' % app_name LOGGER.debug("Loading custom controllers") for ep in working_set.iter_entry_points(group): if not re.match('^[a-z][a-z0-9_]*$', ep.name, re.I): LOGGER.warning(_("Not a valid controller name: %s"), ep.name) else: ctrl = ep.load() if issubclass(ctrl, BaseController): LOGGER.debug("Added custom controller '%s'" % ep.name) setattr(self, ep.name, ctrl()) else: base_ctrl = "%s.%s" % (BaseController.__module__, BaseController.__name__) ep_path = "%s.%s" % (ep.module_name, ep.attrs[0]) LOGGER.warning( _("%(entry)s is not a subclass of %(base)s"), { 'base': base_ctrl, 'entry': ep_path, }) super(CustomController, self).__init__(*args, **kwargs)
def load_all_available_checkers(cls): """ Helper method to retrieve all sub checker classes derived from various base classes. """ cls._load_checkers( working_set.iter_entry_points("compliance_checker.suites"))
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(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(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 _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 load_all_available_checkers(cls): """ Helper method to retrieve all sub checker classes derived from various base classes. """ from pkg_resources import working_set for x in working_set.iter_entry_points('compliance_checker.suites'): try: xl = x.load() cls.checkers[':'.join((xl._cc_spec, xl._cc_spec_version))] = xl # TODO: remove this once all checkers move over to the new # _cc_spec, _cc_spec_version except AttributeError: # if there are versioned classes, it will get overwritten by the # latest version later. If there are not, it will be assigned # the checker as the main class # TODO: nix name attribute in plugins. Keeping in for now # to provide backwards compatibility cls.checkers[getattr(xl, 'name', None) or xl._cc_spec] = xl except Exception as e: print("Could not load", x, ":", e, file=sys.stderr) # find the latest version of versioned checkers and set that as the # default checker for compliance checker if no version is specified ver_checkers = [c.split(':', 1) for c in cls.checkers if ':' in c] for spec, versions in itertools.groupby(ver_checkers, itemgetter(0)): # right now this looks for character order. May break if # version specifications become more complicated latest_version = max(v[-1] for v in versions) cls.checkers[spec] = cls.checkers[spec + ':latest'] = \ cls.checkers[':'.join((spec, latest_version))]
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 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 _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 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)
class Scrape(models.Model): driver_set = { entry.name: entry for entry in working_set.iter_entry_points("quickstats.scrape") } TYPE_CHOICES = [(entry, entry) for entry in driver_set] owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) widget = models.ForeignKey("quickstats.Widget", on_delete=models.CASCADE) driver = models.CharField(max_length=32, choices=TYPE_CHOICES) url = models.URLField(max_length=2000) period = models.CharField( max_length=16, choices=( ("15m", _("Quarter Hour")), ("30m", _("Half Hour")), ("1h", _("Hourly")), ("2h", _("Every other hour")), ("1d", _("Daily")), ), default="2h", ) def scrape(self): driver = self.driver_set[self.driver].load()() logger.info("Scraping %s ", self) driver.scrape(self) class Meta: unique_together = ("widget", "driver") def __str__(self): return "{}:{}:{}".format(self.driver, self.id, self.widget_id)
def iter_plugins(group, name=None): """ Iterate over all unique distributions defining entrypoints with the given group and name """ for entry_point in working_set.iter_entry_points(group, name): yield entry_point.name, dist_metainfo_dict(entry_point.dist)
def plugins_iter(plugin_dir, ep_name): """ @type plugin_dir : C{str} @param plugin_dir : The fqname of the plugin directory @type ep_name : C{str} @param ep_name : The name of the Entry Point to be loaded @yield: The loaded Entry Point (C{obj}) """ working_set.add_entry(plugin_dir) pkg_env = Environment([plugin_dir]) for env_name in pkg_env: egg = pkg_env[env_name][0] LOG.debug("Activating egg: %s"%(egg)) egg.activate() for name in egg.get_entry_map(ep_name): entry_point = egg.get_entry_info(ep_name, name) LOG.debug("Loading entry point: %s"%(entry_point)) cls = entry_point.load() yield cls for entry_point in working_set.iter_entry_points(ep_name): LOG.debug("Loading entry point: %s"%(entry_point)) cls = entry_point.load() yield cls
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(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 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 subnav(request): ''' Loop through the entry points and build a sub navigation dictionary ''' navigation = {} for entry in working_set.iter_entry_points('powerplug.subnav'): navigation.update(entry.load()(entry.name, request)) return {'subnav': navigation}
def register_babel_plugins(): try: from pkg_resources import working_set except ImportError: return for entry_point in working_set.iter_entry_points('babel.extractors'): extractor = babel_wrapper(entry_point.load(require=True)) EXTRACTORS['babel-%s' % entry_point.name] = extractor
def _find_checkers(): try: from pkg_resources import working_set except ImportError: return [num_plurals, python_format] checkers = [] for entry_point in working_set.iter_entry_points('babel.checkers'): checkers.append(entry_point.load()) return checkers
def register_extractors(): for entry_point in working_set.iter_entry_points('lingua.extractors'): extractor = entry_point.load(require=True) if not issubclass(extractor, Extractor): raise ValueError( u'Registered extractor must derive from ``Extractor``') EXTRACTORS[entry_point.name] = extractor() for extension in extractor.extensions: EXTENSIONS[extension] = entry_point.name
def register_babel_plugins(): for entry_point in working_set.iter_entry_points('babel.extractors'): name = entry_point.name extractor = entry_point.load(require=True) cls = type('BabelExtractor_%s' % name, (BabelExtractor, object), {'extractor': staticmethod(extractor), '__doc__': extractor.__doc__.splitlines()[0]}) EXTRACTORS['babel-%s' % name] = cls()
def make_app(global_conf, full_stack=True, **app_conf): """ Set vigigraph up with the settings found in the PasteDeploy configuration file used. This is the PasteDeploy factory for the vigigraph application. C{app_conf} contains all the application-specific settings (those defined under ``[app:main]``). @param global_conf: The global settings for vigigraph (those defined under the ``[DEFAULT]`` section). @type global_conf: C{dict} @param full_stack: Should the whole TG2 stack be set up? @type full_stack: C{str} or C{bool} @return: The vigigraph application with all the relevant middleware loaded. """ app = make_base_app(global_conf, full_stack=full_stack, **app_conf) # Personalisation des fichiers statiques via /etc/vigilo/vigigraph/public/. custom_static = StaticURLParser('/etc/vigilo/vigigraph/public/') # On définit 2 middlewares pour fichiers statiques qui cherchent # les fichiers dans le thème actuellement chargé. # Le premier va les chercher dans le dossier des fichiers spécifiques # à l'application, le second cherche dans les fichiers communs. app_static = StaticURLParser(resource_filename( 'vigilo.themes.public', 'vigigraph')) common_static = StaticURLParser(resource_filename( 'vigilo.themes.public', 'common')) local_static = StaticURLParser(resource_filename( 'vigigraph', 'public')) cascade_list = [custom_static, app_static, common_static, local_static, app] LOGGER = getLogger("vigigraph") ## Mise en place du répertoire d'extensions #setup_plugins_path(base_config.get("plugins_dir", # "/etc/vigilo/vigigraph/plugins")) # Spécifique projets for module in ["turbogears", "vigigraph"]: for entry in working_set.iter_entry_points( "vigilo.%s.public" % module): if (entry.name != "enterprise" and entry.name not in base_config.get("extensions", [])): # les points d'entrée "enterprise" sont automatiquement # chargés, il faut lister les autres dans la conf continue new_public_dir = resource_filename(entry.module_name, "public") LOGGER.debug("Adding static files directory for ext %s: %s", (entry.name, new_public_dir)) cascade_list.insert(0, StaticURLParser(new_public_dir)) app = Cascade(cascade_list) return app
def _get_generator_plugins(cls): """ Return a list of classes from external plugins that are used to generate checker classes """ if not hasattr(cls, 'suite_generators'): gens = working_set.iter_entry_points('compliance_checker.generators') cls.suite_generators = [x.resolve() for x in gens] return cls.suite_generators
def _get_generator_plugins(cls): """ Return a list of classes from external plugins that are used to generate checker classes """ if not hasattr(cls, "suite_generators"): gens = working_set.iter_entry_points("compliance_checker.generators") cls.suite_generators = [x.resolve() for x in gens] return cls.suite_generators
def __init__(self, *args, **kwargs): """Initialisation du contrôleur.""" super(RootController, self).__init__(*args, **kwargs) # Si un module de gestion des tickets a été indiqué dans # le fichier de configuration, on tente de le charger. if config.get('tickets.plugin'): plugins = working_set.iter_entry_points('vigiboard.tickets', config['tickets.plugin']) if plugins: # La classe indiquée par la première valeur de l'itérateur # correspond au plugin que l'on veut instancier. pluginCls = plugins.next().load() self._tickets = pluginCls()
def load_specific(self, grouploader): """Loaders spécifiques""" # deux boucles parce qu'on veut forcer le tri des loaders par leur nom # dans une distribution donnée. Par défaut, il n'y a pas de tri à # l'intérieur d'une même distribution (voir doc de pkg_resources) loaders = list(working_set.iter_entry_points("vigilo.vigiconf.loaders")) loaders.sort(cmp=lambda x, y: cmp(x.name, y.name)) for loader_entry in loaders: loadclass = loader_entry.load() loader_instance = loadclass(grouploader, self.rev_mgr) loader_instance.load() DBSession.flush()
def loadable_parcels(working_set=working_set, env=None, installer=None): """ Yield entry points for loadable parcels in `working_set` """ for ep in working_set.iter_entry_points('chandler.parcels'): try: ep.require(env, installer) except pkg_resources.ResolutionError: # XXX log the error continue # skip unloadable parcels ??? else: yield ep
def load_all_available_checkers(cls): """ Helper method to retrieve all sub checker classes derived from various base classes. """ from pkg_resources import working_set for x in working_set.iter_entry_points('compliance_checker.suites'): try: xl = x.load() cls.checkers[xl.name] = xl except Exception as e: print >> sys.stderr, "Could not load", x, ":", e
def load_all_available_checkers(cls): """ Helper method to retrieve all sub checker classes derived from various base classes. """ from pkg_resources import working_set for x in working_set.iter_entry_points('compliance_checker.suites'): try: xl = x.load() cls.checkers[xl.name] = xl except Exception as e: print("Could not load", x, ":", e, file=sys.stderr)
def _find_checkers(): checkers = [] try: from pkg_resources import working_set except ImportError: pass else: for entry_point in working_set.iter_entry_points('babel.checkers'): checkers.append(entry_point.load()) if len(checkers) == 0: # if pkg_resources is not available or no usable egg-info was found # (see #230), just resort to hard-coded checkers return [num_plurals, python_format] return checkers
def main(): """Entry point.""" if len(sys.argv) > 2: try: args = docopt(__doc__, help=False, version=__version__) except DocoptExit: args = {"<command>": sys.argv[2]} if args["<command>"]: # load <command> from entry_points for entry_point in working_set.iter_entry_points( "pipeline.subcmd"): if entry_point.name == args["<command>"]: subcommand = entry_point.load() sys.exit(subcommand()) print(__doc__) raise DocoptExit
def get_dispatchator_class(): """ @return: La meilleure sous-classe de L{Dispatchator<base.Dispatchator>} disponible, en fonction de l'édition de Vigilo. """ if getattr(conf, "appsGroupsByServer", None): for entry in working_set.iter_entry_points( "vigilo.vigiconf.extensions", "dispatchator_remote"): return entry.load() message = _("You are attempting a remote deployment on the Community " "edition. This feature is only available in the " "Enterprise edition. Aborting.") raise EditionError(message) else: from .local import DispatchatorLocal return DispatchatorLocal
def _list_test_paths(self, confdir): paths = [] for entry in working_set.iter_entry_points( "vigilo.vigiconf.testlib"): path = entry.load().__path__[0] if not os.path.isdir(path): LOGGER.warning(_("Invalid entry point %(epname)s in package " "%(eppkg)s: %(epmodname)s") % {"epname": entry.name, "eppkg": entry.dist, "epmodname": entry.module_name, }) continue paths.append(path) paths.append(os.path.join(confdir, "tests")) return paths
def load_binpubs(): """Loads all binpubs entry points.""" global _binpub_types logger.debug("loading binpubs") if _binpub_types is None: _binpub_types = [] # find all of the installed binpubs for ep in working_set.iter_entry_points('openmdao.binpub'): try: klass = ep.load() except Exception as err: logger.error("Entry point %s failed to load: %s" % (str(ep).split()[0], err)) else: logger.debug("adding binpub entry point: %s" % str(ep).split()[0]) with _lock: _binpub_types.append(klass)
def cli(): """Entry point.""" if len(sys.argv) > 1: try: args = docopt(__doc__, help=False, version=__version__) except DocoptExit: args = {"<command>": sys.argv[1]} if args["<command>"]: # load <command> from entry_points for entry_point in working_set.iter_entry_points("tolkein.subcmd"): if entry_point.name == args["<command>"]: subcommand = entry_point.load(sys.argv[1:]) sys.exit(subcommand()) LOGGER.error("'tolkein %s' is not a valid command", args["<command>"]) sys.exit(1) print(__doc__) raise DocoptExit
def handle(self, verbosity, **options): for entry_point, title in [ ('powerplug.apps', 'Installed Apps'), ('powerplug.rest', 'Installed APIs'), ('powerplug.signal', 'Installed Signals'), ('powerplug.task', 'Installed Tasks'), ('powerplug.urls', 'Installed URL'), ]: self.stdout.write(self.style.SUCCESS(title)) for entry in working_set.iter_entry_points(entry_point): try: entry.load() except ImportError as e: self.stdout.write(self.style.ERROR('\t ' + str(entry))) if verbosity > 0: self.stdout.write(self.style.ERROR(e)) else: print('\t', entry)
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 main(): """ Cette fonction est appelée lorsqu'un utilisateur lance la commande 'vigilo-plugins'. Cet utilitaire permet de lister le contenu d'un point d'entrée. """ prepare_argparse() parser = OptionParser() parser.add_option('-p', '--provider', action="store_true", dest="display_provider", default=False, help=_("Displays the name and location of the Python package " "which provides this feature.")) opts, args = parser.parse_args() # Sans argument, liste les noms des groupes de points d'entrée # se rapportant à Vigilo. if not args: groups = {} vigilo_groups = ('vigilo.', 'vigiadmin.', 'vigiboard.', 'vigiconf.', 'vigigraph.', 'vigimap.', 'vigirrd.') for distro in working_set: for group in distro.get_entry_map().keys(): if group.startswith(vigilo_groups): groups.setdefault(group, []) groups[group].append( distro.project_name + ' ' + distro.version) print _("Available entry-points groups:") for group in sorted(list(groups)): print "-", group, if opts.display_provider: print "--", _("Provided by:"), \ ", ".join(sorted(groups[group])), print sys.exit(0) for ep in working_set.iter_entry_points(args[0]): print "-", ep.name, if opts.display_provider: print "--", _("Provided by:"), ep.dist, print sys.exit(0)
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_entry_points(self, entry_points=None): if not ENTRY_POINTS: logger.debug("entry points disabled - unable to import pkg_resources") return if entry_points is None: entry_points = self._entry_points if entry_points is None: return if not hasattr(entry_points, '__iter__'): entry_points = [entry_points] for entry_point_id in entry_points: for entry in working_set.iter_entry_points(entry_point_id): logger.debug('Loading plugin %s from %s', entry.name, entry.dist.location) try: module = entry.load(require=True) self._modules.add(module) except: logger.exception("Error loading plugin %s from %s" % (entry.name, entry.dist.location))
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)