Fix `--verbose` handling in android_shell. This suppresses stderr for the sub-commands that we don't want to print to the terminal in addition to stdout. It turns out that, for instance, `adb push` prints it's status to stderr for some reason. R=qsr@chromium.org Review URL: https://codereview.chromium.org/1438123003 . Cr-Mirrored-From: https://github.com/domokit/mojo Cr-Mirrored-Commit: 8717d112517cfaa3d2eb3ea5088b0a9cf0cebf97
diff --git a/devtoolslib/android_shell.py b/devtoolslib/android_shell.py index bd0e684..20ec93c 100644 --- a/devtoolslib/android_shell.py +++ b/devtoolslib/android_shell.py
@@ -96,13 +96,14 @@ """ def __init__(self, adb_path="adb", target_device=None, logcat_tags=None, - verbose_pipe=None): + verbose=False): self.adb_path = adb_path self.target_device = target_device self.stop_shell_registered = False self.adb_running_as_root = None self.additional_logcat_tags = logcat_tags - self.verbose_pipe = verbose_pipe if verbose_pipe else open(os.devnull, 'w') + self.verbose_stdout = sys.stdout if verbose else open(os.devnull, 'w') + self.verbose_stderr = sys.stderr if verbose else self.verbose_stdout def _adb_command(self, args): """Forms an adb command from the given arguments, prepending the adb path @@ -208,7 +209,7 @@ # Wait for adbd to restart. subprocess.check_call( self._adb_command(['wait-for-device']), - stdout=self.verbose_pipe) + stdout=self.verbose_stdout, stderr=self.verbose_stderr) self.adb_running_as_root = True else: self.adb_running_as_root = False @@ -297,7 +298,7 @@ subprocess.check_call( self._adb_command(['install', '-r', shell_apk_path, '-i', _MOJO_SHELL_PACKAGE_NAME]), - stdout=self.verbose_pipe) + stdout=self.verbose_stdout, stderr=self.verbose_stderr) # Update the stamp on the device. with tempfile.NamedTemporaryFile() as fp: @@ -305,7 +306,8 @@ fp.flush() subprocess.check_call(self._adb_command(['push', fp.name, device_sha1_path]), - stdout=self.verbose_pipe) + stdout=self.verbose_stdout, + stderr=self.verbose_stderr) else: # To ensure predictable state after running install_apk(), we need to stop # the shell here, as this is what "adb install" implicitly does. @@ -359,13 +361,15 @@ temp.write('\n') temp.close() subprocess.check_call(self._adb_command( - ['push', temp.name, device_filename])) + ['push', temp.name, device_filename]), + stdout=self.verbose_stdout, stderr=self.verbose_stderr) finally: os.remove(temp.name) cmd += ['--es', 'argsFile', device_filename] - subprocess.check_call(cmd, stdout=self.verbose_pipe) + subprocess.check_call(cmd, stdout=self.verbose_stdout, + stderr=self.verbose_stderr) def stop_shell(self): """Stops the mojo shell."""
diff --git a/devtoolslib/shell_arguments.py b/devtoolslib/shell_arguments.py index 024ee51..5ee28b2 100644 --- a/devtoolslib/shell_arguments.py +++ b/devtoolslib/shell_arguments.py
@@ -9,7 +9,6 @@ """ import os.path -import sys import urlparse from devtoolslib.android_shell import AndroidShell @@ -195,11 +194,9 @@ ShellConfigurationException if shell abstraction could not be configured. """ if shell_config.android: - verbose_pipe = sys.stdout if shell_config.verbose else None - shell = AndroidShell(shell_config.adb_path, shell_config.target_device, logcat_tags=shell_config.logcat_tags, - verbose_pipe=verbose_pipe) + verbose=shell_config.verbose) device_status, error = shell.check_device( require_root=shell_config.require_root)