def _list_to_pkglist(packages): """ Convert list of Packages to libcomps PackageList object. Args: list: a list of Packages Returns: pkglist: a libcomps PackageList """ pkglist = libcomps.PackageList() for pkg_lst in packages: for pkg in pkg_lst[1]: lib_pkg = libcomps.Package() if isinstance(pkg, list): lib_pkg.name = pkg[0] lib_pkg.requires = pkg[1] else: lib_pkg.name = pkg lib_pkg.type = pkg_lst[0] pkglist.append(lib_pkg) return pkglist
def test_package_option_type(self): # dnf.comps.Package.option_type libcomps_package = libcomps.Package() libcomps_package.type = 0 package = dnf.comps.Package(libcomps_package) self.assertHasAttr(package, "option_type") self.assertHasType(package.option_type, int)
def test_package_name(self): # dnf.comps.Package.name libcomps_package = libcomps.Package() libcomps_package.name = "name" package = dnf.comps.Package(libcomps_package) self.assertHasAttr(package, "name") self.assertHasType(package.name, str)
def list_to_pkglist(cls, lst): """ Convert list of Packages to libcomps PackageList object. Args: list: a list of Packages Returns: pkglist: a libcomps PackageList """ pkglist = libcomps.PackageList() for pkg in lst: lib_pkg = libcomps.Package() lib_pkg.name = pkg["name"] lib_pkg.type = pkg["type"] lib_pkg.basearchonly = bool(pkg["basearchonly"]) lib_pkg.requires = pkg["requires"] pkglist.append(lib_pkg) return pkglist
def test_instance(self): lc_pkg = libcomps.Package('weather', libcomps.PACKAGE_TYPE_OPTIONAL) pkg = dnf.comps.Package(lc_pkg) self.assertEqual(pkg.name, 'weather') self.assertEqual(pkg.option_type, dnf.comps.OPTIONAL)
def edit_group(self, group): ''' Set attributes and package lists for selected group ''' def langlist_to_strdict(lst): str_dict = libcomps.StrDict() for lang, text in lst: str_dict[lang] = text return str_dict # set group attributes if self.opts.name: group.name = self.opts.name if self.opts.description: group.desc = self.opts.description if self.opts.display_order: group.display_order = self.opts.display_order if self.opts.user_visible is not None: group.uservisible = self.opts.user_visible if self.opts.translated_name: group.name_by_lang = langlist_to_strdict(self.opts.translated_name) if self.opts.translated_description: group.desc_by_lang = langlist_to_strdict( self.opts.translated_description) # edit packages list if self.opts.packages: # find packages according to specifications from command line packages = set() for pkg_spec in self.opts.packages: subj = dnf.subject.Subject(pkg_spec) q = subj.get_best_query(self.base.sack, with_nevra=True, with_provides=False, with_filenames=False).latest() if not q: logger.warning( _("No match for argument: {}").format(pkg_spec)) continue packages.update(q) if self.opts.dependencies: # add packages that provide requirements requirements = set() for pkg in packages: requirements.update(pkg.requires) packages.update( self.base.sack.query().filterm(provides=requirements)) pkg_names = {pkg.name for pkg in packages} if self.opts.remove: for pkg_name in pkg_names: for pkg in group.packages_match( name=pkg_name, type=libcomps.PACKAGE_TYPE_UNKNOWN): group.packages.remove(pkg) else: if self.opts.mandatory: pkg_type = libcomps.PACKAGE_TYPE_MANDATORY elif self.opts.optional: pkg_type = libcomps.PACKAGE_TYPE_OPTIONAL else: pkg_type = libcomps.PACKAGE_TYPE_DEFAULT for pkg_name in sorted(pkg_names): if not group.packages_match(name=pkg_name, type=pkg_type): group.packages.append( libcomps.Package(name=pkg_name, type=pkg_type))
def test_package_init(self): libcomps_package = libcomps.Package() _ = dnf.comps.Package(ipkg=libcomps_package)