LUCENE-6231: smokeTestRelease.py should retry failed downloads

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1658723 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2015-02-10 14:40:27 +00:00
parent 196e031e4e
commit 0b4cdec6ac
1 changed files with 29 additions and 22 deletions

View File

@ -114,30 +114,37 @@ def download(name, urlString, tmpDir, quiet=False):
print(' already done: %.1f MB' % (os.path.getsize(fileName)/1024./1024.))
return
try:
fIn = urllib.request.urlopen(urlString)
fOut = open(fileName, 'wb')
success = False
try:
while True:
s = fIn.read(65536)
if s == b'':
break
fOut.write(s)
fOut.close()
fIn.close()
success = True
finally:
fIn.close()
fOut.close()
if not success:
os.remove(fileName)
if not quiet and fileName.find('.asc') == -1:
t = time.time()-startTime
sizeMB = os.path.getsize(fileName)/1024./1024.
print(' %.1f MB in %.2f sec (%.1f MB/sec)' % (sizeMB, t, sizeMB/t))
attemptDownload(urlString, fileName)
except Exception as e:
raise RuntimeError('failed to download url "%s"' % urlString) from e
print('Retrying download of url %s after exception: %s' % (urlString, e))
try:
attemptDownload(urlString, fileName)
except Exception as e:
raise RuntimeError('failed to download url "%s"' % urlString) from e
if not quiet and fileName.find('.asc') == -1:
t = time.time()-startTime
sizeMB = os.path.getsize(fileName)/1024./1024.
print(' %.1f MB in %.2f sec (%.1f MB/sec)' % (sizeMB, t, sizeMB/t))
def attemptDownload(urlString, fileName):
fIn = urllib.request.urlopen(urlString)
fOut = open(fileName, 'wb')
success = False
try:
while True:
s = fIn.read(65536)
if s == b'':
break
fOut.write(s)
fOut.close()
fIn.close()
success = True
finally:
fIn.close()
fOut.close()
if not success:
os.remove(fileName)
def load(urlString):
return urllib.request.urlopen(urlString).read().decode('utf-8')