Remove trychange.RunCommand and replace it by gclient_utils.CheckCall.
TEST=unit tests
Review URL: http://codereview.chromium.org/502078
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@35052 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient_utils.py b/gclient_utils.py
index 3a6438d..81379c3 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -25,6 +25,30 @@
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:'):