Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """Library to generate, maintain, and read static slave pool maps.""" | 5 """Library to generate, maintain, and read static slave pool maps.""" |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 import itertools | 8 import itertools |
| 9 import json | 9 import json |
| 10 import os | 10 import os |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 | 113 |
| 114 def LoadState(self, path=None, enforce=True): | 114 def LoadState(self, path=None, enforce=True): |
| 115 """Loads slave pools from the store, replacing the current in-memory set. | 115 """Loads slave pools from the store, replacing the current in-memory set. |
| 116 | 116 |
| 117 Args: | 117 Args: |
| 118 path (str): If provided, the path to load from; otherwise, | 118 path (str): If provided, the path to load from; otherwise, |
| 119 DEFAULT_STATE_PATH will be used. | 119 DEFAULT_STATE_PATH will be used. |
| 120 enforce (bool): If True, raise an IOError if the state file does not | 120 enforce (bool): If True, raise an IOError if the state file does not |
| 121 exist or a ValueError if it could not be loaded. | 121 exist or a ValueError if it could not be loaded. |
| 122 """ | 122 """ |
| 123 state = None | 123 state = {} |
|
ghost stip (do not use)
2015/04/10 22:47:04
why is this not None?
dnj
2015/04/12 15:20:38
This handles the case where a state file does not
| |
| 124 path = path or self.DEFAULT_STATE_PATH | 124 path = path or self.DEFAULT_STATE_PATH |
| 125 if not os.path.exists(path): | 125 if not os.path.exists(path): |
| 126 if enforce: | 126 if enforce: |
| 127 raise IOError("State path does not exist: %s" % (path,)) | 127 raise IOError("State path does not exist: %s" % (path,)) |
| 128 try: | 128 try: |
| 129 with open(path or self.DEFAULT_STATE_PATH, 'r') as fd: | 129 with open(path or self.DEFAULT_STATE_PATH, 'r') as fd: |
| 130 state = json.load(fd) | 130 state = json.load(fd) |
| 131 except (IOError, ValueError): | 131 except (IOError, ValueError): |
| 132 if enforce: | 132 if enforce: |
| 133 raise | 133 raise |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 | 334 |
| 335 # Convert SlaveMapEntry fields to immutable form. | 335 # Convert SlaveMapEntry fields to immutable form. |
| 336 result = SlaveMap( | 336 result = SlaveMap( |
| 337 entries={}, | 337 entries={}, |
| 338 unallocated=frozenset(n_state.unallocated)) | 338 unallocated=frozenset(n_state.unallocated)) |
| 339 for k, v in slave_map_entries.iteritems(): | 339 for k, v in slave_map_entries.iteritems(): |
| 340 result.entries[k] = SlaveMapEntry( | 340 result.entries[k] = SlaveMapEntry( |
| 341 classes=frozenset(v.classes), | 341 classes=frozenset(v.classes), |
| 342 keys=tuple(sorted(v.keys))) | 342 keys=tuple(sorted(v.keys))) |
| 343 return result | 343 return result |
| OLD | NEW |