mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Make subprocess2.check_call() compliant with subprocess.check_call().
Rename check_call to check_call_out. It's a quite specific need when stderr is needed or when the user doesn't want the default arguments of check_output. R=dpranke@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org/6882127 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@83023 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@@ -191,7 +191,8 @@ class SvnMixIn(object):
|
||||
"""Runs svn and throws an exception if the command failed."""
|
||||
kwargs.setdefault('cwd', self.project_path)
|
||||
kwargs.setdefault('stdout', self.VOID)
|
||||
return subprocess2.check_call(self._add_svn_flags(args, False), **kwargs)
|
||||
return subprocess2.check_call_out(
|
||||
self._add_svn_flags(args, False), **kwargs)
|
||||
|
||||
def _check_output_svn(self, args, **kwargs):
|
||||
"""Runs svn and throws an exception if the command failed.
|
||||
@@ -429,7 +430,7 @@ class GitCheckoutBase(CheckoutBase):
|
||||
def _check_call_git(self, args, **kwargs):
|
||||
kwargs.setdefault('cwd', self.project_path)
|
||||
kwargs.setdefault('stdout', self.VOID)
|
||||
return subprocess2.check_call(['git'] + args, **kwargs)
|
||||
return subprocess2.check_call_out(['git'] + args, **kwargs)
|
||||
|
||||
def _call_git(self, args, **kwargs):
|
||||
"""Like check_call but doesn't throw on failure."""
|
||||
|
||||
@@ -256,7 +256,7 @@ def call(args, **kwargs):
|
||||
return communicate(args, **kwargs)[1]
|
||||
|
||||
|
||||
def check_call(args, **kwargs):
|
||||
def check_call_out(args, **kwargs):
|
||||
"""Improved version of subprocess.check_call().
|
||||
|
||||
Returns (stdout, stderr), unlike subprocess.check_call().
|
||||
@@ -268,6 +268,12 @@ def check_call(args, **kwargs):
|
||||
return out
|
||||
|
||||
|
||||
def check_call(args, **kwargs):
|
||||
"""Emulate subprocess.check_call()."""
|
||||
check_call_out(args, **kwargs)
|
||||
return 0
|
||||
|
||||
|
||||
def capture(args, **kwargs):
|
||||
"""Captures stdout of a process call and returns it.
|
||||
|
||||
@@ -287,9 +293,9 @@ def capture(args, **kwargs):
|
||||
|
||||
|
||||
def check_output(args, **kwargs):
|
||||
"""Captures stdout of a process call and returns it.
|
||||
"""Emulates subprocess.check_output().
|
||||
|
||||
Returns stdout.
|
||||
Captures stdout of a process call and returns stdout only.
|
||||
|
||||
- Discards stderr. By default sets stderr=STDOUT.
|
||||
- Throws if return code is not 0.
|
||||
@@ -302,4 +308,4 @@ def check_output(args, **kwargs):
|
||||
kwargs['stdout'] = PIPE
|
||||
if kwargs.get('stderr') is None:
|
||||
kwargs['stderr'] = STDOUT
|
||||
return check_call(args, **kwargs)[0]
|
||||
return check_call_out(args, **kwargs)[0]
|
||||
|
||||
@@ -82,7 +82,7 @@ class Subprocess2Test(unittest.TestCase):
|
||||
def test_check_call_defaults(self):
|
||||
results = self._fake_communicate()
|
||||
self.assertEquals(
|
||||
['stdout', 'stderr'], subprocess2.check_call(['foo'], a=True))
|
||||
['stdout', 'stderr'], subprocess2.check_call_out(['foo'], a=True))
|
||||
expected = {
|
||||
'args': ['foo'],
|
||||
'a':True,
|
||||
|
||||
Reference in New Issue
Block a user