From d34ba76eb6292ec6860cb02566b071e8fddbe0e1 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 19 Nov 2019 06:08:20 -0800 Subject: [PATCH] build: use python3 to download external binaries (#21184) * build: use python3 to download external binaries * Update config.py --- DEPS | 2 +- script/lib/config.py | 1 + script/lib/util.py | 14 +++++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/DEPS b/DEPS index 3fb6882e6de0..8757c8812e0e 100644 --- a/DEPS +++ b/DEPS @@ -114,7 +114,7 @@ hooks = [ 'pattern': 'src/electron/script/update-external-binaries.py', 'condition': 'download_external_binaries', 'action': [ - 'python', + 'python3', 'src/electron/script/update-external-binaries.py', ], }, diff --git a/script/lib/config.py b/script/lib/config.py index ffae54190a42..f5b0356f80ad 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -21,6 +21,7 @@ BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ PLATFORM = { 'cygwin': 'win32', 'darwin': 'darwin', + 'linux': 'linux', 'linux2': 'linux', 'win32': 'win32', }[sys.platform] diff --git a/script/lib/util.py b/script/lib/util.py index 5ef42f98f94c..6de00f68a639 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -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