OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=unused-argument | 9 # pylint: disable=unused-argument |
10 | 10 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 else: | 168 else: |
169 raise ValueError('Unsupported device value: %r' % device) | 169 raise ValueError('Unsupported device value: %r' % device) |
170 self._commands_installed = None | 170 self._commands_installed = None |
171 self._default_timeout = default_timeout | 171 self._default_timeout = default_timeout |
172 self._default_retries = default_retries | 172 self._default_retries = default_retries |
173 self._cache = {} | 173 self._cache = {} |
174 self._client_caches = {} | 174 self._client_caches = {} |
175 assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR) | 175 assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR) |
176 assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR) | 176 assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR) |
177 | 177 |
178 def __eq__(self, other): | |
179 """Checks whether |other| refers to the same device as |self|. | |
180 | |
181 Args: | |
182 other: The object to compare to. This can be a basestring, an instance | |
183 of adb_wrapper.AdbWrapper, or an instance of DeviceUtils. | |
184 Returns: | |
185 Whether |other| refers to the same device as |self|. | |
186 """ | |
187 if isinstance(other, basestring): | |
perezju
2015/04/28 14:36:19
why not just do like we do in AdbWrapper, i.e.:
jbudorick
2015/04/28 15:52:53
Wow, that's much better. Done.
| |
188 other_serial = other | |
189 elif isinstance(other, adb_wrapper.AdbWrapper): | |
190 other_serial = other.GetDeviceSerial() | |
191 elif isinstance(other, DeviceUtils): | |
192 other_serial = other.adb.GetDeviceSerial() | |
193 else: | |
194 return False | |
195 return self.adb.GetDeviceSerial() == other_serial | |
196 | |
197 def __lt__(self, other): | |
198 """Compares two instances of DeviceUtils. | |
199 | |
200 This merely compares their serial numbers. | |
201 | |
202 Args: | |
203 other: The instance of DeviceUtils to compare to. | |
204 Returns: | |
205 Whether |self| is less than |other|. | |
206 """ | |
207 return self.adb.GetDeviceSerial() < other.adb.GetDeviceSerial() | |
208 | |
178 def __str__(self): | 209 def __str__(self): |
179 """Returns the device serial.""" | 210 """Returns the device serial.""" |
180 return self.adb.GetDeviceSerial() | 211 return self.adb.GetDeviceSerial() |
181 | 212 |
182 @decorators.WithTimeoutAndRetriesFromInstance() | 213 @decorators.WithTimeoutAndRetriesFromInstance() |
183 def IsOnline(self, timeout=None, retries=None): | 214 def IsOnline(self, timeout=None, retries=None): |
184 """Checks whether the device is online. | 215 """Checks whether the device is online. |
185 | 216 |
186 Args: | 217 Args: |
187 timeout: timeout in seconds | 218 timeout: timeout in seconds |
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1584 blacklist = device_blacklist.ReadBlacklist() | 1615 blacklist = device_blacklist.ReadBlacklist() |
1585 def blacklisted(adb): | 1616 def blacklisted(adb): |
1586 if adb.GetDeviceSerial() in blacklist: | 1617 if adb.GetDeviceSerial() in blacklist: |
1587 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) | 1618 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) |
1588 return True | 1619 return True |
1589 return False | 1620 return False |
1590 | 1621 |
1591 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() | 1622 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() |
1592 if not blacklisted(adb)] | 1623 if not blacklisted(adb)] |
1593 | 1624 |
OLD | NEW |