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

Side by Side Diff: gcl.py

Issue 3111016: Add retry on svn cat. (Closed)
Patch Set: fixed for invalid credentials, use --non-interactive 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) 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 """\ 6 """\
7 Wrapper script around Rietveld's upload.py that simplifies working with groups 7 Wrapper script around Rietveld's upload.py that simplifies working with groups
8 of files. 8 of files.
9 """ 9 """
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 except gclient_utils.Error: 126 except gclient_utils.Error:
127 return None 127 return None
128 if (not os.path.exists(cached_file) or 128 if (not os.path.exists(cached_file) or
129 (time.time() - os.stat(cached_file).st_mtime) > max_age): 129 (time.time() - os.stat(cached_file).st_mtime) > max_age):
130 dir_info = SVN.CaptureInfo(".") 130 dir_info = SVN.CaptureInfo(".")
131 repo_root = dir_info["Repository Root"] 131 repo_root = dir_info["Repository Root"]
132 if use_root: 132 if use_root:
133 url_path = repo_root 133 url_path = repo_root
134 else: 134 else:
135 url_path = dir_info["URL"] 135 url_path = dir_info["URL"]
136 content = ""
137 while True: 136 while True:
138 # Look in the repository at the current level for the file. 137 # Look in the repository at the current level for the file.
139 svn_path = url_path + "/" + filename 138 for _ in range(5):
140 content, rc = RunShellWithReturnCode(["svn", "cat", svn_path]) 139 content = ""
141 if not rc: 140 try:
142 # Exit the loop if the file was found. Override content. 141 # Take advantage of the fact that svn won't output to stderr in case
142 # of success but will do in case of failure so don't mind putting
143 # stderr into content_array.
144 content_array = []
145 svn_path = url_path + "/" + filename
146 SVN.RunAndFilterOutput(['cat', svn_path, '--non-interactive'], '.',
147 False, False, content_array.append)
148 # Exit the loop if the file was found. Override content.
149 content = '\n'.join(content_array)
150 break
151 except gclient_utils.Error, e:
152 if content_array[0].startswith(
153 'svn: Can\'t get username or password'):
154 ErrorExit('Your svn credentials expired. Please run svn log to '
nsylvain 2010/08/19 15:47:07 what about svn ls ? Svn log is evil
155 'fix the cached credentials')
156 if not content_array[0].startswith('svn: File not found:'):
157 # Try again.
158 continue
159 if content:
143 break 160 break
144 # Make sure to mark settings as empty if not found.
145 content = ""
146 if url_path == repo_root: 161 if url_path == repo_root:
147 # Reached the root. Abandoning search. 162 # Reached the root. Abandoning search.
148 break 163 break
149 # Go up one level to try again. 164 # Go up one level to try again.
150 url_path = os.path.dirname(url_path) 165 url_path = os.path.dirname(url_path)
151 # Write a cached version even if there isn't a file, so we don't try to 166 # Write a cached version even if there isn't a file, so we don't try to
152 # fetch it each time. 167 # fetch it each time.
153 gclient_utils.FileWrite(cached_file, content) 168 gclient_utils.FileWrite(cached_file, content)
154 else: 169 else:
155 content = gclient_utils.FileRead(cached_file, 'r') 170 content = gclient_utils.FileRead(cached_file, 'r')
(...skipping 29 matching lines...) Expand all
185 def ErrorExit(msg): 200 def ErrorExit(msg):
186 print >> sys.stderr, msg 201 print >> sys.stderr, msg
187 sys.exit(1) 202 sys.exit(1)
188 203
189 204
190 def RunShellWithReturnCode(command, print_output=False): 205 def RunShellWithReturnCode(command, print_output=False):
191 """Executes a command and returns the output and the return code.""" 206 """Executes a command and returns the output and the return code."""
192 # Use a shell for subcommands on Windows to get a PATH search, and because svn 207 # Use a shell for subcommands on Windows to get a PATH search, and because svn
193 # may be a batch file. 208 # may be a batch file.
194 use_shell = sys.platform.startswith("win") 209 use_shell = sys.platform.startswith("win")
210 env = os.environ.copy()
211 env['LANGUAGE'] = 'en'
195 p = subprocess.Popen(command, stdout=subprocess.PIPE, 212 p = subprocess.Popen(command, stdout=subprocess.PIPE,
196 stderr=subprocess.STDOUT, shell=use_shell, 213 stderr=subprocess.STDOUT, shell=use_shell, env=env,
197 universal_newlines=True) 214 universal_newlines=True)
198 if print_output: 215 if print_output:
199 output_array = [] 216 output_array = []
200 while True: 217 while True:
201 line = p.stdout.readline() 218 line = p.stdout.readline()
202 if not line: 219 if not line:
203 break 220 break
204 if print_output: 221 if print_output:
205 print line.strip('\n') 222 print line.strip('\n')
206 output_array.append(line) 223 output_array.append(line)
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 if command: 1316 if command:
1300 return command(argv[1:]) 1317 return command(argv[1:])
1301 # Unknown command, try to pass that to svn 1318 # Unknown command, try to pass that to svn
1302 return CMDpassthru(argv) 1319 return CMDpassthru(argv)
1303 except gclient_utils.Error, e: 1320 except gclient_utils.Error, e:
1304 print('Got an exception') 1321 print('Got an exception')
1305 print(str(e)) 1322 print(str(e))
1306 1323
1307 if __name__ == "__main__": 1324 if __name__ == "__main__":
1308 sys.exit(main(sys.argv[1:])) 1325 sys.exit(main(sys.argv[1:]))
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