diff options
| author | Graydon Hoare <[email protected]> | 2011-05-02 23:37:52 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-05-02 23:37:52 -0700 |
| commit | d987b49a4bd658d59501b7c4d4ccba3083093037 (patch) | |
| tree | 1584e6fa8e986c1660952d26ea0840be86418d62 /src/etc | |
| parent | Extract ast.is_exported from the resolve module (diff) | |
| download | rust-d987b49a4bd658d59501b7c4d4ccba3083093037.tar.xz rust-d987b49a4bd658d59501b7c4d4ccba3083093037.zip | |
More hacking on the snapshot system.
Diffstat (limited to 'src/etc')
| -rwxr-xr-x | src/etc/get-snapshot.py | 41 | ||||
| -rwxr-xr-x | src/etc/make-snapshot.py | 2 | ||||
| -rw-r--r-- | src/etc/snapshot.py | 21 |
3 files changed, 28 insertions, 36 deletions
diff --git a/src/etc/get-snapshot.py b/src/etc/get-snapshot.py index d9547b2f..475bb316 100755 --- a/src/etc/get-snapshot.py +++ b/src/etc/get-snapshot.py @@ -9,34 +9,15 @@ def snap_filename_hash_part(snap): raise Exception("unable to find hash in filename: " + snap) return match.group(1) -def get_snapshot_and_check_hash(snap): - - hsh = snap_filename_hash_part(snap) - - h = hashlib.sha1() - url = download_url_base + "/" + snap - print "downloading " + url - u = urllib2.urlopen(url) - print "checking hash on download" - data = u.read() - h.update(data) - if h.hexdigest() != hsh: - raise Exception("hash check failed on " + snap) - - print "hash ok" - with open(os.path.join(download_dir_base, snap), "w+b") as f: - f.write(data) - return True - def unpack_snapshot(snap): dl_path = os.path.join(download_dir_base, snap) - print "opening snapshot " + dl_path + print("opening snapshot " + dl_path) tar = tarfile.open(dl_path) kernel = get_kernel() for name in snapshot_files[kernel]: p = os.path.join("rust-stage0", name) fp = os.path.join("stage0", name) - print "extracting " + fp + print("extracting " + fp) tar.extract(p, download_unpack_base) tp = os.path.join(download_unpack_base, p) shutil.move(tp, fp) @@ -80,16 +61,16 @@ def determine_last_snapshot_for_platform(): # Main snap = determine_last_snapshot_for_platform() -print "determined most recent snapshot: " + snap dl = os.path.join(download_dir_base, snap) -if (os.path.exists(dl)): - if (snap_filename_hash_part(snap) == hash_file(dl)): - print "found existing download with ok hash" - else: - print "bad hash on existing download, re-fetching" - get_snapshot_and_check_hash(snap) +url = download_url_base + "/" + snap +print("determined most recent snapshot: " + snap) + +if (not os.path.exists(dl)): + get_url_to_file(url, dl) + +if (snap_filename_hash_part(snap) == hash_file(dl)): + print("got download with ok hash") else: - print "no cached download, fetching" - get_snapshot_and_check_hash(snap) + raise Exception("bad hash on download") unpack_snapshot(snap) diff --git a/src/etc/make-snapshot.py b/src/etc/make-snapshot.py index 3d6c48e3..11209b4c 100755 --- a/src/etc/make-snapshot.py +++ b/src/etc/make-snapshot.py @@ -21,4 +21,4 @@ file1 = full_snapshot_name(date, rev, kernel, cpu, h) shutil.move(file0, file1) -print file1 +print(file1) diff --git a/src/etc/snapshot.py b/src/etc/snapshot.py index 2aa241c5..788b5b62 100644 --- a/src/etc/snapshot.py +++ b/src/etc/snapshot.py @@ -1,6 +1,10 @@ -import re, os, sys, hashlib, tarfile, shutil, subprocess, urllib2, tempfile +import re, os, sys, hashlib, tarfile, shutil, subprocess, tempfile -snapshotfile = "snapshots.txt" +src_dir = os.getenv("CFG_SRC_DIR") +if not src_dir: + raise Exception("missing env var CFG_SRC_DIR") + +snapshotfile = os.path.join(src_dir, "snapshots.txt") download_url_base = "http://dl.rust-lang.org/stage0-snapshots" download_dir_base = "dl" download_unpack_base = os.path.join(download_dir_base, "unpack") @@ -59,11 +63,16 @@ def get_cpu(): def get_platform(): return "%s-%s" % (get_kernel(), get_cpu()) +def scrub(b): + if sys.version_info >= (3,) and type(b) == bytes: + return b.decode('ascii') + else: + return b def cmd_out(cmdline): p = subprocess.Popen(cmdline, stdout=subprocess.PIPE) - return p.communicate()[0].strip() + return scrub(p.communicate()[0].strip()) def local_rev_info(field): @@ -82,8 +91,10 @@ def local_rev_short_sha(): def local_rev_committer_date(): return local_rev_info("ci") +def get_url_to_file(u,f): + subprocess.check_call(["curl", "-o", f, u]) def hash_file(x): h = hashlib.sha1() - h.update(open(x).read()) - return h.hexdigest() + h.update(open(x, "rb").read()) + return scrub(h.hexdigest()) |