diff options
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/bzr.py | 9 | ||||
-rw-r--r-- | libbe/rcs.py | 11 |
2 files changed, 7 insertions, 13 deletions
diff --git a/libbe/bzr.py b/libbe/bzr.py index b53429c..ddda334 100644 --- a/libbe/bzr.py +++ b/libbe/bzr.py @@ -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): diff --git a/libbe/rcs.py b/libbe/rcs.py index 549691a..1c12068 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -46,14 +46,15 @@ class CommandError(Exception): self.err_str = err_str self.status = status -def invoke(args, expect=(0,)): +def invoke(args, expect=(0,), cwd=None): + q = Popen(args, stdout=PIPE, stderr=PIPE, cwd=cwd) if sys.platform != "win32": - q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) + q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=cwd) else: # win32 don't have os.execvp() so have to run command in a shell - q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) - output = q.stdout.read() - error = q.stderr.read() + q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, + cwd=cwd) + output, error = q.communicate() status = q.wait() if status not in expect: raise CommandError(error, status) |