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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 out_q.put('%d> Downloading %s...' % (thread_num, output_filename)) | 219 out_q.put('%d> Downloading %s...' % (thread_num, output_filename)) |
| 220 try: | 220 try: |
| 221 os.remove(output_filename) # Delete the file if it exists already. | 221 os.remove(output_filename) # Delete the file if it exists already. |
| 222 except OSError: | 222 except OSError: |
| 223 if os.path.exists(output_filename): | 223 if os.path.exists(output_filename): |
| 224 out_q.put('%d> Warning: deleting %s failed.' % ( | 224 out_q.put('%d> Warning: deleting %s failed.' % ( |
| 225 thread_num, output_filename)) | 225 thread_num, output_filename)) |
| 226 code, _, err = gsutil.check_call('cp', file_url, output_filename) | 226 code, _, err = gsutil.check_call('cp', file_url, output_filename) |
| 227 if code != 0: | 227 if code != 0: |
| 228 out_q.put('%d> %s' % (thread_num, err)) | 228 out_q.put('%d> %s' % (thread_num, err)) |
| 229 ret_codes.put((code, err)) | 229 ret_codes.put((code, err)) |
|
Vadim Sh.
2015/07/29 20:43:49
is it ok that there's no "continue" after this lin
Ryan Tseng
2015/07/29 20:51:24
Good catch there should be a continue here. I thi
| |
| 230 remote_sha1 = get_sha1(output_filename) | |
| 231 if remote_sha1 != input_sha1_sum: | |
| 232 msg = ('%d> ERROR remote sha1 (%s) does not match expected sha1 (%s).' % | |
| 233 (thread_num, remote_sha1, input_sha1_sum)) | |
| 234 out_q.put(msg) | |
| 235 ret_codes.put((20, msg)) | |
| 236 continue | |
| 230 | 237 |
| 231 # Set executable bit. | 238 # Set executable bit. |
| 232 if sys.platform == 'cygwin': | 239 if sys.platform == 'cygwin': |
| 233 # Under cygwin, mark all files as executable. The executable flag in | 240 # Under cygwin, mark all files as executable. The executable flag in |
| 234 # Google Storage will not be set when uploading from Windows, so if | 241 # Google Storage will not be set when uploading from Windows, so if |
| 235 # this script is running under cygwin and we're downloading an | 242 # this script is running under cygwin and we're downloading an |
| 236 # executable, it will be unrunnable from inside cygwin without this. | 243 # executable, it will be unrunnable from inside cygwin without this. |
| 237 st = os.stat(output_filename) | 244 st = os.stat(output_filename) |
| 238 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) | 245 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) |
| 239 elif sys.platform != 'win32': | 246 elif sys.platform != 'win32': |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 base_url = 'gs://%s' % options.bucket | 456 base_url = 'gs://%s' % options.bucket |
| 450 | 457 |
| 451 return download_from_google_storage( | 458 return download_from_google_storage( |
| 452 input_filename, base_url, gsutil, options.num_threads, options.directory, | 459 input_filename, base_url, gsutil, options.num_threads, options.directory, |
| 453 options.recursive, options.force, options.output, options.ignore_errors, | 460 options.recursive, options.force, options.output, options.ignore_errors, |
| 454 options.sha1_file, options.verbose, options.auto_platform) | 461 options.sha1_file, options.verbose, options.auto_platform) |
| 455 | 462 |
| 456 | 463 |
| 457 if __name__ == '__main__': | 464 if __name__ == '__main__': |
| 458 sys.exit(main(sys.argv)) | 465 sys.exit(main(sys.argv)) |
| OLD | NEW |