[elbe-devel] [PATCH 02/20] shellhelper: add env_add keyword arg to shellhelper.system()
Torben Hohn
torben.hohn at linutronix.de
Fri Oct 12 11:27:48 CEST 2018
shellhelper.system is a small wrapper around os.system() that makes
it behave like subprocess.check_call(). The difference is that it
throws shellhelper.CommandError and not subprocess.CalledProcessError.
add support for the env_add parameter, and now use subprocess.call()
instead of os.system() because that does not allow passing an environment.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
elbepack/shellhelper.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/elbepack/shellhelper.py b/elbepack/shellhelper.py
index ab842e16..8de9e8c2 100644
--- a/elbepack/shellhelper.py
+++ b/elbepack/shellhelper.py
@@ -6,7 +6,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import os
-from subprocess import Popen, PIPE, STDOUT
+from subprocess import Popen, PIPE, STDOUT, call
class CommandError(Exception):
@@ -20,8 +20,12 @@ class CommandError(Exception):
self.returncode, self.cmd)
-def system(cmd, allow_fail=False):
- ret = os.system(cmd)
+def system(cmd, allow_fail=False, env_add=None):
+ new_env = os.environ.copy()
+ if env_add:
+ new_env.update(env_add)
+
+ ret = call(cmd, shell=True, env=new_env)
if ret != 0:
if not allow_fail:
--
2.11.0
More information about the elbe-devel
mailing list