Skip to content

Commit

Permalink
Merge pull request #852 from tsteven4/extensionsmaynotexist
Browse files Browse the repository at this point in the history
handle cases where extensions don't exist.
  • Loading branch information
miurahr authored Dec 16, 2024
2 parents cbfae6b + 7d50def commit b8683af
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
26 changes: 19 additions & 7 deletions aqt/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,21 +438,33 @@ def _get_archives_base(self, name, target_packages):
"online/qtsdkrepository", os_name, "extensions", ext, self._version_str(), arch
)
extensions_xml_url = posixpath.join(extensions_target_folder, "Updates.xml")
extensions_xml_text = self._download_update_xml(extensions_xml_url)
update_xmls.append(UpdateXmls(extensions_target_folder, extensions_xml_text))
# The extension may or may not exist for this version and arch.
try:
extensions_xml_text = self._download_update_xml(extensions_xml_url, True)
except ArchiveDownloadError:
# In case _download_update_xml ignores the hash and tries to get the url.
pass
if extensions_xml_text:
self.logger.info("Found extension {}".format(ext))
update_xmls.append(UpdateXmls(extensions_target_folder, extensions_xml_text))

self._parse_update_xmls(update_xmls, target_packages)

def _download_update_xml(self, update_xml_path):
def _download_update_xml(self, update_xml_path, silent=False):
"""Hook for unit test."""
if not Settings.ignore_hash:
try:
xml_hash = get_hash(update_xml_path, Settings.hash_algorithm, self.timeout)
except ChecksumDownloadFailure:
self.logger.warning(
"Failed to download checksum for the file 'Updates.xml'. This may happen on unofficial mirrors."
)
xml_hash = None
if silent:
return None
else:
self.logger.warning(
"Failed to download checksum for the file '{}'. This may happen on unofficial mirrors.".format(
update_xml_path
)
)
xml_hash = None
else:
xml_hash = None
return getUrl(posixpath.join(self.base, update_xml_path), self.timeout, xml_hash)
Expand Down
37 changes: 31 additions & 6 deletions aqt/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
from semantic_version import Version as SemanticVersion
from texttable import Texttable

from aqt.exceptions import ArchiveConnectionError, ArchiveDownloadError, ArchiveListError, CliInputError, EmptyMetadata
from aqt.exceptions import (
ArchiveConnectionError,
ArchiveDownloadError,
ArchiveListError,
ChecksumDownloadFailure,
CliInputError,
EmptyMetadata,
)
from aqt.helper import Settings, get_hash, getUrl, xml_to_modules


Expand Down Expand Up @@ -556,6 +563,12 @@ def is_in_wasm_range(host: str, version: Version) -> bool:
def is_in_wasm_threaded_range(version: Version) -> bool:
return version in SimpleSpec(">=6.5.0")

@staticmethod
def known_extensions(version: Version) -> List[str]:
if version >= Version("6.8.0"):
return ["qtpdf", "qtwebengine"]
return []


class MetadataFactory:
"""Retrieve metadata of Qt variations, versions, and descriptions from Qt site."""
Expand Down Expand Up @@ -886,9 +899,19 @@ def to_module_arch(name: str) -> Tuple[Optional[str], Optional[str]]:
module, _arch = to_module_arch(name)
if _arch == arch:
modules.add(cast(str, module))
if version >= Version("6.8.0"):
for ext in self.fetch_extensions():
modules.add(ext)

ext_pattern = re.compile(r"^extensions\." + r"(?P<module>[^.]+)\." + qt_ver_str + r"\." + arch + r"$")
for ext in QtRepoProperty.known_extensions(version):
try:
ext_meta = self._fetch_extension_metadata(self.archive_id.to_extension_folder(ext, qt_ver_str, arch))
for key, value in ext_meta.items():
ext_match = ext_pattern.match(key)
if ext_match is not None:
module = ext_match.group("module")
if module is not None:
modules.add(ext)
except (ChecksumDownloadFailure, ArchiveDownloadError):
pass
return sorted(modules)

@staticmethod
Expand Down Expand Up @@ -930,15 +953,17 @@ def matches_arch(element: Element) -> bool:
# Examples: extensions.qtwebengine.680.debug_information
# extensions.qtwebengine.680.win64_msvc2022_64
ext_pattern = re.compile(r"^extensions\." + r"(?P<module>[^.]+)\." + qt_ver_str + r"\." + arch + r"$")
if version >= Version("6.8.0"):
for ext in self.fetch_extensions():
for ext in QtRepoProperty.known_extensions(version):
try:
ext_meta = self._fetch_extension_metadata(self.archive_id.to_extension_folder(ext, qt_ver_str, arch))
for key, value in ext_meta.items():
ext_match = ext_pattern.match(key)
if ext_match is not None:
module = ext_match.group("module")
if module is not None:
m[module] = value
except (ChecksumDownloadFailure, ArchiveDownloadError):
pass
return ModuleData(m)

def fetch_modules_sde(self, cmd_type: str, version: Version) -> List[str]:
Expand Down

0 comments on commit b8683af

Please sign in to comment.