Chromium Code Reviews| 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 fa430f55e32f59da51b1e8664fb3cad0881c7222..ddf7c524125dd11aea1f84bb77c5f8836c3db958 100644 |
| --- a/build/android/pylib/device/adb_wrapper.py |
| +++ b/build/android/pylib/device/adb_wrapper.py |
| @@ -12,18 +12,20 @@ import collections |
| import errno |
| import logging |
| import os |
| +import re |
| from pylib import cmd_helper |
| from pylib import constants |
| from pylib.device import decorators |
| from pylib.device import device_errors |
| -from pylib.device import device_filter |
| from pylib.utils import timeout_retry |
| _DEFAULT_TIMEOUT = 30 |
| _DEFAULT_RETRIES = 2 |
| +_EMULATOR_RE = re.compile(r'^emulator-[0-9]+$') |
| + |
| def _VerifyLocalFileExists(path): |
| """Verifies a local file exists. |
| @@ -160,22 +162,20 @@ class AdbWrapper(object): |
| cpu_affinity=0) |
| @classmethod |
| - def GetDevices(cls, filters=None, timeout=_DEFAULT_TIMEOUT, |
| - retries=_DEFAULT_RETRIES): |
| + def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): |
| """DEPRECATED. Refer to Devices(...) below.""" |
| # TODO(jbudorick): Remove this function once no more clients are using it. |
|
perezju
2015/04/24 08:30:31
nit: maybe log a warning?
jbudorick
2015/04/24 15:59:40
I will be converting the few remaining callers of
|
| - return cls.Devices(filters=filters, timeout=timeout, retries=retries) |
| + return cls.Devices(timeout=timeout, retries=retries) |
| @classmethod |
| - def Devices(cls, filters=None, timeout=_DEFAULT_TIMEOUT, |
| - retries=_DEFAULT_RETRIES): |
| + def Devices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): |
| """Get the list of active attached devices. |
| Args: |
| - filters: (optional) A list of binary functions that take an AdbWrapper |
| - instance and a string description. Any device for which all provided |
| - filter functions do not return True will not be included in the |
| - returned list. |
| + filters: DEPRECATED (optional) A list of binary functions that take an |
| + AdbWrapper instance and a string description. Any device for which |
| + all provided filter functions do not return True will not be included |
| + in the returned list. |
|
perezju
2015/04/24 08:30:31
nit: if option is gone, also remove docstring
jbudorick
2015/04/24 15:59:40
whoops, done.
|
| timeout: (optional) Timeout per try in seconds. |
| retries: (optional) Number of retries to attempt. |
| @@ -184,17 +184,7 @@ class AdbWrapper(object): |
| """ |
| output = cls._RunAdbCmd(['devices'], timeout=timeout, retries=retries) |
| lines = (line.split() for line in output.splitlines()) |
| - devices = (AdbWrapper(line[0]) for line in lines if len(line) == 2) |
| - |
| - def matches_all_filters(device): |
| - for f in filters or (): |
| - if not f(device): |
| - logging.info('Device %s failed filter %s', device.GetDeviceSerial(), |
| - f.__name__) |
| - return False |
| - return True |
| - |
| - return [d for d in devices if matches_all_filters(d)] |
| + return [AdbWrapper(line[0]) for line in lines if len(line) == 2] |
| def GetDeviceSerial(self): |
| """Gets the device serial number associated with this object. |
| @@ -551,3 +541,15 @@ class AdbWrapper(object): |
| if 'cannot' in output: |
| raise device_errors.AdbCommandFailedError( |
| ['root'], output, device_serial=self._device_serial) |
| + |
| + @property |
| + def is_emulator(self): |
| + return _EMULATOR_RE.match(self._device_serial) |
| + |
| + @property |
| + def is_ready(self): |
| + try: |
| + return self.GetState() == 'device' |
| + except device_errors.CommandFailedError: |
| + return False |
| + |