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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 | 75 |
76 def check_bucket_permissions(bucket, gsutil): | 76 def check_bucket_permissions(bucket, gsutil): |
77 if not bucket: | 77 if not bucket: |
78 print >> sys.stderr, 'Missing bucket %s.' | 78 print >> sys.stderr, 'Missing bucket %s.' |
79 return (None, 1) | 79 return (None, 1) |
80 base_url = 'gs://%s' % bucket | 80 base_url = 'gs://%s' % bucket |
81 | 81 |
82 code, _, ls_err = gsutil.check_call('ls', base_url) | 82 code, _, ls_err = gsutil.check_call('ls', base_url) |
83 if code == 403: | 83 if code == 403: |
84 code, _, _ = gsutil.call('config') | 84 print >> sys.stderr, 'Got error 403 while authenticating to %s.' % base_url |
85 if code != 0: | 85 print >> sys.stderr, 'Try running "gsutil config".' |
86 print >> sys.stderr, 'Error while authenticating to %s.' % base_url | |
87 elif code == 404: | 86 elif code == 404: |
88 print >> sys.stderr, '%s not found.' % base_url | 87 print >> sys.stderr, '%s not found.' % base_url |
89 elif code != 0: | 88 elif code != 0: |
90 print >> sys.stderr, ls_err | 89 print >> sys.stderr, ls_err |
91 return (base_url, code) | 90 return (base_url, code) |
92 | 91 |
93 | 92 |
94 def get_sha1(filename): | 93 def get_sha1(filename): |
95 sha1 = hashlib.sha1() | 94 sha1 = hashlib.sha1() |
96 with open(filename, 'rb') as f: | 95 with open(filename, 'rb') as f: |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 return code | 329 return code |
331 | 330 |
332 return download_from_google_storage( | 331 return download_from_google_storage( |
333 input_filename, base_url, gsutil, options.num_threads, options.directory, | 332 input_filename, base_url, gsutil, options.num_threads, options.directory, |
334 options.recursive, options.force, options.output, options.ignore_errors, | 333 options.recursive, options.force, options.output, options.ignore_errors, |
335 options.sha1_file) | 334 options.sha1_file) |
336 | 335 |
337 | 336 |
338 if __name__ == '__main__': | 337 if __name__ == '__main__': |
339 sys.exit(main(sys.argv)) | 338 sys.exit(main(sys.argv)) |
OLD | NEW |