Chromium Code Reviews| 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 tempfile | 8 import tempfile |
| 8 | 9 |
| 9 from slave import recipe_api | 10 from slave import recipe_api |
| 10 from slave import recipe_config_types | 11 from slave import recipe_config_types |
| 11 | 12 |
| 12 | 13 |
| 13 def PathTostring(api, test): | 14 def PathTostring(api, test): |
|
iannucci
2015/03/07 02:55:03
Can you fix the capitalization here? kthx :D
luqui
2015/03/09 18:49:28
Done.
| |
| 14 def PathTostring_inner(path): | 15 def PathTostring_inner(path): |
| 15 assert isinstance(path, recipe_config_types.Path) | 16 assert isinstance(path, recipe_config_types.Path) |
| 16 base_path = None | 17 base_path = None |
| 17 suffix = path.platform_ext.get(api.m.platform.name, '') | 18 suffix = path.platform_ext.get(api.m.platform.name, '') |
| 18 if path.base in api.c.dynamic_paths: | 19 if isinstance(path.base, recipe_config_types.NamedBasePath): |
| 19 base_path = api.c.dynamic_paths[path.base] | 20 name = path.base.name |
| 20 elif path.base in api.c.base_paths: | 21 if name in api.c.dynamic_paths: |
| 22 base_path = api.c.dynamic_paths[name] | |
| 23 elif name in api.c.base_paths: | |
| 24 if test.enabled: | |
| 25 base_path = repr(path.base) | |
|
luqui
2015/03/07 02:48:04
See if you (I) can make this a normal method inste
luqui
2015/03/09 18:49:28
Changed my mind about this...
| |
| 26 else: # pragma: no cover | |
| 27 base_path = api.join(*api.c.base_paths[name]) | |
| 28 elif isinstance(path.base, recipe_config_types.ModuleBasePath): | |
| 21 if test.enabled: | 29 if test.enabled: |
| 22 base_path = '[%s]' % path.base.upper() | 30 base_path = repr(path.base) |
| 23 else: # pragma: no cover | 31 else: # pragma: no cover |
| 24 base_path = api.join(*api.c.base_paths[path.base]) | 32 base_path = os.path.dirname(path.base.module.__file__) |
| 33 else: # pragma: no cover | |
| 34 raise NotImplementedError('PathTostring not implemented for %s' % | |
| 35 path.base.__class__.__name__) | |
| 25 assert base_path, 'Could not get base %r for path' % path.base | 36 assert base_path, 'Could not get base %r for path' % path.base |
| 26 return api.join(base_path, *path.pieces) + suffix | 37 return api.join(base_path, *path.pieces) + suffix |
| 27 return PathTostring_inner | 38 return PathTostring_inner |
| 28 | 39 |
| 29 | 40 |
| 30 def string_filter(func): | 41 def string_filter(func): |
| 31 @functools.wraps(func) | 42 @functools.wraps(func) |
| 32 def inner(*args, **kwargs): | 43 def inner(*args, **kwargs): |
| 33 return func(*map(str, args), **kwargs) | 44 return func(*map(str, args), **kwargs) |
| 34 return inner | 45 return inner |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 @recipe_api.non_step | 297 @recipe_api.non_step |
| 287 def __contains__(self, pathname): | 298 def __contains__(self, pathname): |
| 288 return bool(self.c.dynamic_paths.get(pathname)) | 299 return bool(self.c.dynamic_paths.get(pathname)) |
| 289 | 300 |
| 290 @recipe_api.non_step | 301 @recipe_api.non_step |
| 291 def __setitem__(self, pathname, path): | 302 def __setitem__(self, pathname, path): |
| 292 assert isinstance(path, recipe_config_types.Path), ( | 303 assert isinstance(path, recipe_config_types.Path), ( |
| 293 'Setting dynamic path to something other than a Path: %r' % path) | 304 'Setting dynamic path to something other than a Path: %r' % path) |
| 294 assert pathname in self.c.dynamic_paths, ( | 305 assert pathname in self.c.dynamic_paths, ( |
| 295 'Must declare dynamic path (%r) in config before setting it.' % path) | 306 'Must declare dynamic path (%r) in config before setting it.' % path) |
| 296 assert path.base in self.c.base_paths, ( | 307 assert isinstance(path.base, recipe_config_types.BasePath), ( |
| 297 'Dynamic path values must be based on a base_path.') | 308 'Dynamic path values must be based on a base_path' % path.base) |
| 298 self.c.dynamic_paths[pathname] = path | 309 self.c.dynamic_paths[pathname] = path |
| 299 | 310 |
| 300 @recipe_api.non_step | 311 @recipe_api.non_step |
| 301 def __getitem__(self, name): | 312 def __getitem__(self, name): |
| 302 if name in self.c.dynamic_paths: | 313 if name in self.c.dynamic_paths: |
| 303 r = self.c.dynamic_paths[name] | 314 r = self.c.dynamic_paths[name] |
| 304 assert r is not None, ('Tried to get dynamic path %s but it has not been ' | 315 assert r is not None, ('Tried to get dynamic path %s but it has not been ' |
| 305 'set yet.' % name) | 316 'set yet.' % name) |
| 306 return r | 317 return r |
| 307 if name in self.c.base_paths: | 318 if name in self.c.base_paths: |
| 308 return recipe_config_types.Path(name, _bypass=True) | 319 return recipe_config_types.Path(recipe_config_types.NamedBasePath(name)) |
| 309 | 320 |
| 310 @recipe_api.non_step | 321 @recipe_api.non_step |
| 311 def __getattr__(self, name): | 322 def __getattr__(self, name): |
| 312 # retrieve os.path attributes | 323 # retrieve os.path attributes |
| 313 if name in self.OK_ATTRS: | 324 if name in self.OK_ATTRS: |
| 314 return getattr(self._path_mod, name) | 325 return getattr(self._path_mod, name) |
| 315 if name in self.FILTER_METHODS: | 326 if name in self.FILTER_METHODS: |
| 316 return string_filter(getattr(self._path_mod, name)) | 327 return string_filter(getattr(self._path_mod, name)) |
| 317 raise AttributeError("'%s' object has no attribute '%s'" % | 328 raise AttributeError("'%s' object has no attribute '%s'" % |
| 318 (self._path_mod, name)) # pragma: no cover | 329 (self._path_mod, name)) # pragma: no cover |
| 319 | 330 |
| 320 @recipe_api.non_step | 331 @recipe_api.non_step |
| 321 def __dir__(self): # pragma: no cover | 332 def __dir__(self): # pragma: no cover |
| 322 # Used for helping out show_me_the_modules.py | 333 # Used for helping out show_me_the_modules.py |
| 323 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS) | 334 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS) |
| OLD | NEW |