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

Side by Side Diff: tools/get_archive.py

Issue 10867005: Made get_archive.py resilient to 403 forbidden errors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« 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/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 6
7 # Gets or updates a DumpRenderTree (a nearly headless build of chrome). This is 7 # Gets or updates a DumpRenderTree (a nearly headless build of chrome). This is
8 # used for running browser tests of client applications. 8 # used for running browser tests of client applications.
9 9
10 import json 10 import json
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 LAST_VALID = {'dartium': 4285, 'chromedriver': 7823, 'sdk': 9761, 'drt': 5342} 64 LAST_VALID = {'dartium': 4285, 'chromedriver': 7823, 'sdk': 9761, 'drt': 5342}
65 65
66 sys.path.append(os.path.join(GSUTIL_DIR, 'boto')) 66 sys.path.append(os.path.join(GSUTIL_DIR, 'boto'))
67 import boto 67 import boto
68 68
69 69
70 def ExecuteCommand(*cmd): 70 def ExecuteCommand(*cmd):
71 """Execute a command in a subprocess.""" 71 """Execute a command in a subprocess."""
72 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 72 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
73 output, error = pipe.communicate() 73 output, error = pipe.communicate()
74 return pipe.returncode, output 74 return pipe.returncode, output, error
75 75
76 76
77 def ExecuteCommandVisible(*cmd): 77 def ExecuteCommandVisible(*cmd):
78 """Execute a command in a subprocess, but show stdout/stderr.""" 78 """Execute a command in a subprocess, but show stdout/stderr."""
79 result = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr, 79 result = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr,
80 stdin=sys.stdin) 80 stdin=sys.stdin)
81 if result != 0: 81 if result != 0:
82 raise Exception('Execution of "%s" failed' % ' '.join(cmd)) 82 raise Exception('Execution of "%s" failed' % ' '.join(cmd))
83 83
84 84
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 revision_num = latest[latest.rindex('-') + 1 : latest.index('.')] 147 revision_num = latest[latest.rindex('-') + 1 : latest.index('.')]
148 latest = (permanent_prefix[:permanent_prefix.rindex('/')] % { 'osname' : 148 latest = (permanent_prefix[:permanent_prefix.rindex('/')] % { 'osname' :
149 osname } + latest[latest.rindex('/'):]) 149 osname } + latest[latest.rindex('/'):])
150 else: 150 else:
151 latest = (permanent_prefix % { 'osname' : osname, 'num1' : revision_num, 151 latest = (permanent_prefix % { 'osname' : osname, 'num1' : revision_num,
152 'num2' : revision_num }) 152 'num2' : revision_num })
153 foundURL = False 153 foundURL = False
154 while not foundURL: 154 while not foundURL:
155 # Test to ensure this URL exists because the dartium-archive builds can 155 # Test to ensure this URL exists because the dartium-archive builds can
156 # have unusual numbering (a range of CL numbers) sometimes. 156 # have unusual numbering (a range of CL numbers) sometimes.
157 result, out = Gsutil('ls', permanent_prefix % {'osname' : osname, 157 result, out, _ = Gsutil('ls', permanent_prefix % {'osname' : osname,
158 'num1': '*', 'num2': revision_num }) 158 'num1': '*', 'num2': revision_num })
159 if result == 0: 159 if result == 0:
160 # First try to find one with the the second number the same as the 160 # First try to find one with the the second number the same as the
161 # requested number. 161 # requested number.
162 latest = out.split()[0] 162 latest = out.split()[0]
163 foundURL = True 163 # Now test that the permissions are correct so you can actually
164 # download it.
165 temp_dir = tempfile.mkdtemp()
166 temp_zip = os.path.join(temp_dir, 'foo.zip')
167 returncode, out, err = Gsutil('cp', latest, 'file://' + temp_zip)
vsm 2012/08/22 18:08:09 It doesn't look like you're using err here.
168 if returncode == 0:
169 foundURL = True
170 else:
171 # Unable to download this item (most likely because something went
172 # wrong on the upload and the permissions are bad). Keep looking for
173 # a different URL.
174 revision_num = int(revision_num) - 1
175 shutil.rmtree(temp_dir)
164 else: 176 else:
165 # Now try to find one with a nearby CL num. 177 # Now try to find one with a nearby CL num.
166 revision_num = int(revision_num) - 1 178 revision_num = int(revision_num) - 1
167 if revision_num <= 0: 179 if revision_num <= 0:
168 TooEarlyError() 180 TooEarlyError()
169 return latest 181 return latest
170 182
171 GetFromGsutil(name, directory, version_file, latest_pattern, osdict, 183 GetFromGsutil(name, directory, version_file, latest_pattern, osdict,
172 FindPermanentUrl, revision_num) 184 FindPermanentUrl, revision_num)
173 185
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 osname = os_name_dict[system] 238 osname = os_name_dict[system]
227 except KeyError: 239 except KeyError:
228 print >>sys.stderr, ('WARNING: platform "%s" does not support' 240 print >>sys.stderr, ('WARNING: platform "%s" does not support'
229 '%s.') % (system, name) 241 '%s.') % (system, name)
230 return 0 242 return 0
231 243
232 EnsureConfig() 244 EnsureConfig()
233 245
234 # Query for the lastest version 246 # Query for the lastest version
235 pattern = latest_pattern % { 'osname' : osname } 247 pattern = latest_pattern % { 'osname' : osname }
236 result, out = Gsutil('ls', pattern) 248 result, out, _ = Gsutil('ls', pattern)
237 if result == 0: 249 if result == 0:
238 # use permanent link instead, just in case the latest zip entry gets deleted 250 # use permanent link instead, just in case the latest zip entry gets deleted
239 # while we are downloading it. 251 # while we are downloading it.
240 latest = get_permanent_url(out, osname, revision_num) 252 latest = get_permanent_url(out, osname, revision_num)
241 else: # e.g. no access 253 else: # e.g. no access
242 print "Couldn't download %s: %s\n%s" % (name, pattern, out) 254 print "Couldn't download %s: %s\n%s" % (name, pattern, out)
243 if not os.path.exists(version_file): 255 if not os.path.exists(version_file):
244 print "Using %s will not work. Please try again later." % name 256 print "Using %s will not work. Please try again later." % name
245 return 0 257 return 0
246 258
(...skipping 14 matching lines...) Expand all
261 try: 273 try:
262 temp_zip = os.path.join(temp_dir, 'drt.zip') 274 temp_zip = os.path.join(temp_dir, 'drt.zip')
263 temp_zip_url = 'file://' + temp_zip 275 temp_zip_url = 'file://' + temp_zip
264 # It's nice to show download progress 276 # It's nice to show download progress
265 GsutilVisible('cp', latest, temp_zip_url) 277 GsutilVisible('cp', latest, temp_zip_url)
266 278
267 if platform.system() != 'Windows': 279 if platform.system() != 'Windows':
268 # The Python zip utility does not preserve executable permissions, but 280 # The Python zip utility does not preserve executable permissions, but
269 # this does not seem to be a problem for Windows, which does not have a 281 # this does not seem to be a problem for Windows, which does not have a
270 # built in zip utility. :-/ 282 # built in zip utility. :-/
271 result, out = ExecuteCommand('unzip', temp_zip, '-d', temp_dir) 283 result, out, _ = ExecuteCommand('unzip', temp_zip, '-d', temp_dir)
272 if result != 0: 284 if result != 0:
273 raise Exception('Execution of "unzip %s -d %s" failed: %s' % 285 raise Exception('Execution of "unzip %s -d %s" failed: %s' %
274 (temp_zip, temp_dir, str(out))) 286 (temp_zip, temp_dir, str(out)))
275 unzipped_dir = temp_dir + '/' + os.path.basename(latest)[:-len('.zip')] 287 unzipped_dir = temp_dir + '/' + os.path.basename(latest)[:-len('.zip')]
276 else: 288 else:
277 z = zipfile.ZipFile(temp_zip) 289 z = zipfile.ZipFile(temp_zip)
278 z.extractall(temp_dir) 290 z.extractall(temp_dir)
279 unzipped_dir = os.path.join(temp_dir, 291 unzipped_dir = os.path.join(temp_dir,
280 os.path.basename(latest)[:-len('.zip')]) 292 os.path.basename(latest)[:-len('.zip')])
281 z.close() 293 z.close()
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 elif positional[0] == 'drt': 340 elif positional[0] == 'drt':
329 GetDartiumRevision('DumpRenderTree', DRT_DIR, DRT_VERSION, 341 GetDartiumRevision('DumpRenderTree', DRT_DIR, DRT_VERSION,
330 DRT_LATEST_PATTERN, DRT_PERMANENT_PATTERN, 342 DRT_LATEST_PATTERN, DRT_PERMANENT_PATTERN,
331 args.revision) 343 args.revision)
332 else: 344 else:
333 print ('Please specify the target you wish to download from Google Storage ' 345 print ('Please specify the target you wish to download from Google Storage '
334 '("drt", "dartium", "chromedriver", or "sdk")') 346 '("drt", "dartium", "chromedriver", or "sdk")')
335 347
336 if __name__ == '__main__': 348 if __name__ == '__main__':
337 sys.exit(main()) 349 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