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

Side by Side Diff: build/android/pylib/device/device_blacklist.py

Issue 1292053006: Revert of [Android] Add --blacklist-file as a command-line option. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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/provision_devices.py ('k') | build/android/pylib/device/device_utils.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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 import json 5 import json
6 import os 6 import os
7 import threading 7 import threading
8 8
9 from pylib import constants 9 from pylib import constants
10 10 _BLACKLIST_JSON = os.path.join(
11 # TODO(jbudorick): Remove this once the blacklist is optional.
12 BLACKLIST_JSON = os.path.join(
13 constants.DIR_SOURCE_ROOT, 11 constants.DIR_SOURCE_ROOT,
14 os.environ.get('CHROMIUM_OUT_DIR', 'out'), 12 os.environ.get('CHROMIUM_OUT_DIR', 'out'),
15 'bad_devices.json') 13 'bad_devices.json')
16 14
17 class Blacklist(object): 15 # Note that this only protects against concurrent accesses to the blacklist
18 16 # within a process.
19 def __init__(self, path): 17 _blacklist_lock = threading.RLock()
20 self._blacklist_lock = threading.RLock()
21 self._path = path
22
23 def Read(self):
24 """Reads the blacklist from the blacklist file.
25
26 Returns:
27 A list containing bad devices.
28 """
29 with self._blacklist_lock:
30 if not os.path.exists(self._path):
31 return []
32
33 with open(self._path, 'r') as f:
34 return json.load(f)
35
36 def Write(self, blacklist):
37 """Writes the provided blacklist to the blacklist file.
38
39 Args:
40 blacklist: list of bad devices to write to the blacklist file.
41 """
42 with self._blacklist_lock:
43 with open(self._path, 'w') as f:
44 json.dump(list(set(blacklist)), f)
45
46 def Extend(self, devices):
47 """Adds devices to blacklist file.
48
49 Args:
50 devices: list of bad devices to be added to the blacklist file.
51 """
52 with self._blacklist_lock:
53 blacklist = ReadBlacklist()
54 blacklist.extend(devices)
55 WriteBlacklist(blacklist)
56
57 def Reset(self):
58 """Erases the blacklist file if it exists."""
59 with self._blacklist_lock:
60 if os.path.exists(self._path):
61 os.remove(self._path)
62
63 18
64 def ReadBlacklist(): 19 def ReadBlacklist():
65 # TODO(jbudorick): Phase out once all clients have migrated. 20 """Reads the blacklist from the _BLACKLIST_JSON file.
66 return Blacklist(BLACKLIST_JSON).Read() 21
22 Returns:
23 A list containing bad devices.
24 """
25 with _blacklist_lock:
26 if not os.path.exists(_BLACKLIST_JSON):
27 return []
28
29 with open(_BLACKLIST_JSON, 'r') as f:
30 return json.load(f)
67 31
68 32
69 def WriteBlacklist(blacklist): 33 def WriteBlacklist(blacklist):
70 # TODO(jbudorick): Phase out once all clients have migrated. 34 """Writes the provided blacklist to the _BLACKLIST_JSON file.
71 Blacklist(BLACKLIST_JSON).Write(blacklist) 35
36 Args:
37 blacklist: list of bad devices to write to the _BLACKLIST_JSON file.
38 """
39 with _blacklist_lock:
40 with open(_BLACKLIST_JSON, 'w') as f:
41 json.dump(list(set(blacklist)), f)
72 42
73 43
74 def ExtendBlacklist(devices): 44 def ExtendBlacklist(devices):
75 # TODO(jbudorick): Phase out once all clients have migrated. 45 """Adds devices to _BLACKLIST_JSON file.
76 Blacklist(BLACKLIST_JSON).Extend(devices) 46
47 Args:
48 devices: list of bad devices to be added to the _BLACKLIST_JSON file.
49 """
50 with _blacklist_lock:
51 blacklist = ReadBlacklist()
52 blacklist.extend(devices)
53 WriteBlacklist(blacklist)
77 54
78 55
79 def ResetBlacklist(): 56 def ResetBlacklist():
80 # TODO(jbudorick): Phase out once all clients have migrated. 57 """Erases the _BLACKLIST_JSON file if it exists."""
81 Blacklist(BLACKLIST_JSON).Reset() 58 with _blacklist_lock:
59 if os.path.exists(_BLACKLIST_JSON):
60 os.remove(_BLACKLIST_JSON)
82 61
OLDNEW
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/device/device_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698