Skip to content

Commit 44b23b4

Browse files
committed
---
yaml --- r: 277766 b: refs/heads/try c: 15de207 h: refs/heads/master
1 parent be928db commit 44b23b4

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: 18dafe83b5411e76a13f5e813dae1bec71ef07a6
4+
refs/heads/try: 15de207b9c79c603aa10c30ae54ca07b295aadaf
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/bootstrap/bootstrap.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@
2121

2222
def get(url, path, verbose=False):
2323
sha_url = url + ".sha256"
24-
temp_file = tempfile.NamedTemporaryFile(delete=False)
25-
temp_path = temp_file.name
26-
sha_file = tempfile.NamedTemporaryFile(suffix=".sha256", delete=True)
27-
sha_path = sha_file.name
28-
download(sha_path, sha_url, verbose)
29-
download(temp_path, url, verbose)
30-
verify(sha_path, temp_path, verbose)
31-
sha_file.close()
32-
print("moving " + temp_path + " to " + path)
33-
shutil.move(temp_path, path)
34-
temp_file.close()
24+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
25+
temp_path = temp_file.name
26+
with tempfile.NamedTemporaryFile(suffix=".sha256", delete=False) as sha_file:
27+
sha_path = sha_file.name
28+
29+
try:
30+
download(sha_path, sha_url, verbose)
31+
download(temp_path, url, verbose)
32+
verify(temp_path, sha_path, verbose)
33+
print("moving " + temp_path + " to " + path)
34+
shutil.move(temp_path, path)
35+
finally:
36+
print("removing " + sha_path)
37+
os.unlink(sha_path)
38+
if os.path.isfile(temp_path):
39+
print("removing " + temp_path)
40+
os.unlink(temp_path)
3541

3642

3743
def download(path, url, verbose):
@@ -46,9 +52,9 @@ def download(path, url, verbose):
4652
run(["curl", "-o", path, url], verbose=verbose)
4753

4854

49-
def verify(sha_path, temp_path, verbose):
50-
print("verifying " + temp_path)
51-
with open(temp_path, "rb") as f:
55+
def verify(path, sha_path, verbose):
56+
print("verifying " + path)
57+
with open(path, "rb") as f:
5258
found = hashlib.sha256(f.read()).hexdigest()
5359
with open(sha_path, "r") as f:
5460
expected, _ = f.readline().split()

0 commit comments

Comments
 (0)