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

Side by Side Diff: build/download_utils.py

Issue 6880339: Small cosmetic change - simplify retry logic (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | build/http_download.py » ('j') | 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/python 1 #!/usr/bin/python
2 # Copyright 2010 The Native Client Authors. All rights reserved. 2 # Copyright 2010 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can 3 # Use of this source code is governed by a BSD-style license that can
4 # be found in the LICENSE file. 4 # be found in the LICENSE file.
5 5
6 """A library to assist automatically downloading files. 6 """A library to assist automatically downloading files.
7 7
8 This library is used by scripts that download tarballs, zipfiles, etc. as part 8 This library is used by scripts that download tarballs, zipfiles, etc. as part
9 of the build process. 9 of the build process.
10 """ 10 """
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return StampMatches(stampfile, url) 111 return StampMatches(stampfile, url)
112 112
113 113
114 def WriteSourceStamp(path, url): 114 def WriteSourceStamp(path, url):
115 stampfile = os.path.join(path, SOURCE_STAMP) 115 stampfile = os.path.join(path, SOURCE_STAMP)
116 WriteStamp(stampfile, url) 116 WriteStamp(stampfile, url)
117 117
118 118
119 def Retry(op, *args): 119 def Retry(op, *args):
120 if sys.platform in ('win32', 'cygwin'): 120 if sys.platform in ('win32', 'cygwin'):
121 for i in range(5): 121 for i in xrange(5):
122 if i:
123 sys.stdout.write("RETRY: %s %s\n" % (op.__name__, repr(args)))
124 time.sleep(pow(2, i))
122 try: 125 try:
123 op(*args) 126 op(*args)
124 break 127 break
125 except Exception: 128 except Exception:
126 sys.stdout.write("RETRY: %s %s\n" % (op.__name__, repr(args))) 129 pass
127 time.sleep(pow(2, i)) 130 else
131 sys.stdout.write("FAILED: %s %s\n" % (op.__name__, repr(args)))
132 raise
128 else: 133 else:
129 op(*args) 134 op(*args)
130 135
131 136
132 def MoveDirCleanly(src, dst): 137 def MoveDirCleanly(src, dst):
133 RemoveDir(dst) 138 RemoveDir(dst)
134 MoveDir(src, dst) 139 MoveDir(src, dst)
135 140
136 141
137 def MoveDir(src, dst): 142 def MoveDir(src, dst):
138 Retry(shutil.move, src, dst) 143 Retry(shutil.move, src, dst)
139 144
140 145
141 def RemoveDir(path): 146 def RemoveDir(path):
142 if os.path.exists(path): 147 if os.path.exists(path):
143 Retry(shutil.rmtree, path) 148 Retry(shutil.rmtree, path)
144 149
145 150
146 def RemoveFile(path): 151 def RemoveFile(path):
147 if os.path.exists(path): 152 if os.path.exists(path):
148 Retry(os.unlink, path) 153 Retry(os.unlink, path)
OLDNEW
« no previous file with comments | « no previous file | build/http_download.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698