Add cwd option to gbp.command_wrappers.Command
authorGuido Günther <agx@sigxcpu.org>
Fri, 21 Oct 2011 16:45:58 +0000 (18:45 +0200)
committerGuido Günther <agx@sigxcpu.org>
Fri, 21 Oct 2011 19:10:45 +0000 (21:10 +0200)
gbp/command_wrappers.py

index 6b1c834..dd7bc4c 100644 (file)
@@ -36,12 +36,14 @@ class Command(object):
     Wraps a shell command, so we don't have to store any kind of command line options in 
     one of the git-buildpackage commands
     """
-    def __init__(self, cmd, args=[], shell=False, extra_env=None):
+
+    def __init__(self, cmd, args=[], shell=False, extra_env=None, cwd=None):
         self.cmd = cmd
         self.args = args
         self.run_error = "Couldn't run '%s'" % (" ".join([self.cmd] + self.args))
         self.shell = shell
         self.retcode = 1
+        self.cwd = cwd
         if extra_env is not None:
             self.env = os.environ.copy()
             self.env.update(extra_env)
@@ -58,7 +60,8 @@ 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)
-        return subprocess.call(cmd, shell=self.shell, env=self.env, preexec_fn=default_sigpipe)
+        return subprocess.call(cmd, cwd=self.cwd, shell=self.shell,
+                               env=self.env, preexec_fn=default_sigpipe)
 
     def __run(self, args):
         """