From ae5ee3d856692b5f145059111a46b793fe9835fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 20 Feb 2017 10:35:10 +0100 Subject: [PATCH] iso-wrapper: Refactor functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split the function for getting implant MD5 into two functions, so that we can have access to other information retrieved by checkisomd5 command. A test case is added for both functions. Signed-off-by: Lubomír Sedlář --- pungi/wrappers/iso.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pungi/wrappers/iso.py b/pungi/wrappers/iso.py index 2ee9c79d..ab97e19f 100644 --- a/pungi/wrappers/iso.py +++ b/pungi/wrappers/iso.py @@ -195,11 +195,12 @@ def get_checkisomd5_cmd(iso_path, just_print=False): return cmd -def get_implanted_md5(iso_path, logger=None): +def get_checkisomd5_data(iso_path, logger=None): cmd = get_checkisomd5_cmd(iso_path, just_print=True) retcode, output = run(cmd) - line = output.splitlines()[0] - md5 = line.rsplit(":")[-1].strip() + items = [line.strip().rsplit(":", 1) for line in output.splitlines()] + items = dict([(k, v.strip()) for k, v in items]) + md5 = items.get(iso_path, '') if len(md5) != 32: # We have seen cases where the command finished successfully, but # returned garbage value. We need to handle it, otherwise there would @@ -210,7 +211,11 @@ def get_implanted_md5(iso_path, logger=None): logger.critical('Implanted MD5 in %s is not valid: %r', iso_path, md5) logger.critical('Ran command %r; exit code %r; output %r', cmd, retcode, output) return None - return md5 + return items + + +def get_implanted_md5(iso_path, logger=None): + return (get_checkisomd5_data(iso_path, logger=logger) or {}).get(iso_path) def get_isohybrid_cmd(iso_path, arch):