From: Patrick Ohly <patrick.ohly@intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 1/2] combo-layer: runcmd() with separate output
Date: Tue, 10 Mar 2015 11:10:48 +0100 [thread overview]
Message-ID: <1425982249-17652-2-git-send-email-patrick.ohly@intel.com> (raw)
In-Reply-To: <1425982249-17652-1-git-send-email-patrick.ohly@intel.com>
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>
---
scripts/combo-layer | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/scripts/combo-layer b/scripts/combo-layer
index 5f10e83..fb3fb50 100755
--- a/scripts/combo-layer
+++ b/scripts/combo-layer
@@ -149,23 +149,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
--
2.1.4
next prev parent reply other threads:[~2015-03-10 10:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-10 10:10 [PATCH 0/2] combo-layer: exclude files Patrick Ohly
2015-03-10 10:10 ` Patrick Ohly [this message]
2015-03-12 18:33 ` [PATCH 1/2] combo-layer: runcmd() with separate output Paul Eggleton
2015-03-10 10:10 ` [PATCH 2/2] combo-layer: exclude files Patrick Ohly
2015-03-12 18:37 ` Paul Eggleton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1425982249-17652-2-git-send-email-patrick.ohly@intel.com \
--to=patrick.ohly@intel.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox