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

Unified Diff: lib/cros_build_lib.py

Issue 6575022: Revert "RunCommand was catching and rethrowing an exception, which seemed to generate" (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Created 9 years, 10 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 | lib/cros_build_lib_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/cros_build_lib.py
diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py
index 018bc10cf854c65642e9faf7a5910521e6413811..d7da384e09b48f605246b027fa6eaa4767dbdbd0 100644
--- a/lib/cros_build_lib.py
+++ b/lib/cros_build_lib.py
@@ -70,35 +70,28 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None,
(GetCallerName(), cmd, cwd))
for retry_count in range(num_retries + 1):
+ try:
+ proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin,
+ stdout=stdout, stderr=stderr)
+ (output, error) = proc.communicate(input)
+ if exit_code and retry_count == num_retries:
+ return proc.returncode
+
+ if proc.returncode == 0:
+ break
- # If it's not the first attempt, it's a retry
- if retry_count > 0 and print_cmd:
- Info('PROGRAM(%s) -> RunCommand: retrying %r in dir %s' %
- (GetCallerName(), cmd, cwd))
-
- proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin,
- stdout=stdout, stderr=stderr)
- (output, error) = proc.communicate(input)
-
- # if the command worked, don't retry any more.
- if proc.returncode == 0:
- break
-
- # If the command (and all retries) failed, handle error result
- if proc.returncode != 0:
- if error_ok:
- if print_cmd:
- Warning('Command "%r" failed.\n' % (cmd) +
- (error_message or error or output or ''))
- else:
raise RunCommandException('Command "%r" failed.\n' % (cmd) +
(error_message or error or output or ''))
-
- # return final result
- if exit_code:
- return proc.returncode
- else:
- return output
+ except RunCommandException as e:
+ if not error_ok and retry_count == num_retries:
+ raise e
+ else:
+ Warning(str(e))
+ if print_cmd:
+ Info('PROGRAM(%s) -> RunCommand: retrying %r in dir %s' %
+ (GetCallerName(), cmd, cwd))
+
+ return output
def RunCommandCaptureOutput(cmd, print_cmd=True, cwd=None, input=None,
« no previous file with comments | « no previous file | lib/cros_build_lib_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698