Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: upload_to_google_storage.py

Issue 1824223002: Retry errors setting executable headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: CL comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « download_from_google_storage.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 def _upload_worker( 69 def _upload_worker(
70 thread_num, upload_queue, base_url, gsutil, md5_lock, force, 70 thread_num, upload_queue, base_url, gsutil, md5_lock, force,
71 use_md5, stdout_queue, ret_codes, gzip): 71 use_md5, stdout_queue, ret_codes, gzip):
72 while True: 72 while True:
73 filename, sha1_sum = upload_queue.get() 73 filename, sha1_sum = upload_queue.get()
74 if not filename: 74 if not filename:
75 break 75 break
76 file_url = '%s/%s' % (base_url, sha1_sum) 76 file_url = '%s/%s' % (base_url, sha1_sum)
77 if gsutil.check_call('ls', file_url)[0] == 0 and not force: 77 if gsutil.check_call('ls', file_url)[0] == 0 and not force:
78 # File exists, check MD5 hash. 78 # File exists, check MD5 hash.
79 _, out, _ = gsutil.check_call('ls', '-L', file_url) 79 _, out, _ = gsutil.check_call_with_retries('ls', '-L', file_url)
80 etag_match = re.search('ETag:\s+([a-z0-9]{32})', out) 80 etag_match = re.search('ETag:\s+([a-z0-9]{32})', out)
81 if etag_match: 81 if etag_match:
82 remote_md5 = etag_match.group(1) 82 remote_md5 = etag_match.group(1)
83 # Calculate the MD5 checksum to match it to Google Storage's ETag. 83 # Calculate the MD5 checksum to match it to Google Storage's ETag.
84 with md5_lock: 84 with md5_lock:
85 if use_md5: 85 if use_md5:
86 local_md5 = get_md5_cached(filename) 86 local_md5 = get_md5_cached(filename)
87 else: 87 else:
88 local_md5 = get_md5(filename) 88 local_md5 = get_md5(filename)
89 if local_md5 == remote_md5: 89 if local_md5 == remote_md5:
90 stdout_queue.put( 90 stdout_queue.put(
91 '%d> File %s already exists and MD5 matches, upload skipped' % 91 '%d> File %s already exists and MD5 matches, upload skipped' %
92 (thread_num, filename)) 92 (thread_num, filename))
93 continue 93 continue
94 stdout_queue.put('%d> Uploading %s...' % ( 94 stdout_queue.put('%d> Uploading %s...' % (
95 thread_num, filename)) 95 thread_num, filename))
96 gsutil_args = ['cp'] 96 gsutil_args = ['cp']
97 if gzip: 97 if gzip:
98 gsutil_args.extend(['-z', gzip]) 98 gsutil_args.extend(['-z', gzip])
99 gsutil_args.extend([filename, file_url]) 99 gsutil_args.extend([filename, file_url])
100 code, _, err = gsutil.check_call(*gsutil_args) 100 code, _, err = gsutil.check_call_with_retries(*gsutil_args)
101 if code != 0: 101 if code != 0:
102 ret_codes.put( 102 ret_codes.put(
103 (code, 103 (code,
104 'Encountered error on uploading %s to %s\n%s' % 104 'Encountered error on uploading %s to %s\n%s' %
105 (filename, file_url, err))) 105 (filename, file_url, err)))
106 continue 106 continue
107 107
108 # Mark executable files with the header "x-goog-meta-executable: 1" which 108 # Mark executable files with the header "x-goog-meta-executable: 1" which
109 # the download script will check for to preserve the executable bit. 109 # the download script will check for to preserve the executable bit.
110 if not sys.platform.startswith('win'): 110 if not sys.platform.startswith('win'):
111 if os.stat(filename).st_mode & stat.S_IEXEC: 111 if os.stat(filename).st_mode & stat.S_IEXEC:
112 code, _, err = gsutil.check_call('setmeta', '-h', 112 code, _, err = gsutil.check_call_with_retries(
113 'x-goog-meta-executable:1', file_url) 113 'setmeta', '-h', 'x-goog-meta-executable:1', file_url)
114 if code: 114 if not code:
115 ret_codes.put( 115 ret_codes.put(
116 (code, 116 (code,
117 'Encountered error on setting metadata on %s\n%s' % 117 'Encountered error on setting metadata on %s\n%s' %
118 (file_url, err))) 118 (file_url, err)))
119 119
120 120
121 def get_targets(args, parser, use_null_terminator): 121 def get_targets(args, parser, use_null_terminator):
122 if not args: 122 if not args:
123 parser.error('Missing target.') 123 parser.error('Missing target.')
124 124
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 input_filenames, base_url, gsutil, options.force, options.use_md5, 290 input_filenames, base_url, gsutil, options.force, options.use_md5,
291 options.num_threads, options.skip_hashing, options.gzip) 291 options.num_threads, options.skip_hashing, options.gzip)
292 292
293 293
294 if __name__ == '__main__': 294 if __name__ == '__main__':
295 try: 295 try:
296 sys.exit(main()) 296 sys.exit(main())
297 except KeyboardInterrupt: 297 except KeyboardInterrupt:
298 sys.stderr.write('interrupted\n') 298 sys.stderr.write('interrupted\n')
299 sys.exit(1) 299 sys.exit(1)
OLDNEW
« no previous file with comments | « download_from_google_storage.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698