OLD | NEW |
---|---|
(Empty) | |
1 import json | |
bulach
2014/03/21 14:38:55
nit: copyright notice
| |
2 import os | |
3 | |
4 from pylib import constants | |
5 _BLACKLIST_JSON = os.path.join( | |
6 constants.DIR_SOURCE_ROOT, | |
7 os.environ.get('CHROMIUM_OUT_DIR', 'out'), | |
8 'bad_devices.json') | |
9 | |
bulach
2014/03/21 14:38:55
nit: need two \n between top-levels
| |
10 def ReadBlacklist(): | |
11 """Reads the blacklist from the _BLACKLIST_JSON file. | |
12 | |
13 Returns: | |
14 A list containing bad devices. | |
15 """ | |
16 blacklist = [] | |
bulach
2014/03/21 14:38:55
nit: how about:
if not os.path.exists(_BLACKLIST_
| |
17 if os.path.exists(_BLACKLIST_JSON): | |
18 with open(_BLACKLIST_JSON, 'r') as f: | |
19 blacklist = json.load(f) | |
20 return blacklist | |
21 | |
bulach
2014/03/21 14:38:55
nit: another \n here, 30 and 41
| |
22 def WriteBlacklist(blacklist): | |
23 """Writes the provided blacklist to the _BLACKLIST_JSON file. | |
24 | |
25 Args: | |
26 blacklist: list of bad devices to write to the _BLACKLIST_JSON file. | |
27 """ | |
28 with open(_BLACKLIST_JSON, 'w') as f: | |
29 json.dump(list(set(blacklist)), f) | |
30 | |
31 def ExtendBlacklist(devices): | |
32 """Adds devices to _BLACKLIST_JSON file. | |
33 | |
34 Args: | |
35 devices: list of bad devices to be added to the _BLACKLIST_JSON file. | |
36 """ | |
37 blacklist = ReadBlacklist() | |
38 blacklist.extend(devices) | |
39 WriteBlacklist(blacklist) | |
40 | |
41 def ResetBlacklist(): | |
42 """Erases the _BLACKLIST_JSON file if it exists.""" | |
43 if os.path.exists(_BLACKLIST_JSON): | |
44 os.remove(_BLACKLIST_JSON) | |
45 | |
OLD | NEW |