Esempio n. 1
0
 def _apply_security_filters(self, query, base):
     query = base._merge_update_filters(query, warning=False)
     if not query:
         logger.warning(
             _('No security updates for argument "{}"').format(
                 self._pattern))
     return query
Esempio n. 2
0
        def run_on_module(self):
            mods = self.module_base

            if self.opts.enabled:
                output = mods._get_brief_description(
                    self.opts.module_spec,
                    libdnf.module.ModulePackageContainer.ModuleState_ENABLED)
            elif self.opts.disabled:
                output = mods._get_brief_description(
                    self.opts.module_spec,
                    libdnf.module.ModulePackageContainer.ModuleState_DISABLED)
            elif self.opts.installed:
                output = mods._get_brief_description(
                    self.opts.module_spec,
                    libdnf.module.ModulePackageContainer.ModuleState_INSTALLED)
            else:
                output = mods._get_brief_description(
                    self.opts.module_spec,
                    libdnf.module.ModulePackageContainer.ModuleState_UNKNOWN)
            if output:
                print(output)
                return
            msg = _('No matching Modules to list')
            if self.opts.module_spec:
                raise dnf.exceptions.Error(msg)
            logger.warning(msg)
Esempio n. 3
0
    def install(self, module_specs, strict=True):
        versions, module_specs = self.get_best_versions(module_specs)

        result = False
        for module_version, profiles, default_profiles in versions.values():
            conf = module_version.repo_module.conf
            if conf.locked._get(
            ) and conf.version._get() != module_version.version:
                logger.warning(module_messages[VERSION_LOCKED].format(
                    module_version.name,
                    module_version.repo_module.conf.version._get()))
                continue

            self.enable("{}:{}".format(module_version.name,
                                       module_version.stream))

        self.base.sack.reset_module_excludes()
        self.base.use_module_includes()

        for module_version, profiles, default_profiles in versions.values():
            if module_version.version > module_version.repo_module.conf.version._get(
            ):
                profiles.extend(
                    list(module_version.repo_module.conf.profiles._get()))
                profiles = list(set(profiles))

            if profiles or default_profiles:
                result |= module_version.install(profiles, default_profiles,
                                                 strict)

        if not result and versions and self.base._module_persistor:
            module_versions = [
                "{}:{}".format(module_version.name, module_version.stream)
                for module_version, profiles, default_profiles in
                versions.values()
            ]
            self.base._module_persistor.commit()
            self.base._module_persistor.save()
            logger.info(module_messages[ENABLED_MODULES].format(
                ", ".join(module_versions)))

        return module_specs
    def install(self, module_specs):
        versions, module_specs = self.get_best_versions(module_specs)

        result = False
        for module_version, profiles, default_profiles in versions.values():
            conf = module_version.repo_module.conf
            if conf.locked and conf.version != module_version.version:
                logger.warning(module_messages[VERSION_LOCKED].format(
                    module_version.name,
                    module_version.repo_module.conf.version))
                continue

            self.enable("{}:{}".format(module_version.name,
                                       module_version.stream))

        self.base.sack.reset_includes()
        self.base.sack.reset_excludes()
        self.base._setup_excludes_includes()

        for module_version, profiles, default_profiles in versions.values():
            if module_version.version > module_version.repo_module.conf.version:
                profiles.extend(module_version.repo_module.conf.profiles)
                profiles = list(set(profiles))

            if profiles or default_profiles:
                result |= module_version.install(profiles, default_profiles)

        if not result and versions and self.base._module_persistor:
            module_versions = [
                "{}:{}".format(module_version.name, module_version.stream)
                for module_version, profiles, default_profiles in
                versions.values()
            ]
            self.base._module_persistor.commit()
            self.base._module_persistor.save()
            exit_dnf(module_messages[NOTHING_TO_INSTALL].format(
                ", ".join(module_versions)))

        return module_specs
Esempio n. 5
0
    def switch_to(self, module_specs, strict=True):
        # :api
        no_match_specs, error_specs, module_dicts = self._resolve_specs_enable(
            module_specs)
        # collect name of artifacts from new modules for distrosync
        new_artifacts_names = set()
        # collect name of artifacts from active modules for distrosync before sack update
        active_artifacts_names = set()
        src_arches = {"nosrc", "src"}
        for spec, (nsvcap, moduledict) in module_dicts.items():
            for name in moduledict.keys():
                for module in self.base._moduleContainer.query(
                        name, "", "", "", ""):
                    if self.base._moduleContainer.isModuleActive(module):
                        for artifact in module.getArtifacts():
                            arch = artifact.rsplit(".", 1)[1]
                            if arch in src_arches:
                                continue
                            pkg_name = artifact.rsplit("-", 2)[0]
                            active_artifacts_names.add(pkg_name)

        solver_errors = self._update_sack()

        dependency_error_spec = self._enable_dependencies(module_dicts)
        if dependency_error_spec:
            error_specs.extend(dependency_error_spec)

        # <package_name, set_of_spec>
        fail_safe_repo = hawkey.MODULE_FAIL_SAFE_REPO_NAME
        install_dict = {}
        install_set_artifacts = set()
        fail_safe_repo_used = False

        # list of name: [profiles] for module profiles being removed
        removed_profiles = self.base._moduleContainer.getRemovedProfiles()

        for spec, (nsvcap, moduledict) in module_dicts.items():
            for name, streamdict in moduledict.items():
                for stream, module_list in streamdict.items():
                    install_module_list = [
                        x for x in module_list
                        if self.base._moduleContainer.isModuleActive(x.getId())
                    ]
                    if not install_module_list:
                        "No active matches for argument '{0}' in module '{1}:{2}'"
                        logger.error(
                            _("No active matches for argument '{0}' in module "
                              "'{1}:{2}'").format(spec, name, stream))
                        error_specs.append(spec)
                        continue
                    profiles = []
                    latest_module = self._get_latest(install_module_list)
                    if latest_module.getRepoID() == fail_safe_repo:
                        msg = _(
                            "Installing module '{0}' from Fail-Safe repository {1} is not allowed"
                        )
                        logger.critical(
                            msg.format(latest_module.getNameStream(),
                                       fail_safe_repo))
                        fail_safe_repo_used = True
                    if nsvcap.profile:
                        profiles.extend(
                            latest_module.getProfiles(nsvcap.profile))
                        if not profiles:
                            available_profiles = latest_module.getProfiles()
                            if available_profiles:
                                profile_names = ", ".join(
                                    sorted([
                                        profile.getName()
                                        for profile in available_profiles
                                    ]))
                                msg = _(
                                    "Unable to match profile for argument {}. Available "
                                    "profiles for '{}:{}': {}").format(
                                        spec, name, stream, profile_names)
                            else:
                                msg = _(
                                    "Unable to match profile for argument {}"
                                ).format(spec)
                            logger.error(msg)
                            no_match_specs.append(spec)
                            continue
                    elif name in removed_profiles:

                        for profile in removed_profiles[name]:
                            module_profiles = latest_module.getProfiles(
                                profile)
                            if not module_profiles:
                                logger.warning(
                                    _("Installed profile '{0}' is not available in module "
                                      "'{1}' stream '{2}'").format(
                                          profile, name, stream))
                                continue
                            profiles.extend(module_profiles)
                    for profile in profiles:
                        self.base._moduleContainer.install(
                            latest_module, profile.getName())
                        for pkg_name in profile.getContent():
                            install_dict.setdefault(pkg_name, set()).add(spec)
                    for module in install_module_list:
                        artifacts = module.getArtifacts()
                        install_set_artifacts.update(artifacts)
                        for artifact in artifacts:
                            arch = artifact.rsplit(".", 1)[1]
                            if arch in src_arches:
                                continue
                            pkg_name = artifact.rsplit("-", 2)[0]
                            new_artifacts_names.add(pkg_name)
        if fail_safe_repo_used:
            raise dnf.exceptions.Error(
                _("Installing module from Fail-Safe repository is not allowed")
            )
        install_base_query, profiles_errors = self._install_profiles_internal(
            install_set_artifacts, install_dict, strict)
        if profiles_errors:
            error_specs.extend(profiles_errors)

        # distrosync module name
        all_names = set()
        all_names.update(new_artifacts_names)
        all_names.update(active_artifacts_names)
        remove_query = self.base.sack.query().filterm(empty=True)
        base_no_source_query = self.base.sack.query().filterm(
            arch__neq=['src', 'nosrc']).apply()

        for pkg_name in all_names:
            query = base_no_source_query.filter(name=pkg_name)
            installed = query.installed()
            if not installed:
                continue
            available = query.available()
            if not available:
                logger.warning(
                    _("No packages available to distrosync for package name "
                      "'{}'").format(pkg_name))
                if pkg_name not in new_artifacts_names:
                    remove_query = remove_query.union(query)
                continue

            only_new_module = query.intersection(install_base_query)
            if only_new_module:
                query = only_new_module
            sltr = dnf.selector.Selector(self.base.sack)
            sltr.set(pkg=query)
            self.base._goal.distupgrade(select=sltr)
        self.base._remove_if_unneeded(remove_query)

        if no_match_specs or error_specs or solver_errors:
            raise dnf.exceptions.MarkingErrors(
                no_match_group_specs=no_match_specs,
                error_group_specs=error_specs,
                module_depsolv_errors=solver_errors)
Esempio n. 6
0
def report_module_switch(switchedModules):
    msg1 = _("The operation would result in switching of module '{0}' stream '{1}' to "
             "stream '{2}'")
    for moduleName, streams in switchedModules.items():
        logger.warning(msg1.format(moduleName, streams[0], streams[1]))
Esempio n. 7
0
 def _apply_security_filters(self, query, base):
     query = base._merge_update_filters(query, warning=False)
     if not query:
         logger.warning(_('No security updates for argument "{}"').format(self._pattern))
     return query
Esempio n. 8
0
def report_module_switch(switchedModules):
    msg1 = _("The operation would result in switching of module '{0}' stream '{1}' to "
             "stream '{2}'")
    for moduleName, streams in switchedModules.items():
        logger.warning(msg1.format(moduleName, streams[0], streams[1]))