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

Side by Side Diff: build/android/pylib/device/adb_wrapper.py

Issue 636273004: Make TimeoutRetryThread's stoppable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: do not catch CommandFailedError in _WaitFor Created 6 years, 1 month 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
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
11 import errno 11 import errno
12 import os 12 import os
13 import time
13 14
14 from pylib import cmd_helper 15 from pylib import cmd_helper
15 from pylib.device import decorators 16 from pylib.device import decorators
16 from pylib.device import device_errors 17 from pylib.device import device_errors
18 from pylib.utils import timeout_retry
17 19
18 20
19 _DEFAULT_TIMEOUT = 30 21 _DEFAULT_TIMEOUT = 30
20 _DEFAULT_RETRIES = 2 22 _DEFAULT_RETRIES = 2
21 23
22 24
23 def _VerifyLocalFileExists(path): 25 def _VerifyLocalFileExists(path):
24 """Verifies a local file exists. 26 """Verifies a local file exists.
25 27
26 Args: 28 Args:
(...skipping 10 matching lines...) Expand all
37 """A wrapper around a local Android Debug Bridge executable.""" 39 """A wrapper around a local Android Debug Bridge executable."""
38 40
39 def __init__(self, device_serial): 41 def __init__(self, device_serial):
40 """Initializes the AdbWrapper. 42 """Initializes the AdbWrapper.
41 43
42 Args: 44 Args:
43 device_serial: The device serial number as a string. 45 device_serial: The device serial number as a string.
44 """ 46 """
45 self._device_serial = str(device_serial) 47 self._device_serial = str(device_serial)
46 48
49 @classmethod
50 def Wait(cls, secs):
51 """Wait for the specified ammount of seconds.
jbudorick 2014/10/30 02:27:03 nit: ammount -> amount
52
53 A drop-in replacement for time.sleep, which just waits for a number of
54 seconds. After the wait is over, however, the method checks to see whether
55 we're running under a timed-out thread and raises an exception if needed.
56
57 Args:
58 secs: the number of seconds to sleep
59 """
60 timeout_thread = timeout_retry.GetTimeoutThread()
61 if timeout_thread:
62 remaining = timeout_thread.RemainingTime()
63 if remaining is not None and remaining < secs:
64 # no need to wait, we would time out anyway
jbudorick 2014/10/30 02:27:02 nit: Add a log message here (probably at warning)
perezju 2014/10/30 18:44:44 This is much better now in my new proposal. An exc
65 timeout_thread.RaiseTimeout()
66 time.sleep(secs)
67
47 # pylint: disable=W0613 68 # pylint: disable=W0613
48 @classmethod 69 @classmethod
49 @decorators.WithTimeoutAndRetries 70 @decorators.WithTimeoutAndRetries
50 def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True): 71 def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True):
51 cmd = ['adb'] + arg_list 72 cmd = ['adb'] + arg_list
52 exit_code, output = cmd_helper.GetCmdStatusAndOutput(cmd) 73 exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
74 cmd, timeout_retry.GetTimeoutThread().RemainingTime())
53 if exit_code != 0: 75 if exit_code != 0:
54 raise device_errors.AdbCommandFailedError( 76 raise device_errors.AdbCommandFailedError(
55 cmd, 'returned non-zero exit code %s, output: %s' % 77 cmd, 'returned non-zero exit code %d and output %r' %
56 (exit_code, output)) 78 (exit_code, output))
57 # This catches some errors, including when the device drops offline; 79 # This catches some errors, including when the device drops offline;
58 # unfortunately adb is very inconsistent with error reporting so many 80 # unfortunately adb is very inconsistent with error reporting so many
59 # command failures present differently. 81 # command failures present differently.
60 if check_error and output[:len('error:')] == 'error:': 82 if check_error and output[:len('error:')] == 'error:':
61 raise device_errors.AdbCommandFailedError(arg_list, output) 83 raise device_errors.AdbCommandFailedError(arg_list, output)
62 return output 84 return output
63 # pylint: enable=W0613 85 # pylint: enable=W0613
64 86
65 def _DeviceAdbCmd(self, arg_list, timeout, retries, check_error=True): 87 def _DeviceAdbCmd(self, arg_list, timeout, retries, check_error=True):
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 """Restarts the adbd daemon with root permissions, if possible. 409 """Restarts the adbd daemon with root permissions, if possible.
388 410
389 Args: 411 Args:
390 timeout: (optional) Timeout per try in seconds. 412 timeout: (optional) Timeout per try in seconds.
391 retries: (optional) Number of retries to attempt. 413 retries: (optional) Number of retries to attempt.
392 """ 414 """
393 output = self._DeviceAdbCmd(['root'], timeout, retries) 415 output = self._DeviceAdbCmd(['root'], timeout, retries)
394 if 'cannot' in output: 416 if 'cannot' in output:
395 raise device_errors.AdbCommandFailedError(['root'], output) 417 raise device_errors.AdbCommandFailedError(['root'], output)
396 418
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils.py » ('j') | build/android/pylib/device/device_utils.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698