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

Side by Side 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, 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 unified diff | Download patch
« no previous file with comments | « telemetry/third_party/webpagereplay/README.chromium ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 Google Inc. All Rights Reserved. 1 # Copyright 2014 Google Inc. All Rights Reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 self.cert_path = cert_path 47 self.cert_path = cert_path
48 self.file_name = os.path.basename(self.cert_path) 48 self.file_name = os.path.basename(self.cert_path)
49 self.reformatted_cert_fname = None 49 self.reformatted_cert_fname = None
50 self.reformatted_cert_path = None 50 self.reformatted_cert_path = None
51 self.android_cacerts_path = None 51 self.android_cacerts_path = None
52 52
53 @staticmethod 53 @staticmethod
54 def _run_cmd(cmd, dirname=None): 54 def _run_cmd(cmd, dirname=None):
55 return subprocess.check_output(cmd, cwd=dirname) 55 return subprocess.check_output(cmd, cwd=dirname)
56 56
57 def _adb(self, *args): 57 def _get_adb_cmd(self, *args):
58 """Runs the adb command."""
59 cmd = ['adb'] 58 cmd = ['adb']
60 if self.device_id: 59 if self.device_id:
61 cmd.extend(['-s', self.device_id]) 60 cmd.extend(['-s', self.device_id])
62 cmd.extend(args) 61 cmd.extend(args)
63 return self._run_cmd(cmd) 62 return cmd
63
64 def _adb(self, *args):
65 """Runs the adb command."""
66 return self._run_cmd(self._get_adb_cmd(*args))
64 67
65 def _adb_shell(self, *args): 68 def _adb_shell(self, *args):
66 cmd = ['shell'] 69 """Runs the adb shell command."""
67 cmd.extend(args) 70 # We are not using self._adb() because adb shell return 0 even if the
68 return self._adb(*cmd) 71 # command has failed. This method is taking care of checking the actual
72 # return code of the command line ran on the device.
73 RETURN_CODE_PREFIX = '%%%s%% ' % __file__
74 adb_cmd = self._get_adb_cmd('shell', '(%s); echo %s$?' % (
75 subprocess.list2cmdline(args), RETURN_CODE_PREFIX))
76 process = subprocess.Popen(adb_cmd, stdout=subprocess.PIPE)
77 adb_stdout, _ = process.communicate()
78 if process.returncode != 0:
79 raise subprocess.CalledProcessError(
80 cmd=adb_cmd, returncode=process.returncode, output=adb_stdout)
81 assert adb_stdout[-1] == '\n'
82 prefix_pos = adb_stdout.rfind(RETURN_CODE_PREFIX)
83 assert prefix_pos != -1, \
84 'Couldn\'t find "%s" at the end of the output of %s' % (
85 RETURN_CODE_PREFIX, subprocess.list2cmdline(adb_cmd))
86 returncode = int(adb_stdout[prefix_pos + len(RETURN_CODE_PREFIX):])
87 stdout = adb_stdout[:prefix_pos]
88 if returncode != 0:
89 raise subprocess.CalledProcessError(
90 cmd=args, returncode=returncode, output=stdout)
91 return stdout
69 92
70 def _adb_su_shell(self, *args): 93 def _adb_su_shell(self, *args):
71 """Runs command as root.""" 94 """Runs command as root."""
72 build_version_sdk = int(self._get_property('ro.build.version.sdk')) 95 build_version_sdk = int(self._get_property('ro.build.version.sdk'))
73 if build_version_sdk >= _ANDROID_M_BUILD_VERSION: 96 if build_version_sdk >= _ANDROID_M_BUILD_VERSION:
74 cmd = ['su', '0'] 97 cmd = ['su', '0']
75 else: 98 else:
76 cmd = ['su', '-c'] 99 cmd = ['su', '-c']
77 cmd.extend(args) 100 cmd.extend(args)
78 return self._adb_shell(*cmd) 101 return self._adb_shell(*cmd)
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 cert_installer = AndroidCertInstaller(args.device_id, args.cert_name, 258 cert_installer = AndroidCertInstaller(args.device_id, args.cert_name,
236 args.cert_path) 259 args.cert_path)
237 if args.remove: 260 if args.remove:
238 cert_installer.remove_cert() 261 cert_installer.remove_cert()
239 else: 262 else:
240 cert_installer.install_cert(args.overwrite) 263 cert_installer.install_cert(args.overwrite)
241 264
242 265
243 if __name__ == '__main__': 266 if __name__ == '__main__':
244 sys.exit(main()) 267 sys.exit(main())
OLDNEW
« 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