Browse Source

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

* build: use python3 to download external binaries

* Update config.py
trop[bot] 5 years ago
parent
commit
cd94ab9de3
3 changed files with 13 additions and 4 deletions
  1. 1 1
      DEPS
  2. 1 0
      script/lib/config.py
  3. 11 3
      script/lib/util.py

+ 1 - 1
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',
     ],
   },

+ 1 - 0
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]

+ 11 - 3
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