From 4f0be8a7d03124aa834431e301a2f54abf05cd61 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Fri, 9 Sep 2016 13:09:14 -0400 Subject: [PATCH] layerindex/utils: Update runcmd to decode binary strings to strings Convert binary strings to strings and strip leading/trailing whitespace prior to returning errors and output. Signed-off-by: Liam R. Howlett --- layerindex/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/layerindex/utils.py b/layerindex/utils.py index 50268e0..23b81f5 100644 --- a/layerindex/utils.py +++ b/layerindex/utils.py @@ -32,7 +32,8 @@ def runcmd(cmd, destdir=None, printerr=True, logger=None): execute command, raise CalledProcessError if fail return output if succeed """ - #logger.debug("run cmd '%s' in %s" % (cmd, os.getcwd() if destdir is None else destdir)) + if logger: + logger.debug("run cmd '%s' in %s" % (cmd, os.getcwd() if destdir is None else destdir)) out = tempfile.TemporaryFile() try: subprocess.check_call(cmd, stdout=out, stderr=out, cwd=destdir, shell=True) @@ -40,6 +41,7 @@ def runcmd(cmd, destdir=None, printerr=True, logger=None): out.seek(0) if printerr: output = out.read() + output = output.decode('ascii').strip() if logger: logger.error("%s" % output) else: @@ -49,7 +51,9 @@ def runcmd(cmd, destdir=None, printerr=True, logger=None): out.seek(0) output = out.read() - #logger.debug("output: %s" % output.rstrip() ) + output = output.decode('ascii').strip() + if logger: + logger.debug("output: %s" % output.rstrip() ) return output def setup_django():