|
3 | 3 |
|
4 | 4 | from __future__ import absolute_import, division, print_function, unicode_literals
|
5 | 5 |
|
| 6 | +from itertools import chain |
6 | 7 | import sys
|
7 | 8 |
|
8 | 9 | import requests
|
|
22 | 23 | tarball = 'solr-{0}.tgz'.format(solr_version)
|
23 | 24 | dist_path = 'lucene/solr/{0}/{1}'.format(solr_version, tarball)
|
24 | 25 |
|
25 |
| -download_url = urljoin('http://archive.apache.org/dist/', dist_path) |
26 |
| -mirror_response = requests.get("http://www.apache.org/dyn/mirrors/mirrors.cgi/%s?asjson=1" % dist_path) |
| 26 | +download_url = urljoin('https://archive.apache.org/dist/', dist_path) |
| 27 | +mirror_response = requests.get("https://www.apache.org/dyn/mirrors/mirrors.cgi/%s?asjson=1" % dist_path) |
| 28 | + |
| 29 | +if not mirror_response.ok: |
| 30 | + print('Apache mirror request returned HTTP %d' % mirror_response.status_code, file=sys.stderr) |
| 31 | + sys.exit(1) |
| 32 | + |
| 33 | +mirror_data = mirror_response.json() |
| 34 | + |
| 35 | +# Since the Apache mirrors are often unreliable and releases may disappear without notice we'll |
| 36 | +# try the preferred mirror, all of the alternates and backups, and fall back to the main Apache |
| 37 | +# archive server: |
| 38 | +for base_url in chain((mirror_data['preferred'], ), mirror_data['http'], mirror_data['backup'], |
| 39 | + ('https://archive.apache.org/dist/', )): |
| 40 | + test_url = urljoin(base_url, mirror_data['path_info']) |
27 | 41 |
|
28 |
| -if mirror_response.ok: |
29 |
| - mirror_data = mirror_response.json() |
30 |
| - download_url = urljoin(mirror_data['preferred'], mirror_data['path_info']) |
31 | 42 | # The Apache mirror script's response format has recently changed to exclude the actual file paths:
|
32 |
| - if not download_url.endswith(tarball): |
33 |
| - download_url = urljoin(download_url, dist_path) |
| 43 | + if not test_url.endswith(tarball): |
| 44 | + test_url = urljoin(test_url, dist_path) |
| 45 | + |
| 46 | + if requests.head(test_url, allow_redirects=True).status_code == 200: |
| 47 | + download_url = test_url |
| 48 | + break |
| 49 | +else: |
| 50 | + print('None of the Apache mirrors have %s' % dist_path, file=sys.stderr) |
| 51 | + sys.exit(1) |
34 | 52 |
|
35 | 53 | print(download_url)
|
0 commit comments