OLD | NEW |
1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
4 | 4 |
5 """All functions related to manipulating paths in recipes. | 5 """All functions related to manipulating paths in recipes. |
6 | 6 |
7 Recipes handle paths a bit differently than python does. All path manipulation | 7 Recipes handle paths a bit differently than python does. All path manipulation |
8 in recipes revolves around Path objects. These objects store a base path (always | 8 in recipes revolves around Path objects. These objects store a base path (always |
9 absolute), plus a list of components to join with it. New paths can be derived | 9 absolute), plus a list of components to join with it. New paths can be derived |
10 by calling the .join method with additional components. | 10 by calling the .join method with additional components. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 def _initialize(self): | 77 def _initialize(self): |
78 self._initialize = lambda: None | 78 self._initialize = lambda: None |
79 for path in self._initial_paths: | 79 for path in self._initial_paths: |
80 self.add(path) | 80 self.add(path) |
81 self._initial_paths = None | 81 self._initial_paths = None |
82 self.contains = lambda path: path in self._paths | 82 self.contains = lambda path: path in self._paths |
83 | 83 |
84 def add(self, path): | 84 def add(self, path): |
85 path = str(path) | 85 path = str(path) |
86 self._initialize() | 86 self._initialize() |
87 while path: | 87 prev_path = None |
| 88 while path != prev_path: |
88 self._paths.add(path) | 89 self._paths.add(path) |
89 path = self._path_mod.dirname(path) | 90 prev_path, path = path, self._path_mod.dirname(path) |
90 | 91 |
91 def copy(self, source, dest): | 92 def copy(self, source, dest): |
92 source, dest = str(source), str(dest) | 93 source, dest = str(source), str(dest) |
93 self._initialize() | 94 self._initialize() |
94 to_add = set() | 95 to_add = set() |
95 for p in self._paths: | 96 for p in self._paths: |
96 if p.startswith(source): | 97 if p.startswith(source): |
97 to_add.add(p.replace(source, dest)) | 98 to_add.add(p.replace(source, dest)) |
98 self._paths |= to_add | 99 self._paths |= to_add |
99 | 100 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 if name in self.OK_ATTRS: | 432 if name in self.OK_ATTRS: |
432 return getattr(self._path_mod, name) | 433 return getattr(self._path_mod, name) |
433 if name in self.FILTER_METHODS: | 434 if name in self.FILTER_METHODS: |
434 return string_filter(getattr(self._path_mod, name)) | 435 return string_filter(getattr(self._path_mod, name)) |
435 raise AttributeError("'%s' object has no attribute '%s'" % | 436 raise AttributeError("'%s' object has no attribute '%s'" % |
436 (self._path_mod, name)) # pragma: no cover | 437 (self._path_mod, name)) # pragma: no cover |
437 | 438 |
438 def __dir__(self): # pragma: no cover | 439 def __dir__(self): # pragma: no cover |
439 # Used for helping out show_me_the_modules.py | 440 # Used for helping out show_me_the_modules.py |
440 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS) | 441 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS) |
OLD | NEW |