[oe] [PATCH] base.bbclass: add popen/system convenience functions

Chris Larson clarson at mvista.com
Tue Jan 19 20:00:41 UTC 2010


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 at mvista.com>
---
 classes/base.bbclass |   37 +++++++++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/classes/base.bbclass b/classes/base.bbclass
index f67773a..edda75b 100644
--- a/classes/base.bbclass
+++ b/classes/base.bbclass
@@ -1,5 +1,36 @@
 BB_DEFAULT_TASK ?= "build"
 
+python () {
+    env = {}
+    for v in d.keys():
+        if d.getVarFlag(v, "export"):
+            env[v] = d.getVar(v, True) or ""
+    d.setVar("__oe_popen_env", env)
+}
+
+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:
+        kwargs["env"] = d.getVar("__oe_popen_env", 0)
+
+    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
@@ -750,12 +781,6 @@ base_do_buildall() {
 	:
 }
 
-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_unpack_file(file, data, url = None):
 	import subprocess
 	if not url:
-- 
1.6.6





More information about the Openembedded-devel mailing list