Commit 964fde12 authored by Robert Ma's avatar Robert Ma Committed by Commit Bot

[blinkpy] Always suppress stderr of git-cl

* stderr is now always ignored for git-cl (i.e. the optional argument is
  removed from GitCL.run as no one uses it).
* Instead of only excluding stderr from the return value, we now throws
  away stderr completely by redirecting it to DEVNULL so that the logs
  don't get polluted.

Some drive-by pylint fixes are applied.

Bug: 953499
Change-Id: I5668576e1cc3dfe2a83a7cafc12a09f4a0029358
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1628606
Auto-Submit: Robert Ma <robertma@chromium.org>
Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Commit-Queue: Robert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663599}
parent e42f7e47
...@@ -52,14 +52,11 @@ class GitCL(object): ...@@ -52,14 +52,11 @@ class GitCL(object):
self._cwd = cwd self._cwd = cwd
self._git_executable_name = Git.find_executable_name(host.executive, host.platform) self._git_executable_name = Git.find_executable_name(host.executive, host.platform)
def run(self, args, return_stderr=False): def run(self, args):
"""Runs git-cl with the given arguments and returns the output. """Runs git-cl with the given arguments and returns the output.
Args: Args:
args: A list of arguments passed to `git cl`. args: A list of arguments passed to `git cl`.
return_stderr: Whether to include stderr in the returned output (the
default is False because git-cl will show a warning when running
on Swarming bots with local git cache).
Returns: Returns:
A string (the output from git-cl). A string (the output from git-cl).
...@@ -67,7 +64,9 @@ class GitCL(object): ...@@ -67,7 +64,9 @@ class GitCL(object):
command = [self._git_executable_name, 'cl'] + args command = [self._git_executable_name, 'cl'] + args
if self._auth_refresh_token_json and args[0] in _COMMANDS_THAT_TAKE_REFRESH_TOKEN: if self._auth_refresh_token_json and args[0] in _COMMANDS_THAT_TAKE_REFRESH_TOKEN:
command += ['--auth-refresh-token-json', self._auth_refresh_token_json] command += ['--auth-refresh-token-json', self._auth_refresh_token_json]
return self._host.executive.run_command(command, cwd=self._cwd, return_stderr=return_stderr) # Suppress the stderr of git-cl because git-cl will show a warning when
# running on Swarming bots with local git cache.
return self._host.executive.run_command(command, cwd=self._cwd, ignore_stderr=True)
def trigger_try_jobs(self, builders, bucket=None): def trigger_try_jobs(self, builders, bucket=None):
"""Triggers try jobs on the given builders. """Triggers try jobs on the given builders.
......
...@@ -311,13 +311,17 @@ class Executive(object): ...@@ -311,13 +311,17 @@ class Executive(object):
error_handler=None, error_handler=None,
return_exit_code=False, return_exit_code=False,
return_stderr=True, return_stderr=True,
decode_output=True, debug_logging=True): ignore_stderr=False,
decode_output=True,
debug_logging=True):
"""Popen wrapper for convenience and to work around python bugs.""" """Popen wrapper for convenience and to work around python bugs."""
assert isinstance(args, list) or isinstance(args, tuple) assert isinstance(args, list) or isinstance(args, tuple)
start_time = time.time() start_time = time.time()
assert not (return_stderr and ignore_stderr)
stdin, string_to_communicate = self._compute_stdin(input) stdin, string_to_communicate = self._compute_stdin(input)
stderr = self.STDOUT if return_stderr else None stderr = self.STDOUT if return_stderr else (
self.DEVNULL if ignore_stderr else None)
process = self.popen(args, process = self.popen(args,
stdin=stdin, stdin=stdin,
......
...@@ -123,6 +123,7 @@ class MockExecutive(object): ...@@ -123,6 +123,7 @@ class MockExecutive(object):
error_handler=None, error_handler=None,
return_exit_code=False, return_exit_code=False,
return_stderr=True, return_stderr=True,
ignore_stderr=False,
decode_output=True, decode_output=True,
debug_logging=True): debug_logging=True):
self._append_call(args, cwd=cwd, input=input, env=env) self._append_call(args, cwd=cwd, input=input, env=env)
...@@ -156,7 +157,7 @@ class MockExecutive(object): ...@@ -156,7 +157,7 @@ class MockExecutive(object):
output = self._output output = self._output
if return_stderr: if return_stderr:
output += self._stderr output += self._stderr
if decode_output and type(output) is not unicode: if decode_output and not isinstance(output, unicode):
output = output.decode('utf-8') output = output.decode('utf-8')
return output return output
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment