Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 parser.add_option('-d', '--directory', action='store_true', | 290 parser.add_option('-d', '--directory', action='store_true', |
| 291 help='The target is a directory. ' | 291 help='The target is a directory. ' |
| 292 'Cannot be used with -s/--sha1_file.') | 292 'Cannot be used with -s/--sha1_file.') |
| 293 parser.add_option('-s', '--sha1_file', action='store_true', | 293 parser.add_option('-s', '--sha1_file', action='store_true', |
| 294 help='The target is a file containing a sha1 sum. ' | 294 help='The target is a file containing a sha1 sum. ' |
| 295 'Cannot be used with -d/--directory.') | 295 'Cannot be used with -d/--directory.') |
| 296 parser.add_option('-g', '--config', action='store_true', | 296 parser.add_option('-g', '--config', action='store_true', |
| 297 help='Alias for "gsutil config". Run this if you want ' | 297 help='Alias for "gsutil config". Run this if you want ' |
| 298 'to initialize your saved Google Storage ' | 298 'to initialize your saved Google Storage ' |
| 299 'credentials.') | 299 'credentials.') |
| 300 parser.add_option('-p', '--platform', | 300 parser.add_option('-n', '--no_auth', action='store_true', |
| 301 help='Skip auth checking. Use if its known that the ' | |
|
ghost stip (do not use)
2013/11/19 19:32:37
it's
| |
| 302 'target bucket is a public bucket.') | |
| 303 parser.add_option('-p', '--platform', | |
| 301 help='A regular expression that is compared against ' | 304 help='A regular expression that is compared against ' |
| 302 'Python\'s sys.platform. If this option is specified, ' | 305 'Python\'s sys.platform. If this option is specified, ' |
| 303 'the download will happen only if there is a match.') | 306 'the download will happen only if there is a match.') |
| 304 | 307 |
| 305 (options, args) = parser.parse_args() | 308 (options, args) = parser.parse_args() |
| 306 | 309 |
| 307 # Make sure we should run at all based on platform matching. | 310 # Make sure we should run at all based on platform matching. |
| 308 if options.platform: | 311 if options.platform: |
| 309 if not re.match(options.platform, sys.platform): | 312 if not re.match(options.platform, sys.platform): |
| 310 print('The current platform doesn\'t match "%s", skipping.' % | 313 print('The current platform doesn\'t match "%s", skipping.' % |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 else: | 361 else: |
| 359 parser.error('Unreachable state.') | 362 parser.error('Unreachable state.') |
| 360 | 363 |
| 361 # Check if output file already exists. | 364 # Check if output file already exists. |
| 362 if not options.directory and not options.force and not options.no_resume: | 365 if not options.directory and not options.force and not options.no_resume: |
| 363 if os.path.exists(options.output): | 366 if os.path.exists(options.output): |
| 364 parser.error('Output file %s exists and --no_resume is specified.' | 367 parser.error('Output file %s exists and --no_resume is specified.' |
| 365 % options.output) | 368 % options.output) |
| 366 | 369 |
| 367 # Check we have a valid bucket with valid permissions. | 370 # Check we have a valid bucket with valid permissions. |
| 368 base_url, code = check_bucket_permissions(options.bucket, gsutil) | 371 if not options.no_auth: |
| 372 base_url, code = check_bucket_permissions(options.bucket, gsutil) | |
| 369 if code: | 373 if code: |
| 370 return code | 374 return code |
| 371 | 375 |
| 372 return download_from_google_storage( | 376 return download_from_google_storage( |
| 373 input_filename, base_url, gsutil, options.num_threads, options.directory, | 377 input_filename, base_url, gsutil, options.num_threads, options.directory, |
| 374 options.recursive, options.force, options.output, options.ignore_errors, | 378 options.recursive, options.force, options.output, options.ignore_errors, |
| 375 options.sha1_file) | 379 options.sha1_file) |
| 376 | 380 |
| 377 | 381 |
| 378 if __name__ == '__main__': | 382 if __name__ == '__main__': |
| 379 sys.exit(main(sys.argv)) | 383 sys.exit(main(sys.argv)) |
| OLD | NEW |