def __init__(self, metadata: List[str]): """ __init__ :param metadata: paths of the metadata. :type metadata: List[str] """ self.metadata = metadata self._mod_index: Modulemd.ModuleIndex = None if gi is None or Modulemd is None: raise mlerrcode.MlGeneralException( "No python libmodulemd was found")
def get_module_streams(self, name: str) -> List: if self._mod_index is None: self.index_modules() if self._mod_index is None: raise mlerrcode.MlGeneralException("Module index not found") streams: Set = set() module = self._mod_index.get_module(name) if module: for s_obj in module.get_all_streams(): streams.add(s_obj.get_stream_name()) return list(streams)
def get_stream_contexts(self, s_type: mltypes.MLStreamType) -> List: if self._mod_index is None: self.index_modules() if self._mod_index is None: raise mlerrcode.MlGeneralException("Module index not found") contexts: List = [] module = self._mod_index.get_module(s_type.name) if module: for stream in module.get_all_streams(): if stream.get_stream_name() == s_type.stream: contexts.append(stream) return contexts
def set_repodata(self, repodata: str) -> "MLLibmodAPI": """ set_repodata -- set the repository data from the input JSON. :param repodata: JSON string of the input object. :type repodata: str """ self.repodata = mltypes.MLInputType(repodata) for modulepath in self.repodata.get_paths(): if not os.path.exists(modulepath): raise mlerrcode.MlGeneralException("File {} not found".format(modulepath)) self._proc = MLLibmodProc(self.repodata.get_paths()) return self
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()
def get_pkg_name(self, pkg_name: str) -> str: """ get_pkg_name -- get package name :param pkg_name: package name :type pkg_name: str :raises e: General exception if name doesn't comply. :return: name of the package :rtype: str """ try: woarch = pkg_name.rsplit(".", 1)[0] worel = woarch.rsplit("-", 1)[0] wover = worel.rsplit("-", 1)[0] except Exception as e: raise mlerrcode.MlGeneralException("{}: {}".format(e, pkg_name)) return wover
def get_stream_contexts(self, stream: mltypes.MLStreamType) -> List: ''' get_stream_contexts -- get all the alternative contexts for a module stream :param stream: the specified module stream ''' if self._mod_index is None: self.index_modules() if self._mod_index is None: raise mlerrcode.MlGeneralException("Module index not found") contexts: List = [] module = self._mod_index.get_module(stream.name) if module: stream_name = stream.stream if stream.stream \ else self.get_default_stream(stream.name) for ctx in module.get_all_streams(): if ctx.get_stream_name() == stream_name: contexts.append(ctx) return contexts