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

Unified Diff: build/android/pylib/android_commands.py

Issue 181433020: GetAttachedDevices() should not include bad devices listed in .bad_devices file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add ResetBadDevices and ExtendBadDevices to android_commands.py. Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/buildbot/bb_device_status_check.py ('k') | build/android/pylib/constants.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/android_commands.py
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py
index a62812877de7bb5bd3c24830cc0ec464b83bc944..82dd71e6eafec60372f4aeba648e19b4663c8379 100644
--- a/build/android/pylib/android_commands.py
+++ b/build/android/pylib/android_commands.py
@@ -10,6 +10,7 @@ Assumes adb binary is currently on system path.
import collections
import datetime
import inspect
+import json
import logging
import os
import re
@@ -77,6 +78,29 @@ def GetAVDs():
return avds
+def ResetBadDevices():
+ """Removes the file that keeps track of bad devices for a current build."""
+ if os.path.exists(constants.BAD_DEVICES_JSON):
+ os.remove(constants.BAD_DEVICES_JSON)
+
+
+def ExtendBadDevices(devices):
+ """Adds devices to BAD_DEVICES_JSON file.
+
+ The devices listed in the BAD_DEVICES_JSON file will not be returned by
+ GetAttachedDevices.
+
+ Args:
+ devices: list of bad devices to be added to the BAD_DEVICES_JSON file.
+ """
+ if os.path.exists(constants.BAD_DEVICES_JSON):
+ with open(constants.BAD_DEVICES_JSON, 'r') as f:
+ bad_devices = json.load(f)
+ devices.extend(bad_devices)
+ with open(constants.BAD_DEVICES_JSON, 'w') as f:
+ json.dump(list(set(devices)), f)
+
+
def GetAttachedDevices(hardware=True, emulator=True, offline=False):
"""Returns a list of attached, android devices and emulators.
@@ -124,6 +148,13 @@ def GetAttachedDevices(hardware=True, emulator=True, offline=False):
if offline:
devices = devices + offline_devices
+ # Remove bad devices listed in the bad_devices json file.
+ if os.path.exists(constants.BAD_DEVICES_JSON):
+ with open(constants.BAD_DEVICES_JSON, 'r') as f:
+ bad_devices = json.load(f)
+ logging.info('Avoiding bad devices %s', ' '.join(bad_devices))
+ devices = [device for device in devices if device not in bad_devices]
+
preferred_device = os.environ.get('ANDROID_SERIAL')
if preferred_device in devices:
devices.remove(preferred_device)
« no previous file with comments | « build/android/buildbot/bb_device_status_check.py ('k') | build/android/pylib/constants.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698