mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Drop py2 support in gs-related files
python3 is the only supported version of python in depot_tools. Bug: 1475402 Change-Id: I71db631b5556525dd4932134679c70cacd205a90 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4824616 Reviewed-by: Josip Sokcevic <sokcevic@chromium.org> Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -9,11 +9,7 @@ from __future__ import print_function
|
|||||||
import hashlib
|
import hashlib
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
|
import queue
|
||||||
try:
|
|
||||||
import Queue as queue
|
|
||||||
except ImportError: # For Py3 compatibility
|
|
||||||
import queue
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@@ -44,11 +40,6 @@ PLATFORM_MAPPING = {
|
|||||||
'aix7': 'aix',
|
'aix7': 'aix',
|
||||||
}
|
}
|
||||||
|
|
||||||
if sys.version_info.major == 2:
|
|
||||||
# pylint: disable=redefined-builtin
|
|
||||||
class FileNotFoundError(IOError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidFileError(IOError):
|
class InvalidFileError(IOError):
|
||||||
pass
|
pass
|
||||||
|
|||||||
10
gsutil.py
10
gsutil.py
@@ -18,11 +18,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
import urllib.request
|
||||||
try:
|
|
||||||
import urllib2 as urllib
|
|
||||||
except ImportError: # For Py3 compatibility
|
|
||||||
import urllib.request as urllib
|
|
||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
@@ -65,7 +61,7 @@ def download_gsutil(version, target_dir):
|
|||||||
local_md5 = md5_calc.hexdigest()
|
local_md5 = md5_calc.hexdigest()
|
||||||
|
|
||||||
metadata_url = '%s%s' % (API_URL, filename)
|
metadata_url = '%s%s' % (API_URL, filename)
|
||||||
metadata = json.load(urllib.urlopen(metadata_url))
|
metadata = json.load(urllib.request.urlopen(metadata_url))
|
||||||
remote_md5 = base64.b64decode(metadata['md5Hash']).decode('utf-8')
|
remote_md5 = base64.b64decode(metadata['md5Hash']).decode('utf-8')
|
||||||
|
|
||||||
if local_md5 == remote_md5:
|
if local_md5 == remote_md5:
|
||||||
@@ -74,7 +70,7 @@ def download_gsutil(version, target_dir):
|
|||||||
|
|
||||||
# Do the download.
|
# Do the download.
|
||||||
url = '%s%s' % (GSUTIL_URL, filename)
|
url = '%s%s' % (GSUTIL_URL, filename)
|
||||||
u = urllib.urlopen(url)
|
u = urllib.request.urlopen(url)
|
||||||
with open(target_filename, 'wb') as f:
|
with open(target_filename, 'wb') as f:
|
||||||
while True:
|
while True:
|
||||||
buf = u.read(4096)
|
buf = u.read(4096)
|
||||||
|
|||||||
@@ -10,11 +10,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
|
import queue
|
||||||
try:
|
|
||||||
import Queue as queue
|
|
||||||
except ImportError: # For Py3 compatibility
|
|
||||||
import queue
|
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
@@ -19,11 +19,7 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import urllib.request
|
||||||
try:
|
|
||||||
import urllib2 as urllib
|
|
||||||
except ImportError: # For Py3 compatibility
|
|
||||||
import urllib.request as urllib
|
|
||||||
|
|
||||||
# Add depot_tools to path
|
# Add depot_tools to path
|
||||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -60,15 +56,15 @@ class GsutilUnitTests(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.fake = FakeCall()
|
self.fake = FakeCall()
|
||||||
self.tempdir = tempfile.mkdtemp()
|
self.tempdir = tempfile.mkdtemp()
|
||||||
self.old_urlopen = getattr(urllib, 'urlopen')
|
self.old_urlopen = getattr(urllib.request, 'urlopen')
|
||||||
self.old_call = getattr(subprocess, 'call')
|
self.old_call = getattr(subprocess, 'call')
|
||||||
setattr(urllib, 'urlopen', self.fake)
|
setattr(urllib.request, 'urlopen', self.fake)
|
||||||
setattr(subprocess, 'call', self.fake)
|
setattr(subprocess, 'call', self.fake)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.assertEqual(self.fake.expectations, [])
|
self.assertEqual(self.fake.expectations, [])
|
||||||
shutil.rmtree(self.tempdir)
|
shutil.rmtree(self.tempdir)
|
||||||
setattr(urllib, 'urlopen', self.old_urlopen)
|
setattr(urllib.request, 'urlopen', self.old_urlopen)
|
||||||
setattr(subprocess, 'call', self.old_call)
|
setattr(subprocess, 'call', self.old_call)
|
||||||
|
|
||||||
def test_download_gsutil(self):
|
def test_download_gsutil(self):
|
||||||
|
|||||||
@@ -8,11 +8,7 @@
|
|||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
|
import queue
|
||||||
try:
|
|
||||||
import Queue as queue
|
|
||||||
except ImportError: # For Py3 compatibility
|
|
||||||
import queue
|
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
@@ -10,11 +10,7 @@ from __future__ import print_function
|
|||||||
import hashlib
|
import hashlib
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
|
import queue
|
||||||
try:
|
|
||||||
import Queue as queue
|
|
||||||
except ImportError: # For Py3 compatibility
|
|
||||||
import queue
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import stat
|
import stat
|
||||||
|
|||||||
Reference in New Issue
Block a user