Skip to content

Commit 49923fa

Browse files
committed
---
yaml --- r: 278157 b: refs/heads/auto c: 15de207 h: refs/heads/master i: 278155: 1539601
1 parent c255ec7 commit 49923fa

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
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 18dafe83b5411e76a13f5e813dae1bec71ef07a6
11+
refs/heads/auto: 15de207b9c79c603aa10c30ae54ca07b295aadaf
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/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)