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

Side by Side Diff: download_from_google_storage.py

Issue 1091373004: Report more detailed error from download_from_google_storage.py when gsutil fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 8 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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 """Download files from Google Storage based on SHA1 sums.""" 6 """Download files from Google Storage based on SHA1 sums."""
7 7
8 8
9 import hashlib 9 import hashlib
10 import optparse 10 import optparse
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 env=self.get_sub_env(), 93 env=self.get_sub_env(),
94 timeout=self.timeout) 94 timeout=self.timeout)
95 95
96 # Parse output. 96 # Parse output.
97 status_code_match = re.search('status=([0-9]+)', err) 97 status_code_match = re.search('status=([0-9]+)', err)
98 if status_code_match: 98 if status_code_match:
99 return (int(status_code_match.group(1)), out, err) 99 return (int(status_code_match.group(1)), out, err)
100 if ('You are attempting to access protected data with ' 100 if ('You are attempting to access protected data with '
101 'no configured credentials.' in err): 101 'no configured credentials.' in err):
102 return (403, out, err) 102 return (403, out, err)
103 if 'No such object' in err: 103 if 'matched no objects' in err:
104 return (404, out, err) 104 return (404, out, err)
105 return (code, out, err) 105 return (code, out, err)
106 106
107 107
108 def check_platform(target): 108 def check_platform(target):
109 """Checks if any parent directory of target matches (win|mac|linux).""" 109 """Checks if any parent directory of target matches (win|mac|linux)."""
110 assert os.path.isabs(target) 110 assert os.path.isabs(target)
111 root, target_name = os.path.split(target) 111 root, target_name = os.path.split(target)
112 if not target_name: 112 if not target_name:
113 return None 113 return None
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return 199 return
200 if os.path.exists(output_filename) and not force: 200 if os.path.exists(output_filename) and not force:
201 if get_sha1(output_filename) == input_sha1_sum: 201 if get_sha1(output_filename) == input_sha1_sum:
202 if verbose: 202 if verbose:
203 out_q.put( 203 out_q.put(
204 '%d> File %s exists and SHA1 matches. Skipping.' % ( 204 '%d> File %s exists and SHA1 matches. Skipping.' % (
205 thread_num, output_filename)) 205 thread_num, output_filename))
206 continue 206 continue
207 # Check if file exists. 207 # Check if file exists.
208 file_url = '%s/%s' % (base_url, input_sha1_sum) 208 file_url = '%s/%s' % (base_url, input_sha1_sum)
209 if gsutil.check_call('ls', file_url)[0] != 0: 209 (code, _, err) = gsutil.check_call('ls', file_url)
210 out_q.put('%d> File %s for %s does not exist, skipping.' % ( 210 if code != 0:
211 thread_num, file_url, output_filename)) 211 if code == 404:
212 ret_codes.put((1, 'File %s for %s does not exist.' % ( 212 out_q.put('%d> File %s for %s does not exist, skipping.' % (
213 file_url, output_filename))) 213 thread_num, file_url, output_filename))
214 ret_codes.put((1, 'File %s for %s does not exist.' % (
215 file_url, output_filename)))
216 else:
217 # Other error, probably auth related (bad ~/.boto, etc).
218 out_q.put('%d> Failed to fetch file %s for %s, skipping. [Err: %s]' % (
219 thread_num, file_url, output_filename, err))
220 ret_codes.put((1, 'Failed to fetch file %s for %s. [Err: %s]' % (
221 file_url, output_filename, err)))
214 continue 222 continue
215 # Fetch the file. 223 # Fetch the file.
216 out_q.put('%d> Downloading %s...' % (thread_num, output_filename)) 224 out_q.put('%d> Downloading %s...' % (thread_num, output_filename))
217 try: 225 try:
218 os.remove(output_filename) # Delete the file if it exists already. 226 os.remove(output_filename) # Delete the file if it exists already.
219 except OSError: 227 except OSError:
220 if os.path.exists(output_filename): 228 if os.path.exists(output_filename):
221 out_q.put('%d> Warning: deleting %s failed.' % ( 229 out_q.put('%d> Warning: deleting %s failed.' % (
222 thread_num, output_filename)) 230 thread_num, output_filename))
223 code, _, err = gsutil.check_call('cp', file_url, output_filename) 231 code, _, err = gsutil.check_call('cp', file_url, output_filename)
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 base_url = 'gs://%s' % options.bucket 451 base_url = 'gs://%s' % options.bucket
444 452
445 return download_from_google_storage( 453 return download_from_google_storage(
446 input_filename, base_url, gsutil, options.num_threads, options.directory, 454 input_filename, base_url, gsutil, options.num_threads, options.directory,
447 options.recursive, options.force, options.output, options.ignore_errors, 455 options.recursive, options.force, options.output, options.ignore_errors,
448 options.sha1_file, options.verbose, options.auto_platform) 456 options.sha1_file, options.verbose, options.auto_platform)
449 457
450 458
451 if __name__ == '__main__': 459 if __name__ == '__main__':
452 sys.exit(main(sys.argv)) 460 sys.exit(main(sys.argv))
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