diff --git a/src/etc/get-snapshot.py b/src/etc/get-snapshot.py index 475bb316330..9a076af0176 100755 --- a/src/etc/get-snapshot.py +++ b/src/etc/get-snapshot.py @@ -24,43 +24,48 @@ def unpack_snapshot(snap): tar.close() shutil.rmtree(download_unpack_base) -def determine_last_snapshot_for_platform(): - lines = open(snapshotfile).readlines(); +def determine_curr_snapshot_for_platform(): + i = 0 platform = get_platform() - found = False + found_file = False + found_snap = False hsh = None date = None rev = None - for ln in range(len(lines) - 1, -1, -1): - parsed = parse_line(ln, lines[ln]) - if (not parsed): continue + with open(snapshotfile) as f: + for line in f.xreadlines(): + i += 1 + parsed = parse_line(i, line) + if (not parsed): continue - if parsed["type"] == "file": - if parsed["platform"] == platform: - hsh = parsed["hash"] - elif parsed["type"] == "snapshot": - date = parsed["date"] - rev = parsed["rev"] - found = True - break - elif parsed["type"] == "transition" and not foundSnapshot: - raise Exception("working on a transition, not updating stage0") + if parsed["type"] == "transition": + raise Exception("working on a transition, not updating stage0") - if not found: + 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 + + if not found_snap: raise Exception("no snapshot entries in file") - if not hsh: + if not found_file: raise Exception("no snapshot file found for platform %s, rev %s" % (platform, rev)) - return full_snapshot_name(date, rev, get_kernel(), get_cpu(), hsh) + return full_snapshot_name(date, rev, get_platform(), hsh) # Main -snap = determine_last_snapshot_for_platform() +snap = determine_curr_snapshot_for_platform() dl = os.path.join(download_dir_base, snap) url = download_url_base + "/" + snap print("determined most recent snapshot: " + snap) diff --git a/src/etc/make-snapshot.py b/src/etc/make-snapshot.py index 11209b4cf4a..d02c09487ee 100755 --- a/src/etc/make-snapshot.py +++ b/src/etc/make-snapshot.py @@ -1,24 +1,4 @@ #!/usr/bin/env python -import shutil, tarfile -from snapshot import * - -kernel = get_kernel() -cpu = get_cpu() -rev = local_rev_short_sha() -date = local_rev_committer_date().split()[0] - -file0 = partial_snapshot_name(date, rev, kernel, cpu) - -tar = tarfile.open(file0, "w:bz2") -for name in snapshot_files[kernel]: - tar.add(os.path.join("stage2", name), - os.path.join("rust-stage0", name)) -tar.close() - -h = hash_file(file0) -file1 = full_snapshot_name(date, rev, kernel, cpu, h) - -shutil.move(file0, file1) - -print(file1) +import snapshot +print(snapshot.make_snapshot()) diff --git a/src/etc/snapshot.py b/src/etc/snapshot.py index 788b5b627c3..28f94290bad 100644 --- a/src/etc/snapshot.py +++ b/src/etc/snapshot.py @@ -37,13 +37,13 @@ def parse_line(n, line): "rev": match.group(3)} -def partial_snapshot_name(date, rev, kernel, cpu): - return ("rust-stage0-%s-%s-%s-%s.tar.bz2" - % (date, rev, kernel, cpu)) +def partial_snapshot_name(date, rev, platform): + return ("rust-stage0-%s-%s-%s.tar.bz2" + % (date, rev, platform)) -def full_snapshot_name(date, rev, kernel, cpu, hsh): - return ("rust-stage0-%s-%s-%s-%s-%s.tar.bz2" - % (date, rev, kernel, cpu, hsh)) +def full_snapshot_name(date, rev, platform, hsh): + return ("rust-stage0-%s-%s-%s-%s.tar.bz2" + % (date, rev, platform, hsh)) def get_kernel(): @@ -98,3 +98,24 @@ def hash_file(x): h = hashlib.sha1() h.update(open(x, "rb").read()) return scrub(h.hexdigest()) + + +def make_snapshot(): + kernel = get_kernel() + platform = get_platform() + rev = local_rev_short_sha() + date = local_rev_committer_date().split()[0] + + file0 = partial_snapshot_name(date, rev, platform) + + tar = tarfile.open(file0, "w:bz2") + for name in snapshot_files[kernel]: + tar.add(os.path.join("stage2", name), + os.path.join("rust-stage0", name)) + tar.close() + + h = hash_file(file0) + file1 = full_snapshot_name(date, rev, platform, h) + + shutil.move(file0, file1) + return file1 diff --git a/src/snapshots.txt b/src/snapshots.txt index c70c1aef4dd..8ca9cd50a64 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -1,4 +1,5 @@ S 2011-05-02 ed40c85 + linux-i386 de76e0930be363af87e32ba65e3d6b1284633550 winnt-i386 e69c11fbc62639ac3a3eef7ea36c9ad77209e2b1 S 2011-04-29 7b95b5c