Exemple #1
0
    def get_default_stream(self, name: str):
        if self._mod_index is None:
            raise mlerrcode.MlModuleNotFound("Unable to access module index when resolving default stream")

        module = self._mod_index.get_module(name)

        if not module:
            raise mlerrcode.MlModuleNotFound("Module {} not found".format(name))

        defaults = module.get_defaults()
        if defaults:
            return defaults.get_default_stream()

        return module.get_all_streams()[0].get_stream_name()
Exemple #2
0
    def _get_repodata_streams(self) -> List[Modulemd.ModuleStreamV2]:
        """
        _get_repodata_streams -- collect all repodata streams and select current default.

        :return: List of stream objects
        :rtype: List
        """
        self._proc._streams.clear()
        self._proc.index_modules()

        #TODO: Optimize error data
        not_found = []
        for s_type in self.repodata.get_streams():
            try:
                if s_type.stream:
                    self._proc.pick_stream(s_type)
                else:
                    self._proc.pick_default_stream(s_type=s_type)
            except mlerrcode.MlModuleNotFound as e:
                not_found += e.data["streams"]

        if not_found:
            raise mlerrcode.MlModuleNotFound("Module not found").set_data("streams", not_found)

        return self._proc._streams
Exemple #3
0
    def resolve(self, streams):
        """
        resolve - resolve dependencies for the requested streams

        The algorithm traverses the dependency tree recursively using backtracking to collect multiple solutions.

        :param streams: the requested streams
        :return:
            A list of solution-score pairs that satisfy all the dependency requirements for the requested streams

            Each solution is a list of selected stream contexts for the requested streams and their dependencies.
            The score indicates the number of selected default streams in the solution.
        """
        self._streams = streams

        # Collect all the available contexts for the requested streams
        # to get an initial list of candidates at the root of the tree
        contexts = []
        not_found = []
        for s in streams:
            ctx = self._proc.get_stream_contexts(s)
            if ctx:
                contexts.extend(self._proc.get_stream_contexts(s))
            else:
                not_found.append(s.to_obj())

        # Throw an error if any of the requested streams are not found
        if not_found:
            raise mlerrcode.MlModuleNotFound("Module not found").set_data(
                "streams", not_found)

        self._solutions = []
        self._do_resolve([], contexts)
        return self._solutions
Exemple #4
0
    def get_rpm_blacklist(self):
        if self._mod_index is None:
            raise mlerrcode.MlModuleNotFound("No module index has been found")

        enabled_packages: Set = set()
        for stream in self._enabled_stream_modules.values():
            enabled_packages = enabled_packages.union(stream.get_rpm_artifacts())

        all_packages: Set = set()
        for name in self._mod_index.get_module_names():
            module = self._mod_index.get_module(name)
            for stream in module.get_all_streams():
                all_packages = all_packages.union(stream.get_rpm_artifacts())

        return list(all_packages.difference((enabled_packages)))
Exemple #5
0
    def get_default_stream(self, name: str):
        if self._mod_index is None:
            raise mlerrcode.MlGeneralException("Module index not found")

        module = self._mod_index.get_module(name)

        if not module:
            raise mlerrcode.MlModuleNotFound(
                "Module {} not found".format(name)).set_data(
                    "streams", [mltypes.MLStreamType(name, "").to_obj()])

        defaults = module.get_defaults()
        if defaults:
            return defaults.get_default_stream()

        return module.get_all_streams()[0].get_stream_name()
Exemple #6
0
    def pick_stream(self, s_type: mltypes.MLStreamType):
        if s_type.name in MLLibmodProc.RESERVED_STREAMS:
            # Reserved streams are always enabled
            return

        if self._is_stream_enabled(s_type):
            enabled_stream = self._enabled_stream_modules[s_type.name]
            if enabled_stream.get_stream_name() == s_type.stream:
                # Stream already enabled, nothing to do
                return
            else:
                # Another stream of the same module already enabled
                conflicting = [
                    mltypes.MLStreamType(s_type.name, enabled_stream.get_stream_name()).to_obj(),
                    s_type.to_obj()
                ]
                raise mlerrcode.MlConflictingStreams("Conflicting streams").set_data("streams", conflicting)

        all_deps = set()  # type: ignore
        allContexts = self.get_stream_contexts(s_type=s_type)
        if not allContexts:
            raise mlerrcode.MlModuleNotFound("Module not found").set_data("streams", [s_type.to_obj()])
        for c in allContexts:
            all_deps = all_deps.union(self.get_stream_dependencies(c))

        enabledDeps = []
        for d in all_deps:
            enabledDeps.append((d, self.get_actual_stream(d)))

        for ctx in allContexts:
            currDeps = self.get_dep_streams(ctx)
            if all(i in enabledDeps for i in currDeps):
                for dstream in currDeps:
                    self.pick_stream(s_type=mltypes.MLStreamType(name=dstream[0], streamname=dstream[1]))

                self.enable_stream(ctx)
                self._streams.append(ctx)
            else:
                # Return s_type
                raise mlerrcode.MlDependencyResolutionError("Dependencies cannot be resolved").set_data("streams", [s_type.to_obj()])