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

Side by Side Diff: gcl.py

Issue 150114: Fix 'gcl help' when not run inside a svn checkout. (Closed)
Patch Set: Created 11 years, 5 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) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 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 # Wrapper script around Rietveld's upload.py that groups files into 6 # Wrapper script around Rietveld's upload.py that groups files into
7 # changelists. 7 # changelists.
8 8
9 import getpass 9 import getpass
10 import os 10 import os
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 def GetRepositoryRoot(): 89 def GetRepositoryRoot():
90 """Returns the top level directory of the current repository. 90 """Returns the top level directory of the current repository.
91 91
92 The directory is returned as an absolute path. 92 The directory is returned as an absolute path.
93 """ 93 """
94 global REPOSITORY_ROOT 94 global REPOSITORY_ROOT
95 if not REPOSITORY_ROOT: 95 if not REPOSITORY_ROOT:
96 infos = gclient.CaptureSVNInfo(os.getcwd(), print_error=False) 96 infos = gclient.CaptureSVNInfo(os.getcwd(), print_error=False)
97 cur_dir_repo_root = infos.get("Repository Root") 97 cur_dir_repo_root = infos.get("Repository Root")
98 if not cur_dir_repo_root: 98 if not cur_dir_repo_root:
99 raise Exception("gcl run outside of repository") 99 raise gclient.Error("gcl run outside of repository")
100 100
101 REPOSITORY_ROOT = os.getcwd() 101 REPOSITORY_ROOT = os.getcwd()
102 while True: 102 while True:
103 parent = os.path.dirname(REPOSITORY_ROOT) 103 parent = os.path.dirname(REPOSITORY_ROOT)
104 if (gclient.CaptureSVNInfo(parent, print_error=False).get( 104 if (gclient.CaptureSVNInfo(parent, print_error=False).get(
105 "Repository Root") != cur_dir_repo_root): 105 "Repository Root") != cur_dir_repo_root):
106 break 106 break
107 REPOSITORY_ROOT = parent 107 REPOSITORY_ROOT = parent
108 return REPOSITORY_ROOT 108 return REPOSITORY_ROOT
109 109
(...skipping 21 matching lines...) Expand all
131 directory to the root repository. 131 directory to the root repository.
132 132
133 Note: The cache will be inconsistent if the same file is retrieved with both 133 Note: The cache will be inconsistent if the same file is retrieved with both
134 use_root=True and use_root=False on the same file. Don't be stupid. 134 use_root=True and use_root=False on the same file. Don't be stupid.
135 """ 135 """
136 global FILES_CACHE 136 global FILES_CACHE
137 if filename not in FILES_CACHE: 137 if filename not in FILES_CACHE:
138 # Don't try to look up twice. 138 # Don't try to look up twice.
139 FILES_CACHE[filename] = None 139 FILES_CACHE[filename] = None
140 # First we check if we have a cached version. 140 # First we check if we have a cached version.
141 cached_file = os.path.join(GetCacheDir(), filename) 141 try:
142 cached_file = os.path.join(GetCacheDir(), filename)
143 except gclient.Error:
144 return None
142 if (not os.path.exists(cached_file) or 145 if (not os.path.exists(cached_file) or
143 os.stat(cached_file).st_mtime > max_age): 146 os.stat(cached_file).st_mtime > max_age):
144 dir_info = gclient.CaptureSVNInfo(".") 147 dir_info = gclient.CaptureSVNInfo(".")
145 repo_root = dir_info["Repository Root"] 148 repo_root = dir_info["Repository Root"]
146 if use_root: 149 if use_root:
147 url_path = repo_root 150 url_path = repo_root
148 else: 151 else:
149 url_path = dir_info["URL"] 152 url_path = dir_info["URL"]
150 content = "" 153 content = ""
151 while True: 154 while True:
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 1095
1093 1096
1094 def main(argv=None): 1097 def main(argv=None):
1095 if argv is None: 1098 if argv is None:
1096 argv = sys.argv 1099 argv = sys.argv
1097 1100
1098 if len(argv) == 1: 1101 if len(argv) == 1:
1099 Help() 1102 Help()
1100 return 0; 1103 return 0;
1101 1104
1102 # Create the directories where we store information about changelists if it 1105 try:
1103 # doesn't exist. 1106 # Create the directories where we store information about changelists if it
1104 if not os.path.exists(GetInfoDir()): 1107 # doesn't exist.
1105 os.mkdir(GetInfoDir()) 1108 if not os.path.exists(GetInfoDir()):
1106 if not os.path.exists(GetChangesDir()): 1109 os.mkdir(GetInfoDir())
1107 os.mkdir(GetChangesDir()) 1110 if not os.path.exists(GetChangesDir()):
1108 # For smooth upgrade support, move the files in GetInfoDir() to 1111 os.mkdir(GetChangesDir())
1109 # GetChangesDir(). 1112 # For smooth upgrade support, move the files in GetInfoDir() to
1110 # TODO(maruel): Remove this code in August 2009. 1113 # GetChangesDir().
1111 for file in os.listdir(unicode(GetInfoDir())): 1114 # TODO(maruel): Remove this code in August 2009.
1112 file_path = os.path.join(unicode(GetInfoDir()), file) 1115 for file in os.listdir(unicode(GetInfoDir())):
1113 if os.path.isfile(file_path) and file != CODEREVIEW_SETTINGS_FILE: 1116 file_path = os.path.join(unicode(GetInfoDir()), file)
1114 shutil.move(file_path, GetChangesDir()) 1117 if os.path.isfile(file_path) and file != CODEREVIEW_SETTINGS_FILE:
1115 if not os.path.exists(GetCacheDir()): 1118 shutil.move(file_path, GetChangesDir())
1116 os.mkdir(GetCacheDir()) 1119 if not os.path.exists(GetCacheDir()):
1120 os.mkdir(GetCacheDir())
1121 except gclient.Error:
1122 # Will throw an exception if not run in a svn checkout.
1123 pass
1117 1124
1118 # Commands that don't require an argument. 1125 # Commands that don't require an argument.
1119 command = argv[1] 1126 command = argv[1]
1120 if command == "opened": 1127 if command == "opened":
1121 Opened() 1128 Opened()
1122 return 0 1129 return 0
1123 if command == "status": 1130 if command == "status":
1124 Opened() 1131 Opened()
1125 print "\n--- Not in any changelist:" 1132 print "\n--- Not in any changelist:"
1126 UnknownFiles([]) 1133 UnknownFiles([])
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 # the files. This allows commands such as 'gcl diff xxx' to work. 1205 # the files. This allows commands such as 'gcl diff xxx' to work.
1199 args =["svn", command] 1206 args =["svn", command]
1200 root = GetRepositoryRoot() 1207 root = GetRepositoryRoot()
1201 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) 1208 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()])
1202 RunShell(args, True) 1209 RunShell(args, True)
1203 return 0 1210 return 0
1204 1211
1205 1212
1206 if __name__ == "__main__": 1213 if __name__ == "__main__":
1207 sys.exit(main()) 1214 sys.exit(main())
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