mirror of
https://github.com/miurahr/aqtinstall.git
synced 2025-12-18 05:04:38 +03:00
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:
@@ -7,6 +7,10 @@ matrix:
|
||||
env: TOXENV=check
|
||||
- python: 3.7
|
||||
env: TOXENV=docs
|
||||
- python: 3.6
|
||||
env:
|
||||
TOXENV=py36
|
||||
PYTEST_ADDOPTS="--remote-data"
|
||||
|
||||
install: pip install tox-travis
|
||||
|
||||
|
||||
@@ -105,7 +105,17 @@ class QtArchives:
|
||||
self.logger.error('Download error: %s\n' % e.args, exc_info=True)
|
||||
raise e
|
||||
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)
|
||||
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"):
|
||||
name = packageupdate.find("Name").text
|
||||
if self.all_extra or name in target_packages:
|
||||
|
||||
11
aqt/cli.py
11
aqt/cli.py
@@ -55,6 +55,12 @@ class Cli():
|
||||
return True
|
||||
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):
|
||||
sevenzip = args.external
|
||||
if sevenzip is None:
|
||||
@@ -115,8 +121,11 @@ class Cli():
|
||||
if not self._check_mirror(mirror):
|
||||
self.parser.print_help()
|
||||
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):
|
||||
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
|
||||
if not all_extra and not self._check_modules_arg(qt_version, modules):
|
||||
self.logger.warning("Some of specified modules are unknown.")
|
||||
|
||||
@@ -89,4 +89,12 @@
|
||||
"qtquicktimeline", "qtscript", "qtvirtualkeyboard", "qtwebglplugin"]},
|
||||
{"qt_version": "5.14", "modules": ["qtcharts", "qtlottie", "qtnetworkauth", "qtpurchasing", "qtdatavis3d",
|
||||
"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"
|
||||
]}]
|
||||
|
||||
@@ -57,6 +57,7 @@ class QtInstaller:
|
||||
def retrieve_archive(self, package: QtPackage):
|
||||
archive = package.archive
|
||||
url = package.url
|
||||
start_time = time.perf_counter()
|
||||
self.logger.info("Downloading {}...".format(url))
|
||||
try:
|
||||
r = requests.get(url, allow_redirects=False, stream=True)
|
||||
@@ -84,7 +85,7 @@ class QtInstaller:
|
||||
if self.command is not None:
|
||||
self.extract_archive_ext(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):
|
||||
szf = py7zr.SevenZipFile(archive)
|
||||
@@ -132,8 +133,10 @@ class QtInstaller:
|
||||
def install(self):
|
||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||
futures = [executor.submit(self.retrieve_archive, ar) for ar in self.qt_archives.get_archives()]
|
||||
for future in concurrent.futures.as_completed(futures):
|
||||
future.result()
|
||||
done, not_done = concurrent.futures.wait(futures, return_when=concurrent.futures.FIRST_EXCEPTION)
|
||||
if len(not_done) > 0:
|
||||
self.logger.error("Installation error detected.")
|
||||
exit(1)
|
||||
|
||||
# finalize
|
||||
qt_version, target, arch = self.qt_archives.get_target_config()
|
||||
|
||||
@@ -67,6 +67,10 @@ class Settings(object):
|
||||
def tools_combinations(self):
|
||||
return self._combinations['tools']
|
||||
|
||||
@property
|
||||
def available_versions(self):
|
||||
return self._combinations['versions']
|
||||
|
||||
def available_modules(self, qt_version):
|
||||
"""Known module names
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
requests
|
||||
pytest
|
||||
pytest-pep8
|
||||
pytest-remotedata
|
||||
flake8
|
||||
setuptools>=42
|
||||
setuptools-scm>=3.5.0
|
||||
|
||||
@@ -51,5 +51,6 @@ aqt = *.yml, *.json, *.ini
|
||||
dev =
|
||||
pytest
|
||||
pytest-pep8
|
||||
pytest-remotedata
|
||||
pytest-cov
|
||||
flake8
|
||||
|
||||
@@ -39,6 +39,12 @@ def test_cli_check_combination():
|
||||
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():
|
||||
cli = aqt.cli.Cli()
|
||||
assert cli._check_mirror(None)
|
||||
|
||||
21
tests/test_connection.py
Normal file
21
tests/test_connection.py
Normal 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])
|
||||
Reference in New Issue
Block a user