]> git.lizzy.rs Git - rust.git/blob - src/etc/mirror-all-snapshots.py
Rollup merge of #21336 - rylev:better-nofile-error, r=brson
[rust.git] / src / etc / mirror-all-snapshots.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2011-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
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 for line in f.readlines():
24     i += 1
25     parsed = parse_line(i, line)
26     if (not parsed): continue
27
28     if parsed["type"] == "snapshot":
29         date = parsed["date"]
30         rev = parsed["rev"]
31
32     elif rev != None and parsed["type"] == "file":
33         platform = parsed["platform"]
34         hsh = parsed["hash"]
35         snap = full_snapshot_name(date, rev, platform, hsh)
36         dl = os.path.join(download_dir_base, snap)
37         url = download_url_base + "/" + snap
38         if (not os.path.exists(dl)):
39             print("downloading " + url)
40             get_url_to_file(url, dl)
41         if (snap_filename_hash_part(snap) == hash_file(dl)):
42             print("got download with ok hash")
43         else:
44             raise Exception("bad hash on download")