def test_split_packagename(self): """Test splitting package name into N,E,V,R,A.""" pkg_name = "bash-0:4.2.46-20.el7_2.x86_64.rpm" name, epoch, version, release, arch = utils.split_packagename(pkg_name) assert name == "bash" assert epoch == "0" assert version == "4.2.46" assert release == "20.el7_2" assert arch == "x86_64"
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 = split_packagename( package) 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_packagename(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 process_list(self, api_version, data): # pylint: disable=unused-argument """ Returns package details. :param data: json request parsed into data structure :returns: json response with package details """ validate(data, JSON_SCHEMA) packages = data.get('package_list', None) packagelist = {} if not packages: return packagelist for pkg in packages: packagedata = packagelist.setdefault(pkg, {}) name, epoch, ver, rel, arch = utils.split_packagename(pkg) if name in self.cache.packagename2id \ and (epoch, ver, rel) in self.cache.evr2id \ and arch in self.cache.arch2id: name_id = self.cache.packagename2id[name] evr_id = self.cache.evr2id[(epoch, ver, rel)] arch_id = self.cache.arch2id[arch] if (name_id, evr_id, arch_id) in self.cache.nevra2pkgid: pkg_id = self.cache.nevra2pkgid[(name_id, evr_id, arch_id)] pkg_detail = self.cache.package_details[pkg_id] packagedata['summary'] = self.cache.strings.get( pkg_detail[PKG_SUMMARY_ID], None) packagedata['description'] = self.cache.strings.get( pkg_detail[PKG_DESC_ID], None) packagedata['source_package'] = self._get_source_package( pkg_detail) packagedata['repositories'] = [] packagedata[ 'package_list'] = self._get_built_binary_packages( pkg_id) if pkg_id in self.cache.pkgid2repoids: for repo_id in self.cache.pkgid2repoids[pkg_id]: repodetail = self.cache.repo_detail[repo_id] repodata = { 'label': repodetail[REPO_LABEL], 'name': repodetail[REPO_NAME], 'basearch': utils.none2empty(repodetail[REPO_BASEARCH]), 'releasever': utils.none2empty(repodetail[REPO_RELEASEVER]) } packagedata['repositories'].append(repodata) response = {'package_list': packagelist} return response
def _process_input_packages(self, data, response): """Parse input NEVRAs and filter out unknown (or without updates) package names.""" packages_to_process = data.get('package_list', None) filtered_packages_to_process = {} if packages_to_process is not None: for pkg in packages_to_process: response['update_list'][pkg] = {} name, epoch, ver, rel, arch = split_packagename(pkg) if name in self.db_cache.packagename2id: if self.db_cache.packagename2id[name] in self.db_cache.updates_index: filtered_packages_to_process[pkg] = {'parsed_nevra': (name, epoch, ver, rel, arch)} return filtered_packages_to_process
def process_nevras(self, data): """ Method returns the list of repositories where packages belongs. """ packages = data.get("package_list") response = {"data": {}} db_connection = self.db_pool.get_connection() with db_connection.get_cursor() as cursor: for package in packages: name, epoch, version, release, arch = split_packagename( package) cursor.execute("""select distinct cs.name, cs.label from package p left join package_name pn on p.name_id = pn.id left join evr e on p.evr_id = e.id left join arch a on p.arch_id = a.id left join pkg_repo pr on p.id = pr.pkg_id left join repo r on r.id = pr.repo_id left join content_set cs on cs.id = r.content_set_id where pn.name = '%s' and a.name = '%s' and e.epoch = '%s' and e.version = '%s' and e.release = '%s' """ % (name, arch, epoch, version, release)) response["data"][package] = [] for repository_query in cursor: repository_data = {} if repository_query[REPOSITORY_NAME] is not None: repository_data["repo_name"] = repository_query[ REPOSITORY_NAME] if repository_query[REPOSITORY_LABEL] is not None: repository_data["repo_label"] = repository_query[ REPOSITORY_LABEL] if repository_data: response["data"][package].append(repository_data) return response