From 37e68c0d5468fd26becea12bc6acb194f090e564 Mon Sep 17 00:00:00 2001 From: repo sync --force-sync cd $Mino Date: Mon, 5 Jul 2021 18:01:53 -0400 Subject: [PATCH] Add a utility for extracting patch software version Added a new utility in cgcs_patch/patch_functions.py that extracts only the metadata (and only to stdout) in order to parse it and provide the software release version. Signed-off-by: Jessica Castelino Partial-Bug: 1934674 Change-Id: I39cbc67c5ed8822fe2a21630eec380a43c09de95 --- .../cgcs-patch/cgcs_patch/patch_functions.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py index 0acb10f4..2ffdff71 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py @@ -199,6 +199,24 @@ def parse_pkgver(pkgver): return (epoch, version, release) +def get_release_from_patch(patchfile): + rel = "" + try: + cmd = "tar xf %s -O metadata.tar | tar x -O" % patchfile + metadata_str = subprocess.check_output(cmd, shell=True) + root = ElementTree.fromstring(metadata_str) + # Extract release version + rel = root.findtext('sw_version') + except subprocess.CalledProcessError as e: + LOG.error("Failed to run tar command") + LOG.error("Command output: %s", e.output) + raise e + except Exception as e: + print("Failed to parse patch software version") + raise e + return rel + + class PackageVersion(object): """ The PackageVersion class provides a structure for RPM version information,