Chromium Code Reviews| 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 """Uploads files to Google Storage content addressed.""" | 6 """Uploads files to Google Storage content addressed.""" |
| 7 | 7 |
| 8 import hashlib | 8 import hashlib |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| 11 import Queue | 11 import Queue |
| 12 import re | 12 import re |
| 13 import stat | |
| 13 import sys | 14 import sys |
| 14 import threading | 15 import threading |
| 15 import time | 16 import time |
| 16 | 17 |
| 17 from download_from_google_storage import check_bucket_permissions | 18 from download_from_google_storage import check_bucket_permissions |
| 18 from download_from_google_storage import get_sha1 | 19 from download_from_google_storage import get_sha1 |
| 19 from download_from_google_storage import Gsutil | 20 from download_from_google_storage import Gsutil |
| 20 from download_from_google_storage import printer_worker | 21 from download_from_google_storage import printer_worker |
| 21 | 22 |
| 22 GSUTIL_DEFAULT_PATH = os.path.join( | 23 GSUTIL_DEFAULT_PATH = os.path.join( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 stdout_queue.put('%d> Uploading %s...' % ( | 97 stdout_queue.put('%d> Uploading %s...' % ( |
| 97 thread_num, filename)) | 98 thread_num, filename)) |
| 98 code, _, err = gsutil.check_call('cp', '-q', filename, file_url) | 99 code, _, err = gsutil.check_call('cp', '-q', filename, file_url) |
| 99 if code != 0: | 100 if code != 0: |
| 100 ret_codes.put( | 101 ret_codes.put( |
| 101 (code, | 102 (code, |
| 102 'Encountered error on uploading %s to %s\n%s' % | 103 'Encountered error on uploading %s to %s\n%s' % |
| 103 (filename, file_url, err))) | 104 (filename, file_url, err))) |
| 104 continue | 105 continue |
| 105 | 106 |
| 107 # Mark executable files with the header "x-goog-meta-executable: 1" which | |
| 108 # the download script will check for to preserve the executable bit. | |
| 109 if not sys.platform.startswith('win'): | |
| 110 if (os.stat(filename).st_mode & stat.S_IEXEC): | |
|
M-A Ruel
2013/10/28 15:05:47
if os.stat(filename).st_mode & stat.S_IEXEC:
| |
| 111 code, _, err = gsutil.check_call('setmeta', '-h', | |
| 112 'x-goog-meta-executable:1', file_url) | |
| 113 if (code != 0): | |
|
M-A Ruel
2013/10/28 15:05:47
if code:
| |
| 114 ret_codes.put( | |
| 115 (code, | |
| 116 'Encountered error on setting metadata on %s\n%s' % | |
| 117 (file_url, err))) | |
| 118 | |
| 106 | 119 |
| 107 def get_targets(args, parser, use_null_terminator): | 120 def get_targets(args, parser, use_null_terminator): |
| 108 if not args: | 121 if not args: |
| 109 parser.error('Missing target.') | 122 parser.error('Missing target.') |
| 110 | 123 |
| 111 if len(args) == 1 and args[0] == '-': | 124 if len(args) == 1 and args[0] == '-': |
| 112 # Take stdin as a newline or null seperated list of files. | 125 # Take stdin as a newline or null seperated list of files. |
| 113 if use_null_terminator: | 126 if use_null_terminator: |
| 114 return sys.stdin.read().split('\0') | 127 return sys.stdin.read().split('\0') |
| 115 else: | 128 else: |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 if code: | 249 if code: |
| 237 return code | 250 return code |
| 238 | 251 |
| 239 return upload_to_google_storage( | 252 return upload_to_google_storage( |
| 240 input_filenames, base_url, gsutil, options.force, options.use_md5, | 253 input_filenames, base_url, gsutil, options.force, options.use_md5, |
| 241 options.num_threads, options.skip_hashing) | 254 options.num_threads, options.skip_hashing) |
| 242 | 255 |
| 243 | 256 |
| 244 if __name__ == '__main__': | 257 if __name__ == '__main__': |
| 245 sys.exit(main(sys.argv)) | 258 sys.exit(main(sys.argv)) |
| OLD | NEW |