Ejemplo n.º 1
0
    def detect_os(self):
        """Detects and sets the current OS.

        The most specific OS plugin that returns ``True`` for
        :meth:`OS.is_os` is the detected one.

        If multiple os plugins would accept the current OS and they is
        not single most specific OS, a warning is printed to the user.

        :raises UnsupportedOSError: If no OS plugin accepts the current OS
        """
        result = None
        for os in self.os_plugins:
            if os.is_os():
                if not result:
                    result = os
                else:
                    if os.name in result.all_names:
                        # ignore this 'parent' os
                        pass
                    elif result.name in os.all_names:
                        # found a more specific derivative os; use that instead
                        result = os
                    else:
                        warning("ignoring detection of OS '{0}'; '{1}' already"
                                " detected".format(os.name, result.name))
        if not result:
            raise UnsupportedOSError(
                "None of the OS plugins {} detected the current OS.".format(
                    self.os_plugin_names))
        self._os = result
Ejemplo n.º 2
0
 def check_package_manager_updated(self,
                                   os_tuple,
                                   fix_unsatisfied=False,
                                   interactive=True):
     info_v("Checking if package manager '{}' is updated.".
            format(self.name))
     try:
         updated = self.is_package_manager_updated()
     except NotImplementedError:
         info_v("Check if package manager '{}' is updated not implemented; "
                "skipping check.".format(self.name))
         return
     if updated:
         info_v("Package manager '{}' is updated.".format(self.name))
         return
     info_v("Package manager '{}' not updated.".format(self.name))
     if fix_unsatisfied:
         info_v("Trying to update '{}'.".format(self.name))
         try:
             self.update_package_manager(interactive)
             if self.is_package_manager_updated():
                 return
         except NotImplementedError:
             error("Installer plugin '{}' does not support updating "
                   "itself.".format(self.name))
         else:
             error("Installer plugin '{}' failed to update itself.".
                   format(self.name))
     warning("Package manager '{}' seems to be out-of-date. Please "
             "consider updating for best results.")
Ejemplo n.º 3
0
 def check_package_manager_updated(self,
                                   os_tuple,
                                   fix_unsatisfied=False,
                                   interactive=True):
     info_v("Checking if package manager '{}' is updated.".format(
         self.name))
     try:
         updated = self.is_package_manager_updated()
     except NotImplementedError:
         info_v("Check if package manager '{}' is updated not implemented; "
                "skipping check.".format(self.name))
         return
     if updated:
         info_v("Package manager '{}' is updated.".format(self.name))
         return
     info_v("Package manager '{}' not updated.".format(self.name))
     if fix_unsatisfied:
         info_v("Trying to update '{}'.".format(self.name))
         try:
             self.update_package_manager(interactive)
             if self.is_package_manager_updated():
                 return
         except NotImplementedError:
             error("Installer plugin '{}' does not support updating "
                   "itself.".format(self.name))
         else:
             error("Installer plugin '{}' failed to update itself.".format(
                 self.name))
     warning("Package manager '{}' seems to be out-of-date. Please "
             "consider updating for best results.")
Ejemplo n.º 4
0
def load_plugins(kind, base_class, group, disabled=[]):
    """Load plugins form entry points.

    Load the plugins of given ``kind`` from entry points ``group``,
    instantiating objects and ignoring duplicates. The entry points must
    be valid plugin definitions (see :func:`verify_plugin_definition`).
    The list of plugins is free of duplicates by plugin class name (not
    plugin name), whereas the list of ``disabled`` plugins refer to the
    plugin names instead.

    :param str kind: kind of plugin (e.g. "installer")
    :param base_class: (abstract) base class plugins (must implement
        PluginBase)
    :param group: entry point group to load plugins from
    :param disabled: list of plugins to ignore; these are plugin names,
        not plugin object names
    :type disabled: `list` of `str`
    :return: list of the loaded and instantiated plugin classes
    :rtype: `list`
    """
    plugin_list = []
    name_set = set()
    for entry_point in pkg_resources.iter_entry_points(group=group):
        definition = entry_point.load()
        try:
            verify_plugin_definition(definition, kind, base_class)
        except InvalidPluginError as e:
            # TODO: somehow decide when to reraise and when to display error
            error("Skipping {} plugin. Failed to load from '{}' entry point "
                  "with name '{}':\n{}".format(kind, group, entry_point.name,
                                               e))
            continue
        plugin_name = definition["plugin_name"]
        if plugin_name in disabled:
            info_v("Skipping disabled {} plugin '{}'.".format(
                kind, plugin_name))
            continue
        plugin_class = definition[kind]
        plugin_obj = plugin_class()
        obj_name = plugin_obj.name
        try:
            plugin_class.verify_plugin(plugin_obj)
        except InvalidPluginError as e:
            # TODO: somehow decide when to reraise and when to display error
            error("Skipping {} plugin '{}'. Plugin is invalid:\n{}".format(
                kind, plugin_name, exc_to_str(e)))
            continue
        if obj_name in name_set:
            # TODO: somehow decide when to reraise and when to display error
            warning(
                "Ignoring {0} plugin '{1}' with duplicate name '{1}'".format(
                    kind, definition['plugin_name'], obj_name))
            continue
        info_v("Loaded {0} plugin '{1}' with {0} name '{2}'.".format(
            kind, plugin_name, obj_name))
        name_set.add(obj_name)
        plugin_list.append(plugin_obj)
    return plugin_list
Ejemplo n.º 5
0
def load_plugins(kind, base_class, group, disabled=[]):
    """Load plugins form entry points.

    Load the plugins of given ``kind`` from entry points ``group``,
    instantiating objects and ignoring duplicates. The entry points must
    be valid plugin definitions (see :func:`verify_plugin_definition`).
    The list of plugins is free of duplicates by plugin class name (not
    plugin name), whereas the list of ``disabled`` plugins refer to the
    plugin names instead.

    :param str kind: kind of plugin (e.g. "installer")
    :param base_class: (abstract) base class plugins (must implement
        PluginBase)
    :param group: entry point group to load plugins from
    :param disabled: list of plugins to ignore; these are plugin names,
        not plugin object names
    :type disabled: `list` of `str`
    :return: list of the loaded and instantiated plugin classes
    :rtype: `list`
    """
    plugin_list = []
    name_set = set()
    for entry_point in pkg_resources.iter_entry_points(group=group):
        definition = entry_point.load()
        try:
            verify_plugin_definition(definition, kind, base_class)
        except InvalidPluginError as e:
            # TODO: somehow decide when to reraise and when to display error
            error("Skipping {} plugin. Failed to load from '{}' entry point "
                  "with name '{}':\n{}".format(
                      kind, group, entry_point.name, e))
            continue
        plugin_name = definition["plugin_name"]
        if plugin_name in disabled:
            info_v("Skipping disabled {} plugin '{}'.".
                   format(kind, plugin_name))
            continue
        plugin_class = definition[kind]
        plugin_obj = plugin_class()
        obj_name = plugin_obj.name
        try:
            plugin_class.verify_plugin(plugin_obj)
        except InvalidPluginError as e:
            # TODO: somehow decide when to reraise and when to display error
            error("Skipping {} plugin '{}'. Plugin is invalid:\n{}".format(
                  kind, plugin_name, exc_to_str(e)))
            continue
        if obj_name in name_set:
            # TODO: somehow decide when to reraise and when to display error
            warning("Ignoring {0} plugin '{1}' with duplicate name '{1}'".
                    format(kind, definition['plugin_name'], obj_name))
            continue
        info_v("Loaded {0} plugin '{1}' with {0} name '{2}'.".
               format(kind, plugin_name, obj_name))
        name_set.add(obj_name)
        plugin_list.append(plugin_obj)
    return plugin_list
Ejemplo n.º 6
0
 def options(self, value):
     try:
         self._options = config_from_parsed_yaml(value,
                                                 self.options_description,
                                                 use_defaults=True)
     except ConfigValueError as e:
         raise_from(
             ConfigValueError, "invalid options `{}` for os plugin "
             "'{}'".format(value, self.name), e)
     unused_keys = set(value.keys()) - set(self._options.keys())
     if unused_keys:
         warning("ignoring the following unknown options for os plugin "
                 "'{}': {} -- known options are: {}".format(
                     self.name, to_str(list(unused_keys)),
                     to_str(self._options.keys())))
Ejemplo n.º 7
0
 def _parse_installer_rule(self, installer_rule):
     """Helper to parse installer rule with the installer_description."""
     try:
         parsed_rule = config_from_parsed_yaml(
             installer_rule,
             self.installer_rule_description,
             use_defaults=True)
     except ConfigValueError as e:
         raise_from(
             InvalidRuleError, "invalid installer rule `{}` for "
             "installer '{}'".format(installer_rule, self.name), e)
     unused_keys = set(installer_rule.keys()) - set(parsed_rule.keys())
     if unused_keys:
         warning("ignoring the following unknown installer rule keys for "
                 "installer '{}' while parsing installer rule with "
                 "packages {}: {}".format(self.name,
                                          to_str(parsed_rule.packages),
                                          to_str(list(unused_keys))))
     return parsed_rule
Ejemplo n.º 8
0
 def init_from_sources(self):
     debug("initializing database with sources dir `{}` and cache dir `{}`".
           format(self.sources_context.sources_dir,
                  self.sources_context.cache_dir))
     self.sources = []
     sources_dir = self.sources_context.sources_dir
     sources_gen = get_source_descriptions(sources_dir)
     if sources_gen is None:
         if not self.sources_context.is_default_dirs():
             warning("no source files found in source dir '{0}'; "
                     "using default sources".format(sources_dir))
         if is_verbose():
             info("Loading default source urls")
         sources_gen = get_default_source_descriptions()
     for source_file, source_descriptions in sources_gen:
         for descr in source_descriptions:
             spec_name, arguments = descr.items()[0]
             spec = self.sources_context.get_spec(spec_name)
             self.sources.append(
                 RulesSource(spec, arguments, source_file,
                             self.sources_context))
     self.verify_unique_ids()
Ejemplo n.º 9
0
 def init_from_sources(self):
     debug("initializing database with sources dir `{}` and cache dir `{}`".
           format(self.sources_context.sources_dir,
                  self.sources_context.cache_dir))
     self.sources = []
     sources_dir = self.sources_context.sources_dir
     sources_gen = get_source_descriptions(sources_dir)
     if sources_gen is None:
         if not self.sources_context.is_default_dirs():
             warning("no source files found in source dir '{0}'; "
                     "using default sources".format(sources_dir))
         if is_verbose():
             info("Loading default source urls")
         sources_gen = get_default_source_descriptions()
     for source_file, source_descriptions in sources_gen:
         for descr in source_descriptions:
             spec_name, arguments = descr.items()[0]
             spec = self.sources_context.get_spec(spec_name)
             self.sources.append(RulesSource(
                 spec,
                 arguments,
                 source_file,
                 self.sources_context))
     self.verify_unique_ids()