aboutsummaryrefslogtreecommitdiff
path: root/src/etc
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2011-05-03 07:23:05 -0700
committerGraydon Hoare <[email protected]>2011-05-03 07:23:05 -0700
commita919a3082d04a24a6aaa13ffcef98bb06307addc (patch)
tree8451b0595c3ae849d8f19a7488a9d64396c19a5f /src/etc
parentAdd forgotten 'snap.mk' (diff)
downloadrust-a919a3082d04a24a6aaa13ffcef98bb06307addc.tar.xz
rust-a919a3082d04a24a6aaa13ffcef98bb06307addc.zip
More snapshot logic refactoring.
Diffstat (limited to 'src/etc')
-rwxr-xr-xsrc/etc/get-snapshot.py49
-rwxr-xr-xsrc/etc/make-snapshot.py24
-rw-r--r--src/etc/snapshot.py33
3 files changed, 56 insertions, 50 deletions
diff --git a/src/etc/get-snapshot.py b/src/etc/get-snapshot.py
index 475bb316..9a076af0 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
-
- 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 not found:
+ with open(snapshotfile) as f:
+ for line in f.xreadlines():
+ i += 1
+ parsed = parse_line(i, line)
+ if (not parsed): continue
+
+ if parsed["type"] == "transition":
+ raise Exception("working on a transition, not updating stage0")
+
+ 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 11209b4c..d02c0948 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 788b5b62..28f94290 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