This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.py
48 lines (40 loc) · 1.71 KB
/
update.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
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import os.path as osp
import re
import urllib2
# generate Dockerfiles based on latest artifacts
# TODO: rewrite in rust?
rec_re = re.compile(r'<tr>.*?</tr>', re.DOTALL)
rec_ver_re = re.compile(r'href="/dist/rust-(nightly|beta|[\d.]+)-x86_64-unknown-linux-gnu.tar.gz"')
rec_mod_re = re.compile(r'modification">(\d{4}-\d{2}-\d{2} \d{2}:\d{2})<')
data = {}
if osp.isfile('versions.txt'):
with open('versions.txt') as f:
lines = f.readlines()
data = dict([line.strip().split(': ') for line in lines])
dist_html = urllib2.urlopen('http://static.rust-lang.org/dist/').read()
records = rec_re.findall(dist_html)
new_release = False
for rec in records:
version = rec_ver_re.search(rec)
modified = rec_mod_re.search(rec)
if version and modified:
version = version.group(1)
modified = modified.group(1)
if version not in data or data[version] < modified:
print 'NEW RELEASE: rust %s at %s' % (version, modified)
new_release = True
data[version] = modified
if new_release:
with open('versions.txt', 'w') as f:
for k in sorted(data.keys()):
f.write('%s: %s\n' % (k, data[k]))
versions = sorted(data.keys(), reverse=True)[0:3]
template = open('Dockerfile.template').read()
for version in versions:
mod_date = data[version][0:10]
sign_hash = urllib2.urlopen('http://static.rust-lang.org/dist/%s/rust-%s-x86_64-unknown-linux-gnu.tar.gz.asc.sha256' % (mod_date, version)).read().split(' ')[0]
if not osp.isdir(version):
os.mkdir(version)
with open('%s/Dockerfile' % version, 'w') as f:
f.write(template.format(rust_version=version, mod_date=mod_date, sign_hash=sign_hash))