21
21
22
22
from time import time
23
23
24
+ try :
25
+ from urllib2 import urlopen
26
+ except ImportError :
27
+ from urllib .request import urlopen
28
+
24
29
25
30
def get (url , path , verbose = False ):
26
31
sha_url = url + ".sha256"
@@ -30,15 +35,15 @@ def get(url, path, verbose=False):
30
35
sha_path = sha_file .name
31
36
32
37
try :
33
- download (sha_path , sha_url , verbose )
38
+ download (sha_path , sha_url )
34
39
if os .path .exists (path ):
35
40
if verify (path , sha_path , False ):
36
41
print ("using already-download file " + path )
37
42
return
38
43
else :
39
44
print ("ignoring already-download file " + path + " due to failed verification" )
40
45
os .unlink (path )
41
- download (temp_path , url , verbose )
46
+ download (temp_path , url )
42
47
if not verify (temp_path , sha_path , True ):
43
48
raise RuntimeError ("failed verification" )
44
49
print ("moving {} to {}" .format (temp_path , path ))
@@ -54,16 +59,11 @@ def delete_if_present(path):
54
59
os .unlink (path )
55
60
56
61
57
- def download (path , url , verbose ):
62
+ def download (path , url ):
58
63
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 ())
67
67
68
68
69
69
def verify (path , sha_path , verbose ):
0 commit comments