| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 functools | 5 import functools |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 import tempfile | 8 import tempfile |
| 9 | 9 |
| 10 from recipe_engine import recipe_api | 10 from recipe_engine import recipe_api |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 def __setitem__(self, pathname, path): | 184 def __setitem__(self, pathname, path): |
| 185 assert isinstance(path, config_types.Path), ( | 185 assert isinstance(path, config_types.Path), ( |
| 186 'Setting dynamic path to something other than a Path: %r' % path) | 186 'Setting dynamic path to something other than a Path: %r' % path) |
| 187 assert pathname in self.c.dynamic_paths, ( | 187 assert pathname in self.c.dynamic_paths, ( |
| 188 'Must declare dynamic path (%r) in config before setting it.' % path) | 188 'Must declare dynamic path (%r) in config before setting it.' % path) |
| 189 assert isinstance(path.base, config_types.BasePath), ( | 189 assert isinstance(path.base, config_types.BasePath), ( |
| 190 'Dynamic path values must be based on a base_path' % path.base) | 190 'Dynamic path values must be based on a base_path' % path.base) |
| 191 self.c.dynamic_paths[pathname] = path | 191 self.c.dynamic_paths[pathname] = path |
| 192 | 192 |
| 193 def __getitem__(self, name): | 193 def __getitem__(self, name): |
| 194 if name in self.c.dynamic_paths: | 194 if name in self.c.base_paths or name in self.c.dynamic_paths: |
| 195 r = self.c.dynamic_paths[name] | |
| 196 assert r is not None, ('Tried to get dynamic path %s but it has not been ' | |
| 197 'set yet.' % name) | |
| 198 return r | |
| 199 if name in self.c.base_paths: | |
| 200 return config_types.Path(config_types.NamedBasePath(name)) | 195 return config_types.Path(config_types.NamedBasePath(name)) |
| 201 raise KeyError('Unknown path: %s' % name) # pragma: no cover | 196 raise KeyError('Unknown path: %s' % name) # pragma: no cover |
| 202 | 197 |
| 203 def __getattr__(self, name): | 198 def __getattr__(self, name): |
| 204 # retrieve os.path attributes | 199 # retrieve os.path attributes |
| 205 if name in self.OK_ATTRS: | 200 if name in self.OK_ATTRS: |
| 206 return getattr(self._path_mod, name) | 201 return getattr(self._path_mod, name) |
| 207 if name in self.FILTER_METHODS: | 202 if name in self.FILTER_METHODS: |
| 208 return string_filter(getattr(self._path_mod, name)) | 203 return string_filter(getattr(self._path_mod, name)) |
| 209 raise AttributeError("'%s' object has no attribute '%s'" % | 204 raise AttributeError("'%s' object has no attribute '%s'" % |
| 210 (self._path_mod, name)) # pragma: no cover | 205 (self._path_mod, name)) # pragma: no cover |
| 211 | 206 |
| 212 def __dir__(self): # pragma: no cover | 207 def __dir__(self): # pragma: no cover |
| 213 # Used for helping out show_me_the_modules.py | 208 # Used for helping out show_me_the_modules.py |
| 214 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS) | 209 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS) |
| OLD | NEW |