| 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 import abc | 5 import abc |
| 6 import os | 6 import os |
| 7 import re | 7 import re |
| 8 | 8 |
| 9 from collections import namedtuple | 9 from collections import namedtuple |
| 10 | 10 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 def __eq__(self, other): | 172 def __eq__(self, other): |
| 173 return (self.base == other.base and | 173 return (self.base == other.base and |
| 174 self.pieces == other.pieces and | 174 self.pieces == other.pieces and |
| 175 self.platform_ext == other.platform_ext) | 175 self.platform_ext == other.platform_ext) |
| 176 | 176 |
| 177 def __ne__(self, other): | 177 def __ne__(self, other): |
| 178 return not self == other | 178 return not self == other |
| 179 | 179 |
| 180 def join(self, *pieces, **kwargs): | 180 def join(self, *pieces, **kwargs): |
| 181 """Appends *pieces to this Path, returning a new Path. |
| 182 |
| 183 Empty values ('', None) in pieces will be omitted. |
| 184 |
| 185 Args: |
| 186 pieces (tuple(str)) - The components of the path relative to base. These |
| 187 pieces must be non-relative (i.e. no '..' or '.', etc. as a piece). |
| 188 |
| 189 Kwargs: |
| 190 platform_ext (dict(str, str)) - A mapping from platform name (as defined |
| 191 by the 'platform' module), to a suffix for the path. |
| 192 |
| 193 Returns (Path) - the new Path. |
| 194 """ |
| 181 if not pieces and not kwargs: | 195 if not pieces and not kwargs: |
| 182 return self | 196 return self |
| 183 kwargs.setdefault('platform_ext', self.platform_ext) | 197 kwargs.setdefault('platform_ext', self.platform_ext) |
| 184 return Path(self.base, *filter(bool, self.pieces + pieces), **kwargs) | 198 return Path(self.base, *filter(bool, self.pieces + pieces), **kwargs) |
| 185 | 199 |
| 186 def is_parent_of(self, child): | 200 def is_parent_of(self, child): |
| 187 """True if |child| is in a subdirectory of this path.""" | 201 """True if |child| is in a subdirectory of this path.""" |
| 188 # Assumes base paths are not nested. | 202 # Assumes base paths are not nested. |
| 189 # TODO(vadimsh): We should not rely on this assumption. | 203 # TODO(vadimsh): We should not rely on this assumption. |
| 190 if self.base != child.base: | 204 if self.base != child.base: |
| 191 return False | 205 return False |
| 192 # A path is not a parent to itself. | 206 # A path is not a parent to itself. |
| 193 if len(self.pieces) >= len(child.pieces): | 207 if len(self.pieces) >= len(child.pieces): |
| 194 return False | 208 return False |
| 195 return child.pieces[:len(self.pieces)] == self.pieces | 209 return child.pieces[:len(self.pieces)] == self.pieces |
| 196 | 210 |
| 197 def __repr__(self): | 211 def __repr__(self): |
| 198 s = "Path(%r" % self.base | 212 s = "Path(%r" % self.base |
| 199 if self.pieces: | 213 if self.pieces: |
| 200 s += ", %s" % ",".join(repr(x) for x in self.pieces) | 214 s += ", %s" % ",".join(repr(x) for x in self.pieces) |
| 201 | 215 |
| 202 return s + ")" | 216 return s + ")" |
| OLD | NEW |