Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python | 
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 # TODO(hinoka): Use logging. | 6 # TODO(hinoka): Use logging. | 
| 7 | 7 | 
| 8 import cStringIO | 8 import cStringIO | 
| 9 import codecs | 9 import codecs | 
| 10 import copy | 10 import copy | 
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 print | 199 print | 
| 200 return outval | 200 return outval | 
| 201 if result is FAIL: | 201 if result is FAIL: | 
| 202 break | 202 break | 
| 203 if result is RETRY and attempt < tries: | 203 if result is RETRY and attempt < tries: | 
| 204 sleep_backoff = 4 ** attempt | 204 sleep_backoff = 4 ** attempt | 
| 205 sleep_time = random.randint(sleep_backoff, int(sleep_backoff * 1.2)) | 205 sleep_time = random.randint(sleep_backoff, int(sleep_backoff * 1.2)) | 
| 206 print '===backing off, sleeping for %d secs===' % sleep_time | 206 print '===backing off, sleeping for %d secs===' % sleep_time | 
| 207 time.sleep(sleep_time) | 207 time.sleep(sleep_time) | 
| 208 | 208 | 
| 209 maybe_remove_win_lockfile(sys.platform, outval) | |
| 
 
agable
2016/10/05 16:28:21
If possible, this shouldn't be at the end of call(
 
katthomas
2016/10/06 21:50:20
Done.
 
 | |
| 210 | |
| 209 raise SubprocessFailed('%s failed with code %d in %s after %d attempts.' % | 211 raise SubprocessFailed('%s failed with code %d in %s after %d attempts.' % | 
| 210 (' '.join(args), code, cwd, attempt), | 212 (' '.join(args), code, cwd, attempt), | 
| 211 code, outval) | 213 code, outval) | 
| 212 | 214 | 
| 215 # Windows sometimes has trouble deleting files. This can make git commands | |
| 
 
agable
2016/10/05 16:28:20
Use a docstring on line 218 instead of a comment a
 
katthomas
2016/10/06 21:50:20
Done.
 
 | |
| 216 # fhat rely on locks fail. | |
| 217 def maybe_remove_win_lockfile(platform, error, retries=3): | |
| 218 if platform.startswith('win'): | |
| 219 match = re.search("(Unable to create ')(.*)(\.lock)(': File exists)", error) | |
| 220 if match: | |
| 221 filename = match.group(2) + '.lock' | |
| 222 print '===Attempting to remove lockfile %s===' % filename | |
| 223 for _ in xrange(retries): | |
| 224 exitcode = subprocess.call(['cmd.exe', '/c', 'del', | |
| 
 
Paweł Hajdan Jr.
2016/10/03 11:53:22
Please consider breaking the locks only once, at t
 
agable
2016/10/05 16:28:21
Agreed with this comment -- it makes more sense to
 
katthomas
2016/10/06 21:50:20
Done. I put the lockbreaking before running any gi
 
 | |
| 225 '/f', '/q', os.path.normcase(filename)]) | |
| 226 if exitcode == 0: | |
| 227 return | |
| 228 time.sleep(3) | |
| 229 print '===Failed to remove lockfile %s====' % filename | |
| 213 | 230 | 
| 214 def git(*args, **kwargs): # pragma: no cover | 231 def git(*args, **kwargs): # pragma: no cover | 
| 215 """Wrapper around call specifically for Git commands.""" | 232 """Wrapper around call specifically for Git commands.""" | 
| 216 if args and args[0] == 'cache': | 233 if args and args[0] == 'cache': | 
| 217 # Rewrite "git cache" calls into "python git_cache.py". | 234 # Rewrite "git cache" calls into "python git_cache.py". | 
| 218 cmd = (sys.executable, '-u', GIT_CACHE_PATH) + args[1:] | 235 cmd = (sys.executable, '-u', GIT_CACHE_PATH) + args[1:] | 
| 219 else: | 236 else: | 
| 220 git_executable = 'git' | 237 git_executable = 'git' | 
| 221 # On windows, subprocess doesn't fuzzy-match 'git' to 'git.bat', so we | 238 # On windows, subprocess doesn't fuzzy-match 'git' to 'git.bat', so we | 
| 222 # have to do it explicitly. This is better than passing shell=True. | 239 # have to do it explicitly. This is better than passing shell=True. | 
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1090 # download patch failure is still an infra problem. | 1107 # download patch failure is still an infra problem. | 
| 1091 if e.code == 3: | 1108 if e.code == 3: | 
| 1092 # Patch download problem. | 1109 # Patch download problem. | 
| 1093 return 87 | 1110 return 87 | 
| 1094 # Genuine patch problem. | 1111 # Genuine patch problem. | 
| 1095 return 88 | 1112 return 88 | 
| 1096 | 1113 | 
| 1097 | 1114 | 
| 1098 if __name__ == '__main__': | 1115 if __name__ == '__main__': | 
| 1099 sys.exit(main()) | 1116 sys.exit(main()) | 
| OLD | NEW |