Skip to content

Commit

Permalink
Merge pull request #1539 from dmach/updatepacmetafromspec-expand-macros
Browse files Browse the repository at this point in the history
Improve 'updatepacmetafromspec' command to expand rpm spec macros by calling rpmspec to query the data
  • Loading branch information
dmach authored Apr 18, 2024
2 parents bc935ea + 7bbc147 commit 42e529f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions contrib/osc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
13 changes: 13 additions & 0 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 42e529f

Please sign in to comment.