25
25
26
26
if sys .version_info [0 ] == 3 :
27
27
from urllib .request import urlretrieve
28
+ from urllib .request import urlopen
28
29
unicode = lambda s : str (s )
29
30
else :
30
31
# Not Python 3 - today, it is most likely to be Python 2
31
32
from urllib import urlretrieve
33
+ from urllib import urlopen
32
34
33
35
if 'Windows' in platform .system ():
34
36
import requests
@@ -79,6 +81,26 @@ def unpack(filename, destination):
79
81
shutil .rmtree (rename_to )
80
82
shutil .move (dirname , rename_to )
81
83
84
+ def download_file (url ,filename ):
85
+ import ssl
86
+ import contextlib
87
+ ctx = ssl .create_default_context ()
88
+ ctx .check_hostname = False
89
+ ctx .verify_mode = ssl .CERT_NONE
90
+ with contextlib .closing (urlopen (url ,context = ctx )) as fp :
91
+ block_size = 1024 * 8
92
+ block = fp .read (block_size )
93
+ if block :
94
+ with open (filename ,'wb' ) as out_file :
95
+ out_file .write (block )
96
+ while True :
97
+ block = fp .read (block_size )
98
+ if not block :
99
+ break
100
+ out_file .write (block )
101
+ else :
102
+ raise Exception ('nonexisting file or connection error' )
103
+
82
104
def get_tool (tool ):
83
105
sys_name = platform .system ()
84
106
archive_name = tool ['archiveFileName' ]
@@ -100,7 +122,11 @@ def get_tool(tool):
100
122
f .write (r .content )
101
123
f .close ()
102
124
else :
103
- urlretrieve (url , local_path , report_progress )
125
+ is_ci = os .environ .get ('TRAVIS_BUILD_DIR' );
126
+ if is_ci :
127
+ download_file (url , local_path )
128
+ else :
129
+ urlretrieve (url , local_path , report_progress )
104
130
sys .stdout .write ("\r Done\n " )
105
131
sys .stdout .flush ()
106
132
else :
0 commit comments