]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/shell.py
Add support for a working dir in wizard.shell
[wizard.git] / wizard / shell.py
index 723b50d4e533357cead8d952975ca97e405cae5c..d34740d61eaddc8d4b03341e69a4d01a9c22c0c1 100644 (file)
@@ -55,6 +55,7 @@ class Shell(object):
     """
     def __init__(self, dry = False):
         self.dry = dry
+        self.cwd = None
     def call(self, *args, **kwargs):
         """
         Performs a system call.  The actual executable and options should
@@ -127,7 +128,7 @@ class Shell(object):
         # ourself, and then setting up a
         # SIGCHILD handler to write a single byte to the pipe to get
         # us out of select() when a subprocess exits.
-        proc = subprocess.Popen(args, stdout=stdout, stderr=stderr, stdin=stdin)
+        proc = subprocess.Popen(args, stdout=stdout, stderr=stderr, stdin=stdin, cwd=self.cwd, )
         if self._async(proc, args, **kwargs):
             return proc
         stdout, stderr = proc.communicate(kwargs["input"])
@@ -215,6 +216,12 @@ class Shell(object):
         """
         kwargs["strip"] = True
         return self.call(*args, **kwargs)
+    def setcwd(self, cwd):
+        """
+        Sets the directory processes are executed in. This sets a value
+        to be passed as the ``cwd`` argument to ``subprocess.Popen``.
+        """
+        self.cwd = cwd
 
 class ParallelShell(Shell):
     """