summaryrefslogtreecommitdiff
path: root/classes/utils.bbclass
diff options
context:
space:
mode:
authorChristopher Larson <clarson@mvista.com>2010-01-19 10:00:41 +0000
committerChris Larson <chris_larson@mentor.com>2010-03-21 18:31:40 -0700
commit02630483284a2f31b01e636210715ee1fb6e63b9 (patch)
tree75a74ab3f06c319ad76ec2a6eb0672ea06427c15 /classes/utils.bbclass
parent097e2a981e58fa52837c352283f503f190896433 (diff)
base.bbclass: add popen/system convenience functions
Provides oe_popen, which is a subprocess.Popen wrapper that automatically provides our exported variables in the environment, including the PATH, and oe_system, which is just a wrapper that acts like system. Signed-off-by: Chris Larson <clarson@mvista.com> Acked-by: Tom Rini <tom_rini@mentor.com>
Diffstat (limited to 'classes/utils.bbclass')
-rw-r--r--classes/utils.bbclass30
1 files changed, 30 insertions, 0 deletions
diff --git a/classes/utils.bbclass b/classes/utils.bbclass
index ecb00ec26e..6ff11dd4a7 100644
--- a/classes/utils.bbclass
+++ b/classes/utils.bbclass
@@ -1,3 +1,33 @@
+def subprocess_setup():
+ import signal
+ # Python installs a SIGPIPE handler by default. This is usually not what
+ # non-Python subprocesses expect.
+ signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+
+def oe_popen(d, cmd, **kwargs):
+ """ Convenience function to call out processes with our exported
+ variables in the environment.
+ """
+ from subprocess import Popen
+
+ if kwargs.get("env") is None:
+ env = d.getVar("__oe_popen_env", False)
+ if env is None:
+ env = {}
+ for v in d.keys():
+ if d.getVarFlag(v, "export"):
+ env[v] = d.getVar(v, True) or ""
+ d.setVar("__oe_popen_env", env)
+ kwargs["env"] = env
+
+ kwargs["preexec_fn"] = subprocess_setup
+
+ return Popen(cmd, **kwargs)
+
+def oe_system(d, cmd):
+ """ Popen based version of os.system. """
+ return oe_popen(d, cmd, shell=True).wait()
+
# like os.path.join but doesn't treat absolute RHS specially
def base_path_join(a, *p):
path = a