aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2008-11-13 09:02:22 -0500
committerW. Trevor King <wking@drexel.edu>2008-11-13 09:02:22 -0500
commite5460203573f54a74c06f1b0922dcbbb1076f64c (patch)
tree58719885a3803a6c497e3be09e7f0828debb62ff
parent9055757a1b30c55798173f2454de8d4fa0676d40 (diff)
downloadbugseverywhere-e5460203573f54a74c06f1b0922dcbbb1076f64c.tar.gz
Catch OSErrors from Popen()s
From the subprocess module documentation: http://www.python.org/doc/2.5.2/lib/node530.html "The most common exception raised is OSError. This occurs, for example, when trying to execute a non-existent file. Applications should prepare for OSError exceptions." And from the os module documentation: http://www.python.org/doc/2.5.2/lib/module-os.html "exception error This exception is raised when a function returns a system-related error (not for illegal argument types or other incidental errors). This is also known as the built-in exception OSError. The accompanying value is a pair containing the numeric error code from errno and the corresponding string, as would be printed by the C function perror(). See the module errno, which contains names for the error codes defined by the underlying operating system. When exceptions are classes, this exception carries two attributes, errno and strerror. The first holds the value of the C errno variable, and the latter holds the corresponding error message from strerror(). For exceptions that involve a file system path (such as chdir() or unlink()), the exception instance will contain a third attribute, filename, which is the file name passed to the function." I turned this up running be/test.py, when it defaulted to the tla client which I didn't have installed. I don't have things working yet, so I can't create a bug at the moment...
-rw-r--r--libbe/arch.py6
-rw-r--r--libbe/rcs.py16
2 files changed, 15 insertions, 7 deletions
diff --git a/libbe/arch.py b/libbe/arch.py
index 624aea3..038325a 100644
--- a/libbe/arch.py
+++ b/libbe/arch.py
@@ -24,7 +24,11 @@ if client is None:
config.set_val("arch_client", client)
def invoke(args):
- q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+ try :
+ q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+ except OSError, e :
+ strerror = "%s\nwhile executing %s" % (e.args[1], args)
+ raise Exception("Command failed: %s" % strerror)
output = q.stdout.read()
error = q.stderr.read()
status = q.wait()
diff --git a/libbe/rcs.py b/libbe/rcs.py
index 77d6c9a..4487fba 100644
--- a/libbe/rcs.py
+++ b/libbe/rcs.py
@@ -59,12 +59,16 @@ class CommandError(Exception):
self.status = status
def invoke(args, expect=(0,), cwd=None):
- if sys.platform != "win32":
- 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,
- cwd=cwd)
+ try :
+ if sys.platform != "win32":
+ 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,
+ cwd=cwd)
+ except OSError, e :
+ strerror = "%s\nwhile executing %s" % (e.args[1], args)
+ raise CommandError(strerror, e.args[0])
output, error = q.communicate()
status = q.wait()
if status not in expect: