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

Unified Diff: subprocess2.py

Issue 6877005: Make subprocess2.call() returned values to be the same as subprocess.call(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 8 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/subprocess2_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: subprocess2.py
diff --git a/subprocess2.py b/subprocess2.py
index 3cc79aeb899bcfa1650c79db36d459c2c71ff9db..9997002be9b09b7c330bbd7cc824e9ce6b692258 100644
--- a/subprocess2.py
+++ b/subprocess2.py
@@ -192,7 +192,7 @@ def Popen(args, **kwargs):
raise
-def call(args, timeout=None, **kwargs):
+def communicate(args, timeout=None, **kwargs):
"""Wraps subprocess.Popen().communicate().
Returns ((stdout, stderr), returncode).
@@ -240,12 +240,24 @@ def call(args, timeout=None, **kwargs):
return out, proc.returncode
+def call(args, **kwargs):
+ """Emulates subprocess.call().
+
+ Automatically convert stdout=PIPE or stderr=PIPE to VOID.
+ """
+ if kwargs.get('stdout') == PIPE:
+ kwargs['stdout'] = VOID
+ if kwargs.get('stderr') == PIPE:
+ kwargs['stderr'] = VOID
+ return communicate(args, **kwargs)[1]
+
+
def check_call(args, **kwargs):
"""Improved version of subprocess.check_call().
Returns (stdout, stderr), unlike subprocess.check_call().
"""
- out, returncode = call(args, **kwargs)
+ out, returncode = communicate(args, **kwargs)
if returncode:
raise CalledProcessError(
returncode, args, kwargs.get('cwd'), out[0], out[1])
@@ -267,7 +279,7 @@ def capture(args, **kwargs):
kwargs['stdout'] = PIPE
if kwargs.get('stderr') is None:
kwargs['stderr'] = STDOUT
- return call(args, **kwargs)[0][0]
+ return communicate(args, **kwargs)[0][0]
def check_output(args, **kwargs):
« no previous file with comments | « no previous file | tests/subprocess2_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698