Use subprocess-native functionality for changing directory
authorAaron Bentley <abentley@panoramicfeedback.com>
Wed, 19 Jul 2006 14:14:03 +0000 (10:14 -0400)
committerAaron Bentley <abentley@panoramicfeedback.com>
Wed, 19 Jul 2006 14:14:03 +0000 (10:14 -0400)
libbe/bzr.py
libbe/rcs.py

index b53429ce266d322ad118e596b612b714a4c27eee..ddda334fb6ad28e89c88ab55735bba5d72fb2399 100644 (file)
@@ -25,14 +25,7 @@ def invoke_client(*args, **kwargs):
     expect = kwargs.get('expect', (0, 1))
     cl_args = ["bzr"]
     cl_args.extend(args)
-    if directory:
-        old_dir = os.getcwd()
-        os.chdir(directory)
-    try:
-        status,output,error = invoke(cl_args, expect)
-    finally:
-        if directory:
-            os.chdir(old_dir)
+    status,output,error = invoke(cl_args, expect, cwd=directory)
     return status, output
 
 def add_id(filename, paranoid=False):
index e7097aac57cf74a257d1bdf47934f31d7c2ab36f..fddfeb6c4622aefdfdef9049fad4d093e278c1f7 100644 (file)
@@ -44,8 +44,8 @@ class CommandError(Exception):
         self.err_str = err_str
         self.status = status
 
-def invoke(args, expect=(0,)):
-    q = Popen(args, stdout=PIPE, stderr=PIPE)
+def invoke(args, expect=(0,), cwd=None):
+    q = Popen(args, stdout=PIPE, stderr=PIPE, cwd=cwd)
     output, error = q.communicate()
     status = q.wait()
     if status not in expect: