build: use python3 to download external binaries (#21184)

* build: use python3 to download external binaries

* Update config.py
This commit is contained in:
Samuel Attard 2019-11-19 06:08:20 -08:00 committed by John Kleinschmidt
parent 73467f00e3
commit d34ba76eb6
3 changed files with 13 additions and 4 deletions

View file

@ -16,7 +16,11 @@ import subprocess
import sys
import tarfile
import tempfile
import urllib2
# Python 3 / 2 compat import
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
import zipfile
from lib.config import is_verbose_mode, PLATFORM
@ -69,8 +73,12 @@ def download(text, url, path):
ssl._create_default_https_context = ssl._create_unverified_context
print("Downloading %s to %s" % (url, path))
web_file = urllib2.urlopen(url)
file_size = int(web_file.info().getheaders("Content-Length")[0])
web_file = urlopen(url)
info = web_file.info()
if hasattr(info, 'getheader'):
file_size = int(info.getheaders("Content-Length")[0])
else:
file_size = int(info.get("Content-Length")[0])
downloaded_size = 0
block_size = 4096