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

Side by Side Diff: build/android/pylib/android_commands.py

Issue 19596002: [Translate] Return before the new delegate is created if needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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 unified diff | Download patch
« no previous file with comments | « build/android/buildbot/bb_device_steps.py ('k') | build/android/pylib/utils/emulator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 KEYCODE_DPAD_UP = 19 58 KEYCODE_DPAD_UP = 19
59 KEYCODE_DPAD_DOWN = 20 59 KEYCODE_DPAD_DOWN = 20
60 KEYCODE_DPAD_RIGHT = 22 60 KEYCODE_DPAD_RIGHT = 22
61 KEYCODE_ENTER = 66 61 KEYCODE_ENTER = 66
62 KEYCODE_MENU = 82 62 KEYCODE_MENU = 82
63 63
64 MD5SUM_DEVICE_FOLDER = constants.TEST_EXECUTABLE_DIR + '/md5sum/' 64 MD5SUM_DEVICE_FOLDER = constants.TEST_EXECUTABLE_DIR + '/md5sum/'
65 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin' 65 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin'
66 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER 66 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER
67 67
68 def GetEmulators():
69 """Returns a list of emulators. Does not filter by status (e.g. offline).
70
71 Both devices starting with 'emulator' will be returned in below output:
72
73 * daemon not running. starting it now on port 5037 *
74 * daemon started successfully *
75 List of devices attached
76 027c10494100b4d7 device
77 emulator-5554 offline
78 emulator-5558 device
79 """
80 re_device = re.compile('^emulator-[0-9]+', re.MULTILINE)
81 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH,
82 'devices']))
83 return devices
84
68 85
69 def GetAVDs(): 86 def GetAVDs():
70 """Returns a list of AVDs.""" 87 """Returns a list of AVDs."""
71 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) 88 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE)
72 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) 89 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd']))
73 return avds 90 return avds
74 91
75 92
76 def GetAttachedDevices(hardware=True, emulator=True, offline=False): 93 def GetAttachedDevices():
77 """Returns a list of attached, android devices and emulators. 94 """Returns a list of attached, online android devices.
78 95
79 If a preferred device has been set with ANDROID_SERIAL, it will be first in 96 If a preferred device has been set with ANDROID_SERIAL, it will be first in
80 the returned list. The arguments specify what devices to include in the list. 97 the returned list.
81 98
82 Example output: 99 Example output:
83 100
84 * daemon not running. starting it now on port 5037 * 101 * daemon not running. starting it now on port 5037 *
85 * daemon started successfully * 102 * daemon started successfully *
86 List of devices attached 103 List of devices attached
87 027c10494100b4d7 device 104 027c10494100b4d7 device
88 emulator-5554 offline 105 emulator-5554 offline
89
90 Args:
91 hardware: Include attached actual devices that are online.
92 emulator: Include emulators (i.e. AVD's) currently on host.
93 offline: Include devices and emulators that are offline.
94
95 Returns: List of devices.
96 """ 106 """
97 adb_devices_output = cmd_helper.GetCmdOutput([constants.ADB_PATH, 'devices'])
98
99 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) 107 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE)
100 online_devices = re_device.findall(adb_devices_output) 108 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH,
101 109 'devices']))
102 re_device = re.compile('^(emulator-[0-9]+)\tdevice', re.MULTILINE)
103 emulator_devices = re_device.findall(adb_devices_output)
104
105 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\toffline$', re.MULTILINE)
106 offline_devices = re_device.findall(adb_devices_output)
107
108 devices = []
109 # First determine list of online devices (e.g. hardware and/or emulator).
110 if hardware and emulator:
111 devices = online_devices
112 elif hardware:
113 devices = [device for device in online_devices
114 if device not in emulator_devices]
115 elif emulator:
116 devices = emulator_devices
117
118 # Now add offline devices if offline is true
119 if offline:
120 devices = devices + offline_devices
121
122 preferred_device = os.environ.get('ANDROID_SERIAL') 110 preferred_device = os.environ.get('ANDROID_SERIAL')
123 if preferred_device in devices: 111 if preferred_device in devices:
124 devices.remove(preferred_device) 112 devices.remove(preferred_device)
125 devices.insert(0, preferred_device) 113 devices.insert(0, preferred_device)
126 return devices 114 return devices
127 115
128 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 return re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH,
124 'devices']))
125
126
129 def IsDeviceAttached(device): 127 def IsDeviceAttached(device):
130 """Return true if the device is attached and online.""" 128 """Return true if the device is attached and online."""
131 return device in GetAttachedDevices() 129 return device in GetAttachedDevices()
132 130
133 131
134 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None): 132 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None):
135 """Gets a list of files from `ls` command output. 133 """Gets a list of files from `ls` command output.
136 134
137 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.
138 136
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 """ 1460 """
1463 def __init__(self, output): 1461 def __init__(self, output):
1464 self._output = output 1462 self._output = output
1465 1463
1466 def write(self, data): 1464 def write(self, data):
1467 data = data.replace('\r\r\n', '\n') 1465 data = data.replace('\r\r\n', '\n')
1468 self._output.write(data) 1466 self._output.write(data)
1469 1467
1470 def flush(self): 1468 def flush(self):
1471 self._output.flush() 1469 self._output.flush()
OLDNEW
« no previous file with comments | « build/android/buildbot/bb_device_steps.py ('k') | build/android/pylib/utils/emulator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698