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

Unified Diff: build/android/pylib/device/adb_wrapper.py

Issue 265743002: [Android] Switch to new interfaces of GetAVDs and RestartAdbServer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + nitfixes Created 6 years, 7 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
Index: build/android/pylib/device/adb_wrapper.py
diff --git a/build/android/pylib/device/adb_wrapper.py b/build/android/pylib/device/adb_wrapper.py
index 440a02c33564555c52654f904efb57fea97df243..a3139ba284bd09a09df6ed11c54a597a81e73b02 100644
--- a/build/android/pylib/device/adb_wrapper.py
+++ b/build/android/pylib/device/adb_wrapper.py
@@ -12,37 +12,20 @@ import errno
import os
from pylib import cmd_helper
+from pylib.device import decorators
+from pylib.device import device_errors
-from pylib.utils import reraiser_thread
-from pylib.utils import timeout_retry
_DEFAULT_TIMEOUT = 30
_DEFAULT_RETRIES = 2
-class BaseError(Exception):
- """Base exception for all device and command errors."""
- pass
+BaseError = device_errors.BaseError
craigdh 2014/05/13 16:59:42 I don't like this either. Exceptions raised from d
+CommandFailedError = device_errors.CommandFailedError
+CommandTimeoutError = device_errors.CommandTimeoutError
+DeviceUnreachableError = device_errors.DeviceUnreachableError
-class CommandFailedError(BaseError):
- """Exception for command failures."""
-
- def __init__(self, cmd, msg, device=None):
- super(CommandFailedError, self).__init__(
- (('device %s: ' % device) if device else '') +
- 'adb command \'%s\' failed with message: \'%s\'' % (' '.join(cmd), msg))
-
-
-class CommandTimeoutError(BaseError):
- """Exception for command timeouts."""
- pass
-
-
-class DeviceUnreachableError(BaseError):
- """Exception for device unreachable failures."""
- pass
-
def _VerifyLocalFileExists(path):
"""Verifies a local file exists.
@@ -67,40 +50,23 @@ class AdbWrapper(object):
"""
self._device_serial = str(device_serial)
+ # pylint: disable=W0613
@classmethod
- def _AdbCmd(cls, arg_list, timeout, retries, check_error=True):
- """Runs an adb command with a timeout and retries.
-
- Args:
- arg_list: A list of arguments to adb.
- timeout: Timeout in seconds.
- retries: Number of retries.
- check_error: Check that the command doesn't return an error message. This
- does NOT check the return code of shell commands.
-
- Returns:
- The output of the command.
- """
+ @decorators.WithTimeoutAndRetries
+ def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True):
cmd = ['adb'] + arg_list
-
- # This method runs inside the timeout/retries.
- def RunCmd():
- exit_code, output = cmd_helper.GetCmdStatusAndOutput(cmd)
- if exit_code != 0:
- raise CommandFailedError(
- cmd, 'returned non-zero exit code %s, output: %s' %
- (exit_code, output))
- # This catches some errors, including when the device drops offline;
- # unfortunately adb is very inconsistent with error reporting so many
- # command failures present differently.
- if check_error and output[:len('error:')] == 'error:':
- raise CommandFailedError(arg_list, output)
- return output
-
- try:
- return timeout_retry.Run(RunCmd, timeout, retries)
- except reraiser_thread.TimeoutError as e:
- raise CommandTimeoutError(str(e))
+ exit_code, output = cmd_helper.GetCmdStatusAndOutput(cmd)
+ if exit_code != 0:
+ raise CommandFailedError(
+ cmd, 'returned non-zero exit code %s, output: %s' %
+ (exit_code, output))
+ # This catches some errors, including when the device drops offline;
+ # unfortunately adb is very inconsistent with error reporting so many
+ # command failures present differently.
+ if check_error and output[:len('error:')] == 'error:':
+ raise CommandFailedError(arg_list, output)
+ return output
+ # pylint: enable=W0613
def _DeviceAdbCmd(self, arg_list, timeout, retries, check_error=True):
"""Runs an adb command on the device associated with this object.
@@ -115,9 +81,9 @@ class AdbWrapper(object):
Returns:
The output of the command.
"""
- return self._AdbCmd(
- ['-s', self._device_serial] + arg_list, timeout, retries,
- check_error=check_error)
+ return self._RunAdbCmd(
+ ['-s', self._device_serial] + arg_list, timeout=timeout,
+ retries=retries, check_error=check_error)
def __eq__(self, other):
"""Consider instances equal if they refer to the same device.
@@ -153,7 +119,7 @@ class AdbWrapper(object):
Yields:
AdbWrapper instances.
"""
- output = cls._AdbCmd(['devices'], timeout, retries)
+ output = cls._RunAdbCmd(['devices'], timeout=timeout, retries=retries)
lines = [line.split() for line in output.split('\n')]
return [AdbWrapper(line[0]) for line in lines
if len(line) == 2 and line[1] == 'device']

Powered by Google App Engine
This is Rietveld 408576698