| OLD | NEW |
| 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 logging | |
| 7 import os | 6 import os |
| 8 import threading | 7 import threading |
| 9 | 8 |
| 10 from pylib import constants | 9 from pylib import constants |
| 11 | 10 |
| 12 # TODO(jbudorick): Remove this once the blacklist is optional. | 11 # TODO(jbudorick): Remove this once the blacklist is optional. |
| 13 BLACKLIST_JSON = os.path.join( | 12 BLACKLIST_JSON = os.path.join( |
| 14 constants.DIR_SOURCE_ROOT, | 13 constants.DIR_SOURCE_ROOT, |
| 15 os.environ.get('CHROMIUM_OUT_DIR', 'out'), | 14 os.environ.get('CHROMIUM_OUT_DIR', 'out'), |
| 16 'bad_devices.json') | 15 'bad_devices.json') |
| (...skipping 26 matching lines...) Expand all Loading... |
| 43 with self._blacklist_lock: | 42 with self._blacklist_lock: |
| 44 with open(self._path, 'w') as f: | 43 with open(self._path, 'w') as f: |
| 45 json.dump(list(set(blacklist)), f) | 44 json.dump(list(set(blacklist)), f) |
| 46 | 45 |
| 47 def Extend(self, devices): | 46 def Extend(self, devices): |
| 48 """Adds devices to blacklist file. | 47 """Adds devices to blacklist file. |
| 49 | 48 |
| 50 Args: | 49 Args: |
| 51 devices: list of bad devices to be added to the blacklist file. | 50 devices: list of bad devices to be added to the blacklist file. |
| 52 """ | 51 """ |
| 53 logging.info('Adding %s to blacklist %s', ','.join(devices), self._path) | |
| 54 with self._blacklist_lock: | 52 with self._blacklist_lock: |
| 55 blacklist = self.Read() | 53 blacklist = ReadBlacklist() |
| 56 blacklist.extend(devices) | 54 blacklist.extend(devices) |
| 57 self.Write(blacklist) | 55 WriteBlacklist(blacklist) |
| 58 | 56 |
| 59 def Reset(self): | 57 def Reset(self): |
| 60 """Erases the blacklist file if it exists.""" | 58 """Erases the blacklist file if it exists.""" |
| 61 logging.info('Resetting blacklist %s', self._path) | |
| 62 with self._blacklist_lock: | 59 with self._blacklist_lock: |
| 63 if os.path.exists(self._path): | 60 if os.path.exists(self._path): |
| 64 os.remove(self._path) | 61 os.remove(self._path) |
| 65 | 62 |
| 63 |
| 64 def ReadBlacklist(): |
| 65 # TODO(jbudorick): Phase out once all clients have migrated. |
| 66 return Blacklist(BLACKLIST_JSON).Read() |
| 67 |
| 68 |
| 69 def WriteBlacklist(blacklist): |
| 70 # TODO(jbudorick): Phase out once all clients have migrated. |
| 71 Blacklist(BLACKLIST_JSON).Write(blacklist) |
| 72 |
| 73 |
| 74 def ExtendBlacklist(devices): |
| 75 # TODO(jbudorick): Phase out once all clients have migrated. |
| 76 Blacklist(BLACKLIST_JSON).Extend(devices) |
| 77 |
| 78 |
| 79 def ResetBlacklist(): |
| 80 # TODO(jbudorick): Phase out once all clients have migrated. |
| 81 Blacklist(BLACKLIST_JSON).Reset() |
| 82 |
| OLD | NEW |