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 |
index 0724654be7b9b5575eb551ce9eda7cb82ca5e095..a141d62b81b828f17a243dbb70adbe8772ddba30 100644 |
--- a/build/android/pylib/device/device_blacklist.py |
+++ b/build/android/pylib/device/device_blacklist.py |
@@ -7,76 +7,55 @@ |
import threading |
from pylib import constants |
- |
-# TODO(jbudorick): Remove this once the blacklist is optional. |
-BLACKLIST_JSON = os.path.join( |
+_BLACKLIST_JSON = os.path.join( |
constants.DIR_SOURCE_ROOT, |
os.environ.get('CHROMIUM_OUT_DIR', 'out'), |
'bad_devices.json') |
-class Blacklist(object): |
- |
- def __init__(self, path): |
- self._blacklist_lock = threading.RLock() |
- self._path = path |
- |
- def Read(self): |
- """Reads the blacklist from the blacklist file. |
- |
- Returns: |
- A list containing bad devices. |
- """ |
- with self._blacklist_lock: |
- if not os.path.exists(self._path): |
- return [] |
- |
- with open(self._path, 'r') as f: |
- return json.load(f) |
- |
- def Write(self, blacklist): |
- """Writes the provided blacklist to the blacklist file. |
- |
- Args: |
- blacklist: list of bad devices to write to the blacklist file. |
- """ |
- with self._blacklist_lock: |
- with open(self._path, 'w') as f: |
- json.dump(list(set(blacklist)), f) |
- |
- def Extend(self, devices): |
- """Adds devices to blacklist file. |
- |
- Args: |
- devices: list of bad devices to be added to the blacklist file. |
- """ |
- with self._blacklist_lock: |
- blacklist = ReadBlacklist() |
- blacklist.extend(devices) |
- WriteBlacklist(blacklist) |
- |
- def Reset(self): |
- """Erases the blacklist file if it exists.""" |
- with self._blacklist_lock: |
- if os.path.exists(self._path): |
- os.remove(self._path) |
- |
+# Note that this only protects against concurrent accesses to the blacklist |
+# within a process. |
+_blacklist_lock = threading.RLock() |
def ReadBlacklist(): |
- # TODO(jbudorick): Phase out once all clients have migrated. |
- return Blacklist(BLACKLIST_JSON).Read() |
+ """Reads the blacklist from the _BLACKLIST_JSON file. |
+ |
+ Returns: |
+ A list containing bad devices. |
+ """ |
+ with _blacklist_lock: |
+ if not os.path.exists(_BLACKLIST_JSON): |
+ return [] |
+ |
+ with open(_BLACKLIST_JSON, 'r') as f: |
+ return json.load(f) |
def WriteBlacklist(blacklist): |
- # TODO(jbudorick): Phase out once all clients have migrated. |
- Blacklist(BLACKLIST_JSON).Write(blacklist) |
+ """Writes the provided blacklist to the _BLACKLIST_JSON file. |
+ |
+ Args: |
+ blacklist: list of bad devices to write to the _BLACKLIST_JSON file. |
+ """ |
+ with _blacklist_lock: |
+ with open(_BLACKLIST_JSON, 'w') as f: |
+ json.dump(list(set(blacklist)), f) |
def ExtendBlacklist(devices): |
- # TODO(jbudorick): Phase out once all clients have migrated. |
- Blacklist(BLACKLIST_JSON).Extend(devices) |
+ """Adds devices to _BLACKLIST_JSON file. |
+ |
+ Args: |
+ devices: list of bad devices to be added to the _BLACKLIST_JSON file. |
+ """ |
+ with _blacklist_lock: |
+ blacklist = ReadBlacklist() |
+ blacklist.extend(devices) |
+ WriteBlacklist(blacklist) |
def ResetBlacklist(): |
- # TODO(jbudorick): Phase out once all clients have migrated. |
- Blacklist(BLACKLIST_JSON).Reset() |
+ """Erases the _BLACKLIST_JSON file if it exists.""" |
+ with _blacklist_lock: |
+ if os.path.exists(_BLACKLIST_JSON): |
+ os.remove(_BLACKLIST_JSON) |