mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-25 22:36:13 +01:00
Merge pull request #1539 from dmach/updatepacmetafromspec-expand-macros
Improve 'updatepacmetafromspec' command to expand rpm spec macros by calling rpmspec to query the data
This commit is contained in:
commit
42e529f346
@ -111,6 +111,9 @@ Recommends: obs-service-source_validator
|
||||
Recommends: obs-service-tar_scm
|
||||
Recommends: obs-service-verify_file
|
||||
|
||||
# needed for `osc updatepacmetafromspec` that calls rpmspec to get values with expanded macros
|
||||
Recommends: rpm-build
|
||||
|
||||
# needed for ssh signature auth
|
||||
Recommends: %{ssh_add_pkg}
|
||||
Recommends: %{ssh_keygen_pkg}
|
||||
|
13
osc/core.py
13
osc/core.py
@ -1862,6 +1862,19 @@ def read_meta_from_spec(specfile, *args):
|
||||
if not os.path.isfile(specfile):
|
||||
raise oscerr.OscIOError(None, f'\'{specfile}\' is not a regular file')
|
||||
|
||||
rpmspec_path = shutil.which("rpmspec")
|
||||
if rpmspec_path:
|
||||
result = {}
|
||||
for arg in args:
|
||||
# convert tag to lower case and remove the leading '%'
|
||||
tag = arg.lower().lstrip("%")
|
||||
cmd = [rpmspec_path, "-q", specfile, "--srpm", "--qf", "%{" + tag + "}"]
|
||||
value = subprocess.check_output(cmd, encoding="utf-8")
|
||||
if value == "(none)":
|
||||
value = ""
|
||||
result[arg] = value
|
||||
return result
|
||||
|
||||
try:
|
||||
lines = codecs.open(specfile, 'r', locale.getpreferredencoding()).readlines()
|
||||
except UnicodeDecodeError:
|
||||
|
Loading…
Reference in New Issue
Block a user