Skip to content

Commit

Permalink
rpmbuild: fallback to querying NEVRA from SRPM package header
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Aug 6, 2023
1 parent 54ff96f commit e970e2c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
25 changes: 21 additions & 4 deletions rpmbuild/copr_rpmbuild/automation/srpm_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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}
5 changes: 5 additions & 0 deletions rpmbuild/copr_rpmbuild/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e970e2c

Please sign in to comment.