| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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)) |
| 230 continue |
| 231 |
| 232 remote_sha1 = get_sha1(output_filename) |
| 233 if remote_sha1 != input_sha1_sum: |
| 234 msg = ('%d> ERROR remote sha1 (%s) does not match expected sha1 (%s).' % |
| 235 (thread_num, remote_sha1, input_sha1_sum)) |
| 236 out_q.put(msg) |
| 237 ret_codes.put((20, msg)) |
| 238 continue |
| 230 | 239 |
| 231 # Set executable bit. | 240 # Set executable bit. |
| 232 if sys.platform == 'cygwin': | 241 if sys.platform == 'cygwin': |
| 233 # Under cygwin, mark all files as executable. The executable flag in | 242 # Under cygwin, mark all files as executable. The executable flag in |
| 234 # Google Storage will not be set when uploading from Windows, so if | 243 # Google Storage will not be set when uploading from Windows, so if |
| 235 # this script is running under cygwin and we're downloading an | 244 # this script is running under cygwin and we're downloading an |
| 236 # executable, it will be unrunnable from inside cygwin without this. | 245 # executable, it will be unrunnable from inside cygwin without this. |
| 237 st = os.stat(output_filename) | 246 st = os.stat(output_filename) |
| 238 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) | 247 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) |
| 239 elif sys.platform != 'win32': | 248 elif sys.platform != 'win32': |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 base_url = 'gs://%s' % options.bucket | 458 base_url = 'gs://%s' % options.bucket |
| 450 | 459 |
| 451 return download_from_google_storage( | 460 return download_from_google_storage( |
| 452 input_filename, base_url, gsutil, options.num_threads, options.directory, | 461 input_filename, base_url, gsutil, options.num_threads, options.directory, |
| 453 options.recursive, options.force, options.output, options.ignore_errors, | 462 options.recursive, options.force, options.output, options.ignore_errors, |
| 454 options.sha1_file, options.verbose, options.auto_platform) | 463 options.sha1_file, options.verbose, options.auto_platform) |
| 455 | 464 |
| 456 | 465 |
| 457 if __name__ == '__main__': | 466 if __name__ == '__main__': |
| 458 sys.exit(main(sys.argv)) | 467 sys.exit(main(sys.argv)) |
| OLD | NEW |