calibre/setup/ci-download.py
Kovid Goyal 9c5815d9c0
Retry downloads on travis
Should hopefully work around the flakiness on the travis OS X machines
where curl aborts in the middle of downloads when under load
2017-05-09 22:53:09 +05:30

30 lines
829 B
Python

#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import absolute_import, division, print_function, unicode_literals
import sys, subprocess
from tempfile import NamedTemporaryFile
url, compression, dest = sys.argv[-3:]
def decompress(path):
raise SystemExit(
subprocess.Popen(['tar', 'x' + compression + 'f', path, '-C', dest]).wait()
)
if __name__ == '__main__':
for i in range(5):
if i:
print('Failed to download', url, 'retrying...'.format(url))
else:
print('Downloading', url, '...')
with NamedTemporaryFile() as f:
ret = subprocess.Popen(['curl', url], stdout=f).wait()
if ret == 0:
decompress(f.name)
break