From e60592501e9ad7f5698d9e5b523fea88df0cb121 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 | 2 ++ 2 files changed, 23 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..d93b5a323 100644 --- a/rpmbuild/copr_rpmbuild/helpers.py +++ b/rpmbuild/copr_rpmbuild/helpers.py @@ -108,6 +108,8 @@ def get_rpm_header(path): See docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch16s04.html """ ts = rpm.TransactionSet() + # https://jfearn.fedorapeople.org/en-US/RPM/4/html/RPM_Guide/ch16s04s02.html + ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES) with open(path, "rb") as f: hdr = ts.hdrFromFdno(f.fileno()) return hdr