Skip to content

Commit 731fd19

Browse files
committed
Update get.py
Enable insecure download for CI
1 parent 298c610 commit 731fd19

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tools/get.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525

2626
if sys.version_info[0] == 3:
2727
from urllib.request import urlretrieve
28+
from urllib.request import urlopen
2829
unicode = lambda s: str(s)
2930
else:
3031
# Not Python 3 - today, it is most likely to be Python 2
3132
from urllib import urlretrieve
33+
from urllib import urlopen
3234

3335
if 'Windows' in platform.system():
3436
import requests
@@ -79,6 +81,26 @@ def unpack(filename, destination):
7981
shutil.rmtree(rename_to)
8082
shutil.move(dirname, rename_to)
8183

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+
82104
def get_tool(tool):
83105
sys_name = platform.system()
84106
archive_name = tool['archiveFileName']
@@ -100,7 +122,11 @@ def get_tool(tool):
100122
f.write(r.content)
101123
f.close()
102124
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)
104130
sys.stdout.write("\rDone\n")
105131
sys.stdout.flush()
106132
else:

0 commit comments

Comments
 (0)