forked from django-haystack/pysolr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-solr-download-url.py
executable file
·35 lines (25 loc) · 1.08 KB
/
get-solr-download-url.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# encoding: utf-8
from __future__ import absolute_import, division, print_function, unicode_literals
import sys
import requests
# Try to import urljoin from the Python 3 reorganized stdlib first:
try:
from urllib.parse import urljoin
except ImportError:
from urlparse import urljoin
if len(sys.argv) != 2:
print('Usage: %s SOLR_VERSION' % sys.argv[0], file=sys.stderr)
sys.exit(1)
solr_version = sys.argv[1]
tarball = 'solr-{0}.tgz'.format(solr_version)
dist_path = 'lucene/solr/{0}/{1}'.format(solr_version, tarball)
download_url = urljoin('http://archive.apache.org/dist/', dist_path)
mirror_response = requests.get("http://www.apache.org/dyn/mirrors/mirrors.cgi/%s?asjson=1" % dist_path)
if mirror_response.ok:
mirror_data = mirror_response.json()
download_url = urljoin(mirror_data['preferred'], mirror_data['path_info'])
# The Apache mirror script's response format has recently changed to exclude the actual file paths:
if not download_url.endswith(tarball):
download_url = urljoin(download_url, dist_path)
print(download_url)