Index: build/android/pylib/device/device_blacklist.py |
diff --git a/build/android/pylib/device/device_blacklist.py b/build/android/pylib/device/device_blacklist.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..996af8d23a7065c04809097206ff335d236cb5a4 |
--- /dev/null |
+++ b/build/android/pylib/device/device_blacklist.py |
@@ -0,0 +1,45 @@ |
+import json |
bulach
2014/03/21 14:38:55
nit: copyright notice
|
+import os |
+ |
+from pylib import constants |
+_BLACKLIST_JSON = os.path.join( |
+ constants.DIR_SOURCE_ROOT, |
+ os.environ.get('CHROMIUM_OUT_DIR', 'out'), |
+ 'bad_devices.json') |
+ |
bulach
2014/03/21 14:38:55
nit: need two \n between top-levels
|
+def ReadBlacklist(): |
+ """Reads the blacklist from the _BLACKLIST_JSON file. |
+ |
+ Returns: |
+ A list containing bad devices. |
+ """ |
+ blacklist = [] |
bulach
2014/03/21 14:38:55
nit: how about:
if not os.path.exists(_BLACKLIST_
|
+ if os.path.exists(_BLACKLIST_JSON): |
+ with open(_BLACKLIST_JSON, 'r') as f: |
+ blacklist = json.load(f) |
+ return blacklist |
+ |
bulach
2014/03/21 14:38:55
nit: another \n here, 30 and 41
|
+def WriteBlacklist(blacklist): |
+ """Writes the provided blacklist to the _BLACKLIST_JSON file. |
+ |
+ Args: |
+ blacklist: list of bad devices to write to the _BLACKLIST_JSON file. |
+ """ |
+ with open(_BLACKLIST_JSON, 'w') as f: |
+ json.dump(list(set(blacklist)), f) |
+ |
+def ExtendBlacklist(devices): |
+ """Adds devices to _BLACKLIST_JSON file. |
+ |
+ Args: |
+ devices: list of bad devices to be added to the _BLACKLIST_JSON file. |
+ """ |
+ blacklist = ReadBlacklist() |
+ blacklist.extend(devices) |
+ WriteBlacklist(blacklist) |
+ |
+def ResetBlacklist(): |
+ """Erases the _BLACKLIST_JSON file if it exists.""" |
+ if os.path.exists(_BLACKLIST_JSON): |
+ os.remove(_BLACKLIST_JSON) |
+ |