| OLD | NEW |
| 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 Loading... |
| 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 | |
| OLD | NEW |