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

Side by Side Diff: gclient.py

Issue 115286: Remove the options.path_exists which only existed as a seam. It's not really ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/gclient_test.py » ('j') | 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 # 2 #
3 # Copyright 2008 Google Inc. All Rights Reserved. 3 # Copyright 2008 Google Inc. All Rights Reserved.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 def update(self, options, args, file_list): 746 def update(self, options, args, file_list):
747 """Runs SCM to update or transparently checkout the working copy. 747 """Runs SCM to update or transparently checkout the working copy.
748 748
749 All updated files will be appended to file_list. 749 All updated files will be appended to file_list.
750 750
751 Raises: 751 Raises:
752 Error: if can't get URL for relative path. 752 Error: if can't get URL for relative path.
753 """ 753 """
754 # Only update if git is not controlling the directory. 754 # Only update if git is not controlling the directory.
755 checkout_path = os.path.join(self._root_dir, self.relpath) 755 checkout_path = os.path.join(self._root_dir, self.relpath)
756 git_path = os.path.join(checkout_path, '.git') 756 git_path = os.path.join(self._root_dir, self.relpath, '.git')
757 if options.path_exists(git_path): 757 if os.path.exists(git_path):
758 print("________ found .git directory; skipping %s" % self.relpath) 758 print("________ found .git directory; skipping %s" % self.relpath)
759 return 759 return
760 760
761 if args: 761 if args:
762 raise Error("Unsupported argument(s): %s" % ",".join(args)) 762 raise Error("Unsupported argument(s): %s" % ",".join(args))
763 763
764 url = self.url 764 url = self.url
765 components = url.split("@") 765 components = url.split("@")
766 revision = None 766 revision = None
767 forced_revision = False 767 forced_revision = False
768 if options.revision: 768 if options.revision:
769 # Override the revision number. 769 # Override the revision number.
770 url = '%s@%s' % (components[0], str(options.revision)) 770 url = '%s@%s' % (components[0], str(options.revision))
771 revision = int(options.revision) 771 revision = int(options.revision)
772 forced_revision = True 772 forced_revision = True
773 elif len(components) == 2: 773 elif len(components) == 2:
774 revision = int(components[1]) 774 revision = int(components[1])
775 forced_revision = True 775 forced_revision = True
776 776
777 rev_str = "" 777 rev_str = ""
778 if revision: 778 if revision:
779 rev_str = ' at %d' % revision 779 rev_str = ' at %d' % revision
780 780
781 if not options.path_exists(checkout_path): 781 if not os.path.exists(checkout_path):
782 # We need to checkout. 782 # We need to checkout.
783 command = ['checkout', url, checkout_path] 783 command = ['checkout', url, checkout_path]
784 if revision: 784 if revision:
785 command.extend(['--revision', str(revision)]) 785 command.extend(['--revision', str(revision)])
786 RunSVNAndGetFileList(command, self._root_dir, file_list) 786 RunSVNAndGetFileList(command, self._root_dir, file_list)
787 return 787 return
788 788
789 # Get the existing scm url and the revision number of the current checkout. 789 # Get the existing scm url and the revision number of the current checkout.
790 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.') 790 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.')
791 791
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 """Searches for and loads a .gclient file relative to the current working 958 """Searches for and loads a .gclient file relative to the current working
959 dir. 959 dir.
960 960
961 Returns: 961 Returns:
962 A dict representing the contents of the .gclient file or an empty dict if 962 A dict representing the contents of the .gclient file or an empty dict if
963 the .gclient file doesn't exist. 963 the .gclient file doesn't exist.
964 """ 964 """
965 if not from_dir: 965 if not from_dir:
966 from_dir = os.curdir 966 from_dir = os.curdir
967 path = os.path.realpath(from_dir) 967 path = os.path.realpath(from_dir)
968 while not options.path_exists(os.path.join(path, options.config_filename)): 968 while not os.path.exists(os.path.join(path, options.config_filename)):
969 next = os.path.split(path) 969 next = os.path.split(path)
970 if not next[1]: 970 if not next[1]:
971 return None 971 return None
972 path = next[0] 972 path = next[0]
973 client = options.gclient(path, options) 973 client = options.gclient(path, options)
974 client._LoadConfig() 974 client._LoadConfig()
975 return client 975 return client
976 976
977 def SetDefaultConfig(self, solution_name, solution_url, safesync_url): 977 def SetDefaultConfig(self, solution_name, solution_url, safesync_url):
978 self.SetConfig(DEFAULT_CLIENT_FILE_TEXT % ( 978 self.SetConfig(DEFAULT_CLIENT_FILE_TEXT % (
(...skipping 20 matching lines...) Expand all
999 999
1000 Args: 1000 Args:
1001 client: The client for which the entries file should be read. 1001 client: The client for which the entries file should be read.
1002 1002
1003 Returns: 1003 Returns:
1004 A sequence of solution names, which will be empty if there is the 1004 A sequence of solution names, which will be empty if there is the
1005 entries file hasn't been created yet. 1005 entries file hasn't been created yet.
1006 """ 1006 """
1007 scope = {} 1007 scope = {}
1008 filename = os.path.join(self._root_dir, self._options.entries_filename) 1008 filename = os.path.join(self._root_dir, self._options.entries_filename)
1009 if not self._options.path_exists(filename): 1009 if not os.path.exists(filename):
1010 return [] 1010 return []
1011 exec(FileRead(filename), scope) 1011 exec(FileRead(filename), scope)
1012 return scope["entries"] 1012 return scope["entries"]
1013 1013
1014 class FromImpl: 1014 class FromImpl:
1015 """Used to implement the From syntax.""" 1015 """Used to implement the From syntax."""
1016 1016
1017 def __init__(self, module_name): 1017 def __init__(self, module_name):
1018 self.module_name = module_name 1018 self.module_name = module_name
1019 1019
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 is_using_git = IsUsingGit(self._root_dir, entries.keys()) 1329 is_using_git = IsUsingGit(self._root_dir, entries.keys())
1330 self._RunHooks(command, file_list, is_using_git) 1330 self._RunHooks(command, file_list, is_using_git)
1331 1331
1332 if command == 'update': 1332 if command == 'update':
1333 # notify the user if there is an orphaned entry in their working copy. 1333 # notify the user if there is an orphaned entry in their working copy.
1334 # TODO(darin): we should delete this directory manually if it doesn't 1334 # TODO(darin): we should delete this directory manually if it doesn't
1335 # have any changes in it. 1335 # have any changes in it.
1336 prev_entries = self._ReadEntries() 1336 prev_entries = self._ReadEntries()
1337 for entry in prev_entries: 1337 for entry in prev_entries:
1338 e_dir = os.path.join(self._root_dir, entry) 1338 e_dir = os.path.join(self._root_dir, entry)
1339 if entry not in entries and self._options.path_exists(e_dir): 1339 if entry not in entries and os.path.exists(e_dir):
1340 if CaptureSVNStatus(e_dir): 1340 if CaptureSVNStatus(e_dir):
1341 # There are modified files in this entry 1341 # There are modified files in this entry
1342 entries[entry] = None # Keep warning until removed. 1342 entries[entry] = None # Keep warning until removed.
1343 print("\nWARNING: \"%s\" is no longer part of this client. " 1343 print("\nWARNING: \"%s\" is no longer part of this client. "
1344 "It is recommended that you manually remove it.\n") % entry 1344 "It is recommended that you manually remove it.\n") % entry
1345 else: 1345 else:
1346 # Delete the entry 1346 # Delete the entry
1347 print("\n________ deleting \'%s\' " + 1347 print("\n________ deleting \'%s\' " +
1348 "in \'%s\'") % (entry, self._root_dir) 1348 "in \'%s\'") % (entry, self._root_dir)
1349 RemoveDirectory(e_dir) 1349 RemoveDirectory(e_dir)
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 Args: 1481 Args:
1482 options: If options.spec set, a string providing contents of config file. 1482 options: If options.spec set, a string providing contents of config file.
1483 args: The command line args. If spec is not set, 1483 args: The command line args. If spec is not set,
1484 then args[0] is a string URL to get for config file. 1484 then args[0] is a string URL to get for config file.
1485 1485
1486 Raises: 1486 Raises:
1487 Error: on usage error 1487 Error: on usage error
1488 """ 1488 """
1489 if len(args) < 1 and not options.spec: 1489 if len(args) < 1 and not options.spec:
1490 raise Error("required argument missing; see 'gclient help config'") 1490 raise Error("required argument missing; see 'gclient help config'")
1491 if options.path_exists(options.config_filename): 1491 if os.path.exists(options.config_filename):
1492 raise Error("%s file already exists in the current directory" % 1492 raise Error("%s file already exists in the current directory" %
1493 options.config_filename) 1493 options.config_filename)
1494 client = options.gclient('.', options) 1494 client = options.gclient('.', options)
1495 if options.spec: 1495 if options.spec:
1496 client.SetConfig(options.spec) 1496 client.SetConfig(options.spec)
1497 else: 1497 else:
1498 # TODO(darin): it would be nice to be able to specify an alternate relpath 1498 # TODO(darin): it would be nice to be able to specify an alternate relpath
1499 # for the given URL. 1499 # for the given URL.
1500 base_url = args[0] 1500 base_url = args[0]
1501 name = args[0].split("/")[-1] 1501 name = args[0].split("/")[-1]
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 1706
1707 if len(argv) < 3 and command == "help": 1707 if len(argv) < 3 and command == "help":
1708 option_parser.print_help() 1708 option_parser.print_help()
1709 return 0 1709 return 0
1710 1710
1711 # Files used for configuration and state saving. 1711 # Files used for configuration and state saving.
1712 options.config_filename = os.environ.get("GCLIENT_FILE", ".gclient") 1712 options.config_filename = os.environ.get("GCLIENT_FILE", ".gclient")
1713 options.entries_filename = ".gclient_entries" 1713 options.entries_filename = ".gclient_entries"
1714 options.deps_file = "DEPS" 1714 options.deps_file = "DEPS"
1715 1715
1716 options.path_exists = os.path.exists
1717 options.gclient = GClient 1716 options.gclient = GClient
1718 options.scm_wrapper = SCMWrapper 1717 options.scm_wrapper = SCMWrapper
1719 options.platform = sys.platform 1718 options.platform = sys.platform
1720 return DispatchCommand(command, options, args) 1719 return DispatchCommand(command, options, args)
1721 1720
1722 1721
1723 if "__main__" == __name__: 1722 if "__main__" == __name__:
1724 try: 1723 try:
1725 result = Main(sys.argv) 1724 result = Main(sys.argv)
1726 except Error, e: 1725 except Error, e:
1727 print >> sys.stderr, "Error: %s" % str(e) 1726 print >> sys.stderr, "Error: %s" % str(e)
1728 result = 1 1727 result = 1
1729 sys.exit(result) 1728 sys.exit(result)
1730 1729
1731 # vim: ts=2:sw=2:tw=80:et: 1730 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « no previous file | tests/gclient_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698