Skip to content

Commit 374ace4

Browse files
committed
Simplify rustbuild Rust beta downloading.
No need to shell out to curl or WebClient when we can just use the urllib2 library built into Python.
1 parent 3a5d975 commit 374ace4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/bootstrap/bootstrap.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
from time import time
2323

24+
try:
25+
from urllib2 import urlopen
26+
except ImportError:
27+
from urllib.request import urlopen
28+
2429

2530
def get(url, path, verbose=False):
2631
sha_url = url + ".sha256"
@@ -30,15 +35,15 @@ def get(url, path, verbose=False):
3035
sha_path = sha_file.name
3136

3237
try:
33-
download(sha_path, sha_url, verbose)
38+
download(sha_path, sha_url)
3439
if os.path.exists(path):
3540
if verify(path, sha_path, False):
3641
print("using already-download file " + path)
3742
return
3843
else:
3944
print("ignoring already-download file " + path + " due to failed verification")
4045
os.unlink(path)
41-
download(temp_path, url, verbose)
46+
download(temp_path, url)
4247
if not verify(temp_path, sha_path, True):
4348
raise RuntimeError("failed verification")
4449
print("moving {} to {}".format(temp_path, path))
@@ -54,16 +59,11 @@ def delete_if_present(path):
5459
os.unlink(path)
5560

5661

57-
def download(path, url, verbose):
62+
def download(path, url):
5863
print("downloading {} to {}".format(url, path))
59-
# see http://serverfault.com/questions/301128/how-to-download
60-
if sys.platform == 'win32':
61-
run(["PowerShell.exe", "/nologo", "-Command",
62-
"(New-Object System.Net.WebClient)"
63-
".DownloadFile('{}', '{}')".format(url, path)],
64-
verbose=verbose)
65-
else:
66-
run(["curl", "-o", path, url], verbose=verbose)
64+
request = urlopen(url)
65+
with open(path, 'wb') as file_:
66+
file_.write(request.read())
6767

6868

6969
def verify(path, sha_path, verbose):

0 commit comments

Comments
 (0)