Improve mirror handling

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
Hiroshi Miura
2019-11-24 21:56:41 +09:00
parent a678da038c
commit fbf413be50
4 changed files with 21 additions and 14 deletions

View File

@@ -25,6 +25,8 @@ from logging import getLogger
import requests
from aqt.helper import altlink
class QtPackage:
"""
@@ -92,7 +94,10 @@ class QtArchives:
update_xml_url = "{0}{1}Updates.xml".format(self.BASE_URL, archive_path)
archive_url = "{0}{1}".format(self.base, archive_path)
try:
r = requests.get(update_xml_url)
r = requests.get(update_xml_url, allow_redirects=False)
if r.status_code == 302:
new_url = altlink(update_xml_url)
self.base = new_url[:-len(archive_path)-11]
except requests.exceptions.ConnectionError as e:
self.logger.error('Download error: %s\n' % e.args, exc_info=True)
raise e
@@ -115,7 +120,7 @@ class QtArchives:
self.archives.append(QtPackage(name, package_url, archive, package_desc,
has_mirror=self.has_mirror))
if len(self.archives) == 0:
print("Error while parsing package information!")
self.logger.error("Error while parsing package information!")
exit(1)
def get_archives(self):

View File

@@ -30,7 +30,6 @@ import sys
from packaging.version import Version, parse
from aqt.archives import QtArchives, ToolArchives
from aqt.helper import altlink
from aqt.installer import QtInstaller
from aqt.settings import Settings
@@ -95,8 +94,7 @@ class Cli():
def _check_mirror(self, mirror):
if mirror is None:
new_url = altlink('https://download.qt.io/timestamp.txt', blacklist=self.settings.blacklist)
mirror = new_url[:-14]
return
elif mirror.startswith('http://') or mirror.startswith('https://') or mirror.startswith('ftp://'):
pass
else:
@@ -121,7 +119,8 @@ class Cli():
arch = self._set_arch(args, arch, os_name, target, qt_version)
modules = args.modules
sevenzip = self._set_sevenzip(args)
mirror = self._check_mirror(args.base)
mirror = args.base
self._check_mirror(mirror)
if not self._check_qt_arg_combination(qt_version, os_name, target, arch):
self.logger.warning("Specified target combination is not valid: {} {} {}".format(os_name, target, arch))
if not self._check_modules_arg(qt_version, modules):
@@ -138,7 +137,8 @@ class Cli():
output_dir = args.outputdir
sevenzip = self._set_sevenzip(args)
version = args.version
mirror = self._check_mirror(args.base)
mirror = args.base
self._check_mirror(mirror)
if not self._check_tools_arg_combination(os_name, tool_name, arch):
self.logger.warning("Specified target combination is not valid: {} {} {}".format(os_name, tool_name, arch))
QtInstaller(ToolArchives(os_name, tool_name, version, arch, mirror=mirror, logging=self.logger),
@@ -150,7 +150,6 @@ class Cli():
print('List Qt packages for %s' % args.qt_version)
def show_help(self, args):
print("show help")
self.parser.print_help()
def _create_parser(self):

View File

@@ -2,12 +2,16 @@ import xml.etree.ElementTree as ElementTree
import requests
from aqt.settings import Settings
def altlink(url, priority=None, blacklist=None):
def altlink(url, priority=None):
'''Download .meta4 metalink version4 xml file and parse it.'''
mirrors = {}
url = url
settings = Settings()
blacklist = settings.blacklist
try:
m = requests.get(url + '.meta4')
except requests.exceptions.ConnectionError:

View File

@@ -52,21 +52,20 @@ class QtInstaller:
else:
self.logger = getLogger('aqt')
@staticmethod
def retrieve_archive(package, path=None, command=None):
def retrieve_archive(self, package, path=None, command=None):
archive = package.archive
url = package.url
print("-Downloading {}...".format(url))
self.logger.info("-Downloading {}...".format(url))
try:
r = requests.get(url, stream=True)
except requests.exceptions.ConnectionError as e:
print("Caught download error: %s" % e.args)
self.logger.warning("Caught download error: %s" % e.args)
return False
else:
with open(archive, 'wb') as fd:
for chunk in r.iter_content(chunk_size=8196):
fd.write(chunk)
print("-Extracting {}...".format(archive))
self.logger.info("-Extracting {}...".format(archive))
if sys.version_info > (3, 5):
if not py7zr.is_7zfile(archive):