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

Side by Side Diff: build/http_download.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 | « build/download_utils.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/python2.4 1 #!/usr/bin/python2.4
2 # Copyright 2009, Google Inc. 2 # Copyright 2009, Google Inc.
3 # All rights reserved. 3 # All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are 6 # modification, are permitted provided that the following conditions are
7 # met: 7 # met:
8 # 8 #
9 # * Redistributions of source code must retain the above copyright 9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer. 10 # notice, this list of conditions and the following disclaimer.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 if password: 65 if password:
66 auth_code = base64.b64encode(username + ':' + password) 66 auth_code = base64.b64encode(username + ':' + password)
67 else: 67 else:
68 auth_code = base64.b64encode(username) 68 auth_code = base64.b64encode(username)
69 headers.append(('Authorization', 'Basic ' + auth_code)) 69 headers.append(('Authorization', 'Basic ' + auth_code))
70 opener = urllib2.build_opener() 70 opener = urllib2.build_opener()
71 opener.addheaders = headers 71 opener.addheaders = headers
72 urllib2.install_opener(opener) 72 urllib2.install_opener(opener)
73 _CreateDirectory(os.path.split(target)[0]) 73 _CreateDirectory(os.path.split(target)[0])
74 # Retry up to 10 times (appengine logger is flaky). 74 # Retry up to 10 times (appengine logger is flaky).
75 retries = 10 75 for i in xrange(10):
76 for i in range(retries): 76 if i:
77 sys.stdout.write('Download failed on %s, retrying... (%d)\n' % (url, i))
77 try: 78 try:
78 src = urllib2.urlopen(url) 79 src = urllib2.urlopen(url)
79 try: 80 try:
80 download_utils.WriteDataFromStream(target, src, chunk_size=2**20, 81 download_utils.WriteDataFromStream(target, src, chunk_size=2**20,
81 verbose=verbose) 82 verbose=verbose)
82 finally: 83 finally:
83 src.close() 84 src.close()
84 break 85 break
85 except urllib2.HTTPError: 86 except urllib2.HTTPError:
86 if i < retries - 1: 87 pass
87 sys.stdout.write('Download failed on %s, retrying... (%d)\n' % (url, i)) 88 else:
88 continue 89 sys.stdout.write('Download failed on %s, giving up.\n' % url)
89 sys.stdout.write('Download failed on %s, giving up.\n' % url) 90 raise
90 raise
OLDNEW
« no previous file with comments | « build/download_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698