From 6e2a67576afc1dcb4a947851351e6b3c02564d07 Mon Sep 17 00:00:00 2001 From: Adeodato Simó Date: Sat, 12 Apr 2008 14:19:23 +0200 Subject: 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) --- gbp/command_wrappers.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py index 26064cda..e986113d 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: -- cgit v1.2.3