# HG changeset patch # User Joseph Turian # Date 1215027762 14400 # Node ID 9e73e6dc9823c4dabedb6c59e0c02fe9bff1c2d5 # Parent faece52be094ae462249ea896a0730585c20121c Improved runcmd diff -r faece52be094 -r 9e73e6dc9823 common/misc.py --- a/common/misc.py Tue Jul 01 21:09:24 2008 -0400 +++ b/common/misc.py Wed Jul 02 15:42:42 2008 -0400 @@ -1,10 +1,17 @@ -def runcmd(cmd): +def runcmd(args): """ - Run a command and return its output + Split args into a list, run this command, and return its output. + Raise RuntimeError if the command does not return 0. """ - import popen2 - (pin, pout) = popen2.popen2(cmd) - return pin.read() + import subprocess + print args + import string + proc = subprocess.Popen(string.split(args), stdout=subprocess.PIPE) + output = proc.communicate()[0] + if proc.returncode != 0: + import exceptions + raise exceptions.RuntimeError + return output def sign(i, assertions=True): """ diff -r faece52be094 -r 9e73e6dc9823 common/str.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/str.py Wed Jul 02 15:42:42 2008 -0400 @@ -0,0 +1,9 @@ +def percent(a, b): + """ + Return percentage string of a and b, e.g.: + "1 of 10 (10%)" + """ + assert a <= b + assert a >= 0 + assert b > 0 + return "%s of %s (%.2f%%)" % (a, b, 100.*a/b) diff -r faece52be094 -r 9e73e6dc9823 common/string.py --- a/common/string.py Tue Jul 01 21:09:24 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -def percent(a, b): - """ - Return percentage string of a and b, e.g.: - "1 of 10 (10%)" - """ - assert a <= b - assert a >= 0 - assert b > 0 - return "%s of %s (%.2f%%)" % (a, b, 100.*a/b)