Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: gcl.py

Issue 8344085: Revert r106358 "Get rid of RunShell*() functions in gcl.py to finish the conversion to subprocess2" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/gcl_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gcl.py
diff --git a/gcl.py b/gcl.py
index 171017e12946863daf43033ec63e1edea91630bc..8df5de1bcb9e54c2ef7697bdb5ae72c8e6d9c700 100755
--- a/gcl.py
+++ b/gcl.py
@@ -38,7 +38,7 @@ from scm import SVN
import subprocess2
from third_party import upload
-__version__ = '1.2.2'
+__version__ = '1.2.1'
CODEREVIEW_SETTINGS = {
@@ -69,7 +69,6 @@ DEFAULT_LINT_IGNORE_REGEX = r"$^"
REVIEWERS_REGEX = r'\s*R=(.+)'
-
def CheckHomeForFile(filename):
"""Checks the users home dir for the existence of the given file. Returns
the path to the file if it's there, or None if it is not.
@@ -228,6 +227,33 @@ def ErrorExit(msg):
sys.exit(1)
+def RunShellWithReturnCode(command, print_output=False):
+ """Executes a command and returns the output and the return code."""
+ p = subprocess2.Popen(
+ command, stdout=subprocess2.PIPE,
+ stderr=subprocess2.STDOUT, universal_newlines=True)
+ if print_output:
+ output_array = []
+ while True:
+ line = p.stdout.readline()
+ if not line:
+ break
+ if print_output:
+ print line.strip('\n')
+ output_array.append(line)
+ output = "".join(output_array)
+ else:
+ output = p.stdout.read()
+ p.wait()
+ p.stdout.close()
+ return output, p.returncode
+
+
+def RunShell(command, print_output=False):
+ """Executes a command and returns the output."""
+ return RunShellWithReturnCode(command, print_output)[0]
+
+
def FilterFlag(args, flag):
"""Returns True if the flag is present in args list.
@@ -988,25 +1014,19 @@ def CMDcommit(change_info, args):
handle, commit_filename = tempfile.mkstemp(text=True)
os.write(handle, commit_message)
os.close(handle)
- try:
- handle, targets_filename = tempfile.mkstemp(text=True)
- os.write(handle, "\n".join(change_info.GetFileNames()))
- os.close(handle)
- try:
- commit_cmd += ['--file=' + commit_filename]
- commit_cmd += ['--targets=' + targets_filename]
- # Change the current working directory before calling commit.
- previous_cwd = os.getcwd()
- os.chdir(change_info.GetLocalRoot())
- output = ''
- try:
- output = subprocess2.check_output(commit_cmd)
- except subprocess2.CalledProcessError, e:
- ErrorExit('Commit failed.\n%s' % e)
- finally:
- os.remove(commit_filename)
- finally:
- os.remove(targets_filename)
+
+ handle, targets_filename = tempfile.mkstemp(text=True)
+ os.write(handle, "\n".join(change_info.GetFileNames()))
+ os.close(handle)
+
+ commit_cmd += ['--file=' + commit_filename]
+ commit_cmd += ['--targets=' + targets_filename]
+ # Change the current working directory before calling commit.
+ previous_cwd = os.getcwd()
+ os.chdir(change_info.GetLocalRoot())
+ output = RunShell(commit_cmd, True)
+ os.remove(commit_filename)
+ os.remove(targets_filename)
if output.find("Committed revision") != -1:
change_info.Delete()
@@ -1284,7 +1304,7 @@ def CMDdiff(args):
cmd = ['svn', 'diff']
cmd.extend([os.path.join(root, x) for x in files])
cmd.extend(args)
- return subprocess2.call(cmd)
+ return RunShellWithReturnCode(cmd, print_output=True)[1]
@no_args
@@ -1367,7 +1387,7 @@ def CMDpassthru(args):
root = GetRepositoryRoot()
change_info = ChangeInfo.Load(args[1], root, True, True)
args.extend([os.path.join(root, x) for x in change_info.GetFileNames()])
- return subprocess2.call(args)
+ return RunShellWithReturnCode(args, print_output=True)[1]
def Command(name):
« no previous file with comments | « no previous file | tests/gcl_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698