diff --git a/contrib/osc.spec b/contrib/osc.spec index b0f1007a5a..d26c04b10a 100644 --- a/contrib/osc.spec +++ b/contrib/osc.spec @@ -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} diff --git a/osc/core.py b/osc/core.py index 30d75a524e..ac55f531d6 100644 --- a/osc/core.py +++ b/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: