changeset 359:9e73e6dc9823

Improved runcmd
author Joseph Turian <turian@iro.umontreal.ca>
date Wed, 02 Jul 2008 15:42:42 -0400
parents faece52be094
children 0e3af3c53ac7
files common/misc.py common/str.py common/string.py
diffstat 3 files changed, 21 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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):
     """
--- /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)
--- 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)