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

Side by Side Diff: download_from_google_storage.py

Issue 923473002: [download_from_google_storage] Don't list ALL objects to check for ACLs (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Remove spurious sha1 Created 5 years, 10 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 | upload_to_google_storage.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/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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 'No such object' 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_bucket_permissions(base_url, gsutil):
109 code, _, ls_err = gsutil.check_call('ls', base_url)
110 if code != 0:
111 print >> sys.stderr, ls_err
112 if code == 403:
113 print >> sys.stderr, 'Got error 403 while authenticating to %s.' % base_url
114 print >> sys.stderr, 'Try running "download_from_google_storage --config".'
115 elif code == 404:
116 print >> sys.stderr, '%s not found.' % base_url
117 return code
118
119
120 def check_platform(target): 108 def check_platform(target):
121 """Checks if any parent directory of target matches (win|mac|linux).""" 109 """Checks if any parent directory of target matches (win|mac|linux)."""
122 assert os.path.isabs(target) 110 assert os.path.isabs(target)
123 root, target_name = os.path.split(target) 111 root, target_name = os.path.split(target)
124 if not target_name: 112 if not target_name:
125 return None 113 return None
126 if target_name in ('linux', 'mac', 'win'): 114 if target_name in ('linux', 'mac', 'win'):
127 return target_name 115 return target_name
128 return check_platform(root) 116 return check_platform(root)
129 117
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 parser.error('Unreachable state.') 435 parser.error('Unreachable state.')
448 436
449 # Check if output file already exists. 437 # Check if output file already exists.
450 if not options.directory and not options.force and not options.no_resume: 438 if not options.directory and not options.force and not options.no_resume:
451 if os.path.exists(options.output): 439 if os.path.exists(options.output):
452 parser.error('Output file %s exists and --no_resume is specified.' 440 parser.error('Output file %s exists and --no_resume is specified.'
453 % options.output) 441 % options.output)
454 442
455 base_url = 'gs://%s' % options.bucket 443 base_url = 'gs://%s' % options.bucket
456 444
457 # Check we have a valid bucket with valid permissions.
458 if not options.no_auth:
459 code = check_bucket_permissions(base_url, gsutil)
460 if code:
461 return code
462
463 return download_from_google_storage( 445 return download_from_google_storage(
464 input_filename, base_url, gsutil, options.num_threads, options.directory, 446 input_filename, base_url, gsutil, options.num_threads, options.directory,
465 options.recursive, options.force, options.output, options.ignore_errors, 447 options.recursive, options.force, options.output, options.ignore_errors,
466 options.sha1_file, options.verbose, options.auto_platform) 448 options.sha1_file, options.verbose, options.auto_platform)
467 449
468 450
469 if __name__ == '__main__': 451 if __name__ == '__main__':
470 sys.exit(main(sys.argv)) 452 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | upload_to_google_storage.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698