]> git.lizzy.rs Git - rust.git/blob - src/etc/latest-unix-snaps.py
rollup merge of #21396: japaric/no-parens-in-range
[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, tarfile, hashlib, re, shutil, sys
14 from snapshot import *
15
16 f = open(snapshotfile)
17 date = None
18 rev = None
19 platform = None
20 snap = None
21 i = 0
22
23 newestSet = {}
24
25
26 for line in f.readlines():
27     i += 1
28     parsed = parse_line(i, line)
29     if (not parsed): continue
30
31     if parsed["type"] == "snapshot":
32         if (len(newestSet) == 0 or parsed["date"] > newestSet["date"]):
33             newestSet["date"] = parsed["date"]
34             newestSet["rev"] = parsed["rev"]
35             newestSet["files"] = []
36             addingMode = True
37         else:
38             addingMode = False
39
40     elif addingMode == True and parsed["type"] == "file":
41         tux = re.compile("linux", re.IGNORECASE)
42         if (tux.match(parsed["platform"]) != None):
43            ff = {}
44            ff["platform"] = parsed["platform"]
45            ff["hash"] = parsed["hash"]
46            newestSet["files"] += [ff]
47
48
49 def download_new_file (date, rev, platform, hsh):
50         snap = full_snapshot_name(date, rev, platform, hsh)
51         dl = os.path.join(download_dir_base, snap)
52         url = download_url_base + "/" + snap
53         if (not os.path.exists(dl)):
54             print("downloading " + url)
55             get_url_to_file(url, dl)
56         if (snap_filename_hash_part(snap) == hash_file(dl)):
57             print("got download with ok hash")
58         else:
59             raise Exception("bad hash on download")
60
61 for ff in newestSet["files"]:
62    download_new_file (newestSet["date"], newestSet["rev"],
63                       ff["platform"], ff["hash"])