Skip to content

Commit a919a30

Browse files
committed
More snapshot logic refactoring.
1 parent 73961cc commit a919a30

File tree

4 files changed

+57
-50
lines changed

4 files changed

+57
-50
lines changed

src/etc/get-snapshot.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,48 @@ def unpack_snapshot(snap):
2424
tar.close()
2525
shutil.rmtree(download_unpack_base)
2626

27-
def determine_last_snapshot_for_platform():
28-
lines = open(snapshotfile).readlines();
27+
def determine_curr_snapshot_for_platform():
2928

29+
i = 0
3030
platform = get_platform()
3131

32-
found = False
32+
found_file = False
33+
found_snap = False
3334
hsh = None
3435
date = None
3536
rev = None
3637

37-
for ln in range(len(lines) - 1, -1, -1):
38-
parsed = parse_line(ln, lines[ln])
39-
if (not parsed): continue
40-
41-
if parsed["type"] == "file":
42-
if parsed["platform"] == platform:
43-
hsh = parsed["hash"]
44-
elif parsed["type"] == "snapshot":
45-
date = parsed["date"]
46-
rev = parsed["rev"]
47-
found = True
48-
break
49-
elif parsed["type"] == "transition" and not foundSnapshot:
50-
raise Exception("working on a transition, not updating stage0")
51-
52-
if not found:
38+
with open(snapshotfile) as f:
39+
for line in f.xreadlines():
40+
i += 1
41+
parsed = parse_line(i, line)
42+
if (not parsed): continue
43+
44+
if parsed["type"] == "transition":
45+
raise Exception("working on a transition, not updating stage0")
46+
47+
if found_snap and parsed["type"] == "file":
48+
if parsed["platform"] == platform:
49+
hsh = parsed["hash"]
50+
found_file = True
51+
break;
52+
elif parsed["type"] == "snapshot":
53+
date = parsed["date"]
54+
rev = parsed["rev"]
55+
found_snap = True
56+
57+
if not found_snap:
5358
raise Exception("no snapshot entries in file")
5459

55-
if not hsh:
60+
if not found_file:
5661
raise Exception("no snapshot file found for platform %s, rev %s" %
5762
(platform, rev))
5863

59-
return full_snapshot_name(date, rev, get_kernel(), get_cpu(), hsh)
64+
return full_snapshot_name(date, rev, get_platform(), hsh)
6065

6166
# Main
6267

63-
snap = determine_last_snapshot_for_platform()
68+
snap = determine_curr_snapshot_for_platform()
6469
dl = os.path.join(download_dir_base, snap)
6570
url = download_url_base + "/" + snap
6671
print("determined most recent snapshot: " + snap)

src/etc/make-snapshot.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
11
#!/usr/bin/env python
22

3-
import shutil, tarfile
4-
from snapshot import *
5-
6-
kernel = get_kernel()
7-
cpu = get_cpu()
8-
rev = local_rev_short_sha()
9-
date = local_rev_committer_date().split()[0]
10-
11-
file0 = partial_snapshot_name(date, rev, kernel, cpu)
12-
13-
tar = tarfile.open(file0, "w:bz2")
14-
for name in snapshot_files[kernel]:
15-
tar.add(os.path.join("stage2", name),
16-
os.path.join("rust-stage0", name))
17-
tar.close()
18-
19-
h = hash_file(file0)
20-
file1 = full_snapshot_name(date, rev, kernel, cpu, h)
21-
22-
shutil.move(file0, file1)
23-
24-
print(file1)
3+
import snapshot
4+
print(snapshot.make_snapshot())

src/etc/snapshot.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ def parse_line(n, line):
3737
"rev": match.group(3)}
3838

3939

40-
def partial_snapshot_name(date, rev, kernel, cpu):
41-
return ("rust-stage0-%s-%s-%s-%s.tar.bz2"
42-
% (date, rev, kernel, cpu))
40+
def partial_snapshot_name(date, rev, platform):
41+
return ("rust-stage0-%s-%s-%s.tar.bz2"
42+
% (date, rev, platform))
4343

44-
def full_snapshot_name(date, rev, kernel, cpu, hsh):
45-
return ("rust-stage0-%s-%s-%s-%s-%s.tar.bz2"
46-
% (date, rev, kernel, cpu, hsh))
44+
def full_snapshot_name(date, rev, platform, hsh):
45+
return ("rust-stage0-%s-%s-%s-%s.tar.bz2"
46+
% (date, rev, platform, hsh))
4747

4848

4949
def get_kernel():
@@ -98,3 +98,24 @@ def hash_file(x):
9898
h = hashlib.sha1()
9999
h.update(open(x, "rb").read())
100100
return scrub(h.hexdigest())
101+
102+
103+
def make_snapshot():
104+
kernel = get_kernel()
105+
platform = get_platform()
106+
rev = local_rev_short_sha()
107+
date = local_rev_committer_date().split()[0]
108+
109+
file0 = partial_snapshot_name(date, rev, platform)
110+
111+
tar = tarfile.open(file0, "w:bz2")
112+
for name in snapshot_files[kernel]:
113+
tar.add(os.path.join("stage2", name),
114+
os.path.join("rust-stage0", name))
115+
tar.close()
116+
117+
h = hash_file(file0)
118+
file1 = full_snapshot_name(date, rev, platform, h)
119+
120+
shutil.move(file0, file1)
121+
return file1

src/snapshots.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
S 2011-05-02 ed40c85
2+
linux-i386 de76e0930be363af87e32ba65e3d6b1284633550
23
winnt-i386 e69c11fbc62639ac3a3eef7ea36c9ad77209e2b1
34

45
S 2011-04-29 7b95b5c

0 commit comments

Comments
 (0)