2011-05-02 20:56:13 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2011-11-21 15:11:40 -06:00
|
|
|
import os, tarfile, hashlib, re, shutil, sys
|
2011-05-02 20:56:13 -05:00
|
|
|
from snapshot import *
|
|
|
|
|
2011-11-28 14:13:42 -06:00
|
|
|
def unpack_snapshot(triple, snap):
|
2011-05-02 20:56:13 -05:00
|
|
|
dl_path = os.path.join(download_dir_base, snap)
|
2011-05-03 01:37:52 -05:00
|
|
|
print("opening snapshot " + dl_path)
|
2011-05-02 20:56:13 -05:00
|
|
|
tar = tarfile.open(dl_path)
|
2011-11-28 14:13:42 -06:00
|
|
|
kernel = get_kernel(triple)
|
2011-12-13 12:54:48 -06:00
|
|
|
for p in tar.getnames():
|
2011-12-13 14:31:50 -06:00
|
|
|
|
|
|
|
# FIXME: Fix this once win32 snapshot globs are fixed.
|
|
|
|
name = p.replace("rust-stage0/stage3/", "", 1);
|
|
|
|
name = name.replace("rust-stage0/", "", 1);
|
|
|
|
|
2011-11-21 15:11:40 -06:00
|
|
|
stagep = os.path.join(triple, "stage0")
|
|
|
|
fp = os.path.join(stagep, name)
|
2011-12-13 12:54:48 -06:00
|
|
|
print("extracting " + p)
|
2011-05-02 20:56:13 -05:00
|
|
|
tar.extract(p, download_unpack_base)
|
|
|
|
tp = os.path.join(download_unpack_base, p)
|
|
|
|
shutil.move(tp, fp)
|
|
|
|
tar.close()
|
|
|
|
shutil.rmtree(download_unpack_base)
|
|
|
|
|
2011-11-28 08:06:32 -06:00
|
|
|
def determine_curr_snapshot(triple):
|
2011-05-03 09:23:05 -05:00
|
|
|
i = 0
|
2011-11-28 08:06:32 -06:00
|
|
|
platform = get_platform(triple)
|
2011-05-02 20:56:13 -05:00
|
|
|
|
2011-05-03 09:23:05 -05:00
|
|
|
found_file = False
|
|
|
|
found_snap = False
|
2011-05-02 20:56:13 -05:00
|
|
|
hsh = None
|
|
|
|
date = None
|
|
|
|
rev = None
|
|
|
|
|
2011-05-03 18:22:00 -05:00
|
|
|
f = open(snapshotfile)
|
|
|
|
for line in f.readlines():
|
|
|
|
i += 1
|
|
|
|
parsed = parse_line(i, line)
|
|
|
|
if (not parsed): continue
|
|
|
|
|
|
|
|
if found_snap and parsed["type"] == "file":
|
|
|
|
if parsed["platform"] == platform:
|
|
|
|
hsh = parsed["hash"]
|
|
|
|
found_file = True
|
|
|
|
break;
|
|
|
|
elif parsed["type"] == "snapshot":
|
|
|
|
date = parsed["date"]
|
|
|
|
rev = parsed["rev"]
|
|
|
|
found_snap = True
|
2011-05-03 09:23:05 -05:00
|
|
|
|
|
|
|
if not found_snap:
|
2011-05-02 20:56:13 -05:00
|
|
|
raise Exception("no snapshot entries in file")
|
|
|
|
|
2011-05-03 09:23:05 -05:00
|
|
|
if not found_file:
|
2011-05-02 20:56:13 -05:00
|
|
|
raise Exception("no snapshot file found for platform %s, rev %s" %
|
|
|
|
(platform, rev))
|
|
|
|
|
2011-11-28 14:13:42 -06:00
|
|
|
return full_snapshot_name(date, rev, platform, hsh)
|
2011-05-02 20:56:13 -05:00
|
|
|
|
|
|
|
# Main
|
|
|
|
|
2011-11-21 15:11:40 -06:00
|
|
|
triple = sys.argv[1]
|
2011-11-28 14:13:42 -06:00
|
|
|
snap = determine_curr_snapshot(triple)
|
2011-05-02 20:56:13 -05:00
|
|
|
dl = os.path.join(download_dir_base, snap)
|
2011-05-03 01:37:52 -05:00
|
|
|
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")
|
2011-05-02 20:56:13 -05:00
|
|
|
else:
|
2011-05-03 01:37:52 -05:00
|
|
|
raise Exception("bad hash on download")
|
2011-05-02 20:56:13 -05:00
|
|
|
|
2011-11-28 14:13:42 -06:00
|
|
|
unpack_snapshot(triple, snap)
|