aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/combo-layer
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2015-03-10 09:48:15 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-03-20 11:03:08 +0000
commita084162a9dc4718ab453723f1f28aefc55100e2e (patch)
tree169fe01528edc6801f763c0216fdf8b28a7a9547 /scripts/combo-layer
parentdba34e5a6f0a4c726266654dc5f26e0f7f13db0f (diff)
downloadopenembedded-core-contrib-a084162a9dc4718ab453723f1f28aefc55100e2e.tar.gz
combo-layer: runcmd() with separate output
Allow the caller to specify a separate output stream. stderr is always a temporary file opened by runcmd(), so read from that to capture output for error reporting *and* the return value. The reasoning for the latter is a) that this preserves the traditional behavior when out=None and b) if the caller wants the content of stdout, it can read from the stream itself, which is not possible for the temporary stderr. Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com>
Diffstat (limited to 'scripts/combo-layer')
-rwxr-xr-xscripts/combo-layer18
1 files changed, 11 insertions, 7 deletions
diff --git a/scripts/combo-layer b/scripts/combo-layer
index 62f2cf8fa33..3ee9eb203d2 100755
--- a/scripts/combo-layer
+++ b/scripts/combo-layer
@@ -152,23 +152,27 @@ class Configuration(object):
logger.error("ERROR: patchutils package is missing, please install it (e.g. # apt-get install patchutils)")
sys.exit(1)
-def runcmd(cmd,destdir=None,printerr=True):
+def runcmd(cmd,destdir=None,printerr=True,out=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))
- out = os.tmpfile()
+ if not out:
+ out = os.tmpfile()
+ err = out
+ else:
+ err = os.tmpfile()
try:
- subprocess.check_call(cmd, stdout=out, stderr=out, cwd=destdir, shell=True)
+ subprocess.check_call(cmd, stdout=out, stderr=err, cwd=destdir, shell=isinstance(cmd, str))
except subprocess.CalledProcessError,e:
- out.seek(0)
+ err.seek(0)
if printerr:
- logger.error("%s" % out.read())
+ logger.error("%s" % err.read())
raise e
- out.seek(0)
- output = out.read()
+ err.seek(0)
+ output = err.read()
logger.debug("output: %s" % output )
return output