コード例 #1
0
    def get_info(self, module_spec):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        default_stream = module_version.repo_module.defaults.peek_default_stream(
        )
        default_str = " (default)" if module_version.stream == default_stream else ""

        default_profiles = []
        default_stream = module_version.repo_module.defaults.peek_default_stream(
        )
        profile_defaults = module_version.repo_module.defaults.peek_profile_defaults(
        )
        if default_stream in profile_defaults:
            default_profiles.extend(profile_defaults[default_stream].get())

        lines = OrderedDict()
        lines["Name"] = module_version.name
        lines["Stream"] = module_version.stream + default_str
        lines["Version"] = module_version.version
        lines["Profiles"] = " ".join(module_version.profiles)
        lines["Default profiles"] = " ".join(default_profiles)
        lines["Repo"] = module_version.repo.id
        lines["Summary"] = module_version.summary()
        lines["Description"] = module_version.description()
        lines["Artifacts"] = "\n".join(sorted(module_version.artifacts()))

        table = self.create_simple_table(lines)

        return table
コード例 #2
0
        def run_on_module(self):
            module_versions = dict()
            for module_ns in self.opts.module_spec:
                subj = ModuleSubject(module_ns)
                module_version, module_form = subj.find_module_version(
                    self.base.repo_module_dict)

                if module_version.name in module_versions:
                    raise EnableMultipleStreamsException(module_version.name)

                module_versions[module_version.name] = (module_version,
                                                        module_form)

            for module_version, module_form in module_versions.values():
                if module_form.profile:
                    logger.info("Ignoring unnecessary profile: '{}/{}'".format(
                        module_form.name, module_form.profile))

                self.base.repo_module_dict.enable_by_version(module_version)

            self.base.do_transaction()

            logger.info(
                _("\nTo switch to the new streams' RPMs, run '{} distro-sync'. \n"
                  "Then migrate configuration files and data as necessary.".
                  format(os.path.basename(sys.argv[0]))))
コード例 #3
0
    def remove(self, module_specs):
        skipped = []
        for module_spec in module_specs:
            subj = ModuleSubject(module_spec)

            try:
                module_version, module_form = subj.find_module_version(self)
            except NoModuleException:
                skipped.append(module_spec)
                continue

            conf = self[module_form.name].conf
            if module_form.stream and module_form.stream != conf.stream:
                raise DifferentStreamEnabledException(module_form.name)

            if conf and conf.profiles:
                installed_profiles = conf.profiles
            else:
                raise NoProfileToRemoveException(module_spec)
            if module_form.profile:
                if module_form.profile not in installed_profiles:
                    raise ProfileNotInstalledException(module_spec)
                profiles = [module_form.profile]
            else:
                profiles = installed_profiles

            module_version.remove(profiles)
        return skipped
コード例 #4
0
    def lock(self, module_spec, save_immediately=False):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        repo_module = module_version.repo_module

        if not repo_module.conf.enabled._get():
            raise EnabledStreamException(module_spec)
        elif repo_module.conf.locked._get() and \
                (repo_module.conf.stream._get() != module_version.stream or
                 repo_module.conf.version._get() != module_version.version):
            raise VersionLockedException(module_spec, module_version.version)

        version_to_lock = module_version.version
        if list(repo_module.conf.profiles._get()):
            version_to_lock = module_version.repo_module.conf.version._get()
        repo_module.lock(version_to_lock)

        if module_form.version and version_to_lock != module_form.version:
            raise CannotLockVersionException(module_spec, module_form.version,
                                             "Different version installed.")

        if save_immediately:
            self.base._module_persistor.commit()
            self.base._module_persistor.save()

        return module_version.stream, version_to_lock
コード例 #5
0
ファイル: repo_module_dict.py プロジェクト: sshyran/dnf
    def remove(self, module_specs):
        skipped = []
        for module_spec in module_specs:
            subj = ModuleSubject(module_spec)

            try:
                module_version, module_form = subj.find_module_version(self)
            except NoModuleException:
                # TODO: report skipped module specs to the user
                skipped.append(module_spec)
                continue

            conf = self[module_form.name].conf
            if module_version.stream != conf.stream._get():
                raise DifferentStreamEnabledException(module_form.name)

            if list(conf.profiles._get()):
                installed_profiles = list(conf.profiles._get())
            else:
                raise NoProfileToRemoveException(module_spec)
            if module_form.profile:
                if module_form.profile not in installed_profiles:
                    raise ProfileNotInstalledException(module_spec)
                profiles = [module_form.profile]
            else:
                profiles = installed_profiles

            module_version.remove(profiles)
        return skipped
コード例 #6
0
ファイル: repo_module_dict.py プロジェクト: sshyran/dnf
    def upgrade(self, module_specs, create_goal=False):
        skipped = []
        query = None

        module_versions = []
        for module_spec in module_specs:
            subj = ModuleSubject(module_spec)
            try:
                module_version, module_form = subj.find_module_version(self)
                module_versions.append(module_version)

                # in case there is new dependency
                self.enable_by_version(module_version)
            except NoModuleException:
                skipped.append(module_spec)
                continue
            except NoStreamSpecifiedException:
                continue

        hot_fix_repos = [
            i.id for i in self.base.repos.iter_enabled() if i.module_hotfixes
        ]
        self.base.sack.filter_modules(self.base._moduleContainer,
                                      hot_fix_repos,
                                      self.base.conf.installroot,
                                      self.base.conf.module_platform_id,
                                      update_only=True)

        for module_version in module_versions:
            if module_version.repo_module.conf.state._get() != "enabled":
                continue

            conf = self[module_form.name].conf
            if conf:
                installed_profiles = list(conf.profiles._get())
            else:
                installed_profiles = []
            if module_form.profile:
                if module_form.profile not in installed_profiles:
                    raise ProfileNotInstalledException(module_version.name)
                profiles = [module_form.profile]
            else:
                profiles = installed_profiles

            if not profiles:
                continue

            returned_query = module_version.upgrade(profiles)
            if query is None and returned_query:
                query = returned_query
            elif returned_query:
                query = query.union(returned_query)

        if create_goal and query:
            sltr = Selector(self.base.sack)
            sltr.set(pkg=query)
            self.base._goal.upgrade(select=sltr)

        return skipped
コード例 #7
0
ファイル: test_modules.py プロジェクト: sshyran/dnf
 def test_nap(self):
     subj = ModuleSubject(MODULE_NAP)
     result = list(subj.get_module_form_possibilities(forms=hawkey.MODULE_FORM_NAP))
     self.assertEqual(len(result), 1)
     actual = result[0]
     expected = NSVCAP(name="module-name", stream=None, version=None,
                       arch="x86_64", profile="profile")
     self.assertEqual(actual, expected)
コード例 #8
0
ファイル: test_modules.py プロジェクト: sshyran/dnf
 def test_nsv(self):
     subj = ModuleSubject(MODULE_NSV)
     result = list(subj.get_module_form_possibilities(forms=hawkey.MODULE_FORM_NSV))
     self.assertEqual(len(result), 1)
     actual = result[0]
     expected = NSVCAP(name="module-name", stream="stream", version=1,
                       arch=None, profile=None)
     self.assertEqual(actual, expected)
コード例 #9
0
ファイル: test_modules.py プロジェクト: sshyran/dnf
    def test_all(self):
        subj = ModuleSubject(MODULE_NSVAP)
        result = list(subj.get_module_form_possibilities())
        self.assertEqual(len(result), 1)

        actual = result[0]
        expected = NSVCAP(name="module-name", stream="stream", version=1,
                          arch="x86_64", profile="profile")
        self.assertEqual(actual, expected)
コード例 #10
0
ファイル: repo_module_dict.py プロジェクト: sshyran/dnf
    def get_full_info(self, module_spec):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        if module_form.profile:
            logger.info("Ignoring unnecessary profile: '{}/{}'".format(
                module_form.name, module_form.profile))

        return module_version.module_metadata.dumps().rstrip("\n")
コード例 #11
0
ファイル: repo_module_dict.py プロジェクト: sshyran/dnf
    def get_info(self, module_spec):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        if module_form.profile:
            logger.info("Ignoring unnecessary profile: '{}/{}'".format(
                module_form.name, module_form.profile))

        conf = module_version.repo_module.conf

        default_stream = module_version.repo_module.defaults.peek_default_stream(
        )
        default_str = " [d]" if module_version.stream == default_stream else ""
        enabled_str = ""
        if module_version.stream == conf.stream._get() and conf.state._get(
        ) == "enabled":
            if not default_str:
                enabled_str = " "
            enabled_str += "[e]"

        default_profiles = []
        stream = module_form.stream or module_version.repo_module.defaults.peek_default_stream(
        )
        profile_defaults = module_version.repo_module.defaults.peek_profile_defaults(
        )
        if stream in profile_defaults:
            default_profiles.extend(profile_defaults[stream].dup())

        profiles_str = ""
        available_profiles = module_version.profiles
        installed_profiles = []

        if module_version.stream == conf.stream._get():
            installed_profiles = list(conf.profiles._get())

        for profile in available_profiles:
            profiles_str += "{}{}".format(
                profile, " [d]" if profile in default_profiles else "")
            profiles_str += "[i], " if profile in installed_profiles else ", "

        profiles_str = profiles_str[:-2]

        lines = OrderedDict()
        lines["Name"] = module_version.name
        lines["Stream"] = module_version.stream + default_str + enabled_str
        lines["Version"] = module_version.version
        lines["Profiles"] = profiles_str
        lines["Default profiles"] = " ".join(default_profiles)
        lines["Repo"] = module_version.repo.id
        lines["Summary"] = module_version.summary()
        lines["Description"] = module_version.description()
        lines["Artifacts"] = "\n".join(sorted(module_version.artifacts()))

        str_table = str(self.create_simple_table(lines))

        return str_table + "\n\nHint: [d]efault, [e]nabled, [i]nstalled"
コード例 #12
0
ファイル: module.py プロジェクト: KoubiZhi/dnf
        def run_on_module(self):
            for module_n in self.opts.module_nsvp:
                subj = ModuleSubject(module_n)
                module_version, module_form = subj.find_module_version(self.base.repo_module_dict)

                if module_form.profile:
                    logger.info("Ignoring unnecessary profile: '{}/{}'".format(module_form.name,
                                                                               module_form.profile))

                self.base.repo_module_dict.disable_by_version(module_version, True)
                logger.info("Module stream has been disabled: {}:{}".format(module_version.name,
                                                                            module_version.stream))
コード例 #13
0
    def upgrade(self, module_specs, create_goal=False):
        skipped = []
        query = None
        query_exclude = None
        for module_spec in module_specs:
            subj = ModuleSubject(module_spec)
            try:
                module_version, module_form = subj.find_module_version(self)
            except NoModuleException:
                skipped.append(module_spec)
                continue
            except NoStreamSpecifiedException:
                continue

            if module_version.repo_module.conf.locked._get():
                continue
            if not module_version.repo_module.conf.enabled._get():
                for rpm in module_version.artifacts():
                    query_for_rpm = self.base.sack.query().filter(nevra=rpm)
                    if query_exclude is None:
                        query_exclude = query_for_rpm
                    else:
                        query_exclude = query_exclude.union(query_for_rpm)
                continue

            conf = self[module_form.name].conf
            if conf:
                installed_profiles = list(conf.profiles._get())
            else:
                installed_profiles = []
            if module_form.profile:
                if module_form.profile not in installed_profiles:
                    raise ProfileNotInstalledException(module_spec)
                profiles = [module_form.profile]
            else:
                profiles = installed_profiles

            if not profiles:
                continue

            returned_query = module_version.upgrade(profiles)
            if query is None and returned_query:
                query = returned_query
            elif returned_query:
                query = query.union(returned_query)

        if create_goal and query:
            sltr = Selector(self.base.sack)
            sltr.set(pkg=query)
            self.base._goal.upgrade(select=sltr)

        return skipped, query, query_exclude
コード例 #14
0
        def run_on_module(self):
            for module_n in self.opts.module_spec:
                subj = ModuleSubject(module_n)
                module_version, module_form = subj.find_module_version(
                    self.base.repo_module_dict)

                if module_form.profile:
                    logger.info("Ignoring unnecessary profile: '{}/{}'".format(
                        module_form.name, module_form.profile))

                self.base.repo_module_dict.reset_by_version(module_version)

            self.base.do_transaction()
コード例 #15
0
    def enable(self, module_spec, save_immediately=False):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        version_dependencies = self.get_module_dependency_latest(
            module_version.name, module_version.stream)

        for dependency in version_dependencies:
            self[dependency.name].enable(dependency.stream,
                                         self.base.conf.assumeyes)

        if save_immediately:
            self.base._module_persistor.commit()
            self.base._module_persistor.save()
コード例 #16
0
    def disable(self, module_spec, save_immediately=False):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        repo_module = module_version.repo_module

        if repo_module.conf.locked._get():
            raise VersionLockedException(module_spec, module_version.version)

        repo_module.disable()

        if save_immediately:
            self.base._module_persistor.commit()
            self.base._module_persistor.save()
コード例 #17
0
    def get_info_profiles(self, module_spec):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        lines = OrderedDict()
        lines["Name"] = module_version.full_version

        for profile in module_version.profiles:
            nevra_objects = module_version.profile_nevra_objects(profile)
            lines[profile] = "\n".join([
                "{}-{}".format(nevra.name, nevra.evr())
                for nevra in nevra_objects
            ])

        return self.create_simple_table(lines)
コード例 #18
0
    def unlock(self, module_spec, save_immediately=False):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        repo_module = module_version.repo_module

        if not repo_module.conf.enabled._get():
            raise EnabledStreamException(module_spec)

        repo_module.unlock()

        if save_immediately:
            self.base._module_persistor.commit()
            self.base._module_persistor.save()

        return module_version.stream, module_version.version
コード例 #19
0
    def get_info_profiles(self, module_spec):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        if module_form.profile:
            logger.info("Ignoring unnecessary profile: '{}/{}'".format(
                module_form.name, module_form.profile))

        lines = OrderedDict()
        lines["Name"] = module_version.full_version

        for profile in module_version.profiles:
            nevra_objects = module_version.profile_nevra_objects(profile)
            lines[profile] = "\n".join([
                "{}-{}".format(nevra.name, nevra.evr())
                for nevra in nevra_objects
            ])

        return self.create_simple_table(lines).toString()
コード例 #20
0
    def test_nsva(self):
        subj = ModuleSubject(MODULE_NSVA)
        result = list(
            subj.get_module_form_possibilities(forms=hawkey.MODULE_FORM_NSVA))
        self.assertEqual(len(result), 1)
        actual = result[0]
        expected = ModuleForm(name="module-name",
                              stream="stream",
                              version=1,
                              arch="x86_64",
                              profile=None)
        self.assertEqual(actual, expected)

        # empty profile spec -> no profile
        subj = ModuleSubject(MODULE_NSVA + "/")
        result = list(
            subj.get_module_form_possibilities(forms=hawkey.MODULE_FORM_NSVA))
        self.assertEqual(len(result), 1)
        actual = result[0]
        expected = ModuleForm(name="module-name",
                              stream="stream",
                              version=1,
                              arch="x86_64",
                              profile=None)
        self.assertEqual(actual, expected)
コード例 #21
0
    def get_full_info(self, module_spec):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        return module_version.module_metadata.dumps().rstrip("\n")
コード例 #22
0
ファイル: repo_module_dict.py プロジェクト: sshyran/dnf
    def get_best_versions(self, module_specs):
        best_versions = {}
        skipped = []
        for module_spec in module_specs:
            subj = ModuleSubject(module_spec)

            try:
                module_version, module_form = subj.find_module_version(self)
            except NoModuleException:
                skipped.append(module_spec)
                continue

            key = module_version.name
            if key in best_versions:
                best_version, profiles, default_profiles = best_versions[key]
                if best_version.stream != module_version.stream:
                    raise EnableMultipleStreamsException(module_version.name)

                if module_form.profile:
                    profiles.append(module_form.profile)
                else:
                    stream = module_form.stream or module_version.repo_module.defaults \
                        .peek_default_stream()
                    profile_defaults = module_version.repo_module.defaults.peek_profile_defaults(
                    )
                    if stream in profile_defaults:
                        default_profiles.extend(profile_defaults[stream].dup())

                if best_version < module_version:
                    logger.info(
                        module_messages[INSTALLING_NEWER_VERSION].format(
                            best_version, module_version))
                    best_versions[key] = [
                        module_version, profiles, default_profiles
                    ]
                else:
                    best_versions[key] = [
                        best_version, profiles, default_profiles
                    ]
            else:
                default_profiles = []
                profiles = []

                stream = module_form.stream or module_version.repo_module.defaults \
                    .peek_default_stream()
                profile_defaults = module_version.repo_module.defaults.peek_profile_defaults(
                )
                if stream in profile_defaults:
                    default_profiles.extend(profile_defaults[stream].dup())

                if module_form.profile:
                    profiles = [module_form.profile]
                elif default_profiles:
                    profiles = []
                else:
                    default_profiles = ['default']

                best_versions[key] = [
                    module_version, profiles, default_profiles
                ]

        return best_versions, skipped
コード例 #23
0
ファイル: repo_module_dict.py プロジェクト: sshyran/dnf
    def reset(self, module_spec, save_immediately=False):
        subj = ModuleSubject(module_spec)
        module_version, module_form = subj.find_module_version(self)

        self.reset_by_version(module_version, save_immediately)