Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: gclient.py

Issue 3179001: A small refactor I had lying around for a while. (Closed)
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 else: 740 else:
741 # Delete the entry 741 # Delete the entry
742 print('\n________ deleting \'%s\' in \'%s\'' % ( 742 print('\n________ deleting \'%s\' in \'%s\'' % (
743 entry_fixed, self.root_dir())) 743 entry_fixed, self.root_dir()))
744 gclient_utils.RemoveDirectory(e_dir) 744 gclient_utils.RemoveDirectory(e_dir)
745 # record the current list of entries for next time 745 # record the current list of entries for next time
746 self._SaveEntries() 746 self._SaveEntries()
747 return 0 747 return 0
748 748
749 def PrintRevInfo(self): 749 def PrintRevInfo(self):
750 """Output revision info mapping for the client and its dependencies.
751
752 This allows the capture of an overall "revision" for the source tree that
753 can be used to reproduce the same tree in the future. It is only useful for
754 "unpinned dependencies", i.e. DEPS/deps references without a svn revision
755 number or a git hash. A git branch name isn't "pinned" since the actual
756 commit can change.
757
758 The --snapshot option allows creating a .gclient file to reproduce the tree.
759 """
760 if not self.dependencies: 750 if not self.dependencies:
761 raise gclient_utils.Error('No solution specified') 751 raise gclient_utils.Error('No solution specified')
762 # Load all the settings. 752 # Load all the settings.
763 self.RunCommandRecursively(self._options, {}, None, [], None) 753 self.RunCommandRecursively(self._options, {}, None, [], None)
764 754
765 def GetURLAndRev(name, original_url): 755 def GetURLAndRev(dep):
766 """Returns the revision-qualified SCM url.""" 756 """Returns the revision-qualified SCM url for a Dependency."""
767 if original_url is None: 757 if dep.parsed_url is None:
768 return None 758 return None
769 if isinstance(original_url, self.FileImpl): 759 if isinstance(dep.parsed_url, self.FileImpl):
770 original_url = original_url.file_location 760 original_url = dep.parsed_url.file_location
761 else:
762 original_url = dep.parsed_url
771 url, _ = gclient_utils.SplitUrlRevision(original_url) 763 url, _ = gclient_utils.SplitUrlRevision(original_url)
772 scm = gclient_scm.CreateSCM(original_url, self.root_dir(), name) 764 scm = gclient_scm.CreateSCM(original_url, self.root_dir(), dep.name)
773 if not os.path.isdir(scm.checkout_path): 765 if not os.path.isdir(scm.checkout_path):
774 return None 766 return None
775 return '%s@%s' % (url, scm.revinfo(self._options, [], None)) 767 return '%s@%s' % (url, scm.revinfo(self._options, [], None))
776 768
777 if self._options.snapshot: 769 if self._options.snapshot:
778 new_gclient = '' 770 new_gclient = ''
779 # First level at .gclient 771 # First level at .gclient
780 for d in self.dependencies: 772 for d in self.dependencies:
781 entries = {} 773 entries = {}
782 def GrabDeps(sol): 774 def GrabDeps(dep):
783 """Recursively grab dependencies.""" 775 """Recursively grab dependencies."""
784 for i in sol.dependencies: 776 for d in dep.dependencies:
785 entries[i.name] = GetURLAndRev(i.name, i.parsed_url) 777 entries[d.name] = GetURLAndRev(d)
786 GrabDeps(i) 778 GrabDeps(d)
787 GrabDeps(d) 779 GrabDeps(d)
788 custom_deps = [] 780 custom_deps = []
789 for k in sorted(entries.keys()): 781 for k in sorted(entries.keys()):
790 if entries[k]: 782 if entries[k]:
791 # Quotes aren't escaped... 783 # Quotes aren't escaped...
792 custom_deps.append(' \"%s\": \'%s\',\n' % (k, entries[k])) 784 custom_deps.append(' \"%s\": \'%s\',\n' % (k, entries[k]))
793 else: 785 else:
794 custom_deps.append(' \"%s\": None,\n' % k) 786 custom_deps.append(' \"%s\": None,\n' % k)
795 new_gclient += self.DEFAULT_SNAPSHOT_SOLUTION_TEXT % { 787 new_gclient += self.DEFAULT_SNAPSHOT_SOLUTION_TEXT % {
796 'solution_name': d.name, 788 'solution_name': d.name,
797 'solution_url': d.url, 789 'solution_url': d.url,
798 'safesync_url' : d.safesync_url or '', 790 'safesync_url' : d.safesync_url or '',
799 'solution_deps': ''.join(custom_deps), 791 'solution_deps': ''.join(custom_deps),
800 } 792 }
801 # Print the snapshot configuration file 793 # Print the snapshot configuration file
802 print(self.DEFAULT_SNAPSHOT_FILE_TEXT % {'solution_list': new_gclient}) 794 print(self.DEFAULT_SNAPSHOT_FILE_TEXT % {'solution_list': new_gclient})
803 else: 795 else:
804 entries = sorted(self.tree(False), key=lambda i: i.name) 796 entries = sorted(self.tree(False), key=lambda i: i.name)
805 for entry in entries: 797 for d in entries:
806 entry_url = GetURLAndRev(entry.name, entry.parsed_url) 798 entry_url = GetURLAndRev(d)
807 line = '%s: %s' % (entry.name, entry_url) 799 line = '%s: %s' % (d.name, entry_url)
808 if not entry is entries[-1]: 800 if not d is entries[-1]:
809 line += ';' 801 line += ';'
810 print line 802 print line
811 logging.info(str(self)) 803 logging.info(str(self))
812 804
813 def ParseDepsFile(self, direct_reference): 805 def ParseDepsFile(self, direct_reference):
814 """No DEPS to parse for a .gclient file.""" 806 """No DEPS to parse for a .gclient file."""
815 self.direct_reference = True 807 self.direct_reference = True
816 self.deps_parsed = True 808 self.deps_parsed = True
817 809
818 def root_dir(self): 810 def root_dir(self):
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 return CMDhelp(parser, argv) 1203 return CMDhelp(parser, argv)
1212 except gclient_utils.Error, e: 1204 except gclient_utils.Error, e:
1213 print >> sys.stderr, 'Error: %s' % str(e) 1205 print >> sys.stderr, 'Error: %s' % str(e)
1214 return 1 1206 return 1
1215 1207
1216 1208
1217 if '__main__' == __name__: 1209 if '__main__' == __name__:
1218 sys.exit(Main(sys.argv[1:])) 1210 sys.exit(Main(sys.argv[1:]))
1219 1211
1220 # vim: ts=2:sw=2:tw=80:et: 1212 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698