aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdeodato Simó <dato@net.com.org.es>2008-04-12 14:19:23 +0200
committerGuido Guenther <agx@sigxcpu.org>2008-04-14 14:55:40 +0200
commit6e2a67576afc1dcb4a947851351e6b3c02564d07 (patch)
tree8c53e3ee53b08823a592826817de62595edc76e2
parent636a4b2e7720817fa3f84e415a963e343b1546a4 (diff)
Add support for passing extra env. vars to Command objects.
When creating a Command(), pass an "extra_env" argument to __init__. This should be a dict of additional variables to pass to the command. (cherry picked from commit cba467a70664d8f8b1e61e4bb7beda421aec543f)
-rw-r--r--gbp/command_wrappers.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py
index 26064cd..e986113 100644
--- a/gbp/command_wrappers.py
+++ b/gbp/command_wrappers.py
@@ -8,6 +8,7 @@ git-buildpackage and friends
import subprocess
import sys
+import os
import os.path
from errors import GbpError
@@ -23,11 +24,16 @@ class Command(object):
"""
verbose = False
- def __init__(self, cmd, args=[], shell=False):
+ def __init__(self, cmd, args=[], shell=False, extra_env=None):
self.cmd = cmd
self.args = args
self.run_error = "Couldn't run '%s'" % (" ".join([self.cmd] + self.args))
self.shell = shell
+ if extra_env is not None:
+ self.env = os.environ.copy()
+ self.env.update(extra_env)
+ else:
+ self.env = None
def __run(self, args):
"""run self.cmd adding args as additional arguments"""
@@ -37,7 +43,7 @@ class Command(object):
cmd = [ self.cmd ] + self.args + args
if self.shell: # subprocess.call only cares about the first argument if shell=True
cmd = " ".join(cmd)
- retcode = subprocess.call(cmd, shell=self.shell)
+ retcode = subprocess.call(cmd, shell=self.shell, env=self.env)
if retcode < 0:
print >>sys.stderr, "%s was terminated by signal %d" % (self.cmd, -retcode)
elif retcode > 0: