[oe-commits] Christopher Larson : base.bbclass: add popen/system convenience functions
git version control
git at git.openembedded.org
Sun Jan 24 10:39:20 UTC 2010
Module: openembedded.git
Branch: holger/staging-branch
Commit: ca92de7475d4f7e93ff84831d7f2958502bd562a
URL: http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=ca92de7475d4f7e93ff84831d7f2958502bd562a
Author: Christopher Larson <clarson at mvista.com>
Date: Tue Jan 19 10:00:41 2010 +0000
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 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 2172aac..a9badc9 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
@@ -753,12 +784,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:
More information about the Openembedded-commits
mailing list