OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
6 | 6 |
7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) | 107 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) |
108 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, | 108 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, |
109 'devices'])) | 109 'devices'])) |
110 preferred_device = os.environ.get('ANDROID_SERIAL') | 110 preferred_device = os.environ.get('ANDROID_SERIAL') |
111 if preferred_device in devices: | 111 if preferred_device in devices: |
112 devices.remove(preferred_device) | 112 devices.remove(preferred_device) |
113 devices.insert(0, preferred_device) | 113 devices.insert(0, preferred_device) |
114 return devices | 114 return devices |
115 | 115 |
116 | 116 |
117 def GetAttachedOfflineDevices(): | |
118 """Returns a list of attached, offline android devices. | |
119 | |
120 Returns: List of devices with status 'offline'. | |
121 """ | |
122 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\toffline$', re.MULTILINE) | |
123 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, | |
frankf
2013/07/16 17:51:19
just return, no intermediate var
navabi
2013/07/16 19:01:16
Done.
| |
124 'devices'])) | |
125 return devices | |
126 | |
127 | |
117 def IsDeviceAttached(device): | 128 def IsDeviceAttached(device): |
frankf
2013/07/16 17:51:19
Add a doc that this only cares about online device
navabi
2013/07/16 19:01:16
Done.
| |
118 return device in GetAttachedDevices() | 129 return device in GetAttachedDevices() |
119 | 130 |
120 | 131 |
121 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None): | 132 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None): |
122 """Gets a list of files from `ls` command output. | 133 """Gets a list of files from `ls` command output. |
123 | 134 |
124 Python's os.walk isn't used because it doesn't work over adb shell. | 135 Python's os.walk isn't used because it doesn't work over adb shell. |
125 | 136 |
126 Args: | 137 Args: |
127 path: The path to list. | 138 path: The path to list. |
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1368 """ | 1379 """ |
1369 def __init__(self, output): | 1380 def __init__(self, output): |
1370 self._output = output | 1381 self._output = output |
1371 | 1382 |
1372 def write(self, data): | 1383 def write(self, data): |
1373 data = data.replace('\r\r\n', '\n') | 1384 data = data.replace('\r\r\n', '\n') |
1374 self._output.write(data) | 1385 self._output.write(data) |
1375 | 1386 |
1376 def flush(self): | 1387 def flush(self): |
1377 self._output.flush() | 1388 self._output.flush() |
OLD | NEW |