def _build_package_list(self, errata, source=False): package_list = [] source_package_list = [] db_connection = self.db_pool.get_connection() with db_connection.get_cursor() as cursor: cursor.execute( """select pn.name, evr.epoch, evr.version, evr.release, a.name as arch from errata e left join pkg_errata pkge on e.id = pkge.errata_id left join package p on pkge.pkg_id = p.id left join package_name pn on p.name_id = pn.id left join evr on p.evr_id = evr.id left join arch a on p.arch_id = a.id where e.name in %s """, [tuple(errata, )]) query = cursor.fetchall() self.db_pool.return_connection(db_connection) for item in query: package = join_rpm_name(item[ERRATA_PKG_NAME], item[ERRATA_PKG_EPOCH], item[ERRATA_PKG_VERSION], item[ERRATA_PKG_RELEASE], item[ERRATA_PKG_ARCH]) if package and not source and not package in package_list and not package[ -4:] == ".src": package_list.append(package) elif package and source and not package in source_package_list and package[ -4:] == ".src": source_package_list.append(package) if source: return source_package_list return package_list
def _build_nevra(self, update_pkg_id: int) -> str: name_id, evr_id, arch_id, _, _, _, _ = self.db_cache.package_details[update_pkg_id] name = self.db_cache.id2packagename[name_id] epoch, ver, rel = self.db_cache.id2evr[evr_id] arch = self.db_cache.id2arch[arch_id] nevra = join_rpm_name(name, epoch, ver, rel, arch) return nevra
def process_list(self, data): """ Processes whole package_list and returns info. """ packages = data.get("package_list") response = {"package_list": {}} db_connection = self.db_pool.get_connection() with db_connection.get_cursor() as cursor: for package in packages: name, epoch, version, release, arch = parse_rpm_name(package, default_epoch='0') cursor.execute("""select distinct p.summary, p.description, pn2.name, evr2.epoch, evr2.version, evr2.release, a2.name, cs.label, cs.name, a.name, r.releasever, pn3.name from package p left join package_name pn on pn.id = p.name_id left join arch ap on p.arch_id = ap.id left join evr on p.evr_id = evr.id left join package p2 on p2.id = p.source_package_id left join package_name pn2 on p2.name_id = pn2.id left join evr evr2 on p2.evr_id = evr2.id left join arch a2 on p2.arch_id = a2.id left join pkg_repo pr on pr.pkg_id = p.id left join repo r on r.id = pr.repo_id left join content_set cs on cs.id = r.content_set_id left join arch a on a.id = r.basearch_id left join package p3 on p3.source_package_id = p.id left join package_name pn3 on p3.name_id = pn3.id where pn.name = '%s' and ap.name = '%s' and evr.epoch = '%s' and evr.version = '%s' and evr.release = '%s' """ % (name, arch, epoch, version, release)) query = cursor.fetchall() pkgs = {} pkgs[package] = {} for item in query: pkgs[package] = {"summary": item[PACKAGE_SUMMARY], "description": item[PACKAGE_DESCRIPTION], "source_package": join_rpm_name(item[SOURCE_PACKAGE_NAME], item[SOURCE_PACKAGE_EPOCH], item[SOURCE_PACKAGE_VERSION], item[SOURCE_PACKAGE_RELEASE], item[SOURCE_PACKAGE_ARCH]), "repositories": self._build_repositories(query), "binary_package_list": self._build_binary_packages(query) } response["package_list"].update(pkgs) self.db_pool.return_connection(db_connection) return response
def _add_package_entry(self, pkg_id, name_id, evr_id, arch_id): """Add package to the ultimate response""" if name_id not in self.pkgnameid2pkgname: LOGGER.error( "INCONSISTENT DATA: pkg id %s - package name id %s not found", pkg_id, name_id) if evr_id not in self.evrid2evr: LOGGER.error("INCONSISTEN DATA: pkg id %s - evr id %s not found", pkg_id, evr_id) if arch_id not in self.archid2arch: LOGGER.error("INCONSISTENT DATA: pkg id %s - arch id %s not found", pkg_id, arch_id) (epoch, ver, rel) = self.evrid2evr[evr_id] package_nevra = join_rpm_name(self.pkgnameid2pkgname[name_id], epoch, ver, rel, self.archid2arch[arch_id]) self.packagedata[pkg_id] = { 'data': { 'nevra': package_nevra, 'repositories': [] } } self.datadict[name_id].append(self.packagedata[pkg_id]['data'])
def pkg_detail2nevra(cache, pkg_detail): """Create package object from pkg_detail using cache object.""" name = cache.id2packagename[pkg_detail[PKG_NAME_ID]] epoch, ver, rel = cache.id2evr[pkg_detail[PKG_EVR_ID]] arch = cache.id2arch[pkg_detail[PKG_ARCH_ID]] return join_rpm_name(name, epoch, ver, rel, arch)
def _build_nevra(self, pkg_detail: tuple): name_id, evr_id, arch_id, _, _, _, _ = pkg_detail name = self.cache.id2packagename[name_id] epoch, ver, rel = self.cache.id2evr[evr_id] arch = self.cache.id2arch[arch_id] return join_rpm_name(name, epoch, ver, rel, arch)
def test_join_pkgname(self): """Test joining package name""" pkg_name = rpm_utils.join_rpm_name("test", "2", "1.2", "4.el7", "x86_64") assert pkg_name == "test-2:1.2-4.el7.x86_64"