combo-layer: runcmd() enhancements
Allow setting the environment. Due to a subprocess quirk, it must always be set explicitly (reuses the one from the previous call if not set, instead of falling back to os.environ). Embedding nul characters will be useful for parsing git output more reliably; support dumping such output a bit better. (From OE-Core rev: 0af4fadafce690fc8357196cf7247bd222c08d10) Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
aa4de3c8c5
commit
107c35e87e
|
@ -174,7 +174,7 @@ class Configuration(object):
|
||||||
logger.error("ERROR: patchutils package is missing, please install it (e.g. # apt-get install patchutils)")
|
logger.error("ERROR: patchutils package is missing, please install it (e.g. # apt-get install patchutils)")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def runcmd(cmd,destdir=None,printerr=True,out=None):
|
def runcmd(cmd,destdir=None,printerr=True,out=None,env=None):
|
||||||
"""
|
"""
|
||||||
execute command, raise CalledProcessError if fail
|
execute command, raise CalledProcessError if fail
|
||||||
return output if succeed
|
return output if succeed
|
||||||
|
@ -186,7 +186,7 @@ def runcmd(cmd,destdir=None,printerr=True,out=None):
|
||||||
else:
|
else:
|
||||||
err = os.tmpfile()
|
err = os.tmpfile()
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(cmd, stdout=out, stderr=err, cwd=destdir, shell=isinstance(cmd, str))
|
subprocess.check_call(cmd, stdout=out, stderr=err, cwd=destdir, shell=isinstance(cmd, str), env=env or os.environ)
|
||||||
except subprocess.CalledProcessError,e:
|
except subprocess.CalledProcessError,e:
|
||||||
err.seek(0)
|
err.seek(0)
|
||||||
if printerr:
|
if printerr:
|
||||||
|
@ -195,7 +195,7 @@ def runcmd(cmd,destdir=None,printerr=True,out=None):
|
||||||
|
|
||||||
err.seek(0)
|
err.seek(0)
|
||||||
output = err.read()
|
output = err.read()
|
||||||
logger.debug("output: %s" % output )
|
logger.debug("output: %s" % output.replace(chr(0), '\\0'))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def action_init(conf, args):
|
def action_init(conf, args):
|
||||||
|
|
Loading…
Reference in New Issue