]> git.lizzy.rs Git - rust.git/blob - src/etc/latest-unix-snaps.py
Auto merge of #31077 - nagisa:mir-temp-promotion, r=dotdash
[rust.git] / src / etc / latest-unix-snaps.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
6 #
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
12
13 import os
14 import re
15 from snapshot import *
16
17 f = open(snapshotfile)
18 date = None
19 rev = None
20 platform = None
21 snap = None
22 i = 0
23
24 newestSet = {}
25
26
27 for line in f.readlines():
28     i += 1
29     parsed = parse_line(i, line)
30     if not parsed:
31         continue
32
33     if parsed["type"] == "snapshot":
34         if (len(newestSet) == 0 or parsed["date"] > newestSet["date"]):
35             newestSet["date"] = parsed["date"]
36             newestSet["rev"] = parsed["rev"]
37             newestSet["files"] = []
38             addingMode = True
39         else:
40             addingMode = False
41
42     elif addingMode is True and parsed["type"] == "file":
43         tux = re.compile("linux", re.IGNORECASE)
44         if (tux.match(parsed["platform"]) is not None):
45             ff = {}
46             ff["platform"] = parsed["platform"]
47             ff["hash"] = parsed["hash"]
48             newestSet["files"] += [ff]
49
50
51 def download_new_file(date, rev, platform, hsh):
52         snap = full_snapshot_name(date, rev, platform, hsh)
53         dl = os.path.join(download_dir_base, snap)
54         url = download_url_base + "/" + snap
55         if (not os.path.exists(dl)):
56             print("downloading " + url)
57             get_url_to_file(url, dl)
58         if (snap_filename_hash_part(snap) == hash_file(dl)):
59             print("got download with ok hash")
60         else:
61             raise Exception("bad hash on download")
62
63 for ff in newestSet["files"]:
64     download_new_file(newestSet["date"], newestSet["rev"],
65                       ff["platform"], ff["hash"])