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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 continue | 229 continue |
230 # Check if file exists. | 230 # Check if file exists. |
231 file_url = '%s/%s' % (base_url, input_sha1_sum) | 231 file_url = '%s/%s' % (base_url, input_sha1_sum) |
232 if gsutil.check_call('ls', file_url)[0] != 0: | 232 if gsutil.check_call('ls', file_url)[0] != 0: |
233 out_q.put('%d> File %s for %s does not exist, skipping.' % ( | 233 out_q.put('%d> File %s for %s does not exist, skipping.' % ( |
234 thread_num, file_url, output_filename)) | 234 thread_num, file_url, output_filename)) |
235 ret_codes.put((1, 'File %s for %s does not exist.' % ( | 235 ret_codes.put((1, 'File %s for %s does not exist.' % ( |
236 file_url, output_filename))) | 236 file_url, output_filename))) |
237 continue | 237 continue |
238 # Fetch the file. | 238 # Fetch the file. |
239 out_q.put('%d> Downloading %s...' % ( | 239 out_q.put('%d> Downloading %s...' % (thread_num, output_filename)) |
240 thread_num, output_filename)) | 240 try: |
| 241 os.remove(output_filename) # Delete the file if it exists already. |
| 242 except OSError: |
| 243 if os.path.exists(output_filename): |
| 244 out_q.put('%d> Warning: deleting %s failed.' % ( |
| 245 thread_num, output_filename)) |
241 code, _, err = gsutil.check_call('cp', '-q', file_url, output_filename) | 246 code, _, err = gsutil.check_call('cp', '-q', file_url, output_filename) |
242 if code != 0: | 247 if code != 0: |
243 out_q.put('%d> %s' % (thread_num, err)) | 248 out_q.put('%d> %s' % (thread_num, err)) |
244 ret_codes.put((code, err)) | 249 ret_codes.put((code, err)) |
245 | 250 |
246 # Set executable bit. | 251 # Set executable bit. |
247 if sys.platform == 'cygwin': | 252 if sys.platform == 'cygwin': |
248 # Under cygwin, mark all files as executable. The executable flag in | 253 # Under cygwin, mark all files as executable. The executable flag in |
249 # Google Storage will not be set when uploading from Windows, so if | 254 # Google Storage will not be set when uploading from Windows, so if |
250 # this script is running under cygwin and we're downloading an | 255 # this script is running under cygwin and we're downloading an |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 return code | 463 return code |
459 | 464 |
460 return download_from_google_storage( | 465 return download_from_google_storage( |
461 input_filename, base_url, gsutil, options.num_threads, options.directory, | 466 input_filename, base_url, gsutil, options.num_threads, options.directory, |
462 options.recursive, options.force, options.output, options.ignore_errors, | 467 options.recursive, options.force, options.output, options.ignore_errors, |
463 options.sha1_file, options.verbose, options.auto_platform) | 468 options.sha1_file, options.verbose, options.auto_platform) |
464 | 469 |
465 | 470 |
466 if __name__ == '__main__': | 471 if __name__ == '__main__': |
467 sys.exit(main(sys.argv)) | 472 sys.exit(main(sys.argv)) |
OLD | NEW |