| Submitter | Christopher Larson |
|---|---|
| Date | 2010-01-19 20:00:41 |
| Message ID | <1263931241-18389-1-git-send-email-clarson@mvista.com> |
| Download | mbox | patch |
| Permalink | /patch/1484/ |
| State | Applied |
| Headers | show |
Comments
On Tue, 2010-01-19 at 10:00 +0000, Christopher Larson wrote: > 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> > --- > 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:
Patch
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:
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> --- classes/base.bbclass | 37 +++++++++++++++++++++++++++++++------ 1 files changed, 31 insertions(+), 6 deletions(-)