From d2e296ddd7b85b7b7f89b3c4fc975110715348ef Mon Sep 17 00:00:00 2001 From: Christopher O'Brien Date: Jul 22 2020 15:11:51 +0000 Subject: [PATCH 1/2] allow getRPMHeaders to get all headers if none are explicitly requested --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 4d7eed4..d06ba9d 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -11660,8 +11660,7 @@ class RootExports(object): is not valid or the rpm does not exist on the file system, an empty map will be returned. """ - if not headers: - headers = [] + if rpmID: rpm_info = get_rpm(rpmID) if not rpm_info or not rpm_info['build_id']: diff --git a/koji/__init__.py b/koji/__init__.py index 5511dd8..606f36c 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -1037,7 +1037,7 @@ def _get_header_field(hdr, name): return hdr[hdr_key] -def get_header_fields(X, fields, src_arch=False): +def get_header_fields(X, fields=None, src_arch=False): """Extract named fields from an rpm header and return as a dictionary X may be either the rpm header or the rpm filename @@ -1047,8 +1047,13 @@ def get_header_fields(X, fields, src_arch=False): else: hdr = X ret = {} + + if fields is None: + fields = [rpm.tagnames[k] for k in hdr.keys()] + for f in fields: ret[f] = get_header_field(hdr, f, src_arch=src_arch) + return ret From 891069b327b6bd1e34d700d4275db383564411b9 Mon Sep 17 00:00:00 2001 From: Christopher O'Brien Date: Jul 22 2020 15:22:24 +0000 Subject: [PATCH 2/2] some safety netting --- diff --git a/koji/__init__.py b/koji/__init__.py index 606f36c..7a55fd6 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -1042,6 +1042,7 @@ def get_header_fields(X, fields=None, src_arch=False): X may be either the rpm header or the rpm filename """ + if isinstance(X, str): hdr = get_rpm_header(X) else: @@ -1049,6 +1050,13 @@ def get_header_fields(X, fields=None, src_arch=False): ret = {} if fields is None: + if not rpm: + # while get_rpm_header will also check this, it's possible + # that X was constructed without rpm's help, bypassing + # that function. + raise GenericError("rpm's python bindings are not installed") + + # resolve the names of all the keys we found in the header fields = [rpm.tagnames[k] for k in hdr.keys()] for f in fields: