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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 file_url, output_filename))) | 192 file_url, output_filename))) |
193 continue | 193 continue |
194 # Fetch the file. | 194 # Fetch the file. |
195 out_q.put('%d> Downloading %s...' % ( | 195 out_q.put('%d> Downloading %s...' % ( |
196 thread_num, output_filename)) | 196 thread_num, output_filename)) |
197 code, _, err = gsutil.check_call('cp', '-q', file_url, output_filename) | 197 code, _, err = gsutil.check_call('cp', '-q', file_url, output_filename) |
198 if code != 0: | 198 if code != 0: |
199 out_q.put('%d> %s' % (thread_num, err)) | 199 out_q.put('%d> %s' % (thread_num, err)) |
200 ret_codes.put((code, err)) | 200 ret_codes.put((code, err)) |
201 | 201 |
202 # Mark executable if necessary. We key off of the custom header | 202 # Set executable bit. |
203 # "x-goog-meta-executable". | 203 if sys.platform == 'cygwin': |
204 # | 204 # Under cygwin, mark all files as executable. The executable flag in |
205 # TODO(hinoka): It is supposedly faster to use "gsutil stat" but that | 205 # Google Storage will not be set when uploading from Windows, so if |
206 # doesn't appear to be supported by the gsutil currently in our tree. When | 206 # this script is running under cygwin and we're downloading an |
207 # we update, this code should use that instead of "gsutil ls -L". | 207 # executable, it will be unrunnable from inside cygwin without this. |
208 if sys.platform != 'win32': | 208 st = os.stat(output_filename) |
| 209 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) |
| 210 elif sys.platform != 'win32': |
| 211 # On non-Windows platforms, key off of the custom header |
| 212 # "x-goog-meta-executable". |
| 213 # |
| 214 # TODO(hinoka): It is supposedly faster to use "gsutil stat" but that |
| 215 # doesn't appear to be supported by the gsutil currently in our tree. When |
| 216 # we update, this code should use that instead of "gsutil ls -L". |
209 code, out, _ = gsutil.check_call('ls', '-L', file_url) | 217 code, out, _ = gsutil.check_call('ls', '-L', file_url) |
210 if code != 0: | 218 if code != 0: |
211 out_q.put('%d> %s' % (thread_num, err)) | 219 out_q.put('%d> %s' % (thread_num, err)) |
212 ret_codes.put((code, err)) | 220 ret_codes.put((code, err)) |
213 elif re.search('x-goog-meta-executable:', out): | 221 elif re.search('x-goog-meta-executable:', out): |
214 st = os.stat(output_filename) | 222 st = os.stat(output_filename) |
215 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) | 223 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) |
216 | 224 |
217 def printer_worker(output_queue): | 225 def printer_worker(output_queue): |
218 while True: | 226 while True: |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 return code | 402 return code |
395 | 403 |
396 return download_from_google_storage( | 404 return download_from_google_storage( |
397 input_filename, base_url, gsutil, options.num_threads, options.directory, | 405 input_filename, base_url, gsutil, options.num_threads, options.directory, |
398 options.recursive, options.force, options.output, options.ignore_errors, | 406 options.recursive, options.force, options.output, options.ignore_errors, |
399 options.sha1_file, options.verbose) | 407 options.sha1_file, options.verbose) |
400 | 408 |
401 | 409 |
402 if __name__ == '__main__': | 410 if __name__ == '__main__': |
403 sys.exit(main(sys.argv)) | 411 sys.exit(main(sys.argv)) |
OLD | NEW |