Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / build / android / pylib / device / device_blacklist.py
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
3 # found in the LICENSE file.
4
5 import json
6 import os
7
8 from pylib import constants
9 _BLACKLIST_JSON = os.path.join(
10     constants.DIR_SOURCE_ROOT,
11     os.environ.get('CHROMIUM_OUT_DIR', 'out'),
12     'bad_devices.json')
13
14 def ReadBlacklist():
15   """Reads the blacklist from the _BLACKLIST_JSON file.
16
17   Returns:
18     A list containing bad devices.
19   """
20   if not os.path.exists(_BLACKLIST_JSON):
21     return []
22
23   with open(_BLACKLIST_JSON, 'r') as f:
24     return json.load(f)
25
26
27 def WriteBlacklist(blacklist):
28   """Writes the provided blacklist to the _BLACKLIST_JSON file.
29
30   Args:
31     blacklist: list of bad devices to write to the _BLACKLIST_JSON file.
32   """
33   with open(_BLACKLIST_JSON, 'w') as f:
34     json.dump(list(set(blacklist)), f)
35
36
37 def ExtendBlacklist(devices):
38   """Adds devices to _BLACKLIST_JSON file.
39
40   Args:
41     devices: list of bad devices to be added to the _BLACKLIST_JSON file.
42   """
43   blacklist = ReadBlacklist()
44   blacklist.extend(devices)
45   WriteBlacklist(blacklist)
46
47
48 def ResetBlacklist():
49   """Erases the _BLACKLIST_JSON file if it exists."""
50   if os.path.exists(_BLACKLIST_JSON):
51     os.remove(_BLACKLIST_JSON)
52