| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 if sys.platform == 'cygwin': | 241 if sys.platform == 'cygwin': |
| 242 # Under cygwin, mark all files as executable. The executable flag in | 242 # Under cygwin, mark all files as executable. The executable flag in |
| 243 # 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 |
| 244 # this script is running under cygwin and we're downloading an | 244 # this script is running under cygwin and we're downloading an |
| 245 # executable, it will be unrunnable from inside cygwin without this. | 245 # executable, it will be unrunnable from inside cygwin without this. |
| 246 st = os.stat(output_filename) | 246 st = os.stat(output_filename) |
| 247 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) | 247 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) |
| 248 elif sys.platform != 'win32': | 248 elif sys.platform != 'win32': |
| 249 # On non-Windows platforms, key off of the custom header | 249 # On non-Windows platforms, key off of the custom header |
| 250 # "x-goog-meta-executable". | 250 # "x-goog-meta-executable". |
| 251 # | 251 code, out, _ = gsutil.check_call('stat', file_url) |
| 252 # TODO(hinoka): It is supposedly faster to use "gsutil stat" but that | |
| 253 # doesn't appear to be supported by the gsutil currently in our tree. When | |
| 254 # we update, this code should use that instead of "gsutil ls -L". | |
| 255 code, out, _ = gsutil.check_call('ls', '-L', file_url) | |
| 256 if code != 0: | 252 if code != 0: |
| 257 out_q.put('%d> %s' % (thread_num, err)) | 253 out_q.put('%d> %s' % (thread_num, err)) |
| 258 ret_codes.put((code, err)) | 254 ret_codes.put((code, err)) |
| 259 elif re.search('x-goog-meta-executable:', out): | 255 elif re.search(r'executable:\s*1', out): |
| 260 st = os.stat(output_filename) | 256 st = os.stat(output_filename) |
| 261 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) | 257 os.chmod(output_filename, st.st_mode | stat.S_IEXEC) |
| 262 | 258 |
| 263 def printer_worker(output_queue): | 259 def printer_worker(output_queue): |
| 264 while True: | 260 while True: |
| 265 line = output_queue.get() | 261 line = output_queue.get() |
| 266 # Its plausible we want to print empty lines. | 262 # Its plausible we want to print empty lines. |
| 267 if line is None: | 263 if line is None: |
| 268 break | 264 break |
| 269 print line | 265 print line |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 return code | 450 return code |
| 455 | 451 |
| 456 return download_from_google_storage( | 452 return download_from_google_storage( |
| 457 input_filename, base_url, gsutil, options.num_threads, options.directory, | 453 input_filename, base_url, gsutil, options.num_threads, options.directory, |
| 458 options.recursive, options.force, options.output, options.ignore_errors, | 454 options.recursive, options.force, options.output, options.ignore_errors, |
| 459 options.sha1_file, options.verbose, options.auto_platform) | 455 options.sha1_file, options.verbose, options.auto_platform) |
| 460 | 456 |
| 461 | 457 |
| 462 if __name__ == '__main__': | 458 if __name__ == '__main__': |
| 463 sys.exit(main(sys.argv)) | 459 sys.exit(main(sys.argv)) |
| OLD | NEW |