aboutsummaryrefslogtreecommitdiffstats
path: root/classes/utils.bbclass
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-08-24 14:06:01 -0700
committerChris Larson <chris_larson@mentor.com>2010-08-25 07:31:52 -0700
commit013d632d46ef474086db46158c74f2ae158ae9ff (patch)
tree8affc68f88e74433a36c88defe9e67de562f54bd /classes/utils.bbclass
parent962aacf151e224482ba3c34aafbbc3bfe8d2a66b (diff)
downloadopenembedded-013d632d46ef474086db46158c74f2ae158ae9ff.tar.gz
oe.utils: add oe_run convenience function
This one is intended to be used from python snippets in variables. It returns the stdout of the subprocess and raises an exception if the exit code isn't 0. Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'classes/utils.bbclass')
-rw-r--r--classes/utils.bbclass18
1 files changed, 18 insertions, 0 deletions
diff --git a/classes/utils.bbclass b/classes/utils.bbclass
index 4840c4f233..0a7a045cc4 100644
--- a/classes/utils.bbclass
+++ b/classes/utils.bbclass
@@ -63,6 +63,24 @@ def subprocess_setup():
# non-Python subprocesses expect.
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+def oe_run(d, cmd, **kwargs):
+ """Convenience function to run a command and return its output, raising an
+ exception when the command fails"""
+ from subprocess import PIPE
+
+ options = {
+ "stdout": PIPE,
+ "stderr": PIPE,
+ "shell": True,
+ }
+ options.update(kwargs)
+ pipe = oe_popen(d, cmd, **options)
+ stdout, stderr = pipe.communicate()
+ if pipe.returncode != 0:
+ raise RuntimeError("Execution of '%s' failed with '%s':\n%s" %
+ (cmd, pipe.returncode, stderr))
+ return stdout
+
def oe_popen(d, cmd, **kwargs):
""" Convenience function to call out processes with our exported
variables in the environment.