aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2010-07-02 19:54:10 +0200
committerGuido Günther <agx@sigxcpu.org>2010-07-04 16:53:22 +0200
commit6e9f3874a5f4a2549045dda0146c0263d258b631 (patch)
tree923c4cc00200e5310776b0d70dfee06b3be1d827 /gbp
parentb59ed0e946422628b09ec60c35e207f585580fe7 (diff)
Allow to pass extra_env to __git_getoutput and __git_inout
Git-Dch: Ignore
Diffstat (limited to 'gbp')
-rw-r--r--gbp/git.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/gbp/git.py b/gbp/git.py
index 32bed451..7d03e287 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -29,22 +29,34 @@ class GitRepository(object):
if os.getcwd() != self.path:
raise GitRepositoryError
- def __git_getoutput(self, command, args=[]):
+ def __build_env(self, extra_env):
+ """Prepare environment for subprocess calls"""
+ env = None
+ if extra_env is not None:
+ env = os.environ.copy()
+ env.update(extra_env)
+ return env
+
+ def __git_getoutput(self, command, args=[], extra_env=None):
"""exec a git command and return the output"""
output = []
- popen = subprocess.Popen(['git', command] + args, stdout=subprocess.PIPE)
+
+ env = self.__build_env(extra_env)
+ popen = subprocess.Popen(['git', command] + args, stdout=subprocess.PIPE, env=env)
while popen.poll() == None:
output += popen.stdout.readlines()
ret = popen.poll()
output += popen.stdout.readlines()
return output, ret
- def __git_inout(self, command, args, input):
+ def __git_inout(self, command, args, input, extra_env=None):
"""Send input and return output (stdout)"""
ret = False
+ env = self.__build_env(extra_env)
popen = subprocess.Popen(['git', command ] + args,
stdin=subprocess.PIPE,
- stdout=subprocess.PIPE)
+ stdout=subprocess.PIPE,
+ env=env)
(stdin, stderr) = popen.communicate(input)
if popen.returncode:
stdin = None