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

Side by Side Diff: devil/devil/android/sdk/adb_wrapper.py

Issue 3002993002: devil: Raise DeviceUnreachableError on cmd output "waiting for device" (Closed)
Patch Set: Created 3 years, 4 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 | « no previous file | devil/devil/android/sdk/adb_wrapper_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """This module wraps Android's adb tool. 5 """This module wraps Android's adb tool.
6 6
7 This is a thin wrapper around the adb interface. Any additional complexity 7 This is a thin wrapper around the adb interface. Any additional complexity
8 should be delegated to a higher level (ex. DeviceUtils). 8 should be delegated to a higher level (ex. DeviceUtils).
9 """ 9 """
10 10
(...skipping 23 matching lines...) Expand all
34 34
35 DEFAULT_TIMEOUT = 30 35 DEFAULT_TIMEOUT = 30
36 DEFAULT_RETRIES = 2 36 DEFAULT_RETRIES = 2
37 37
38 _ADB_VERSION_RE = re.compile(r'Android Debug Bridge version (\d+\.\d+\.\d+)') 38 _ADB_VERSION_RE = re.compile(r'Android Debug Bridge version (\d+\.\d+\.\d+)')
39 _EMULATOR_RE = re.compile(r'^emulator-[0-9]+$') 39 _EMULATOR_RE = re.compile(r'^emulator-[0-9]+$')
40 _DEVICE_NOT_FOUND_RE = re.compile(r"error: device '(?P<serial>.+)' not found") 40 _DEVICE_NOT_FOUND_RE = re.compile(r"error: device '(?P<serial>.+)' not found")
41 _READY_STATE = 'device' 41 _READY_STATE = 'device'
42 _VERITY_DISABLE_RE = re.compile(r'Verity (already )?disabled') 42 _VERITY_DISABLE_RE = re.compile(r'Verity (already )?disabled')
43 _VERITY_ENABLE_RE = re.compile(r'Verity (already )?enabled') 43 _VERITY_ENABLE_RE = re.compile(r'Verity (already )?enabled')
44 _WAITING_FOR_DEVICE_RE = re.compile(r'- waiting for device -')
44 45
45 46
46 def VerifyLocalFileExists(path): 47 def VerifyLocalFileExists(path):
47 """Verifies a local file exists. 48 """Verifies a local file exists.
48 49
49 Args: 50 Args:
50 path: Path to the local file. 51 path: Path to the local file.
51 52
52 Raises: 53 Raises:
53 IOError: If the file doesn't exist. 54 IOError: If the file doesn't exist.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 except OSError as e: 263 except OSError as e:
263 if e.errno in (errno.ENOENT, errno.ENOEXEC): 264 if e.errno in (errno.ENOENT, errno.ENOEXEC):
264 raise device_errors.NoAdbError(msg=str(e)) 265 raise device_errors.NoAdbError(msg=str(e))
265 else: 266 else:
266 raise 267 raise
267 268
268 # Best effort to catch errors from adb; unfortunately adb is very 269 # Best effort to catch errors from adb; unfortunately adb is very
269 # inconsistent with error reporting so many command failures present 270 # inconsistent with error reporting so many command failures present
270 # differently. 271 # differently.
271 if status != 0 or (check_error and output.startswith('error:')): 272 if status != 0 or (check_error and output.startswith('error:')):
272 m = _DEVICE_NOT_FOUND_RE.match(output) 273 not_found_m = _DEVICE_NOT_FOUND_RE.match(output)
273 if m is not None and m.group('serial') == device_serial: 274 device_waiting_m = _WAITING_FOR_DEVICE_RE.match(output)
275 if device_waiting_m is not None or (not_found_m is not None and
jbudorick 2017/08/19 00:22:13 nit: this would be a bit easier to read w/ the lin
bpastene 2017/08/19 00:50:31 Done.
276 not_found_m.group('serial') == device_serial):
274 raise device_errors.DeviceUnreachableError(device_serial) 277 raise device_errors.DeviceUnreachableError(device_serial)
275 else: 278 else:
276 raise device_errors.AdbCommandFailedError( 279 raise device_errors.AdbCommandFailedError(
277 args, output, status, device_serial) 280 args, output, status, device_serial)
278 281
279 return output 282 return output
280 # pylint: enable=unused-argument 283 # pylint: enable=unused-argument
281 284
282 def _RunDeviceAdbCmd(self, args, timeout, retries, check_error=True): 285 def _RunDeviceAdbCmd(self, args, timeout, retries, check_error=True):
283 """Runs an adb command on the device associated with this object. 286 """Runs an adb command on the device associated with this object.
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 @property 930 @property
928 def is_emulator(self): 931 def is_emulator(self):
929 return _EMULATOR_RE.match(self._device_serial) 932 return _EMULATOR_RE.match(self._device_serial)
930 933
931 @property 934 @property
932 def is_ready(self): 935 def is_ready(self):
933 try: 936 try:
934 return self.GetState() == _READY_STATE 937 return self.GetState() == _READY_STATE
935 except device_errors.CommandFailedError: 938 except device_errors.CommandFailedError:
936 return False 939 return False
OLDNEW
« no previous file with comments | « no previous file | devil/devil/android/sdk/adb_wrapper_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698