Example #1
0
    def _create_module_dict_and_enable(self, module_list, enable=True):
        moduleDict = {}
        for module in module_list:
            moduleDict.setdefault(
                module.getName(), {}).setdefault(module.getStream(), []).append(module)

        for moduleName, streamDict in moduleDict.items():
            moduleState = self.base._moduleContainer.getModuleState(moduleName)
            if len(streamDict) > 1:
                if moduleState != STATE_DEFAULT and moduleState != STATE_ENABLED \
                        and moduleState != STATE_DISABLED:
                    raise EnableMultipleStreamsException(moduleName)
                if moduleState == STATE_ENABLED:
                    stream = self.base._moduleContainer.getEnabledStream(moduleName)
                else:
                    stream = self.base._moduleContainer.getDefaultStream(moduleName)
                if not stream or stream not in streamDict:
                    raise EnableMultipleStreamsException(moduleName)
                for key in sorted(streamDict.keys()):
                    if key == stream:
                        if enable:
                            self.base._moduleContainer.enable(moduleName, key)
                        continue
                    del streamDict[key]
            elif enable:
                for key in streamDict.keys():
                    self.base._moduleContainer.enable(moduleName, key)
            assert len(streamDict) == 1
        return moduleDict
Example #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]))))
Example #3
0
    def _create_module_dict_and_enable(self, module_list, spec, enable=True):
        moduleDict = {}
        for module in module_list:
            moduleDict.setdefault(module.getName(),
                                  {}).setdefault(module.getStream(),
                                                 []).append(module)

        for moduleName, streamDict in moduleDict.items():
            moduleState = self.base._moduleContainer.getModuleState(moduleName)
            if len(streamDict) > 1:
                if moduleState != STATE_DEFAULT and moduleState != STATE_ENABLED \
                        and moduleState != STATE_DISABLED:
                    streams_str = "', '".join(
                        sorted(streamDict.keys(),
                               key=functools.cmp_to_key(
                                   self.base.sack.evr_cmp)))
                    msg = _(
                        "Argument '{argument}' matches {stream_count} streams ('{streams}') of "
                        "module '{module}', but non of the streams are enabled or "
                        "default").format(argument=spec,
                                          stream_count=len(streamDict),
                                          streams=streams_str,
                                          module=moduleName)
                    raise EnableMultipleStreamsException(moduleName, msg)
                if moduleState == STATE_ENABLED:
                    stream = self.base._moduleContainer.getEnabledStream(
                        moduleName)
                else:
                    stream = self.base._moduleContainer.getDefaultStream(
                        moduleName)
                if not stream or stream not in streamDict:
                    raise EnableMultipleStreamsException(moduleName)
                for key in sorted(streamDict.keys()):
                    if key == stream:
                        if enable:
                            self.base._moduleContainer.enable(moduleName, key)
                        continue
                    del streamDict[key]
            elif enable:
                for key in streamDict.keys():
                    self.base._moduleContainer.enable(moduleName, key)
            assert len(streamDict) == 1
        return moduleDict
Example #4
0
    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