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

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

Issue 204353007: [Android] Extract device blacklisting into its own module. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 8 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
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 # pylint: disable-all 9 # pylint: disable-all
10 10
(...skipping 21 matching lines...) Expand all
32 from pylib import pexpect 32 from pylib import pexpect
33 except ImportError: 33 except ImportError:
34 pexpect = None 34 pexpect = None
35 35
36 sys.path.append(os.path.join( 36 sys.path.append(os.path.join(
37 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) 37 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner'))
38 import adb_interface 38 import adb_interface
39 import am_instrument_parser 39 import am_instrument_parser
40 import errors 40 import errors
41 41
42 from pylib.device import device_blacklist
42 43
43 # Pattern to search for the next whole line of pexpect output and capture it 44 # Pattern to search for the next whole line of pexpect output and capture it
44 # into a match group. We can't use ^ and $ for line start end with pexpect, 45 # into a match group. We can't use ^ and $ for line start end with pexpect,
45 # see http://www.noah.org/python/pexpect/#doc for explanation why. 46 # see http://www.noah.org/python/pexpect/#doc for explanation why.
46 PEXPECT_LINE_RE = re.compile('\n([^\r]*)\r') 47 PEXPECT_LINE_RE = re.compile('\n([^\r]*)\r')
47 48
48 # Set the adb shell prompt to be a unique marker that will [hopefully] not 49 # Set the adb shell prompt to be a unique marker that will [hopefully] not
49 # appear at the start of any line of a command's output. 50 # appear at the start of any line of a command's output.
50 SHELL_PROMPT = '~+~PQ\x17RS~+~' 51 SHELL_PROMPT = '~+~PQ\x17RS~+~'
51 52
(...skipping 20 matching lines...) Expand all
72 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin' 73 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin'
73 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER 74 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER
74 75
75 76
76 def GetAVDs(): 77 def GetAVDs():
77 """Returns a list of AVDs.""" 78 """Returns a list of AVDs."""
78 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) 79 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE)
79 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) 80 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd']))
80 return avds 81 return avds
81 82
82
83 def ResetBadDevices(): 83 def ResetBadDevices():
84 """Removes the file that keeps track of bad devices for a current build.""" 84 """Removes the blacklist that keeps track of bad devices for a current
85 if os.path.exists(constants.BAD_DEVICES_JSON): 85 build.
86 os.remove(constants.BAD_DEVICES_JSON) 86 """
87 87 device_blacklist.ResetBlacklist()
88 88
89 def ExtendBadDevices(devices): 89 def ExtendBadDevices(devices):
90 """Adds devices to BAD_DEVICES_JSON file. 90 """Adds devices to the blacklist that keeps track of bad devices for a
91 current build.
91 92
92 The devices listed in the BAD_DEVICES_JSON file will not be returned by 93 The devices listed in the bad devices file will not be returned by
93 GetAttachedDevices. 94 GetAttachedDevices.
94 95
95 Args: 96 Args:
96 devices: list of bad devices to be added to the BAD_DEVICES_JSON file. 97 devices: list of bad devices to be added to the bad devices file.
97 """ 98 """
98 if os.path.exists(constants.BAD_DEVICES_JSON): 99 device_blacklist.ExtendBlacklist(devices)
99 with open(constants.BAD_DEVICES_JSON, 'r') as f:
100 bad_devices = json.load(f)
101 devices.extend(bad_devices)
102 with open(constants.BAD_DEVICES_JSON, 'w') as f:
103 json.dump(list(set(devices)), f)
104 100
105 101
106 def GetAttachedDevices(hardware=True, emulator=True, offline=False): 102 def GetAttachedDevices(hardware=True, emulator=True, offline=False):
107 """Returns a list of attached, android devices and emulators. 103 """Returns a list of attached, android devices and emulators.
108 104
109 If a preferred device has been set with ANDROID_SERIAL, it will be first in 105 If a preferred device has been set with ANDROID_SERIAL, it will be first in
110 the returned list. The arguments specify what devices to include in the list. 106 the returned list. The arguments specify what devices to include in the list.
111 107
112 Example output: 108 Example output:
113 109
(...skipping 29 matching lines...) Expand all
143 elif hardware: 139 elif hardware:
144 devices = [device for device in online_devices 140 devices = [device for device in online_devices
145 if device not in emulator_devices] 141 if device not in emulator_devices]
146 elif emulator: 142 elif emulator:
147 devices = emulator_devices 143 devices = emulator_devices
148 144
149 # Now add offline devices if offline is true 145 # Now add offline devices if offline is true
150 if offline: 146 if offline:
151 devices = devices + offline_devices 147 devices = devices + offline_devices
152 148
153 # Remove bad devices listed in the bad_devices json file. 149 # Remove any devices in the blacklist.
154 if os.path.exists(constants.BAD_DEVICES_JSON): 150 blacklist = device_blacklist.ReadBlacklist()
155 with open(constants.BAD_DEVICES_JSON, 'r') as f: 151 if len(blacklist):
156 bad_devices = json.load(f) 152 logging.info('Avoiding bad devices %s', ' '.join(blacklist))
157 logging.info('Avoiding bad devices %s', ' '.join(bad_devices)) 153 devices = [device for device in devices if device not in blacklist]
158 devices = [device for device in devices if device not in bad_devices]
159 154
160 preferred_device = os.environ.get('ANDROID_SERIAL') 155 preferred_device = os.environ.get('ANDROID_SERIAL')
161 if preferred_device in devices: 156 if preferred_device in devices:
162 devices.remove(preferred_device) 157 devices.remove(preferred_device)
163 devices.insert(0, preferred_device) 158 devices.insert(0, preferred_device)
164 return devices 159 return devices
165 160
166 161
167 def IsDeviceAttached(device): 162 def IsDeviceAttached(device):
168 """Return true if the device is attached and online.""" 163 """Return true if the device is attached and online."""
(...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 """ 1837 """
1843 def __init__(self, output): 1838 def __init__(self, output):
1844 self._output = output 1839 self._output = output
1845 1840
1846 def write(self, data): 1841 def write(self, data):
1847 data = data.replace('\r\r\n', '\n') 1842 data = data.replace('\r\r\n', '\n')
1848 self._output.write(data) 1843 self._output.write(data)
1849 1844
1850 def flush(self): 1845 def flush(self):
1851 self._output.flush() 1846 self._output.flush()
OLDNEW
« no previous file with comments | « build/android/buildbot/bb_device_status_check.py ('k') | build/android/pylib/device/device_blacklist.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698