From e970e2ca325f42bacdd2fce29f40351f250df714 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Sun, 6 Aug 2023 16:23:41 +0200 Subject: [PATCH] rpmbuild: fallback to querying NEVRA from SRPM package header --- .../copr_rpmbuild/automation/srpm_results.py | 25 ++++++++++++++++--- rpmbuild/copr_rpmbuild/helpers.py | 5 ++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/rpmbuild/copr_rpmbuild/automation/srpm_results.py b/rpmbuild/copr_rpmbuild/automation/srpm_results.py index 8d2b353ea..be4d75741 100644 --- a/rpmbuild/copr_rpmbuild/automation/srpm_results.py +++ b/rpmbuild/copr_rpmbuild/automation/srpm_results.py @@ -5,7 +5,12 @@ import os import simplejson from copr_rpmbuild.automation.base import AutomationTool -from copr_rpmbuild.helpers import locate_spec, Spec +from copr_rpmbuild.helpers import ( + get_rpm_header, + locate_srpm, + locate_spec, + Spec, +) class SRPMResults(AutomationTool): @@ -33,8 +38,20 @@ def get_package_info(self): """ Return ``dict`` with interesting package metadata """ - spec_path = locate_spec(self.resultdir) - spec = Spec(spec_path) keys = ["name", "epoch", "version", "release", "exclusivearch", "excludearch"] - return {key: getattr(spec, key) for key in keys} + try: + path = locate_spec(self.resultdir) + spec = Spec(path) + return {key: getattr(spec, key) for key in keys} + + except Exception: # pylint: disable=broad-exception-caught + # Specfile library raises too many exception to name the + # in except block + msg = "Exception appeared during handling spec file: {0}".format(path) + self.log.exception(msg) + + # Fallback to querying NEVRA from the SRPM package header + path = locate_srpm(self.resultdir) + hdr = get_rpm_header(path) + return {key: hdr[key] for key in keys} diff --git a/rpmbuild/copr_rpmbuild/helpers.py b/rpmbuild/copr_rpmbuild/helpers.py index 247446622..aa445d1ee 100644 --- a/rpmbuild/copr_rpmbuild/helpers.py +++ b/rpmbuild/copr_rpmbuild/helpers.py @@ -108,6 +108,11 @@ def get_rpm_header(path): See docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch16s04.html """ ts = rpm.TransactionSet() + # I don't want to copy-paste the value of the protected variable. + # IMHO there is only a low chance it will get removed and even if it gets, + # we have tests to catch it anyway + # pylint: disable=protected-access + ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES) with open(path, "rb") as f: hdr = ts.hdrFromFdno(f.fileno()) return hdr