Index: gclient_utils.py |
diff --git a/gclient_utils.py b/gclient_utils.py |
index 3a6438d1c0226dd1bf8d1d288e574dbdef0ed399..81379c30e886d110b9aaf23bda819cf6bf72dcbe 100644 |
--- a/gclient_utils.py |
+++ b/gclient_utils.py |
@@ -25,6 +25,30 @@ import xml.dom.minidom |
import xml.parsers.expat |
+class CheckCallError(OSError): |
+ """CheckCall() returned non-0.""" |
+ def __init__(self, command, cwd, retcode, stdout): |
+ OSError.__init__(self, command, cwd, retcode, stdout) |
+ self.command = command |
+ self.cwd = cwd |
+ self.retcode = retcode |
+ self.stdout = stdout |
+ |
+ |
+def CheckCall(command, cwd=None): |
+ """Like subprocess.check_call() but returns stdout. |
+ |
+ Works on python 2.4 |
+ """ |
+ process = subprocess.Popen(command, cwd=cwd, |
+ shell=sys.platform.startswith('win'), |
+ stdout=subprocess.PIPE) |
+ output = process.communicate()[0] |
+ if process.retcode: |
+ raise CheckCallError(command, cwd, process.retcode, output) |
+ return output |
+ |
+ |
def SplitUrlRevision(url): |
"""Splits url and returns a two-tuple: url, rev""" |
if url.startswith('ssh:'): |