Commit 0aabd634 authored by Viktor Samun's avatar Viktor Samun Committed by LUCI CQ

Fix python2/3 compatibility in DownloadUsingHttp function

Change-Id: I59ed965d066b7875c1739408054498b328652be5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2988315
Commit-Queue: Dirk Pranke <dpranke@google.com>
Reviewed-by: 's avatarDirk Pranke <dpranke@google.com>
parent f0d7ed89
......@@ -21,6 +21,7 @@ won't be properly maintained. See http://crbug.com/323300.
from __future__ import print_function
import argparse
from contextlib import closing
import hashlib
import filecmp
import json
......@@ -31,6 +32,13 @@ import subprocess
import sys
import tempfile
import time
if sys.version_info[0] < 3:
from urllib2 import urlopen, URLError
from urlparse import urljoin
else:
from urllib.request import urlopen
from urllib.parse import urljoin
from urllib.error import URLError
import zipfile
# Environment variable that, if set, specifies the default Visual Studio
......@@ -310,19 +318,16 @@ def DelayBeforeRemoving(target_dir):
def DownloadUsingHttp(filename):
"""Downloads the given file from a url defined in
DEPOT_TOOLS_WIN_TOOLCHAIN_BASE_URL environment variable."""
import urlparse
import urllib2
from contextlib import closing
temp_dir = tempfile.mkdtemp()
assert os.path.basename(filename) == filename
target_path = os.path.join(temp_dir, filename)
base_url = ToolchainBaseURL()
src_url = urlparse.urljoin(base_url, filename)
src_url = urljoin(base_url, filename)
try:
with closing(urllib2.urlopen(src_url)) as fsrc, \
with closing(urlopen(src_url)) as fsrc, \
open(target_path, 'wb') as fdst:
shutil.copyfileobj(fsrc, fdst)
except urllib2.URLError as e:
except URLError as e:
RmDir(temp_dir)
sys.exit('Failed to retrieve file: %s' % e)
return temp_dir, target_path
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment