blob: 1f8cac9ed3436d86eaeefb97d6685ba57de3a984 (
plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/env python3
import os
import re
import sys
import http.client
import urllib.request, urllib.error, urllib.parse
import urllib.parse
def main():
product = sys.argv[1]
conn = http.client.HTTPSConnection('download.mozilla.org')
conn.request('HEAD', '/?product=%s-latest&os=linux&lang=en-US' % product)
res = conn.getresponse()
assert res.status == 302
location = res.getheader('Location')
if '-' in product:
product, variant = product.split('-', 1)
else:
variant = ''
u = urllib.parse.urlparse(location)
p = u.path.split('/')
assert p[0] == ''
assert p[1] == 'pub'
assert p[2] == product
assert p[3] in ('releases', 'nightly')
if p[3] == 'nightly':
filename = os.path.basename(location)
assert filename.startswith(product + '-')
version = filename[len(product) + 1:]
m = re.match(r'([0-9]+(?:\.[0-9]+)*(?:[ab][0-9]+)?)\.', version)
assert m
version = m.group(1)
url = location.replace('.tar.bz2', '.txt')
assert url != location
f = urllib.request.urlopen(url)
print(version, ' '.join(l.rstrip() for l in f.readlines()))
f.close()
elif p[3] == 'releases':
version = p[4]
print(version)
if __name__ == '__main__':
main()
|