Check version number and improve error messages (#102)

* Check Qt versions and report 404 error

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
Hiroshi Miura
2020-03-01 11:35:39 +09:00
committed by GitHub
parent 36238fc007
commit 79b5a297b5
11 changed files with 75 additions and 8 deletions

View File

@@ -7,6 +7,10 @@ matrix:
env: TOXENV=check env: TOXENV=check
- python: 3.7 - python: 3.7
env: TOXENV=docs env: TOXENV=docs
- python: 3.6
env:
TOXENV=py36
PYTEST_ADDOPTS="--remote-data"
install: pip install tox-travis install: pip install tox-travis

View File

@@ -105,7 +105,17 @@ class QtArchives:
self.logger.error('Download error: %s\n' % e.args, exc_info=True) self.logger.error('Download error: %s\n' % e.args, exc_info=True)
raise e raise e
else: else:
if r.status_code != 200:
self.logger.error('Download error when access to {}\n'
'Server response code: {}, reason: {}'.format(update_xml_url,
r.status_code, r.reason))
exit(1)
try:
self.update_xml = ElementTree.fromstring(r.text) self.update_xml = ElementTree.fromstring(r.text)
except ElementTree.ParseError as perror:
self.logger.error("Downloaded metadata is corrupted. {}".format(perror))
exit(1)
else:
for packageupdate in self.update_xml.iter("PackageUpdate"): for packageupdate in self.update_xml.iter("PackageUpdate"):
name = packageupdate.find("Name").text name = packageupdate.find("Name").text
if self.all_extra or name in target_packages: if self.all_extra or name in target_packages:

View File

@@ -55,6 +55,12 @@ class Cli():
return True return True
return False return False
def _check_qt_arg_versions(self, qt_version):
for ver in self.settings.available_versions:
if ver == qt_version:
return True
return False
def _set_sevenzip(self, args): def _set_sevenzip(self, args):
sevenzip = args.external sevenzip = args.external
if sevenzip is None: if sevenzip is None:
@@ -115,8 +121,11 @@ class Cli():
if not self._check_mirror(mirror): if not self._check_mirror(mirror):
self.parser.print_help() self.parser.print_help()
exit(1) exit(1)
if not self._check_qt_arg_versions(qt_version):
self.logger.warning("Specified Qt version is unknown: {}.".format(qt_version))
if not self._check_qt_arg_combination(qt_version, os_name, target, arch): 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)) self.logger.warning("Specified target combination is not valid or unknown: {} {} {}".format(os_name,
target, arch))
all_extra = True if modules is not None and 'all' in modules else False all_extra = True if modules is not None and 'all' in modules else False
if not all_extra and not self._check_modules_arg(qt_version, modules): if not all_extra and not self._check_modules_arg(qt_version, modules):
self.logger.warning("Some of specified modules are unknown.") self.logger.warning("Some of specified modules are unknown.")

View File

@@ -89,4 +89,12 @@
"qtquicktimeline", "qtscript", "qtvirtualkeyboard", "qtwebglplugin"]}, "qtquicktimeline", "qtscript", "qtvirtualkeyboard", "qtwebglplugin"]},
{"qt_version": "5.14", "modules": ["qtcharts", "qtlottie", "qtnetworkauth", "qtpurchasing", "qtdatavis3d", {"qt_version": "5.14", "modules": ["qtcharts", "qtlottie", "qtnetworkauth", "qtpurchasing", "qtdatavis3d",
"qtquick3d", "qtquicktimeline", "qtscript", "qtvirtualkeyboard", "qtwebglplugin"]} "qtquick3d", "qtquicktimeline", "qtscript", "qtvirtualkeyboard", "qtwebglplugin"]}
], "versions": [
"5.5", "5.6", "5.7", "5.8",
"5.9", "5.9.1", "5.9.2", "5.9.3", "5.9.4", "5.9.5", "5.9.6", "5.9.7", "5.9.8", "5.9.9",
"5.10.0", "5.10.1", "5.11.0", "5.11.1", "5.11.2", "5.11.3",
"5.12.0", "5.12.1", "5.12.2", "5.12.3", "5.12.4", "5.12.5", "5.12.6", "5.12.7",
"5.13.0", "5.13.1", "5.13.2",
"5.14.0", "5.14.1", "5.14.2",
"5.15.0"
]}] ]}]

View File

@@ -57,6 +57,7 @@ class QtInstaller:
def retrieve_archive(self, package: QtPackage): def retrieve_archive(self, package: QtPackage):
archive = package.archive archive = package.archive
url = package.url url = package.url
start_time = time.perf_counter()
self.logger.info("Downloading {}...".format(url)) self.logger.info("Downloading {}...".format(url))
try: try:
r = requests.get(url, allow_redirects=False, stream=True) r = requests.get(url, allow_redirects=False, stream=True)
@@ -84,7 +85,7 @@ class QtInstaller:
if self.command is not None: if self.command is not None:
self.extract_archive_ext(archive) self.extract_archive_ext(archive)
os.unlink(archive) os.unlink(archive)
self.logger.info("Finish installation of {} in {}".format(archive, time.process_time())) self.logger.info("Finish installation of {} in {}".format(archive, time.perf_counter() - start_time))
def extract_archive(self, archive): def extract_archive(self, archive):
szf = py7zr.SevenZipFile(archive) szf = py7zr.SevenZipFile(archive)
@@ -132,8 +133,10 @@ class QtInstaller:
def install(self): def install(self):
with concurrent.futures.ThreadPoolExecutor() as executor: with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(self.retrieve_archive, ar) for ar in self.qt_archives.get_archives()] futures = [executor.submit(self.retrieve_archive, ar) for ar in self.qt_archives.get_archives()]
for future in concurrent.futures.as_completed(futures): done, not_done = concurrent.futures.wait(futures, return_when=concurrent.futures.FIRST_EXCEPTION)
future.result() if len(not_done) > 0:
self.logger.error("Installation error detected.")
exit(1)
# finalize # finalize
qt_version, target, arch = self.qt_archives.get_target_config() qt_version, target, arch = self.qt_archives.get_target_config()

View File

@@ -67,6 +67,10 @@ class Settings(object):
def tools_combinations(self): def tools_combinations(self):
return self._combinations['tools'] return self._combinations['tools']
@property
def available_versions(self):
return self._combinations['versions']
def available_modules(self, qt_version): def available_modules(self, qt_version):
"""Known module names """Known module names

View File

@@ -1,6 +1,7 @@
requests requests
pytest pytest
pytest-pep8 pytest-pep8
pytest-remotedata
flake8 flake8
setuptools>=42 setuptools>=42
setuptools-scm>=3.5.0 setuptools-scm>=3.5.0

View File

@@ -51,5 +51,6 @@ aqt = *.yml, *.json, *.ini
dev = dev =
pytest pytest
pytest-pep8 pytest-pep8
pytest-remotedata
pytest-cov pytest-cov
flake8 flake8

View File

@@ -39,6 +39,12 @@ def test_cli_check_combination():
assert not cli._check_qt_arg_combination('5.14.0', 'android', 'desktop', 'clang_64') assert not cli._check_qt_arg_combination('5.14.0', 'android', 'desktop', 'clang_64')
def test_cli_check_version():
cli = aqt.cli.Cli()
assert cli._check_qt_arg_versions('5.12.0')
assert not cli._check_qt_arg_versions('5.12')
def test_cli_check_mirror(): def test_cli_check_mirror():
cli = aqt.cli.Cli() cli = aqt.cli.Cli()
assert cli._check_mirror(None) assert cli._check_mirror(None)

21
tests/test_connection.py Normal file
View File

@@ -0,0 +1,21 @@
import pytest
import aqt
@pytest.mark.remote_data
def test_cli_unknown_version(capsys):
wrong_version = "5.12"
wrong_url = "https://download.qt.io/online/qtsdkrepository/mac_x64/desktop/qt5_512/Updates.xml"
expected = ["aqt - WARNING - Specified Qt version is unknown: {}.".format(wrong_version),
"aqt - ERROR - Download error when access to {}"
" Server response code: 404, reason code: Not Found".format(wrong_url)
]
with pytest.raises(SystemExit) as pytest_wrapped_e:
cli = aqt.cli.Cli()
cli.run(["install", wrong_version, "mac", "desktop"])
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
out, err = capsys.readouterr()
for i, line in enumerate(out):
assert line.endswith(expected[i])

View File

@@ -2,7 +2,7 @@
envlist = check, docs, py36 envlist = check, docs, py36
[testenv] [testenv]
passenv = TRAVIS TRAVIS_* passenv = TRAVIS TRAVIS_* PYTEST_ADDOPTS
basepython = python3 basepython = python3
deps = -rrequirements.txt deps = -rrequirements.txt
commands = commands =