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

Unified Diff: telemetry/third_party/webpagereplay/adb_install_cert.py

Issue 1848323002: Roll webpagereplay to latest version (Closed) Base URL: https://github.com/catapult-project/catapult@master
Patch Set: Created 4 years, 9 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 | « telemetry/third_party/webpagereplay/README.chromium ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/third_party/webpagereplay/adb_install_cert.py
diff --git a/telemetry/third_party/webpagereplay/adb_install_cert.py b/telemetry/third_party/webpagereplay/adb_install_cert.py
index 61d2973a945c0ae2ed83c43bb3a70ad699ac4731..1b5c8c2542875db8ab5559cf3ec4bcaac762e6d5 100644
--- a/telemetry/third_party/webpagereplay/adb_install_cert.py
+++ b/telemetry/third_party/webpagereplay/adb_install_cert.py
@@ -54,18 +54,41 @@ class AndroidCertInstaller(object):
def _run_cmd(cmd, dirname=None):
return subprocess.check_output(cmd, cwd=dirname)
- def _adb(self, *args):
- """Runs the adb command."""
+ def _get_adb_cmd(self, *args):
cmd = ['adb']
if self.device_id:
cmd.extend(['-s', self.device_id])
cmd.extend(args)
- return self._run_cmd(cmd)
+ return cmd
+
+ def _adb(self, *args):
+ """Runs the adb command."""
+ return self._run_cmd(self._get_adb_cmd(*args))
def _adb_shell(self, *args):
- cmd = ['shell']
- cmd.extend(args)
- return self._adb(*cmd)
+ """Runs the adb shell command."""
+ # We are not using self._adb() because adb shell return 0 even if the
+ # command has failed. This method is taking care of checking the actual
+ # return code of the command line ran on the device.
+ RETURN_CODE_PREFIX = '%%%s%% ' % __file__
+ adb_cmd = self._get_adb_cmd('shell', '(%s); echo %s$?' % (
+ subprocess.list2cmdline(args), RETURN_CODE_PREFIX))
+ process = subprocess.Popen(adb_cmd, stdout=subprocess.PIPE)
+ adb_stdout, _ = process.communicate()
+ if process.returncode != 0:
+ raise subprocess.CalledProcessError(
+ cmd=adb_cmd, returncode=process.returncode, output=adb_stdout)
+ assert adb_stdout[-1] == '\n'
+ prefix_pos = adb_stdout.rfind(RETURN_CODE_PREFIX)
+ assert prefix_pos != -1, \
+ 'Couldn\'t find "%s" at the end of the output of %s' % (
+ RETURN_CODE_PREFIX, subprocess.list2cmdline(adb_cmd))
+ returncode = int(adb_stdout[prefix_pos + len(RETURN_CODE_PREFIX):])
+ stdout = adb_stdout[:prefix_pos]
+ if returncode != 0:
+ raise subprocess.CalledProcessError(
+ cmd=args, returncode=returncode, output=stdout)
+ return stdout
def _adb_su_shell(self, *args):
"""Runs command as root."""
« no previous file with comments | « telemetry/third_party/webpagereplay/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698