 Chromium Code Reviews
 Chromium Code Reviews Issue 1824223002:
  Retry errors setting executable headers.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
    
  
    Issue 1824223002:
  Retry errors setting executable headers.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 """Returns the result of sys.platform accounting for cygwin. | 48 """Returns the result of sys.platform accounting for cygwin. | 
| 49 Under cygwin, this will always return "win32" like the native Python.""" | 49 Under cygwin, this will always return "win32" like the native Python.""" | 
| 50 if sys.platform == 'cygwin': | 50 if sys.platform == 'cygwin': | 
| 51 return 'win32' | 51 return 'win32' | 
| 52 return sys.platform | 52 return sys.platform | 
| 53 | 53 | 
| 54 # Common utilities | 54 # Common utilities | 
| 55 class Gsutil(object): | 55 class Gsutil(object): | 
| 56 """Call gsutil with some predefined settings. This is a convenience object, | 56 """Call gsutil with some predefined settings. This is a convenience object, | 
| 57 and is also immutable.""" | 57 and is also immutable.""" | 
| 58 | |
| 59 MAX_TRIES = 5 | |
| 60 RETRY_BASE_DELAY = 5.0 | |
| 61 | |
| 58 def __init__(self, path, boto_path=None, timeout=None, version='4.15'): | 62 def __init__(self, path, boto_path=None, timeout=None, version='4.15'): | 
| 59 if not os.path.exists(path): | 63 if not os.path.exists(path): | 
| 60 raise FileNotFoundError('GSUtil not found in %s' % path) | 64 raise FileNotFoundError('GSUtil not found in %s' % path) | 
| 61 self.path = path | 65 self.path = path | 
| 62 self.timeout = timeout | 66 self.timeout = timeout | 
| 63 self.boto_path = boto_path | 67 self.boto_path = boto_path | 
| 64 self.version = version | 68 self.version = version | 
| 65 | 69 | 
| 66 def get_sub_env(self): | 70 def get_sub_env(self): | 
| 67 env = os.environ.copy() | 71 env = os.environ.copy() | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 93 status_code_match = re.search('status=([0-9]+)', err) | 97 status_code_match = re.search('status=([0-9]+)', err) | 
| 94 if status_code_match: | 98 if status_code_match: | 
| 95 return (int(status_code_match.group(1)), out, err) | 99 return (int(status_code_match.group(1)), out, err) | 
| 96 if ('You are attempting to access protected data with ' | 100 if ('You are attempting to access protected data with ' | 
| 97 'no configured credentials.' in err): | 101 'no configured credentials.' in err): | 
| 98 return (403, out, err) | 102 return (403, out, err) | 
| 99 if 'matched no objects' in err: | 103 if 'matched no objects' in err: | 
| 100 return (404, out, err) | 104 return (404, out, err) | 
| 101 return (code, out, err) | 105 return (code, out, err) | 
| 102 | 106 | 
| 107 def check_call_with_retries(self, *args): | |
| 108 delay = self.RETRY_BASE_DELAY | |
| 109 for i in xrange(self.MAX_TRIES): | |
| 110 code, out, err = self.check_call(*args) | |
| 111 if not code or i == self.MAX_TRIES - 1: | |
| 112 break | |
| 113 | |
| 114 time.sleep(delay) | |
| 115 delay *= 1.3 | |
| 
tandrii(chromium)
2016/03/24 09:49:24
nit: maybe self.DELAY_MULTIPLE then?
 
dsansome
2016/03/29 03:24:54
Done.
 | |
| 116 | |
| 117 return code, out, err | |
| 118 | |
| 103 | 119 | 
| 104 def check_platform(target): | 120 def check_platform(target): | 
| 105 """Checks if any parent directory of target matches (win|mac|linux).""" | 121 """Checks if any parent directory of target matches (win|mac|linux).""" | 
| 106 assert os.path.isabs(target) | 122 assert os.path.isabs(target) | 
| 107 root, target_name = os.path.split(target) | 123 root, target_name = os.path.split(target) | 
| 108 if not target_name: | 124 if not target_name: | 
| 109 return None | 125 return None | 
| 110 if target_name in ('linux', 'mac', 'win'): | 126 if target_name in ('linux', 'mac', 'win'): | 
| 111 return target_name | 127 return target_name | 
| 112 return check_platform(root) | 128 return check_platform(root) | 
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 | 521 | 
| 506 return download_from_google_storage( | 522 return download_from_google_storage( | 
| 507 input_filename, base_url, gsutil, options.num_threads, options.directory, | 523 input_filename, base_url, gsutil, options.num_threads, options.directory, | 
| 508 options.recursive, options.force, options.output, options.ignore_errors, | 524 options.recursive, options.force, options.output, options.ignore_errors, | 
| 509 options.sha1_file, options.verbose, options.auto_platform, | 525 options.sha1_file, options.verbose, options.auto_platform, | 
| 510 options.extract) | 526 options.extract) | 
| 511 | 527 | 
| 512 | 528 | 
| 513 if __name__ == '__main__': | 529 if __name__ == '__main__': | 
| 514 sys.exit(main(sys.argv)) | 530 sys.exit(main(sys.argv)) | 
| OLD | NEW |