Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Meta checkout manager supporting both Subversion and GIT. | 6 """Meta checkout manager supporting both Subversion and GIT. |
| 7 | 7 |
| 8 Files | 8 Files |
| 9 .gclient : Current client configuration, written by 'config' command. | 9 .gclient : Current client configuration, written by 'config' command. |
| 10 Format is a Python script defining 'solutions', a list whose | 10 Format is a Python script defining 'solutions', a list whose |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 (self.FromImpl, self.FileImpl, None.__class__)): | 172 (self.FromImpl, self.FileImpl, None.__class__)): |
| 173 raise gclient_utils.Error( | 173 raise gclient_utils.Error( |
| 174 ('dependency url must be either a string, None, ' | 174 ('dependency url must be either a string, None, ' |
| 175 'File() or From() instead of %s') % self._url.__class__.__name__) | 175 'File() or From() instead of %s') % self._url.__class__.__name__) |
| 176 if '/' in self._deps_file or '\\' in self._deps_file: | 176 if '/' in self._deps_file or '\\' in self._deps_file: |
| 177 raise gclient_utils.Error('deps_file name must not be a path, just a ' | 177 raise gclient_utils.Error('deps_file name must not be a path, just a ' |
| 178 'filename. %s' % self._deps_file) | 178 'filename. %s' % self._deps_file) |
| 179 | 179 |
| 180 @property | 180 @property |
| 181 def deps_file(self): | 181 def deps_file(self): |
| 182 """Immutable so no need to lock.""" | |
| 183 return self._deps_file | 182 return self._deps_file |
| 184 | 183 |
| 185 @property | 184 @property |
| 186 def managed(self): | 185 def managed(self): |
| 187 """Immutable so no need to lock.""" | |
| 188 return self._managed | 186 return self._managed |
| 189 | 187 |
| 190 @property | 188 @property |
| 191 def parent(self): | 189 def parent(self): |
| 192 """Immutable so no need to lock.""" | |
| 193 return self._parent | 190 return self._parent |
| 194 | 191 |
| 195 @property | 192 @property |
| 193 def root(self): | |
| 194 """Returns the root node, a GClient object.""" | |
| 195 if not self.parent: | |
| 196 # This line is to signal pylint that it could be a GClient instance. | |
| 197 return self or GClient(None, None) | |
| 198 return self.parent.root | |
| 199 | |
| 200 @property | |
| 196 def safesync_url(self): | 201 def safesync_url(self): |
| 197 """Immutable so no need to lock.""" | |
| 198 return self._safesync_url | 202 return self._safesync_url |
| 199 | 203 |
| 200 @property | 204 @property |
| 201 def should_process(self): | 205 def should_process(self): |
| 202 """True if this dependency should be processed, i.e. checked out.""" | 206 """True if this dependency should be processed, i.e. checked out.""" |
| 203 return self._should_process | 207 return self._should_process |
| 204 | 208 |
| 205 @property | 209 @property |
| 206 def custom_vars(self): | 210 def custom_vars(self): |
| 207 """Immutable so no need to lock.""" | |
| 208 return self._custom_vars.copy() | 211 return self._custom_vars.copy() |
| 209 | 212 |
| 210 @property | 213 @property |
| 211 def custom_deps(self): | 214 def custom_deps(self): |
| 212 """Immutable so no need to lock.""" | |
| 213 return self._custom_deps.copy() | 215 return self._custom_deps.copy() |
| 214 | 216 |
| 215 @property | 217 @property |
| 216 def url(self): | 218 def url(self): |
| 217 return self._url | 219 return self._url |
| 218 | 220 |
| 221 @property | |
| 222 def recursion_limit(self): | |
| 223 """Returns > 0 if this dependency is not too recursed to be processed. | |
| 224 | |
| 225 Immutable so no need to lock. | |
|
Dirk Pranke
2011/10/03 21:10:04
Nit: if you're deleting the "immutable" comments f
M-A Ruel
2011/10/03 21:29:48
Thanks, copy-paste fail.
| |
| 226 """ | |
| 227 return max(self.parent.recursion_limit - 1, 0) | |
| 228 | |
| 229 def get_custom_deps(self, name, url): | |
|
Dirk Pranke
2011/10/03 21:10:04
Should this be a property (i.e., @property def cus
M-A Ruel
2011/10/03 21:29:48
there's already a custom_deps property. This one i
| |
| 230 """Returns a custom deps if applicable.""" | |
| 231 if self.parent: | |
| 232 url = self.parent.get_custom_deps(name, url) | |
| 233 # None is a valid return value to disable a dependency. | |
| 234 return self.custom_deps.get(name, url) | |
| 235 | |
| 219 | 236 |
| 220 class Dependency(gclient_utils.WorkItem, DependencySettings): | 237 class Dependency(gclient_utils.WorkItem, DependencySettings): |
| 221 """Object that represents a dependency checkout.""" | 238 """Object that represents a dependency checkout.""" |
| 222 | 239 |
| 223 def __init__(self, parent, name, url, safesync_url, managed, custom_deps, | 240 def __init__(self, parent, name, url, safesync_url, managed, custom_deps, |
| 224 custom_vars, deps_file, should_process): | 241 custom_vars, deps_file, should_process): |
| 225 gclient_utils.WorkItem.__init__(self, name) | 242 gclient_utils.WorkItem.__init__(self, name) |
| 226 DependencySettings.__init__( | 243 DependencySettings.__init__( |
| 227 self, parent, url, safesync_url, managed, custom_deps, custom_vars, | 244 self, parent, url, safesync_url, managed, custom_deps, custom_vars, |
| 228 deps_file, should_process) | 245 deps_file, should_process) |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 yield i | 629 yield i |
| 613 | 630 |
| 614 def depth_first_tree(self): | 631 def depth_first_tree(self): |
| 615 """Depth-first recursion including the root node.""" | 632 """Depth-first recursion including the root node.""" |
| 616 yield self | 633 yield self |
| 617 for i in self.dependencies: | 634 for i in self.dependencies: |
| 618 for j in i.depth_first_tree(): | 635 for j in i.depth_first_tree(): |
| 619 if j.should_process: | 636 if j.should_process: |
| 620 yield j | 637 yield j |
| 621 | 638 |
| 622 def get_custom_deps(self, name, url): | |
| 623 """Returns a custom deps if applicable.""" | |
| 624 if self.parent: | |
| 625 url = self.parent.get_custom_deps(name, url) | |
| 626 # None is a valid return value to disable a dependency. | |
| 627 return self.custom_deps.get(name, url) | |
| 628 | |
| 629 @property | |
| 630 def recursion_limit(self): | |
| 631 """Returns > 0 if this dependency is not too recursed to be processed. | |
| 632 | |
| 633 Immutable so no need to lock. | |
| 634 """ | |
| 635 return max(self.parent.recursion_limit - 1, 0) | |
| 636 | |
| 637 @property | 639 @property |
| 638 def dependencies(self): | 640 def dependencies(self): |
| 639 return tuple(self._dependencies) | 641 return tuple(self._dependencies) |
| 640 | 642 |
| 641 @property | 643 @property |
| 642 def deps_hooks(self): | 644 def deps_hooks(self): |
| 643 return tuple(self._deps_hooks) | 645 return tuple(self._deps_hooks) |
| 644 | 646 |
| 645 @property | 647 @property |
| 646 def parsed_url(self): | 648 def parsed_url(self): |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 | 690 |
| 689 def hierarchy(self): | 691 def hierarchy(self): |
| 690 """Returns a human-readable hierarchical reference to a Dependency.""" | 692 """Returns a human-readable hierarchical reference to a Dependency.""" |
| 691 out = '%s(%s)' % (self.name, self.url) | 693 out = '%s(%s)' % (self.name, self.url) |
| 692 i = self.parent | 694 i = self.parent |
| 693 while i and i.name: | 695 while i and i.name: |
| 694 out = '%s(%s) -> %s' % (i.name, i.url, out) | 696 out = '%s(%s) -> %s' % (i.name, i.url, out) |
| 695 i = i.parent | 697 i = i.parent |
| 696 return out | 698 return out |
| 697 | 699 |
| 698 @property | |
| 699 def root(self): | |
| 700 """Returns the root node, a GClient object.""" | |
| 701 if not self.parent: | |
| 702 # This line is to signal pylint that it could be a GClient instance. | |
| 703 return self or GClient(None, None) | |
| 704 return self.parent.root | |
| 705 | |
| 706 | 700 |
| 707 class GClient(Dependency): | 701 class GClient(Dependency): |
| 708 """Object that represent a gclient checkout. A tree of Dependency(), one per | 702 """Object that represent a gclient checkout. A tree of Dependency(), one per |
| 709 solution or DEPS entry.""" | 703 solution or DEPS entry.""" |
| 710 | 704 |
| 711 DEPS_OS_CHOICES = { | 705 DEPS_OS_CHOICES = { |
| 712 "win32": "win", | 706 "win32": "win", |
| 713 "win": "win", | 707 "win": "win", |
| 714 "cygwin": "win", | 708 "cygwin": "win", |
| 715 "darwin": "mac", | 709 "darwin": "mac", |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1460 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1454 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 1461 print >> sys.stderr, 'Error: %s' % str(e) | 1455 print >> sys.stderr, 'Error: %s' % str(e) |
| 1462 return 1 | 1456 return 1 |
| 1463 | 1457 |
| 1464 | 1458 |
| 1465 if '__main__' == __name__: | 1459 if '__main__' == __name__: |
| 1466 fix_encoding.fix_encoding() | 1460 fix_encoding.fix_encoding() |
| 1467 sys.exit(Main(sys.argv[1:])) | 1461 sys.exit(Main(sys.argv[1:])) |
| 1468 | 1462 |
| 1469 # vim: ts=2:sw=2:tw=80:et: | 1463 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |