Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- python/py313/Lib/site-packages/Cryptodome/__init__.py +6 -0
- python/py313/Lib/site-packages/Cryptodome/__init__.pyi +4 -0
- python/py313/Lib/site-packages/Cryptodome/py.typed +0 -0
- python/py313/Lib/site-packages/README.rst +1 -0
- python/py313/Lib/site-packages/__pycache__/brotli.cpython-313.pyc +0 -0
- python/py313/Lib/site-packages/__pycache__/patch_ng.cpython-313.pyc +0 -0
- python/py313/Lib/site-packages/__pycache__/texttable.cpython-313.pyc +0 -0
- python/py313/Lib/site-packages/aqt/__init__.py +40 -0
- python/py313/Lib/site-packages/aqt/__main__.py +27 -0
- python/py313/Lib/site-packages/aqt/archives.py +716 -0
- python/py313/Lib/site-packages/aqt/commercial.py +395 -0
- python/py313/Lib/site-packages/aqt/exceptions.py +114 -0
- python/py313/Lib/site-packages/aqt/helper.py +786 -0
- python/py313/Lib/site-packages/aqt/installer.py +1708 -0
- python/py313/Lib/site-packages/aqt/logging.ini +78 -0
- python/py313/Lib/site-packages/aqt/metadata.py +1235 -0
- python/py313/Lib/site-packages/aqt/settings.ini +256 -0
- python/py313/Lib/site-packages/aqt/updater.py +353 -0
- python/py313/Lib/site-packages/aqt/version.py +1 -0
- python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/INSTALLER +1 -0
- python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/METADATA +290 -0
- python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/RECORD +31 -0
- python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/REQUESTED +0 -0
- python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/WHEEL +5 -0
- python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/entry_points.txt +2 -0
- python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/top_level.txt +1 -0
- python/py313/Lib/site-packages/backports_zstd-1.5.0.dist-info/INSTALLER +1 -0
- python/py313/Lib/site-packages/backports_zstd-1.5.0.dist-info/METADATA +216 -0
- python/py313/Lib/site-packages/backports_zstd-1.5.0.dist-info/RECORD +50 -0
- python/py313/Lib/site-packages/backports_zstd-1.5.0.dist-info/WHEEL +5 -0
- python/py313/Lib/site-packages/backports_zstd-1.5.0.dist-info/top_level.txt +1 -0
- python/py313/Lib/site-packages/bcj/__init__.py +74 -0
- python/py313/Lib/site-packages/bcj/_bcj.cp313-win_amd64.pyd +0 -0
- python/py313/Lib/site-packages/bcj/_bcjfilter.py +264 -0
- python/py313/Lib/site-packages/bcj/py.typed +0 -0
- python/py313/Lib/site-packages/beautifulsoup4-4.14.3.dist-info/INSTALLER +1 -0
- python/py313/Lib/site-packages/beautifulsoup4-4.14.3.dist-info/METADATA +123 -0
- python/py313/Lib/site-packages/beautifulsoup4-4.14.3.dist-info/RECORD +37 -0
- python/py313/Lib/site-packages/beautifulsoup4-4.14.3.dist-info/WHEEL +4 -0
- python/py313/Lib/site-packages/brotli-1.2.0.dist-info/INSTALLER +1 -0
- python/py313/Lib/site-packages/brotli-1.2.0.dist-info/METADATA +158 -0
- python/py313/Lib/site-packages/brotli-1.2.0.dist-info/RECORD +9 -0
- python/py313/Lib/site-packages/brotli-1.2.0.dist-info/WHEEL +5 -0
- python/py313/Lib/site-packages/brotli-1.2.0.dist-info/top_level.txt +2 -0
- python/py313/Lib/site-packages/brotli.py +57 -0
- python/py313/Lib/site-packages/bs4-0.0.2.dist-info/INSTALLER +1 -0
- python/py313/Lib/site-packages/bs4-0.0.2.dist-info/METADATA +10 -0
- python/py313/Lib/site-packages/bs4-0.0.2.dist-info/RECORD +5 -0
- python/py313/Lib/site-packages/bs4-0.0.2.dist-info/WHEEL +5 -0
- python/py313/Lib/site-packages/bs4/__init__.py +1174 -0
python/py313/Lib/site-packages/Cryptodome/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ['Cipher', 'Hash', 'Protocol', 'PublicKey', 'Util', 'Signature',
|
| 2 |
+
'IO', 'Math']
|
| 3 |
+
|
| 4 |
+
version_info = (3, 23, '0')
|
| 5 |
+
|
| 6 |
+
__version__ = ".".join([str(x) for x in version_info])
|
python/py313/Lib/site-packages/Cryptodome/__init__.pyi
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Tuple, Union
|
| 2 |
+
|
| 3 |
+
version_info : Tuple[int, int, Union[int, str]]
|
| 4 |
+
__version__ : str
|
python/py313/Lib/site-packages/Cryptodome/py.typed
ADDED
|
File without changes
|
python/py313/Lib/site-packages/README.rst
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
This is a dummy package designed to prevent namesquatting on PyPI. You should install `beautifulsoup4 <https://pypi.python.org/pypi/beautifulsoup4>`_ instead.
|
python/py313/Lib/site-packages/__pycache__/brotli.cpython-313.pyc
ADDED
|
Binary file (1.93 kB). View file
|
|
|
python/py313/Lib/site-packages/__pycache__/patch_ng.cpython-313.pyc
ADDED
|
Binary file (60.8 kB). View file
|
|
|
python/py313/Lib/site-packages/__pycache__/texttable.cpython-313.pyc
ADDED
|
Binary file (29.8 kB). View file
|
|
|
python/py313/Lib/site-packages/aqt/__init__.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2018 Linus Jahn <lnj@kaidan.im>
|
| 4 |
+
# Copyright (C) 2019-2021 Hiroshi Miura <miurahr@linux.com>
|
| 5 |
+
#
|
| 6 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 7 |
+
# this software and associated documentation files (the "Software"), to deal in
|
| 8 |
+
# the Software without restriction, including without limitation the rights to
|
| 9 |
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 10 |
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
| 11 |
+
# subject to the following conditions:
|
| 12 |
+
#
|
| 13 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
# copies or substantial portions of the Software.
|
| 15 |
+
#
|
| 16 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 18 |
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 19 |
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 20 |
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 21 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 22 |
+
|
| 23 |
+
import sys
|
| 24 |
+
from multiprocessing import freeze_support
|
| 25 |
+
|
| 26 |
+
if sys.version_info.major == 2:
|
| 27 |
+
print("aqtinstall requires python 3!")
|
| 28 |
+
sys.exit(1)
|
| 29 |
+
|
| 30 |
+
from aqt.installer import Cli
|
| 31 |
+
from aqt.version import __version__
|
| 32 |
+
|
| 33 |
+
__all__ = ["__version__"]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def main():
|
| 37 |
+
# For Windows standalone binaries, this is a noop on all other environments.
|
| 38 |
+
freeze_support()
|
| 39 |
+
cli = Cli()
|
| 40 |
+
return cli.run()
|
python/py313/Lib/site-packages/aqt/__main__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2019-2021 Hiroshi Miura <miurahr@linux.com>
|
| 4 |
+
#
|
| 5 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 6 |
+
# this software and associated documentation files (the "Software"), to deal in
|
| 7 |
+
# the Software without restriction, including without limitation the rights to
|
| 8 |
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 9 |
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
| 10 |
+
# subject to the following conditions:
|
| 11 |
+
#
|
| 12 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
# copies or substantial portions of the Software.
|
| 14 |
+
#
|
| 15 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 17 |
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 18 |
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 19 |
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 20 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
+
|
| 22 |
+
import sys
|
| 23 |
+
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2018 Linus Jahn <lnj@kaidan.im>
|
| 4 |
+
# Copyright (C) 2019-2022 Hiroshi Miura <miurahr@linux.com>
|
| 5 |
+
#
|
| 6 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 7 |
+
# this software and associated documentation files (the "Software"), to deal in
|
| 8 |
+
# the Software without restriction, including without limitation the rights to
|
| 9 |
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 10 |
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
| 11 |
+
# subject to the following conditions:
|
| 12 |
+
#
|
| 13 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
# copies or substantial portions of the Software.
|
| 15 |
+
#
|
| 16 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 18 |
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 19 |
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 20 |
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 21 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 22 |
+
import posixpath
|
| 23 |
+
from dataclasses import dataclass, field
|
| 24 |
+
from itertools import islice, zip_longest
|
| 25 |
+
from logging import getLogger
|
| 26 |
+
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
|
| 27 |
+
from xml.etree.ElementTree import Element # noqa
|
| 28 |
+
|
| 29 |
+
from defusedxml import ElementTree
|
| 30 |
+
|
| 31 |
+
from aqt.exceptions import ArchiveDownloadError, ArchiveListError, ChecksumDownloadFailure, NoPackageFound
|
| 32 |
+
from aqt.helper import Settings, get_hash, getUrl, ssplit
|
| 33 |
+
from aqt.metadata import QtRepoProperty, Version
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@dataclass
|
| 37 |
+
class UpdateXmls:
|
| 38 |
+
target_folder: str
|
| 39 |
+
xml_text: str
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
@dataclass
|
| 43 |
+
class TargetConfig:
|
| 44 |
+
version: str
|
| 45 |
+
target: str
|
| 46 |
+
arch: str
|
| 47 |
+
os_name: str
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@dataclass
|
| 51 |
+
class QtPackage:
|
| 52 |
+
name: str
|
| 53 |
+
base_url: str
|
| 54 |
+
archive_path: str
|
| 55 |
+
archive: str
|
| 56 |
+
archive_install_path: str
|
| 57 |
+
package_desc: str
|
| 58 |
+
pkg_update_name: str
|
| 59 |
+
version: Optional[Version] = field(default=None)
|
| 60 |
+
|
| 61 |
+
def __repr__(self):
|
| 62 |
+
v_info = f", version={self.version}" if self.version else ""
|
| 63 |
+
return f"QtPackage(name={self.name}, archive={self.archive}{v_info})"
|
| 64 |
+
|
| 65 |
+
def __str__(self):
|
| 66 |
+
v_info = f", version={self.version}" if self.version else ""
|
| 67 |
+
return (
|
| 68 |
+
f"QtPackage(name={self.name}, url={self.archive_path}, "
|
| 69 |
+
f"archive={self.archive}, desc={self.package_desc}"
|
| 70 |
+
f"{v_info})"
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class ModuleToPackage:
|
| 75 |
+
"""
|
| 76 |
+
Holds a mapping of module names to a list of Updates.xml PackageUpdate names.
|
| 77 |
+
For example, we could have the following:
|
| 78 |
+
{"qtcharts": ["qt.qt6.620.addons.qtcharts.arch", qt.qt6.620.qtcharts.arch", qt.620.addons.qtcharts.arch",])
|
| 79 |
+
It also contains a reverse mapping of PackageUpdate names to module names, so that
|
| 80 |
+
lookup of a package name and removal of a module name can be done in constant time.
|
| 81 |
+
Without this reverse mapping, QtArchives._parse_update_xml would run at least one
|
| 82 |
+
linear search on the forward mapping for each module installed.
|
| 83 |
+
|
| 84 |
+
The list of PackageUpdate names consists of all the possible names for the PackageUpdate.
|
| 85 |
+
The naming conventions for each PackageUpdate are not predictable, so we need to maintain
|
| 86 |
+
a list of possibilities. While reading Updates.xml, if we encounter any one of the package
|
| 87 |
+
names on this list, we can use it to install the package "qtcharts".
|
| 88 |
+
|
| 89 |
+
Once we have installed the package, we need to remove the package "qtcharts" from this
|
| 90 |
+
mapping, so we can keep track of what still needs to be installed.
|
| 91 |
+
"""
|
| 92 |
+
|
| 93 |
+
def __init__(self, initial_map: Dict[str, List[str]]):
|
| 94 |
+
self._modules_to_packages: Dict[str, List[str]] = initial_map
|
| 95 |
+
self._packages_to_modules: Dict[str, str] = {
|
| 96 |
+
value: key for key, list_of_values in initial_map.items() for value in list_of_values
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
def add(self, module_name: str, package_names: List[str]):
|
| 100 |
+
self._modules_to_packages[module_name] = self._modules_to_packages.get(module_name, []) + package_names
|
| 101 |
+
for package_name in package_names:
|
| 102 |
+
assert package_name not in self._packages_to_modules, "Detected a package name collision"
|
| 103 |
+
self._packages_to_modules[package_name] = module_name
|
| 104 |
+
|
| 105 |
+
def remove_module_for_package(self, package_name: str):
|
| 106 |
+
module_name = self._packages_to_modules[package_name]
|
| 107 |
+
for package_name in self._modules_to_packages[module_name]:
|
| 108 |
+
self._packages_to_modules.pop(package_name)
|
| 109 |
+
self._modules_to_packages.pop(module_name)
|
| 110 |
+
|
| 111 |
+
def has_package(self, package_name: str):
|
| 112 |
+
return package_name in self._packages_to_modules
|
| 113 |
+
|
| 114 |
+
def get_modules(self) -> Iterable[str]:
|
| 115 |
+
return self._modules_to_packages.keys()
|
| 116 |
+
|
| 117 |
+
def __len__(self) -> int:
|
| 118 |
+
return len(self._modules_to_packages)
|
| 119 |
+
|
| 120 |
+
def __format__(self, format_spec) -> str:
|
| 121 |
+
return str(sorted(set(self._modules_to_packages.keys())))
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
@dataclass
|
| 125 |
+
class PackageUpdate:
|
| 126 |
+
"""
|
| 127 |
+
Data class to hold package data.
|
| 128 |
+
key is its name.
|
| 129 |
+
"""
|
| 130 |
+
|
| 131 |
+
name: str
|
| 132 |
+
display_name: str
|
| 133 |
+
description: str
|
| 134 |
+
release_date: str
|
| 135 |
+
full_version: str
|
| 136 |
+
dependencies: Iterable[str]
|
| 137 |
+
auto_dependon: Iterable[str]
|
| 138 |
+
downloadable_archives: Iterable[str]
|
| 139 |
+
archive_install_paths: Iterable[str]
|
| 140 |
+
default: bool
|
| 141 |
+
virtual: bool
|
| 142 |
+
base: str
|
| 143 |
+
|
| 144 |
+
def __post_init__(self):
|
| 145 |
+
for iter_of_str in self.dependencies, self.auto_dependon, self.downloadable_archives, self.archive_install_paths:
|
| 146 |
+
assert isinstance(iter_of_str, Iterable) and not isinstance(iter_of_str, str)
|
| 147 |
+
for _str in self.name, self.display_name, self.description, self.release_date, self.full_version, self.base:
|
| 148 |
+
assert isinstance(_str, str)
|
| 149 |
+
for boolean in self.default, self.virtual:
|
| 150 |
+
assert isinstance(boolean, bool)
|
| 151 |
+
|
| 152 |
+
@property
|
| 153 |
+
def version(self):
|
| 154 |
+
return Version.permissive(self.full_version)
|
| 155 |
+
|
| 156 |
+
@property
|
| 157 |
+
def arch(self):
|
| 158 |
+
return self.name.split(".")[-1]
|
| 159 |
+
|
| 160 |
+
def is_base_package(self) -> bool:
|
| 161 |
+
return self.name in (
|
| 162 |
+
f"qt.qt{self.version.major}.{self._version_str()}.{self.arch}",
|
| 163 |
+
f"qt.{self._version_str()}.{self.arch}",
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
def _version_str(self) -> str:
|
| 167 |
+
return ("{0.major}{0.minor}" if self.version == Version("5.9.0") else "{0.major}{0.minor}{0.patch}").format(
|
| 168 |
+
self.version
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
@dataclass(init=False)
|
| 173 |
+
class Updates:
|
| 174 |
+
package_updates: List[PackageUpdate]
|
| 175 |
+
|
| 176 |
+
def __init__(self) -> None:
|
| 177 |
+
self.package_updates = []
|
| 178 |
+
|
| 179 |
+
def extend(self, other):
|
| 180 |
+
self.package_updates.extend(other.package_updates)
|
| 181 |
+
|
| 182 |
+
@staticmethod
|
| 183 |
+
def fromstring(base, update_xml_text: str):
|
| 184 |
+
try:
|
| 185 |
+
update_xml = ElementTree.fromstring(update_xml_text)
|
| 186 |
+
except ElementTree.ParseError as perror:
|
| 187 |
+
raise ArchiveListError(f"Downloaded metadata is corrupted. {perror}") from perror
|
| 188 |
+
updates = Updates()
|
| 189 |
+
extract_xpath = "Operations/Operation[@name='Extract']/Argument"
|
| 190 |
+
for packageupdate in update_xml.iter("PackageUpdate"):
|
| 191 |
+
pkg_name = updates._get_text(packageupdate.find("Name"))
|
| 192 |
+
display_name = updates._get_text(packageupdate.find("DisplayName"))
|
| 193 |
+
full_version = updates._get_text(packageupdate.find("Version"))
|
| 194 |
+
package_desc = updates._get_text(packageupdate.find("Description"))
|
| 195 |
+
release_date = updates._get_text(packageupdate.find("ReleaseDate"))
|
| 196 |
+
dependencies = updates._get_list(packageupdate.find("Dependencies"))
|
| 197 |
+
auto_dependon = updates._get_list(packageupdate.find("AutoDependOn"))
|
| 198 |
+
archives = updates._get_list(packageupdate.find("DownloadableArchives"))
|
| 199 |
+
archive_install_paths = updates._get_list(None)
|
| 200 |
+
default = updates._get_boolean(packageupdate.find("Default"))
|
| 201 |
+
virtual = updates._get_boolean(packageupdate.find("Virtual"))
|
| 202 |
+
if packageupdate.find(extract_xpath) is not None:
|
| 203 |
+
arc_args = map(
|
| 204 |
+
lambda x: x.text,
|
| 205 |
+
islice(packageupdate.iterfind(extract_xpath), 1, None, 2),
|
| 206 |
+
)
|
| 207 |
+
archives = ssplit(", ".join(arc_args))
|
| 208 |
+
path_args = map(
|
| 209 |
+
lambda x: x.text.replace("@TargetDir@/", "", 1),
|
| 210 |
+
islice(packageupdate.iterfind(extract_xpath), 0, None, 2),
|
| 211 |
+
)
|
| 212 |
+
archive_install_paths = ssplit(", ".join(path_args))
|
| 213 |
+
updates.package_updates.append(
|
| 214 |
+
PackageUpdate(
|
| 215 |
+
pkg_name,
|
| 216 |
+
display_name,
|
| 217 |
+
package_desc,
|
| 218 |
+
release_date,
|
| 219 |
+
full_version,
|
| 220 |
+
dependencies,
|
| 221 |
+
auto_dependon,
|
| 222 |
+
archives,
|
| 223 |
+
archive_install_paths,
|
| 224 |
+
default,
|
| 225 |
+
virtual,
|
| 226 |
+
base,
|
| 227 |
+
)
|
| 228 |
+
)
|
| 229 |
+
return updates
|
| 230 |
+
|
| 231 |
+
def get(self, target: Optional[str] = None):
|
| 232 |
+
if target is None:
|
| 233 |
+
return self.package_updates
|
| 234 |
+
for update in self.package_updates:
|
| 235 |
+
if update.name == target:
|
| 236 |
+
return update
|
| 237 |
+
return None
|
| 238 |
+
|
| 239 |
+
def get_from(self, arch: str, is_include_base: bool, target_packages: Optional[ModuleToPackage] = None):
|
| 240 |
+
result = []
|
| 241 |
+
for update in self.package_updates:
|
| 242 |
+
# If we asked for `--noarchives`, we don't want the base module
|
| 243 |
+
if not is_include_base and update.is_base_package():
|
| 244 |
+
continue
|
| 245 |
+
if target_packages is not None and not target_packages.has_package(update.name):
|
| 246 |
+
continue
|
| 247 |
+
if arch in update.name:
|
| 248 |
+
result.append(update)
|
| 249 |
+
return result
|
| 250 |
+
|
| 251 |
+
def merge(self, other):
|
| 252 |
+
self.package_updates.extend(other.package_updates)
|
| 253 |
+
|
| 254 |
+
def get_depends(self, target: str) -> Iterable[str]:
|
| 255 |
+
# initialize
|
| 256 |
+
filo = [target]
|
| 257 |
+
packages = []
|
| 258 |
+
visited = []
|
| 259 |
+
# dfs look-up
|
| 260 |
+
while len(filo) > 0:
|
| 261 |
+
next = filo.pop()
|
| 262 |
+
packages.append(next)
|
| 263 |
+
for entry in self.package_updates:
|
| 264 |
+
if entry.name == next:
|
| 265 |
+
visited.append(next)
|
| 266 |
+
if entry.dependencies is not None:
|
| 267 |
+
for depend in entry.dependencies:
|
| 268 |
+
if depend not in visited:
|
| 269 |
+
filo.append(depend)
|
| 270 |
+
return packages
|
| 271 |
+
|
| 272 |
+
def _get_text(self, item: Optional[Element]) -> str:
|
| 273 |
+
if item is not None and item.text is not None:
|
| 274 |
+
return item.text
|
| 275 |
+
return ""
|
| 276 |
+
|
| 277 |
+
def _get_list(self, item: Optional[Element]) -> Iterable[str]:
|
| 278 |
+
if item is not None and item.text is not None:
|
| 279 |
+
return ssplit(item.text)
|
| 280 |
+
else:
|
| 281 |
+
return []
|
| 282 |
+
|
| 283 |
+
def _get_boolean(self, item) -> bool:
|
| 284 |
+
return bool("true" == item)
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
class QtArchives:
|
| 288 |
+
"""Download and hold Qt archive packages list.
|
| 289 |
+
It access to download.qt.io site and get Update.xml file.
|
| 290 |
+
It parse XML file and store metadata into list of QtPackage object.
|
| 291 |
+
"""
|
| 292 |
+
|
| 293 |
+
def __init__(
|
| 294 |
+
self,
|
| 295 |
+
os_name: str,
|
| 296 |
+
target: str,
|
| 297 |
+
version_str: str,
|
| 298 |
+
arch: str,
|
| 299 |
+
base: str,
|
| 300 |
+
subarchives: Optional[Iterable[str]] = None,
|
| 301 |
+
modules: Optional[Iterable[str]] = None,
|
| 302 |
+
all_extra: bool = False,
|
| 303 |
+
is_include_base_package: bool = True,
|
| 304 |
+
timeout=(5, 5),
|
| 305 |
+
):
|
| 306 |
+
self.version: Version = Version(version_str)
|
| 307 |
+
self.target: str = target
|
| 308 |
+
self.arch: str = arch
|
| 309 |
+
self.os_name: str = os_name
|
| 310 |
+
self.all_extra: bool = all_extra
|
| 311 |
+
self.base: str = base
|
| 312 |
+
self.logger = getLogger("aqt.archives")
|
| 313 |
+
self.archives: List[QtPackage] = []
|
| 314 |
+
self.subarchives: Optional[Iterable[str]] = subarchives
|
| 315 |
+
self.mod_list: Set[str] = set(modules or [])
|
| 316 |
+
self.is_include_base_package: bool = is_include_base_package
|
| 317 |
+
self.timeout = timeout
|
| 318 |
+
try:
|
| 319 |
+
self._get_archives()
|
| 320 |
+
except ArchiveDownloadError as e:
|
| 321 |
+
self.handle_missing_updates_xml(e)
|
| 322 |
+
|
| 323 |
+
def handle_missing_updates_xml(self, e: ArchiveDownloadError):
|
| 324 |
+
msg = f"Failed to locate XML data for Qt version '{self.version}'."
|
| 325 |
+
help_msg = f"Please use 'aqt list-qt {self.os_name} {self.target}' to show versions available."
|
| 326 |
+
raise ArchiveListError(msg, suggested_action=[help_msg]) from e
|
| 327 |
+
|
| 328 |
+
def should_filter_archives(self, package_name: str) -> bool:
|
| 329 |
+
"""
|
| 330 |
+
This tells us, based on the PackageUpdate.Name property, whether or not the `self.subarchives`
|
| 331 |
+
list should be used to filter out archives that we are not interested in.
|
| 332 |
+
|
| 333 |
+
If `package_name` is a base module or a debug_info module, the `subarchives` list will apply to it.
|
| 334 |
+
"""
|
| 335 |
+
return package_name in self._base_package_names() or "debug_info" in package_name
|
| 336 |
+
|
| 337 |
+
def _version_str(self) -> str:
|
| 338 |
+
return ("{0.major}{0.minor}" if self.version == Version("5.9.0") else "{0.major}{0.minor}{0.patch}").format(
|
| 339 |
+
self.version
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
def _arch_ext(self) -> str:
|
| 343 |
+
ext = QtRepoProperty.extension_for_arch(self.arch, self.version >= Version("6.0.0"))
|
| 344 |
+
return ("_" + ext) if ext else ""
|
| 345 |
+
|
| 346 |
+
def _base_module_name(self) -> str:
|
| 347 |
+
"""
|
| 348 |
+
This is the name for the base Qt module, whose PackageUpdate.Name property would be
|
| 349 |
+
'qt.123.gcc_64' or 'qt.qt1.123.gcc_64' for Qt 1.2.3, for architecture gcc_64.
|
| 350 |
+
"""
|
| 351 |
+
return "qt_base"
|
| 352 |
+
|
| 353 |
+
def _base_package_names(self) -> Iterable[str]:
|
| 354 |
+
"""
|
| 355 |
+
This is a list of all potential PackageUpdate.Name properties for the base Qt module,
|
| 356 |
+
which would be 'qt.123.gcc_64' or 'qt.qt1.123.gcc_64' for Qt 1.2.3, for architecture gcc_64,
|
| 357 |
+
or 'qt.123.src' or 'qt.qt1.123.src' for the source module.
|
| 358 |
+
"""
|
| 359 |
+
return (
|
| 360 |
+
f"qt.qt{self.version.major}.{self._version_str()}.{self.arch}",
|
| 361 |
+
f"qt.{self._version_str()}.{self.arch}",
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
def _module_name_suffix(self, module: str) -> str:
|
| 365 |
+
return f"{module}.{self.arch}"
|
| 366 |
+
|
| 367 |
+
def _target_packages(self) -> ModuleToPackage:
|
| 368 |
+
"""Build mapping between module names and their possible package names"""
|
| 369 |
+
if self.all_extra:
|
| 370 |
+
return ModuleToPackage({})
|
| 371 |
+
|
| 372 |
+
base_package = {self._base_module_name(): list(self._base_package_names())}
|
| 373 |
+
target_packages = ModuleToPackage(base_package if self.is_include_base_package else {})
|
| 374 |
+
|
| 375 |
+
for module in self.mod_list:
|
| 376 |
+
suffix = self._module_name_suffix(module)
|
| 377 |
+
prefix = "qt.qt{}.{}.".format(self.version.major, self._version_str())
|
| 378 |
+
basic_prefix = "qt.{}.".format(self._version_str())
|
| 379 |
+
|
| 380 |
+
# All possible package name formats
|
| 381 |
+
package_names = [
|
| 382 |
+
f"{prefix}{suffix}",
|
| 383 |
+
f"{basic_prefix}{suffix}",
|
| 384 |
+
f"{prefix}addons.{suffix}",
|
| 385 |
+
f"{basic_prefix}addons.{suffix}",
|
| 386 |
+
f"extensions.{module}.{self._version_str()}.{self.arch}",
|
| 387 |
+
f"{prefix}{module}.{self.arch}", # Qt6.8+ format
|
| 388 |
+
f"{basic_prefix}{module}.{self.arch}", # Qt6.8+ format
|
| 389 |
+
f"{prefix}addons.{module}.{self.arch}", # Qt6.8+ addons format
|
| 390 |
+
f"{basic_prefix}addons.{module}.{self.arch}", # Qt6.8+ addons format
|
| 391 |
+
]
|
| 392 |
+
|
| 393 |
+
target_packages.add(module, list(set(package_names))) # Remove duplicates
|
| 394 |
+
|
| 395 |
+
return target_packages
|
| 396 |
+
|
| 397 |
+
def _get_archives(self):
|
| 398 |
+
if self.version >= Version("6.8.0"):
|
| 399 |
+
name = (
|
| 400 |
+
f"qt{self.version.major}_{self._version_str()}"
|
| 401 |
+
f"/qt{self.version.major}_{self._version_str()}{self._arch_ext()}"
|
| 402 |
+
)
|
| 403 |
+
else:
|
| 404 |
+
name = f"qt{self.version.major}_{self._version_str()}{self._arch_ext()}"
|
| 405 |
+
self._get_archives_base(name, self._target_packages())
|
| 406 |
+
|
| 407 |
+
def _get_archives_base(self, name, target_packages):
|
| 408 |
+
os_name = self.os_name
|
| 409 |
+
if self.target == "android" and self.version >= Version("6.7.0"):
|
| 410 |
+
os_name = "all_os"
|
| 411 |
+
elif self.os_name == "windows":
|
| 412 |
+
os_name += "_x86"
|
| 413 |
+
elif os_name != "linux_arm64" and os_name != "all_os" and os_name != "windows_arm64":
|
| 414 |
+
os_name += "_x64"
|
| 415 |
+
os_target_folder = posixpath.join(
|
| 416 |
+
"online/qtsdkrepository",
|
| 417 |
+
os_name,
|
| 418 |
+
self.target,
|
| 419 |
+
# tools_ifw/
|
| 420 |
+
name,
|
| 421 |
+
)
|
| 422 |
+
update_xml_url = posixpath.join(os_target_folder, "Updates.xml")
|
| 423 |
+
update_xml_text = self._download_update_xml(update_xml_url)
|
| 424 |
+
update_xmls = [UpdateXmls(os_target_folder, update_xml_text)]
|
| 425 |
+
|
| 426 |
+
if self.version >= Version("6.8.0"):
|
| 427 |
+
arch = self.arch
|
| 428 |
+
if self.os_name == "windows":
|
| 429 |
+
arch = self.arch.replace("win64_", "", 1)
|
| 430 |
+
elif self.os_name == "linux":
|
| 431 |
+
arch = "x86_64"
|
| 432 |
+
elif self.os_name == "linux_arm64":
|
| 433 |
+
arch = "arm64"
|
| 434 |
+
for ext in ["qtwebengine", "qtpdf"]:
|
| 435 |
+
extensions_target_folder = posixpath.join(
|
| 436 |
+
"online/qtsdkrepository", os_name, "extensions", ext, self._version_str(), arch
|
| 437 |
+
)
|
| 438 |
+
extensions_xml_url = posixpath.join(extensions_target_folder, "Updates.xml")
|
| 439 |
+
# The extension may or may not exist for this version and arch.
|
| 440 |
+
try:
|
| 441 |
+
extensions_xml_text = self._download_update_xml(extensions_xml_url, True)
|
| 442 |
+
except ArchiveDownloadError:
|
| 443 |
+
# In case _download_update_xml failed to get the url because of no extension.
|
| 444 |
+
pass
|
| 445 |
+
else:
|
| 446 |
+
if extensions_xml_text:
|
| 447 |
+
self.logger.info("Found extension {}".format(ext))
|
| 448 |
+
update_xmls.append(UpdateXmls(extensions_target_folder, extensions_xml_text))
|
| 449 |
+
|
| 450 |
+
self._parse_update_xmls(update_xmls, target_packages)
|
| 451 |
+
|
| 452 |
+
def _download_update_xml(self, update_xml_path: str, silent: bool = False) -> Optional[str]:
|
| 453 |
+
"""Hook for unit test."""
|
| 454 |
+
if not Settings.ignore_hash:
|
| 455 |
+
try:
|
| 456 |
+
xml_hash: Optional[bytes] = get_hash(update_xml_path, Settings.hash_algorithm, self.timeout)
|
| 457 |
+
except ChecksumDownloadFailure:
|
| 458 |
+
if silent:
|
| 459 |
+
return None
|
| 460 |
+
else:
|
| 461 |
+
self.logger.warning(
|
| 462 |
+
"Failed to download checksum for the file '{}'. This may happen on unofficial mirrors.".format(
|
| 463 |
+
update_xml_path
|
| 464 |
+
)
|
| 465 |
+
)
|
| 466 |
+
xml_hash = None
|
| 467 |
+
else:
|
| 468 |
+
xml_hash = None
|
| 469 |
+
return getUrl(posixpath.join(self.base, update_xml_path), self.timeout, xml_hash)
|
| 470 |
+
|
| 471 |
+
def _parse_update_xml(
|
| 472 |
+
self, os_target_folder: str, update_xml_text: str, target_packages: Optional[ModuleToPackage]
|
| 473 |
+
) -> None:
|
| 474 |
+
if not target_packages:
|
| 475 |
+
target_packages = ModuleToPackage({})
|
| 476 |
+
update_xml = Updates.fromstring(self.base, update_xml_text)
|
| 477 |
+
base_url = self.base
|
| 478 |
+
if self.all_extra:
|
| 479 |
+
package_updates = update_xml.get_from(self.arch, self.is_include_base_package)
|
| 480 |
+
else:
|
| 481 |
+
package_updates = update_xml.get_from(self.arch, self.is_include_base_package, target_packages)
|
| 482 |
+
for packageupdate in package_updates:
|
| 483 |
+
if not self.all_extra:
|
| 484 |
+
target_packages.remove_module_for_package(packageupdate.name)
|
| 485 |
+
should_filter_archives: bool = bool(self.subarchives) and self.should_filter_archives(packageupdate.name)
|
| 486 |
+
|
| 487 |
+
for archive, archive_install_path in zip_longest(
|
| 488 |
+
packageupdate.downloadable_archives, packageupdate.archive_install_paths, fillvalue=""
|
| 489 |
+
):
|
| 490 |
+
archive_name = archive.split("-", maxsplit=1)[0]
|
| 491 |
+
if should_filter_archives and self.subarchives is not None and archive_name not in self.subarchives:
|
| 492 |
+
continue
|
| 493 |
+
archive_path = posixpath.join(
|
| 494 |
+
# online/qtsdkrepository/linux_x64/desktop/qt5_5150/
|
| 495 |
+
os_target_folder,
|
| 496 |
+
# qt.qt5.5150.gcc_64/
|
| 497 |
+
packageupdate.name,
|
| 498 |
+
# 5.15.0-0-202005140804qtbase-Linux-RHEL_7_6-GCC-Linux-RHEL_7_6-X86_64.7z
|
| 499 |
+
packageupdate.full_version + archive,
|
| 500 |
+
)
|
| 501 |
+
self.archives.append(
|
| 502 |
+
QtPackage(
|
| 503 |
+
name=archive_name,
|
| 504 |
+
base_url=base_url,
|
| 505 |
+
archive_path=archive_path,
|
| 506 |
+
archive=archive,
|
| 507 |
+
archive_install_path=archive_install_path,
|
| 508 |
+
package_desc=packageupdate.description,
|
| 509 |
+
pkg_update_name=packageupdate.name, # For testing purposes
|
| 510 |
+
)
|
| 511 |
+
)
|
| 512 |
+
|
| 513 |
+
def _parse_update_xmls(self, update_xmls: list[UpdateXmls], target_packages: Optional[ModuleToPackage]) -> None:
|
| 514 |
+
if not target_packages:
|
| 515 |
+
target_packages = ModuleToPackage({})
|
| 516 |
+
for update_xml in update_xmls:
|
| 517 |
+
self._parse_update_xml(update_xml.target_folder, update_xml.xml_text, target_packages)
|
| 518 |
+
# if we have located every requested package, then target_packages will be empty
|
| 519 |
+
if not self.all_extra and len(target_packages) > 0:
|
| 520 |
+
message = f"The packages {target_packages} were not found while parsing XML of package information!"
|
| 521 |
+
raise NoPackageFound(message, suggested_action=self.help_msg(list(target_packages.get_modules())))
|
| 522 |
+
|
| 523 |
+
def _append_tool_update(self, os_target_folder, update_xml, target, tool_version_str):
|
| 524 |
+
packageupdate = update_xml.get(target)
|
| 525 |
+
if packageupdate is None:
|
| 526 |
+
message = f"The package '{self.arch}' was not found while parsing XML of package information!"
|
| 527 |
+
raise NoPackageFound(message, suggested_action=self.help_msg())
|
| 528 |
+
name = packageupdate.name
|
| 529 |
+
named_version = packageupdate.full_version
|
| 530 |
+
if tool_version_str and named_version != tool_version_str:
|
| 531 |
+
message = f"The package '{self.arch}' has the version '{named_version}', not the requested '{self.version}'."
|
| 532 |
+
raise NoPackageFound(message, suggested_action=self.help_msg())
|
| 533 |
+
package_desc = packageupdate.description
|
| 534 |
+
downloadable_archives = packageupdate.downloadable_archives
|
| 535 |
+
archive_install_paths = packageupdate.archive_install_paths
|
| 536 |
+
if not downloadable_archives:
|
| 537 |
+
message = f"The package '{self.arch}' contains no downloadable archives!"
|
| 538 |
+
raise NoPackageFound(message)
|
| 539 |
+
for archive, archive_install_path in zip_longest(downloadable_archives, archive_install_paths, fillvalue=""):
|
| 540 |
+
archive_path = posixpath.join(
|
| 541 |
+
# online/qtsdkrepository/linux_x64/desktop/tools_ifw/
|
| 542 |
+
os_target_folder,
|
| 543 |
+
# qt.tools.ifw.41/
|
| 544 |
+
name,
|
| 545 |
+
# 4.1.1-202105261130ifw-linux-x64.7z
|
| 546 |
+
f"{named_version}{archive}",
|
| 547 |
+
)
|
| 548 |
+
self.archives.append(
|
| 549 |
+
QtPackage(
|
| 550 |
+
name=name,
|
| 551 |
+
base_url=self.base,
|
| 552 |
+
archive_path=archive_path,
|
| 553 |
+
archive=archive,
|
| 554 |
+
archive_install_path=archive_install_path,
|
| 555 |
+
package_desc=package_desc,
|
| 556 |
+
pkg_update_name=name, # Redundant
|
| 557 |
+
)
|
| 558 |
+
)
|
| 559 |
+
|
| 560 |
+
def help_msg(self, missing_modules: Optional[List[str]] = None) -> List[str]:
|
| 561 |
+
_missing_modules: List[str] = missing_modules or []
|
| 562 |
+
base_cmd = f"aqt list-qt {self.os_name} {self.target}"
|
| 563 |
+
arch = f"Please use '{base_cmd} --arch {self.version}' to show architectures available."
|
| 564 |
+
mods = f"Please use '{base_cmd} --modules {self.version} <arch>' to show modules available."
|
| 565 |
+
has_base_pkg: bool = self._base_module_name() in _missing_modules
|
| 566 |
+
has_non_base_pkg: bool = len(list(_missing_modules)) > 1 or not has_base_pkg
|
| 567 |
+
messages = []
|
| 568 |
+
if has_base_pkg:
|
| 569 |
+
messages.append(arch)
|
| 570 |
+
if has_non_base_pkg:
|
| 571 |
+
messages.append(mods)
|
| 572 |
+
return messages
|
| 573 |
+
|
| 574 |
+
def get_packages(self) -> List[QtPackage]:
|
| 575 |
+
"""
|
| 576 |
+
It returns an archive package list.
|
| 577 |
+
|
| 578 |
+
:return package list
|
| 579 |
+
:rtype: List[QtPackage]
|
| 580 |
+
"""
|
| 581 |
+
return self.archives
|
| 582 |
+
|
| 583 |
+
def get_target_config(self) -> TargetConfig:
|
| 584 |
+
"""Get target configuration
|
| 585 |
+
|
| 586 |
+
:return: configured target and its version with arch
|
| 587 |
+
:rtype: TargetConfig object
|
| 588 |
+
"""
|
| 589 |
+
return TargetConfig(str(self.version), self.target, self.arch, self.os_name)
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
class SrcDocExamplesArchives(QtArchives):
|
| 593 |
+
"""Hold doc/src/example archive package list."""
|
| 594 |
+
|
| 595 |
+
def __init__(
|
| 596 |
+
self,
|
| 597 |
+
flavor: str,
|
| 598 |
+
os_name,
|
| 599 |
+
target,
|
| 600 |
+
version,
|
| 601 |
+
base,
|
| 602 |
+
subarchives=None,
|
| 603 |
+
modules=None,
|
| 604 |
+
all_extra=False,
|
| 605 |
+
is_include_base_package: bool = True,
|
| 606 |
+
timeout=(5, 5),
|
| 607 |
+
):
|
| 608 |
+
self.flavor: str = flavor
|
| 609 |
+
self.target = target
|
| 610 |
+
self.os_name = os_name
|
| 611 |
+
self.base = base
|
| 612 |
+
self.logger = getLogger("aqt.archives")
|
| 613 |
+
super(SrcDocExamplesArchives, self).__init__(
|
| 614 |
+
os_name,
|
| 615 |
+
target,
|
| 616 |
+
version,
|
| 617 |
+
arch=self.flavor,
|
| 618 |
+
base=base,
|
| 619 |
+
subarchives=subarchives,
|
| 620 |
+
modules=modules,
|
| 621 |
+
all_extra=all_extra,
|
| 622 |
+
is_include_base_package=is_include_base_package,
|
| 623 |
+
timeout=timeout,
|
| 624 |
+
)
|
| 625 |
+
|
| 626 |
+
def _arch_ext(self) -> str:
|
| 627 |
+
return "_" + QtRepoProperty.sde_ext(self.version)
|
| 628 |
+
|
| 629 |
+
def _base_module_name(self) -> str:
|
| 630 |
+
"""
|
| 631 |
+
This is the name for the base Qt Src/Doc/Example module, whose PackageUpdate.Name
|
| 632 |
+
property would be 'qt.123.examples' or 'qt.qt1.123.examples' for Qt 1.2.3 examples.
|
| 633 |
+
"""
|
| 634 |
+
return self.flavor # src | doc | examples
|
| 635 |
+
|
| 636 |
+
def _module_name_suffix(self, module: str) -> str:
|
| 637 |
+
return f"{self.flavor}.{module}"
|
| 638 |
+
|
| 639 |
+
def get_target_config(self) -> TargetConfig:
|
| 640 |
+
"""Get target configuration.
|
| 641 |
+
|
| 642 |
+
:return tuple of three parameter, "src_doc_examples", target and arch
|
| 643 |
+
"""
|
| 644 |
+
return TargetConfig("src_doc_examples", self.target, self.arch, self.os_name)
|
| 645 |
+
|
| 646 |
+
def _get_archives(self):
|
| 647 |
+
name = f"qt{self.version.major}_{self._version_str()}{self._arch_ext()}"
|
| 648 |
+
self._get_archives_base(name, self._target_packages())
|
| 649 |
+
|
| 650 |
+
def help_msg(self, missing_modules: Optional[List[str]] = None) -> List[str]:
|
| 651 |
+
_missing_modules: List[str] = missing_modules or []
|
| 652 |
+
cmd_type = "example" if self.flavor == "examples" else self.flavor
|
| 653 |
+
base_cmd = f"aqt list-{cmd_type} {self.os_name} {self.version}"
|
| 654 |
+
mods = f"Please use '{base_cmd} --modules' to show modules available."
|
| 655 |
+
has_non_base_pkg: bool = len(list(_missing_modules)) > 1
|
| 656 |
+
messages = []
|
| 657 |
+
if has_non_base_pkg:
|
| 658 |
+
messages.append(mods)
|
| 659 |
+
return messages
|
| 660 |
+
|
| 661 |
+
|
| 662 |
+
class ToolArchives(QtArchives):
|
| 663 |
+
"""Hold tool archive package list
|
| 664 |
+
when installing mingw tool, argument would be
|
| 665 |
+
ToolArchive(windows, desktop, 4.9.1-3, mingw)
|
| 666 |
+
when installing ifw tool, argument would be
|
| 667 |
+
ToolArchive(linux, desktop, 3.1.1, ifw)
|
| 668 |
+
"""
|
| 669 |
+
|
| 670 |
+
def __init__(
|
| 671 |
+
self,
|
| 672 |
+
os_name: str,
|
| 673 |
+
target: str,
|
| 674 |
+
tool_name: str,
|
| 675 |
+
base: str,
|
| 676 |
+
version_str: Optional[str] = None,
|
| 677 |
+
arch: str = "",
|
| 678 |
+
timeout: Tuple[float, float] = (5, 5),
|
| 679 |
+
):
|
| 680 |
+
self.tool_name = tool_name
|
| 681 |
+
self.os_name = os_name
|
| 682 |
+
self.logger = getLogger("aqt.archives")
|
| 683 |
+
self.tool_version_str: Optional[str] = version_str
|
| 684 |
+
super(ToolArchives, self).__init__(
|
| 685 |
+
os_name=os_name,
|
| 686 |
+
target=target,
|
| 687 |
+
version_str="0.0.1", # dummy value
|
| 688 |
+
arch=arch,
|
| 689 |
+
base=base,
|
| 690 |
+
timeout=timeout,
|
| 691 |
+
)
|
| 692 |
+
|
| 693 |
+
def __str__(self):
|
| 694 |
+
return f"ToolArchives(tool_name={self.tool_name}, version={self.version}, arch={self.arch})"
|
| 695 |
+
|
| 696 |
+
def handle_missing_updates_xml(self, e: ArchiveDownloadError):
|
| 697 |
+
msg = f"Failed to locate XML data for the tool '{self.tool_name}'."
|
| 698 |
+
help_msg = f"Please use 'aqt list-tool {self.os_name} {self.target}' to show tools available."
|
| 699 |
+
raise ArchiveListError(msg, suggested_action=[help_msg]) from e
|
| 700 |
+
|
| 701 |
+
def _get_archives(self):
|
| 702 |
+
self._get_archives_base(self.tool_name, None)
|
| 703 |
+
|
| 704 |
+
def _parse_update_xml(self, os_target_folder: str, update_xml_text: str, *ignored: Any) -> None:
|
| 705 |
+
update_xml = Updates.fromstring(self.base, update_xml_text)
|
| 706 |
+
self._append_tool_update(os_target_folder, update_xml, self.arch, self.tool_version_str)
|
| 707 |
+
|
| 708 |
+
def help_msg(self, *args) -> List[str]:
|
| 709 |
+
return [f"Please use 'aqt list-tool {self.os_name} {self.target} {self.tool_name}' to show tool variants available."]
|
| 710 |
+
|
| 711 |
+
def get_target_config(self) -> TargetConfig:
|
| 712 |
+
"""Get target configuration.
|
| 713 |
+
|
| 714 |
+
:return tuple of three parameter, "Tools", target and arch
|
| 715 |
+
"""
|
| 716 |
+
return TargetConfig("Tools", self.target, self.arch, self.os_name)
|
python/py313/Lib/site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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2025 Alexandre Poumaroux, Hiroshi Miura
|
| 4 |
+
#
|
| 5 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 6 |
+
# this software and associated documentation files (the "Software"), to deal in
|
| 7 |
+
# the Software without restriction, including without limitation the rights to
|
| 8 |
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 9 |
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
| 10 |
+
# subject to the following conditions:
|
| 11 |
+
#
|
| 12 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
# copies or substantial portions of the Software.
|
| 14 |
+
#
|
| 15 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 17 |
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 18 |
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 19 |
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 20 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
+
import json
|
| 22 |
+
import os
|
| 23 |
+
from dataclasses import dataclass
|
| 24 |
+
from logging import Logger, getLogger
|
| 25 |
+
from pathlib import Path
|
| 26 |
+
from typing import List, Optional
|
| 27 |
+
|
| 28 |
+
from defusedxml import ElementTree
|
| 29 |
+
|
| 30 |
+
from aqt.exceptions import DiskAccessNotPermitted
|
| 31 |
+
from aqt.helper import (
|
| 32 |
+
Settings,
|
| 33 |
+
download_installer,
|
| 34 |
+
extract_auth,
|
| 35 |
+
get_os_name,
|
| 36 |
+
get_qt_account_path,
|
| 37 |
+
get_qt_installer_name,
|
| 38 |
+
prepare_installer,
|
| 39 |
+
safely_run,
|
| 40 |
+
safely_run_save_output,
|
| 41 |
+
)
|
| 42 |
+
from aqt.metadata import Version
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@dataclass
|
| 46 |
+
class QtPackageInfo:
|
| 47 |
+
name: str
|
| 48 |
+
displayname: str
|
| 49 |
+
version: str
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class QtPackageManager:
|
| 53 |
+
def __init__(
|
| 54 |
+
self, arch: str, version: Version, target: str, username: Optional[str] = None, password: Optional[str] = None
|
| 55 |
+
):
|
| 56 |
+
self.arch = arch
|
| 57 |
+
self.version = version
|
| 58 |
+
self.target = target
|
| 59 |
+
self.cache_dir = self._get_cache_dir()
|
| 60 |
+
self.packages: List[QtPackageInfo] = []
|
| 61 |
+
self.username = username
|
| 62 |
+
self.password = password
|
| 63 |
+
self.logger = getLogger("aqt.commercial")
|
| 64 |
+
|
| 65 |
+
def _get_cache_dir(self) -> Path:
|
| 66 |
+
"""Create and return cache directory path."""
|
| 67 |
+
base_cache = Settings.qt_installer_cache_path
|
| 68 |
+
cache_path = os.path.join(base_cache, self.target, self.arch, str(self.version))
|
| 69 |
+
Path(cache_path).mkdir(parents=True, exist_ok=True)
|
| 70 |
+
return Path(cache_path)
|
| 71 |
+
|
| 72 |
+
def _get_cache_file(self) -> Path:
|
| 73 |
+
"""Get the cache file path."""
|
| 74 |
+
return self.cache_dir / "packages.json"
|
| 75 |
+
|
| 76 |
+
def _save_to_cache(self) -> None:
|
| 77 |
+
"""Save packages information to cache."""
|
| 78 |
+
cache_data = [{"name": pkg.name, "displayname": pkg.displayname, "version": pkg.version} for pkg in self.packages]
|
| 79 |
+
|
| 80 |
+
with open(self._get_cache_file(), "w") as f:
|
| 81 |
+
json.dump(cache_data, f, indent=2)
|
| 82 |
+
|
| 83 |
+
def _load_from_cache(self) -> bool:
|
| 84 |
+
"""Load packages information from cache if available."""
|
| 85 |
+
cache_file = self._get_cache_file()
|
| 86 |
+
if not cache_file.exists():
|
| 87 |
+
return False
|
| 88 |
+
|
| 89 |
+
try:
|
| 90 |
+
with open(cache_file, "r") as f:
|
| 91 |
+
cache_data = json.load(f)
|
| 92 |
+
self.packages = [
|
| 93 |
+
QtPackageInfo(name=pkg["name"], displayname=pkg["displayname"], version=pkg["version"])
|
| 94 |
+
for pkg in cache_data
|
| 95 |
+
]
|
| 96 |
+
return True
|
| 97 |
+
except (json.JSONDecodeError, KeyError):
|
| 98 |
+
return False
|
| 99 |
+
|
| 100 |
+
def _parse_packages_xml(self, xml_content: str) -> None:
|
| 101 |
+
"""Parse packages XML content and extract package information using defusedxml."""
|
| 102 |
+
try:
|
| 103 |
+
# Use defusedxml.ElementTree to safely parse the XML content
|
| 104 |
+
root = ElementTree.fromstring(xml_content)
|
| 105 |
+
self.packages = []
|
| 106 |
+
|
| 107 |
+
# Find all package elements using XPath-like expression
|
| 108 |
+
# Note: defusedxml supports a subset of XPath
|
| 109 |
+
for pkg in root.findall(".//package"):
|
| 110 |
+
name = pkg.get("name", "")
|
| 111 |
+
displayname = pkg.get("displayname", "")
|
| 112 |
+
version = pkg.get("version", "")
|
| 113 |
+
|
| 114 |
+
if all([name, displayname, version]): # Ensure all required attributes are present
|
| 115 |
+
self.packages.append(QtPackageInfo(name=name, displayname=displayname, version=version))
|
| 116 |
+
except ElementTree.ParseError as e:
|
| 117 |
+
raise RuntimeError(f"Failed to parse package XML: {e}")
|
| 118 |
+
|
| 119 |
+
def _get_version_string(self) -> str:
|
| 120 |
+
"""Get formatted version string for package names."""
|
| 121 |
+
return f"{self.version.major}{self.version.minor}{self.version.patch}"
|
| 122 |
+
|
| 123 |
+
def _get_base_package_name(self) -> str:
|
| 124 |
+
"""Get the base package name for the current configuration."""
|
| 125 |
+
version_str = self._get_version_string()
|
| 126 |
+
return f"qt.qt{self.version.major}.{version_str}"
|
| 127 |
+
|
| 128 |
+
def gather_packages(self, installer_path: str) -> None:
|
| 129 |
+
"""Gather package information using qt installer search command."""
|
| 130 |
+
if self._load_from_cache():
|
| 131 |
+
return
|
| 132 |
+
|
| 133 |
+
version_str = self._get_version_string()
|
| 134 |
+
base_package = f"qt.qt{self.version.major}.{version_str}"
|
| 135 |
+
|
| 136 |
+
cmd = [installer_path, "--accept-licenses", "--accept-obligations", "--confirm-command", "--default-answer"]
|
| 137 |
+
|
| 138 |
+
if self.username and self.password:
|
| 139 |
+
cmd.extend(["--email", self.username, "--pw", self.password])
|
| 140 |
+
|
| 141 |
+
cmd.append("search")
|
| 142 |
+
cmd.append(base_package)
|
| 143 |
+
|
| 144 |
+
try:
|
| 145 |
+
self.logger.info(f"Running: {cmd}")
|
| 146 |
+
output = safely_run_save_output(cmd, Settings.qt_installer_timeout)
|
| 147 |
+
|
| 148 |
+
# Handle both string and CompletedProcess outputs
|
| 149 |
+
output_text = output.stdout if hasattr(output, "stdout") else str(output)
|
| 150 |
+
|
| 151 |
+
# Extract the XML portion from the output
|
| 152 |
+
xml_start = output_text.find("<availablepackages>")
|
| 153 |
+
xml_end = output_text.find("</availablepackages>") + len("</availablepackages>")
|
| 154 |
+
|
| 155 |
+
if xml_start != -1 and xml_end != -1:
|
| 156 |
+
xml_content = output_text[xml_start:xml_end]
|
| 157 |
+
self._parse_packages_xml(xml_content)
|
| 158 |
+
self._save_to_cache()
|
| 159 |
+
else:
|
| 160 |
+
# Log the actual output for debugging
|
| 161 |
+
self.logger.debug(f"Installer output: {output_text}")
|
| 162 |
+
raise RuntimeError("Failed to find package information in installer output")
|
| 163 |
+
|
| 164 |
+
except Exception as e:
|
| 165 |
+
raise RuntimeError(f"Failed to get package information: {str(e)}")
|
| 166 |
+
|
| 167 |
+
def get_install_command(self, modules: Optional[List[str]], temp_dir: str) -> List[str]:
|
| 168 |
+
"""Generate installation command based on requested modules."""
|
| 169 |
+
package_name = f"{self._get_base_package_name()}.{self.arch}"
|
| 170 |
+
cmd = ["install", package_name]
|
| 171 |
+
|
| 172 |
+
# No modules requested, return base package only
|
| 173 |
+
if not modules:
|
| 174 |
+
return cmd
|
| 175 |
+
|
| 176 |
+
# Ensure package cache exists
|
| 177 |
+
self.gather_packages(temp_dir)
|
| 178 |
+
|
| 179 |
+
if "all" in modules:
|
| 180 |
+
# Find all addon and direct module packages
|
| 181 |
+
for pkg in self.packages:
|
| 182 |
+
if f"{self._get_base_package_name()}.addons." in pkg.name or pkg.name.startswith(
|
| 183 |
+
f"{self._get_base_package_name()}."
|
| 184 |
+
):
|
| 185 |
+
module_name = pkg.name.split(".")[-1]
|
| 186 |
+
if module_name != self.arch: # Skip the base package
|
| 187 |
+
cmd.append(pkg.name)
|
| 188 |
+
else:
|
| 189 |
+
# Add specifically requested modules that exist in either format
|
| 190 |
+
for module in modules:
|
| 191 |
+
addon_name = f"{self._get_base_package_name()}.addons.{module}"
|
| 192 |
+
direct_name = f"{self._get_base_package_name()}.{module}"
|
| 193 |
+
|
| 194 |
+
# Check if either package name exists
|
| 195 |
+
matching_pkg = next(
|
| 196 |
+
(pkg.name for pkg in self.packages if pkg.name == addon_name or pkg.name == direct_name), None
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
if matching_pkg:
|
| 200 |
+
cmd.append(matching_pkg)
|
| 201 |
+
|
| 202 |
+
return cmd
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
class CommercialInstaller:
|
| 206 |
+
"""Qt Commercial installer that handles module installation and package management."""
|
| 207 |
+
|
| 208 |
+
def __init__(
|
| 209 |
+
self,
|
| 210 |
+
target: str,
|
| 211 |
+
arch: Optional[str],
|
| 212 |
+
version: Optional[str],
|
| 213 |
+
username: Optional[str] = None,
|
| 214 |
+
password: Optional[str] = None,
|
| 215 |
+
output_dir: Optional[str] = None,
|
| 216 |
+
logger: Optional[Logger] = None,
|
| 217 |
+
base_url: str = "https://download.qt.io",
|
| 218 |
+
override: Optional[List[str]] = None,
|
| 219 |
+
modules: Optional[List[str]] = None,
|
| 220 |
+
no_unattended: bool = False,
|
| 221 |
+
dry_run: bool = False,
|
| 222 |
+
):
|
| 223 |
+
self.override = override
|
| 224 |
+
self.target = target
|
| 225 |
+
self.arch = arch or ""
|
| 226 |
+
self.version = Version(version) if version else Version("0.0.0")
|
| 227 |
+
self.output_dir = output_dir
|
| 228 |
+
self.logger = logger or getLogger(__name__)
|
| 229 |
+
self.base_url = base_url
|
| 230 |
+
self.modules = modules
|
| 231 |
+
self.no_unattended = no_unattended
|
| 232 |
+
self.dry_run = dry_run
|
| 233 |
+
|
| 234 |
+
# Extract credentials from override if present
|
| 235 |
+
if override:
|
| 236 |
+
extracted_username, extracted_password, self.override = extract_auth(override)
|
| 237 |
+
self.username = extracted_username or username
|
| 238 |
+
self.password = extracted_password or password
|
| 239 |
+
else:
|
| 240 |
+
self.username = username
|
| 241 |
+
self.password = password
|
| 242 |
+
|
| 243 |
+
# Set OS-specific properties
|
| 244 |
+
self.os_name = get_os_name()
|
| 245 |
+
self._installer_filename = get_qt_installer_name()
|
| 246 |
+
self.qt_account = get_qt_account_path()
|
| 247 |
+
self.package_manager = QtPackageManager(self.arch, self.version, self.target, self.username, self.password)
|
| 248 |
+
|
| 249 |
+
@staticmethod
|
| 250 |
+
def get_auto_answers() -> str:
|
| 251 |
+
"""Get auto-answer options from settings."""
|
| 252 |
+
settings_map = {
|
| 253 |
+
"OperationDoesNotExistError": Settings.qt_installer_operationdoesnotexisterror,
|
| 254 |
+
"OverwriteTargetDirectory": Settings.qt_installer_overwritetargetdirectory,
|
| 255 |
+
"stopProcessesForUpdates": Settings.qt_installer_stopprocessesforupdates,
|
| 256 |
+
"installationErrorWithCancel": Settings.qt_installer_installationerrorwithcancel,
|
| 257 |
+
"installationErrorWithIgnore": Settings.qt_installer_installationerrorwithignore,
|
| 258 |
+
"AssociateCommonFiletypes": Settings.qt_installer_associatecommonfiletypes,
|
| 259 |
+
"telemetry-question": Settings.qt_installer_telemetry,
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
answers = []
|
| 263 |
+
for key, value in settings_map.items():
|
| 264 |
+
answers.append(f"{key}={value}")
|
| 265 |
+
|
| 266 |
+
return ",".join(answers)
|
| 267 |
+
|
| 268 |
+
@staticmethod
|
| 269 |
+
def build_command(
|
| 270 |
+
installer_path: str,
|
| 271 |
+
override: Optional[List[str]] = None,
|
| 272 |
+
username: Optional[str] = None,
|
| 273 |
+
password: Optional[str] = None,
|
| 274 |
+
output_dir: Optional[str] = None,
|
| 275 |
+
no_unattended: bool = False,
|
| 276 |
+
) -> List[str]:
|
| 277 |
+
"""Build the installation command with proper safeguards."""
|
| 278 |
+
cmd = [installer_path]
|
| 279 |
+
|
| 280 |
+
# Add unattended flags unless explicitly disabled
|
| 281 |
+
if not no_unattended:
|
| 282 |
+
cmd.extend(["--accept-licenses", "--accept-obligations", "--confirm-command"])
|
| 283 |
+
|
| 284 |
+
# Add authentication if provided
|
| 285 |
+
if username and password:
|
| 286 |
+
cmd.extend(["--email", username, "--pw", password])
|
| 287 |
+
|
| 288 |
+
if override:
|
| 289 |
+
# When using override, still include unattended flags unless disabled
|
| 290 |
+
cmd.extend(override)
|
| 291 |
+
return cmd
|
| 292 |
+
|
| 293 |
+
# Add output directory if specified
|
| 294 |
+
if output_dir:
|
| 295 |
+
cmd.extend(["--root", str(Path(output_dir).resolve())])
|
| 296 |
+
|
| 297 |
+
# Add auto-answer options from settings
|
| 298 |
+
auto_answers = CommercialInstaller.get_auto_answers()
|
| 299 |
+
if auto_answers:
|
| 300 |
+
cmd.extend(["--auto-answer", auto_answers])
|
| 301 |
+
|
| 302 |
+
return cmd
|
| 303 |
+
|
| 304 |
+
def install(self) -> None:
|
| 305 |
+
"""Run the Qt installation process."""
|
| 306 |
+
if (
|
| 307 |
+
not self.qt_account.exists()
|
| 308 |
+
and (not self.username or not self.password)
|
| 309 |
+
and not os.environ.get("QT_INSTALLER_JWT_TOKEN")
|
| 310 |
+
):
|
| 311 |
+
raise RuntimeError(
|
| 312 |
+
"No Qt account credentials found. Provide username and password or ensure qtaccount.ini exists."
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
+
# Setup cache directory
|
| 316 |
+
cache_path = Path(Settings.qt_installer_cache_path)
|
| 317 |
+
cache_path.mkdir(parents=True, exist_ok=True)
|
| 318 |
+
|
| 319 |
+
# Setup output directory and validate access
|
| 320 |
+
output_dir = Path(self.output_dir) if self.output_dir else Path(os.getcwd()) / "Qt"
|
| 321 |
+
version_dir = output_dir / str(self.version)
|
| 322 |
+
qt_base_dir = output_dir
|
| 323 |
+
|
| 324 |
+
if qt_base_dir.exists():
|
| 325 |
+
if Settings.qt_installer_overwritetargetdirectory.lower() == "yes":
|
| 326 |
+
self.logger.warning(f"Target directory {qt_base_dir} exists - removing as overwrite is enabled")
|
| 327 |
+
try:
|
| 328 |
+
import shutil
|
| 329 |
+
|
| 330 |
+
if version_dir.exists():
|
| 331 |
+
shutil.rmtree(version_dir)
|
| 332 |
+
except (OSError, PermissionError) as e:
|
| 333 |
+
raise DiskAccessNotPermitted(f"Failed to remove existing version directory {version_dir}: {str(e)}")
|
| 334 |
+
|
| 335 |
+
# Setup temp directory
|
| 336 |
+
temp_dir = Settings.qt_installer_temp_path
|
| 337 |
+
temp_path = Path(temp_dir)
|
| 338 |
+
if not temp_path.exists():
|
| 339 |
+
temp_path.mkdir(parents=True, exist_ok=True)
|
| 340 |
+
else:
|
| 341 |
+
Settings.qt_installer_cleanup()
|
| 342 |
+
installer_path = temp_path / self._installer_filename
|
| 343 |
+
|
| 344 |
+
self.logger.info(f"Downloading Qt installer to {installer_path}")
|
| 345 |
+
timeout = (Settings.connection_timeout, Settings.response_timeout)
|
| 346 |
+
download_installer(self.base_url, self._installer_filename, installer_path, timeout)
|
| 347 |
+
installer_path = prepare_installer(installer_path, self.os_name)
|
| 348 |
+
|
| 349 |
+
try:
|
| 350 |
+
if self.override:
|
| 351 |
+
if not self.username or not self.password:
|
| 352 |
+
self.username, self.password, self.override = extract_auth(self.override)
|
| 353 |
+
|
| 354 |
+
cmd: list[str] = self.build_command(
|
| 355 |
+
str(installer_path),
|
| 356 |
+
override=self.override,
|
| 357 |
+
no_unattended=self.no_unattended,
|
| 358 |
+
username=self.username,
|
| 359 |
+
password=self.password,
|
| 360 |
+
)
|
| 361 |
+
else:
|
| 362 |
+
# Initialize package manager and gather packages
|
| 363 |
+
self.package_manager.gather_packages(str(installer_path))
|
| 364 |
+
|
| 365 |
+
base_cmd = self.build_command(
|
| 366 |
+
str(installer_path.absolute()),
|
| 367 |
+
username=self.username,
|
| 368 |
+
password=self.password,
|
| 369 |
+
output_dir=str(qt_base_dir.absolute()),
|
| 370 |
+
no_unattended=self.no_unattended,
|
| 371 |
+
)
|
| 372 |
+
|
| 373 |
+
install_cmd = self.package_manager.get_install_command(self.modules, temp_dir)
|
| 374 |
+
cmd = [*base_cmd, *install_cmd]
|
| 375 |
+
|
| 376 |
+
log_cmd = cmd.copy()
|
| 377 |
+
for i in range(len(log_cmd) - 1):
|
| 378 |
+
if log_cmd[i] == "--email" or log_cmd[i] == "--pw":
|
| 379 |
+
log_cmd[i + 1] = "***"
|
| 380 |
+
|
| 381 |
+
if not self.dry_run:
|
| 382 |
+
self.logger.info(f"Running: {log_cmd}")
|
| 383 |
+
safely_run(cmd, Settings.qt_installer_timeout)
|
| 384 |
+
else:
|
| 385 |
+
self.logger.info(f"Would run: {log_cmd}")
|
| 386 |
+
|
| 387 |
+
except Exception as e:
|
| 388 |
+
self.logger.error(f"Installation failed: {str(e)}")
|
| 389 |
+
raise
|
| 390 |
+
finally:
|
| 391 |
+
self.logger.info("Qt installation completed successfully")
|
| 392 |
+
|
| 393 |
+
def _get_package_name(self) -> str:
|
| 394 |
+
qt_version = f"{self.version.major}{self.version.minor}{self.version.patch}"
|
| 395 |
+
return f"qt.qt{self.version.major}.{qt_version}.{self.arch}"
|
python/py313/Lib/site-packages/aqt/exceptions.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2019-2021 Hiroshi Miura <miurahr@linux.com>
|
| 4 |
+
#
|
| 5 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 6 |
+
# this software and associated documentation files (the "Software"), to deal in
|
| 7 |
+
# the Software without restriction, including without limitation the rights to
|
| 8 |
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 9 |
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
| 10 |
+
# subject to the following conditions:
|
| 11 |
+
#
|
| 12 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
# copies or substantial portions of the Software.
|
| 14 |
+
#
|
| 15 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 17 |
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 18 |
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 19 |
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 20 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
+
from typing import Any, List, Optional
|
| 22 |
+
|
| 23 |
+
DOCS_CONFIG = "https://aqtinstall.readthedocs.io/en/stable/configuration.html#configuration"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class AqtException(Exception):
|
| 27 |
+
def __init__(
|
| 28 |
+
self, *args, suggested_action: Optional[List[str]] = None, should_show_help: bool = False, **kwargs: Any
|
| 29 |
+
) -> None:
|
| 30 |
+
self.suggested_action: List[str] = suggested_action or []
|
| 31 |
+
self.should_show_help: bool = should_show_help or False
|
| 32 |
+
super(AqtException, self).__init__(*args, **kwargs)
|
| 33 |
+
|
| 34 |
+
def __format__(self, format_spec: str) -> str:
|
| 35 |
+
base_msg = "{}".format(super(AqtException, self).__format__(format_spec))
|
| 36 |
+
if not self.suggested_action:
|
| 37 |
+
return base_msg
|
| 38 |
+
return f"{base_msg}\n{self._format_suggested_follow_up()}"
|
| 39 |
+
|
| 40 |
+
def _format_suggested_follow_up(self) -> str:
|
| 41 |
+
return ("=" * 30 + "Suggested follow-up:" + "=" * 30 + "\n") + "\n".join(
|
| 42 |
+
["* " + suggestion for suggestion in self.suggested_action]
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
def append_suggested_follow_up(self, suggestions: List[str]) -> None:
|
| 46 |
+
self.suggested_action.extend(suggestions)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class ArchiveDownloadError(AqtException):
|
| 50 |
+
pass
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class ArchiveChecksumError(ArchiveDownloadError):
|
| 54 |
+
pass
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class ChecksumDownloadFailure(ArchiveDownloadError):
|
| 58 |
+
def __init__(self, *args, suggested_action: Optional[List[str]] = None, **kwargs) -> None:
|
| 59 |
+
if suggested_action is None:
|
| 60 |
+
suggested_action = []
|
| 61 |
+
suggested_action.extend(
|
| 62 |
+
[
|
| 63 |
+
"Check your internet connection",
|
| 64 |
+
"Consider modifying `requests.max_retries_to_retrieve_hash` in settings.ini",
|
| 65 |
+
f"Consider modifying `mirrors.trusted_mirrors` in settings.ini (see {DOCS_CONFIG})",
|
| 66 |
+
]
|
| 67 |
+
)
|
| 68 |
+
super(ChecksumDownloadFailure, self).__init__(
|
| 69 |
+
*args, suggested_action=suggested_action, should_show_help=True, **kwargs
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class ArchiveConnectionError(AqtException):
|
| 74 |
+
pass
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class ArchiveListError(AqtException):
|
| 78 |
+
pass
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class NoPackageFound(AqtException):
|
| 82 |
+
pass
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class EmptyMetadata(AqtException):
|
| 86 |
+
pass
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class CliInputError(AqtException):
|
| 90 |
+
pass
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class CliKeyboardInterrupt(AqtException):
|
| 94 |
+
pass
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class ArchiveExtractionError(AqtException):
|
| 98 |
+
pass
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
class UpdaterError(AqtException):
|
| 102 |
+
pass
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class OutOfMemory(AqtException):
|
| 106 |
+
pass
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class OutOfDiskSpace(AqtException):
|
| 110 |
+
pass
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class DiskAccessNotPermitted(AqtException):
|
| 114 |
+
pass
|
python/py313/Lib/site-packages/aqt/helper.py
ADDED
|
@@ -0,0 +1,786 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2019-2021 Hiroshi Miura <miurahr@linux.com>
|
| 4 |
+
#
|
| 5 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 6 |
+
# this software and associated documentation files (the "Software"), to deal in
|
| 7 |
+
# the Software without restriction, including without limitation the rights to
|
| 8 |
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 9 |
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
| 10 |
+
# subject to the following conditions:
|
| 11 |
+
#
|
| 12 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
# copies or substantial portions of the Software.
|
| 14 |
+
#
|
| 15 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 17 |
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 18 |
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 19 |
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 20 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
+
import binascii
|
| 22 |
+
import hashlib
|
| 23 |
+
import logging.config
|
| 24 |
+
import os
|
| 25 |
+
import platform
|
| 26 |
+
import posixpath
|
| 27 |
+
import secrets
|
| 28 |
+
import shutil
|
| 29 |
+
import subprocess
|
| 30 |
+
import sys
|
| 31 |
+
import uuid
|
| 32 |
+
from configparser import ConfigParser
|
| 33 |
+
from logging import Handler, getLogger
|
| 34 |
+
from logging.handlers import QueueListener
|
| 35 |
+
from pathlib import Path
|
| 36 |
+
from threading import Lock
|
| 37 |
+
from typing import Any, Callable, Dict, Generator, List, Optional, TextIO, Tuple, Union
|
| 38 |
+
from urllib.parse import urlparse
|
| 39 |
+
from xml.etree.ElementTree import Element
|
| 40 |
+
|
| 41 |
+
import humanize
|
| 42 |
+
import requests
|
| 43 |
+
import requests.adapters
|
| 44 |
+
from bs4 import BeautifulSoup
|
| 45 |
+
from defusedxml import ElementTree
|
| 46 |
+
|
| 47 |
+
from aqt.exceptions import (
|
| 48 |
+
ArchiveChecksumError,
|
| 49 |
+
ArchiveConnectionError,
|
| 50 |
+
ArchiveDownloadError,
|
| 51 |
+
ArchiveListError,
|
| 52 |
+
ChecksumDownloadFailure,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def get_os_name() -> str:
|
| 57 |
+
system = sys.platform.lower()
|
| 58 |
+
if system == "darwin":
|
| 59 |
+
return "mac"
|
| 60 |
+
if system == "linux":
|
| 61 |
+
return "linux"
|
| 62 |
+
if system in ("windows", "win32"): # Accept both windows and win32
|
| 63 |
+
return "windows"
|
| 64 |
+
raise ValueError(f"Unsupported operating system: {system}")
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def get_os_arch() -> str:
|
| 68 |
+
"""
|
| 69 |
+
Returns a simplified os-arch string for the current system
|
| 70 |
+
"""
|
| 71 |
+
os_name = get_os_name()
|
| 72 |
+
|
| 73 |
+
machine = platform.machine().lower()
|
| 74 |
+
if machine in ["x86_64", "amd64"]:
|
| 75 |
+
arch = "x64"
|
| 76 |
+
elif machine in ["arm64", "aarch64"]:
|
| 77 |
+
arch = "arm64"
|
| 78 |
+
else:
|
| 79 |
+
arch = "x64" # Default to x64 for unknown architectures
|
| 80 |
+
|
| 81 |
+
return f"{os_name}-{arch}"
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def get_qt_local_folder_path() -> Path:
|
| 85 |
+
os_name = get_os_name()
|
| 86 |
+
if os_name == "windows":
|
| 87 |
+
appdata = os.environ.get("APPDATA", str(Path.home() / "AppData" / "Roaming"))
|
| 88 |
+
return Path(appdata) / "Qt"
|
| 89 |
+
if os_name == "mac":
|
| 90 |
+
return Path.home() / "Library" / "Application Support" / "Qt"
|
| 91 |
+
return Path.home() / ".local" / "share" / "Qt"
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def get_qt_account_path() -> Path:
|
| 95 |
+
return get_qt_local_folder_path() / "qtaccount.ini"
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def get_qt_installers() -> dict[str, str]:
|
| 99 |
+
"""
|
| 100 |
+
Extracts Qt installer information from {Settings.baseurl}/official_releases/online_installers/
|
| 101 |
+
Maps OS types and architectures to their respective installer filenames
|
| 102 |
+
Returns:
|
| 103 |
+
dict: Mapping of OS identifiers to installer filenames with appropriate aliases
|
| 104 |
+
"""
|
| 105 |
+
url = f"{Settings.baseurl}/official_releases/online_installers/"
|
| 106 |
+
|
| 107 |
+
try:
|
| 108 |
+
response = requests.get(url, timeout=Settings.response_timeout)
|
| 109 |
+
response.raise_for_status()
|
| 110 |
+
|
| 111 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
| 112 |
+
|
| 113 |
+
installers = {}
|
| 114 |
+
|
| 115 |
+
os_types = ["windows", "linux", "mac"]
|
| 116 |
+
|
| 117 |
+
for link in soup.find_all("a"):
|
| 118 |
+
filename = link.text.strip()
|
| 119 |
+
|
| 120 |
+
if "Parent Directory" in filename or not any(ext in filename.lower() for ext in [".exe", ".dmg", ".run"]):
|
| 121 |
+
continue
|
| 122 |
+
|
| 123 |
+
for os_type in os_types:
|
| 124 |
+
if os_type.lower() in filename.lower():
|
| 125 |
+
# Found an OS match, now look for architecture
|
| 126 |
+
if "arm64" in filename.lower():
|
| 127 |
+
installers[f"{os_type}-arm64"] = filename
|
| 128 |
+
elif "x64" in filename.lower():
|
| 129 |
+
installers[f"{os_type}-x64"] = filename
|
| 130 |
+
# Also add generic OS entry for x64 variants of Windows and Linux
|
| 131 |
+
if os_type in ["windows", "linux"]:
|
| 132 |
+
installers[os_type] = filename
|
| 133 |
+
else:
|
| 134 |
+
# Handle case with no explicit architecture
|
| 135 |
+
# Most likely for macOS which might just say "mac" without arch
|
| 136 |
+
installers[os_type] = filename
|
| 137 |
+
|
| 138 |
+
return installers
|
| 139 |
+
|
| 140 |
+
except requests.exceptions.RequestException as e:
|
| 141 |
+
print(f"Error fetching installer data: {e}")
|
| 142 |
+
return {}
|
| 143 |
+
except Exception as e:
|
| 144 |
+
print(f"Unexpected error processing installer data: {e}")
|
| 145 |
+
return {}
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def get_qt_installer_name() -> str:
|
| 149 |
+
installer_dict = get_qt_installers()
|
| 150 |
+
return installer_dict[get_os_arch()]
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def get_qt_installer_path() -> Path:
|
| 154 |
+
return get_qt_local_folder_path() / get_qt_installer_name()
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def get_default_local_cache_path() -> Path:
|
| 158 |
+
os_name = get_os_name()
|
| 159 |
+
if os_name == "windows":
|
| 160 |
+
appdata = os.environ.get("APPDATA", str(Path.home() / "AppData" / "Roaming"))
|
| 161 |
+
return Path(appdata) / "aqt" / "cache"
|
| 162 |
+
if os_name == "mac":
|
| 163 |
+
return Path.home() / "Library" / "Application Support" / "aqt" / "cache"
|
| 164 |
+
return Path.home() / ".local" / "share" / "aqt" / "cache"
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def get_default_local_temp_path() -> Path:
|
| 168 |
+
os_name = get_os_name()
|
| 169 |
+
if os_name == "windows":
|
| 170 |
+
appdata = os.environ.get("APPDATA", str(Path.home() / "AppData" / "Roaming"))
|
| 171 |
+
return Path(appdata) / "aqt" / "tmp"
|
| 172 |
+
if os_name == "mac":
|
| 173 |
+
return Path.home() / "Library" / "Application Support" / "aqt" / "tmp"
|
| 174 |
+
return Path.home() / ".local" / "share" / "aqt" / "tmp"
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def _get_meta(url: str) -> requests.Response:
|
| 178 |
+
return requests.get(url + ".meta4")
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _check_content_type(ct: str) -> bool:
|
| 182 |
+
candidate = ["application/metalink4+xml", "text/plain"]
|
| 183 |
+
return any(ct.startswith(t) for t in candidate)
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def getUrl(url: str, timeout: Tuple[float, float], expected_hash: Optional[bytes] = None) -> str:
|
| 187 |
+
"""
|
| 188 |
+
Gets a file from `url` via HTTP GET.
|
| 189 |
+
|
| 190 |
+
No caller should call this function without providing an expected_hash, unless
|
| 191 |
+
the caller is `get_hash`, which cannot know what the expected hash should be.
|
| 192 |
+
"""
|
| 193 |
+
logger = getLogger("aqt.helper")
|
| 194 |
+
with requests.sessions.Session() as session:
|
| 195 |
+
retries = requests.adapters.Retry(
|
| 196 |
+
total=Settings.max_retries_on_connection_error, backoff_factor=Settings.backoff_factor
|
| 197 |
+
)
|
| 198 |
+
adapter = requests.adapters.HTTPAdapter(max_retries=retries)
|
| 199 |
+
session.mount("http://", adapter)
|
| 200 |
+
session.mount("https://", adapter)
|
| 201 |
+
try:
|
| 202 |
+
r = session.get(url, allow_redirects=False, timeout=timeout)
|
| 203 |
+
num_redirects = 0
|
| 204 |
+
while 300 < r.status_code < 309 and num_redirects < 10:
|
| 205 |
+
num_redirects += 1
|
| 206 |
+
logger.debug("Asked to redirect({}) to: {}".format(r.status_code, r.headers["Location"]))
|
| 207 |
+
newurl = altlink(r.url, r.headers["Location"])
|
| 208 |
+
logger.info("Redirected: {}".format(urlparse(newurl).hostname))
|
| 209 |
+
r = session.get(newurl, stream=True, timeout=timeout)
|
| 210 |
+
except (
|
| 211 |
+
ConnectionResetError,
|
| 212 |
+
requests.exceptions.ConnectionError,
|
| 213 |
+
requests.exceptions.Timeout,
|
| 214 |
+
) as e:
|
| 215 |
+
raise ArchiveConnectionError(f"Failure to connect to {url}: {type(e).__name__}") from e
|
| 216 |
+
else:
|
| 217 |
+
if r.status_code != 200:
|
| 218 |
+
msg = f"Failed to retrieve file at {url}\nServer response code: {r.status_code}, reason: {r.reason}"
|
| 219 |
+
raise ArchiveDownloadError(msg)
|
| 220 |
+
result: str = r.text
|
| 221 |
+
filename = url.split("/")[-1]
|
| 222 |
+
_kwargs = {"usedforsecurity": False} if sys.version_info >= (3, 9) else {}
|
| 223 |
+
if Settings.hash_algorithm == "sha256":
|
| 224 |
+
actual_hash = hashlib.sha256(bytes(result, "utf-8"), **_kwargs).digest()
|
| 225 |
+
elif Settings.hash_algorithm == "sha1":
|
| 226 |
+
actual_hash = hashlib.sha1(bytes(result, "utf-8"), **_kwargs).digest()
|
| 227 |
+
elif Settings.hash_algorithm == "md5":
|
| 228 |
+
actual_hash = hashlib.md5(bytes(result, "utf-8"), **_kwargs).digest()
|
| 229 |
+
else:
|
| 230 |
+
raise ArchiveChecksumError(f"Unknown hash algorithm: {Settings.hash_algorithm}.\nPlease check settings.ini")
|
| 231 |
+
if expected_hash is not None and expected_hash != actual_hash:
|
| 232 |
+
raise ArchiveChecksumError(
|
| 233 |
+
f"Downloaded file {filename} is corrupted! Detect checksum error.\n"
|
| 234 |
+
f"Expect {expected_hash.hex()}: {url}\n"
|
| 235 |
+
f"Actual {actual_hash.hex()}: {filename}"
|
| 236 |
+
)
|
| 237 |
+
return result
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def downloadBinaryFile(url: str, out: Path, hash_algo: str, exp: Optional[bytes], timeout: Tuple[float, float]) -> None:
|
| 241 |
+
logger = getLogger("aqt.helper")
|
| 242 |
+
filename = Path(url).name
|
| 243 |
+
with requests.sessions.Session() as session:
|
| 244 |
+
retries = requests.adapters.Retry(
|
| 245 |
+
total=Settings.max_retries_on_connection_error, backoff_factor=Settings.backoff_factor
|
| 246 |
+
)
|
| 247 |
+
adapter = requests.adapters.HTTPAdapter(max_retries=retries)
|
| 248 |
+
session.mount("http://", adapter)
|
| 249 |
+
session.mount("https://", adapter)
|
| 250 |
+
try:
|
| 251 |
+
r = session.get(url, allow_redirects=False, stream=True, timeout=timeout)
|
| 252 |
+
if 300 < r.status_code < 309:
|
| 253 |
+
logger.debug("Asked to redirect({}) to: {}".format(r.status_code, r.headers["Location"]))
|
| 254 |
+
newurl = altlink(r.url, r.headers["Location"])
|
| 255 |
+
logger.info("Redirected: {}".format(urlparse(newurl).hostname))
|
| 256 |
+
r = session.get(newurl, stream=True, timeout=timeout)
|
| 257 |
+
except requests.exceptions.ConnectionError as e:
|
| 258 |
+
raise ArchiveConnectionError(f"Connection error: {e.args}") from e
|
| 259 |
+
except requests.exceptions.Timeout as e:
|
| 260 |
+
raise ArchiveConnectionError(f"Connection timeout: {e.args}") from e
|
| 261 |
+
else:
|
| 262 |
+
if sys.version_info >= (3, 9):
|
| 263 |
+
hash = hashlib.new(hash_algo, usedforsecurity=False)
|
| 264 |
+
else:
|
| 265 |
+
hash = hashlib.new(hash_algo)
|
| 266 |
+
try:
|
| 267 |
+
with open(out, "wb") as fd:
|
| 268 |
+
for chunk in r.iter_content(chunk_size=8196):
|
| 269 |
+
fd.write(chunk)
|
| 270 |
+
hash.update(chunk)
|
| 271 |
+
fd.flush()
|
| 272 |
+
except requests.exceptions.ReadTimeout as e:
|
| 273 |
+
raise ArchiveConnectionError(f"Read timeout: {e.args}") from e
|
| 274 |
+
except Exception as e:
|
| 275 |
+
raise ArchiveDownloadError(f"Download of {filename} has error: {e}") from e
|
| 276 |
+
if exp is not None and hash.digest() != exp:
|
| 277 |
+
raise ArchiveChecksumError(
|
| 278 |
+
f"Downloaded file {filename} is corrupted! Detect checksum error.\n"
|
| 279 |
+
f"Expect {exp.hex()}: {url}\n"
|
| 280 |
+
f"Actual {hash.digest().hex()}: {out.name}"
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def retry_on_errors(action: Callable[[], Any], acceptable_errors: Tuple, num_retries: int, name: str) -> Any:
|
| 285 |
+
logger = getLogger("aqt.helper")
|
| 286 |
+
for i in range(num_retries):
|
| 287 |
+
try:
|
| 288 |
+
retry_msg = f": attempt #{1 + i}" if i > 0 else ""
|
| 289 |
+
logger.info(f"{name}{retry_msg}...")
|
| 290 |
+
ret = action()
|
| 291 |
+
if i > 0:
|
| 292 |
+
logger.info(f"Success on attempt #{1 + i}: {name}")
|
| 293 |
+
return ret
|
| 294 |
+
except acceptable_errors as e:
|
| 295 |
+
if i < num_retries - 1:
|
| 296 |
+
continue # just try again
|
| 297 |
+
raise e from e
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
def retry_on_bad_connection(function: Callable[[str], Any], base_url: str) -> Any:
|
| 301 |
+
logger = getLogger("aqt.helper")
|
| 302 |
+
fallback_url = secrets.choice(Settings.fallbacks)
|
| 303 |
+
try:
|
| 304 |
+
return function(base_url)
|
| 305 |
+
except ArchiveConnectionError:
|
| 306 |
+
logger.warning(f"Connection to '{base_url}' failed. Retrying with fallback '{fallback_url}'.")
|
| 307 |
+
return function(fallback_url)
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def iter_list_reps(_list: List, num_reps: int) -> Generator:
|
| 311 |
+
list_index = 0
|
| 312 |
+
for i in range(num_reps):
|
| 313 |
+
yield _list[list_index]
|
| 314 |
+
list_index += 1
|
| 315 |
+
if list_index >= len(_list):
|
| 316 |
+
list_index = 0
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def get_hash(archive_path: str, algorithm: str, timeout: Tuple[float, float]) -> bytes:
|
| 320 |
+
"""
|
| 321 |
+
Downloads a checksum and unhexlifies it to a `bytes` object, guaranteed to be the right length.
|
| 322 |
+
Raises ChecksumDownloadFailure if the download failed, or if the checksum was un unexpected length.
|
| 323 |
+
|
| 324 |
+
:param archive_path: The path to the file that we want to check, not the path to the checksum.
|
| 325 |
+
:param algorithm: sha256 is the only safe value to use here.
|
| 326 |
+
:param timeout: The timeout used by getUrl.
|
| 327 |
+
:return: A checksum in `bytes`
|
| 328 |
+
"""
|
| 329 |
+
logger = getLogger("aqt.helper")
|
| 330 |
+
hash_lengths = {"sha256": 64, "sha1": 40, "md5": 32}
|
| 331 |
+
for base_url in iter_list_reps(Settings.trusted_mirrors, Settings.max_retries_to_retrieve_hash):
|
| 332 |
+
url = posixpath.join(base_url, f"{archive_path}.{algorithm}")
|
| 333 |
+
logger.debug(f"Attempt to download checksum at {url}")
|
| 334 |
+
try:
|
| 335 |
+
r = getUrl(url, timeout)
|
| 336 |
+
# sha256 & md5 files are: "some_hash archive_filename"
|
| 337 |
+
_hash = r.split(" ")[0]
|
| 338 |
+
if len(_hash) == hash_lengths[algorithm]:
|
| 339 |
+
return binascii.unhexlify(_hash)
|
| 340 |
+
except (ArchiveConnectionError, ArchiveDownloadError, binascii.Incomplete, binascii.Error):
|
| 341 |
+
pass
|
| 342 |
+
filename = archive_path.split("/")[-1]
|
| 343 |
+
raise ChecksumDownloadFailure(
|
| 344 |
+
f"Failed to download checksum for the file '{filename}' from mirrors '{Settings.trusted_mirrors}"
|
| 345 |
+
)
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def altlink(url: str, alt: str) -> str:
|
| 349 |
+
"""
|
| 350 |
+
Blacklisting redirected(alt) location based on Settings. Blacklist configuration.
|
| 351 |
+
When found black url, then try download an url + .meta4 that is a metalink version4
|
| 352 |
+
xml file, parse it and retrieve the best alternative url.
|
| 353 |
+
"""
|
| 354 |
+
logger = getLogger("aqt.helper")
|
| 355 |
+
if not any(alt.startswith(b) for b in Settings.blacklist):
|
| 356 |
+
return alt
|
| 357 |
+
try:
|
| 358 |
+
m = _get_meta(url)
|
| 359 |
+
except requests.exceptions.ConnectionError:
|
| 360 |
+
logger.error("Got connection error. Fall back to recovery plan...")
|
| 361 |
+
return alt
|
| 362 |
+
else:
|
| 363 |
+
# Expected response->'application/metalink4+xml; charset=utf-8'
|
| 364 |
+
if not _check_content_type(m.headers["content-type"]):
|
| 365 |
+
logger.error("Unexpected meta4 response;content-type: {}".format(m.headers["content-type"]))
|
| 366 |
+
return alt
|
| 367 |
+
try:
|
| 368 |
+
mirror_xml = ElementTree.fromstring(m.text)
|
| 369 |
+
meta_urls: Dict[str, str] = {}
|
| 370 |
+
for f in mirror_xml.iter("{urn:ietf:params:xml:ns:metalink}file"):
|
| 371 |
+
for u in f.iter("{urn:ietf:params:xml:ns:metalink}url"):
|
| 372 |
+
meta_urls[u.attrib["priority"]] = u.text
|
| 373 |
+
mirrors = [meta_urls[i] for i in sorted(meta_urls.keys(), key=lambda x: int(x))]
|
| 374 |
+
except Exception:
|
| 375 |
+
exc_info = sys.exc_info()
|
| 376 |
+
logger.error("Unexpected meta4 file; parse error: {}".format(exc_info[1]))
|
| 377 |
+
return alt
|
| 378 |
+
else:
|
| 379 |
+
# Return first priority item which is not blacklist in mirrors list,
|
| 380 |
+
# if not found then return alt in default
|
| 381 |
+
try:
|
| 382 |
+
return next(mirror for mirror in mirrors if not any(mirror.startswith(b) for b in Settings.blacklist))
|
| 383 |
+
except StopIteration:
|
| 384 |
+
return alt
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
class MyQueueListener(QueueListener):
|
| 388 |
+
def __init__(self, queue) -> None:
|
| 389 |
+
handlers: List[Handler] = []
|
| 390 |
+
super().__init__(queue, *handlers)
|
| 391 |
+
|
| 392 |
+
def handle(self, record) -> None:
|
| 393 |
+
"""
|
| 394 |
+
Handle a record from subprocess.
|
| 395 |
+
Override logger name then handle at proper logger.
|
| 396 |
+
"""
|
| 397 |
+
record = self.prepare(record)
|
| 398 |
+
logger = getLogger("aqt.installer")
|
| 399 |
+
record.name = "aqt.installer"
|
| 400 |
+
logger.handle(record)
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
def ssplit(data: str) -> Generator[str, None, None]:
|
| 404 |
+
for element in data.split(","):
|
| 405 |
+
yield element.strip()
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
def xml_to_modules(
|
| 409 |
+
xml_text: str,
|
| 410 |
+
predicate: Callable[[Element], bool],
|
| 411 |
+
) -> Dict[str, Dict[str, str]]:
|
| 412 |
+
"""Converts an XML document to a dict of `PackageUpdate` dicts, indexed by `Name` attribute.
|
| 413 |
+
Only report elements that satisfy `predicate(element)`.
|
| 414 |
+
Reports all keys available in the PackageUpdate tag as strings.
|
| 415 |
+
|
| 416 |
+
:param xml_text: The entire contents of an xml file
|
| 417 |
+
:param predicate: A function that decides which elements to keep or discard
|
| 418 |
+
"""
|
| 419 |
+
try:
|
| 420 |
+
parsed_xml = ElementTree.fromstring(xml_text)
|
| 421 |
+
except ElementTree.ParseError as perror:
|
| 422 |
+
raise ArchiveListError(f"Downloaded metadata is corrupted. {perror}") from perror
|
| 423 |
+
packages: Dict[str, Dict[str, str]] = {}
|
| 424 |
+
for packageupdate in parsed_xml.iter("PackageUpdate"):
|
| 425 |
+
if not predicate(packageupdate):
|
| 426 |
+
continue
|
| 427 |
+
name = packageupdate.find("Name").text
|
| 428 |
+
packages[name] = {}
|
| 429 |
+
for child in packageupdate:
|
| 430 |
+
if child.tag == "UpdateFile":
|
| 431 |
+
for attr in "CompressedSize", "UncompressedSize":
|
| 432 |
+
if attr not in child.attrib:
|
| 433 |
+
continue
|
| 434 |
+
packages[name][attr] = humanize.naturalsize(child.attrib[attr], gnu=True)
|
| 435 |
+
else:
|
| 436 |
+
packages[name][child.tag] = child.text
|
| 437 |
+
return packages
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
class MyConfigParser(ConfigParser):
|
| 441 |
+
def getlist(self, section: str, option: str, fallback: List[str] = []) -> List[str]:
|
| 442 |
+
value = self.get(section, option, fallback=None)
|
| 443 |
+
if value is None:
|
| 444 |
+
return fallback
|
| 445 |
+
try:
|
| 446 |
+
result = list(filter(None, (x.strip() for x in value.splitlines())))
|
| 447 |
+
except Exception:
|
| 448 |
+
result = fallback
|
| 449 |
+
return result
|
| 450 |
+
|
| 451 |
+
def getlistint(self, section: str, option: str, fallback: List[int] = []) -> List[int]:
|
| 452 |
+
try:
|
| 453 |
+
result = [int(x) for x in self.getlist(section, option)]
|
| 454 |
+
except Exception:
|
| 455 |
+
result = fallback
|
| 456 |
+
return result
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
class SettingsClass:
|
| 460 |
+
"""
|
| 461 |
+
Class to hold configuration and settings.
|
| 462 |
+
Actual values are stored in 'settings.ini' file.
|
| 463 |
+
"""
|
| 464 |
+
|
| 465 |
+
# this class is Borg
|
| 466 |
+
_shared_state: Dict[str, Any] = {
|
| 467 |
+
"config": None,
|
| 468 |
+
"configfile": None,
|
| 469 |
+
"loggingconf": None,
|
| 470 |
+
"_ignore_hash_override": None,
|
| 471 |
+
"_lock": Lock(),
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
def __init__(self) -> None:
|
| 475 |
+
self.config: Optional[ConfigParser]
|
| 476 |
+
self._lock: Lock
|
| 477 |
+
self._ignore_hash_override: Optional[bool] = None
|
| 478 |
+
self._initialize()
|
| 479 |
+
|
| 480 |
+
def __new__(cls, *p, **k):
|
| 481 |
+
self = object.__new__(cls, *p, **k)
|
| 482 |
+
self.__dict__ = cls._shared_state
|
| 483 |
+
return self
|
| 484 |
+
|
| 485 |
+
def _initialize(self) -> None:
|
| 486 |
+
"""Initialize configuration if not already initialized."""
|
| 487 |
+
if self.config is None:
|
| 488 |
+
with self._lock:
|
| 489 |
+
if self.config is None:
|
| 490 |
+
self.config = MyConfigParser()
|
| 491 |
+
self.configfile = os.path.join(os.path.dirname(__file__), "settings.ini")
|
| 492 |
+
self.loggingconf = os.path.join(os.path.dirname(__file__), "logging.ini")
|
| 493 |
+
self.config.read(self.configfile)
|
| 494 |
+
|
| 495 |
+
logging.info(f"Cache folder: {self.qt_installer_cache_path}")
|
| 496 |
+
logging.info(f"Temp folder: {self.qt_installer_temp_path}")
|
| 497 |
+
|
| 498 |
+
temp_dir = self.qt_installer_temp_path
|
| 499 |
+
temp_path = Path(temp_dir)
|
| 500 |
+
if not temp_path.exists():
|
| 501 |
+
temp_path.mkdir(parents=True, exist_ok=True)
|
| 502 |
+
else:
|
| 503 |
+
self.qt_installer_cleanup()
|
| 504 |
+
|
| 505 |
+
def _get_config(self) -> ConfigParser:
|
| 506 |
+
"""Safe getter for config that ensures it's initialized."""
|
| 507 |
+
self._initialize()
|
| 508 |
+
assert self.config is not None
|
| 509 |
+
return self.config
|
| 510 |
+
|
| 511 |
+
def set_ignore_hash_for_session(self, value: bool) -> None:
|
| 512 |
+
"""Override the INSECURE_NOT_FOR_PRODUCTION_ignore_hash setting for the current session without modifying config."""
|
| 513 |
+
self._ignore_hash_override = value
|
| 514 |
+
|
| 515 |
+
def load_settings(self, file: Optional[Union[str, TextIO]] = None) -> None:
|
| 516 |
+
if self.config is None:
|
| 517 |
+
return
|
| 518 |
+
|
| 519 |
+
if file is not None:
|
| 520 |
+
if isinstance(file, str):
|
| 521 |
+
result = self.config.read(file)
|
| 522 |
+
if len(result) == 0:
|
| 523 |
+
raise IOError("Fails to load specified config file {}".format(file))
|
| 524 |
+
self.configfile = file
|
| 525 |
+
else:
|
| 526 |
+
# passed through command line argparse.FileType("r")
|
| 527 |
+
self.config.read_file(file)
|
| 528 |
+
self.configfile = file.name
|
| 529 |
+
file.close()
|
| 530 |
+
else:
|
| 531 |
+
with open(self.configfile, "r") as f:
|
| 532 |
+
self.config.read_file(f)
|
| 533 |
+
|
| 534 |
+
@property
|
| 535 |
+
def qt_installer_cache_path(self) -> str:
|
| 536 |
+
"""Path for Qt installer cache."""
|
| 537 |
+
config = self._get_config()
|
| 538 |
+
# If no cache_path or blank, return default without modifying config
|
| 539 |
+
if not config.has_option("qtofficial", "cache_path") or config.get("qtofficial", "cache_path").strip() == "":
|
| 540 |
+
return str(get_default_local_cache_path())
|
| 541 |
+
return config.get("qtofficial", "cache_path")
|
| 542 |
+
|
| 543 |
+
@property
|
| 544 |
+
def qt_installer_temp_path(self) -> str:
|
| 545 |
+
"""Path for Qt installer cache."""
|
| 546 |
+
config = self._get_config()
|
| 547 |
+
# If no cache_path or blank, return default without modifying config
|
| 548 |
+
if not config.has_option("qtofficial", "temp_path") or config.get("qtofficial", "temp_path").strip() == "":
|
| 549 |
+
return str(get_default_local_temp_path())
|
| 550 |
+
return config.get("qtofficial", "temp_path")
|
| 551 |
+
|
| 552 |
+
@property
|
| 553 |
+
def archive_download_location(self):
|
| 554 |
+
return self.config.get("aqt", "archive_download_location", fallback=".")
|
| 555 |
+
|
| 556 |
+
@property
|
| 557 |
+
def always_keep_archives(self):
|
| 558 |
+
return self.config.getboolean("aqt", "always_keep_archives", fallback=False)
|
| 559 |
+
|
| 560 |
+
@property
|
| 561 |
+
def concurrency(self):
|
| 562 |
+
"""concurrency configuration.
|
| 563 |
+
|
| 564 |
+
:return: concurrency
|
| 565 |
+
:rtype: int
|
| 566 |
+
"""
|
| 567 |
+
return self.config.getint("aqt", "concurrency", fallback=4)
|
| 568 |
+
|
| 569 |
+
@property
|
| 570 |
+
def blacklist(self):
|
| 571 |
+
"""list of sites in a blacklist
|
| 572 |
+
|
| 573 |
+
:returns: list of site URLs(scheme and host part)
|
| 574 |
+
:rtype: List[str]
|
| 575 |
+
"""
|
| 576 |
+
return self.config.getlist("mirrors", "blacklist", fallback=[])
|
| 577 |
+
|
| 578 |
+
@property
|
| 579 |
+
def baseurl(self):
|
| 580 |
+
return self.config.get("aqt", "baseurl", fallback="https://download.qt.io")
|
| 581 |
+
|
| 582 |
+
@property
|
| 583 |
+
def connection_timeout(self):
|
| 584 |
+
return self.config.getfloat("requests", "connection_timeout", fallback=3.5)
|
| 585 |
+
|
| 586 |
+
@property
|
| 587 |
+
def response_timeout(self):
|
| 588 |
+
return self.config.getfloat("requests", "response_timeout", fallback=10)
|
| 589 |
+
|
| 590 |
+
@property
|
| 591 |
+
def max_retries(self):
|
| 592 |
+
"""Deprecated: please use `max_retries_on_connection_error` and `max_retries_on_checksum_error` instead!"""
|
| 593 |
+
return self.config.getfloat("requests", "max_retries", fallback=5)
|
| 594 |
+
|
| 595 |
+
@property
|
| 596 |
+
def max_retries_on_connection_error(self):
|
| 597 |
+
return self.config.getfloat("requests", "max_retries_on_connection_error", fallback=self.max_retries)
|
| 598 |
+
|
| 599 |
+
@property
|
| 600 |
+
def max_retries_on_checksum_error(self):
|
| 601 |
+
return self.config.getint("requests", "max_retries_on_checksum_error", fallback=int(self.max_retries))
|
| 602 |
+
|
| 603 |
+
@property
|
| 604 |
+
def max_retries_to_retrieve_hash(self):
|
| 605 |
+
return self.config.getint("requests", "max_retries_to_retrieve_hash", fallback=int(self.max_retries))
|
| 606 |
+
|
| 607 |
+
@property
|
| 608 |
+
def hash_algorithm(self):
|
| 609 |
+
return self.config.get("requests", "hash_algorithm", fallback="sha256")
|
| 610 |
+
|
| 611 |
+
@property
|
| 612 |
+
def ignore_hash(self):
|
| 613 |
+
if self._ignore_hash_override is not None:
|
| 614 |
+
return self._ignore_hash_override
|
| 615 |
+
return self.config.getboolean("requests", "INSECURE_NOT_FOR_PRODUCTION_ignore_hash", fallback=False)
|
| 616 |
+
|
| 617 |
+
@property
|
| 618 |
+
def backoff_factor(self):
|
| 619 |
+
return self.config.getfloat("requests", "retry_backoff", fallback=0.1)
|
| 620 |
+
|
| 621 |
+
@property
|
| 622 |
+
def trusted_mirrors(self):
|
| 623 |
+
return self.config.getlist("mirrors", "trusted_mirrors", fallback=[self.baseurl])
|
| 624 |
+
|
| 625 |
+
@property
|
| 626 |
+
def fallbacks(self):
|
| 627 |
+
return self.config.getlist("mirrors", "fallbacks", fallback=[])
|
| 628 |
+
|
| 629 |
+
@property
|
| 630 |
+
def zipcmd(self):
|
| 631 |
+
return self.config.get("aqt", "7zcmd", fallback="7z")
|
| 632 |
+
|
| 633 |
+
@property
|
| 634 |
+
def kde_patches(self):
|
| 635 |
+
return self.config.getlist("kde_patches", "patches", fallback=[])
|
| 636 |
+
|
| 637 |
+
@property
|
| 638 |
+
def print_stacktrace_on_error(self):
|
| 639 |
+
return self.config.getboolean("aqt", "print_stacktrace_on_error", fallback=False)
|
| 640 |
+
|
| 641 |
+
@property
|
| 642 |
+
def min_module_size(self):
|
| 643 |
+
"""
|
| 644 |
+
Some modules in the Qt repository contain only empty directories.
|
| 645 |
+
We have found that these modules are no more than 40 bytes after decompression.
|
| 646 |
+
This setting is used to filter out these empty modules in `list-*` output.
|
| 647 |
+
"""
|
| 648 |
+
return self.config.getint("aqt", "min_module_size", fallback=41)
|
| 649 |
+
|
| 650 |
+
# Qt Commercial Installer properties
|
| 651 |
+
@property
|
| 652 |
+
def qt_installer_timeout(self) -> int:
|
| 653 |
+
"""Timeout for Qt commercial installer operations in seconds."""
|
| 654 |
+
return self._get_config().getint("qtofficial", "installer_timeout", fallback=3600)
|
| 655 |
+
|
| 656 |
+
@property
|
| 657 |
+
def qt_installer_operationdoesnotexisterror(self) -> str:
|
| 658 |
+
"""Handle OperationDoesNotExistError in Qt installer."""
|
| 659 |
+
return self._get_config().get("qtofficial", "operation_does_not_exist_error", fallback="Ignore")
|
| 660 |
+
|
| 661 |
+
@property
|
| 662 |
+
def qt_installer_overwritetargetdirectory(self) -> str:
|
| 663 |
+
"""Handle overwriting target directory in Qt installer."""
|
| 664 |
+
return self._get_config().get("qtofficial", "overwrite_target_directory", fallback="No")
|
| 665 |
+
|
| 666 |
+
@property
|
| 667 |
+
def qt_installer_stopprocessesforupdates(self) -> str:
|
| 668 |
+
"""Handle stopping processes for updates in Qt installer."""
|
| 669 |
+
return self._get_config().get("qtofficial", "stop_processes_for_updates", fallback="Cancel")
|
| 670 |
+
|
| 671 |
+
@property
|
| 672 |
+
def qt_installer_installationerrorwithcancel(self) -> str:
|
| 673 |
+
"""Handle installation errors with cancel option in Qt installer."""
|
| 674 |
+
return self._get_config().get("qtofficial", "installation_error_with_cancel", fallback="Cancel")
|
| 675 |
+
|
| 676 |
+
@property
|
| 677 |
+
def qt_installer_installationerrorwithignore(self) -> str:
|
| 678 |
+
"""Handle installation errors with ignore option in Qt installer."""
|
| 679 |
+
return self._get_config().get("qtofficial", "installation_error_with_ignore", fallback="Ignore")
|
| 680 |
+
|
| 681 |
+
@property
|
| 682 |
+
def qt_installer_associatecommonfiletypes(self) -> str:
|
| 683 |
+
"""Handle file type associations in Qt installer."""
|
| 684 |
+
return self._get_config().get("qtofficial", "associate_common_filetypes", fallback="Yes")
|
| 685 |
+
|
| 686 |
+
@property
|
| 687 |
+
def qt_installer_telemetry(self) -> str:
|
| 688 |
+
"""Handle telemetry settings in Qt installer."""
|
| 689 |
+
return self._get_config().get("qtofficial", "telemetry", fallback="No")
|
| 690 |
+
|
| 691 |
+
@property
|
| 692 |
+
def qt_installer_unattended(self) -> bool:
|
| 693 |
+
"""Control whether to use unattended installation flags."""
|
| 694 |
+
return self._get_config().getboolean("qtofficial", "unattended", fallback=True)
|
| 695 |
+
|
| 696 |
+
def qt_installer_cleanup(self) -> None:
|
| 697 |
+
"""Clean tmp folder."""
|
| 698 |
+
for item in Path(self.qt_installer_temp_path).iterdir():
|
| 699 |
+
if item.is_dir():
|
| 700 |
+
shutil.rmtree(item)
|
| 701 |
+
else:
|
| 702 |
+
item.unlink()
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
Settings = SettingsClass()
|
| 706 |
+
|
| 707 |
+
|
| 708 |
+
def setup_logging(env_key="LOG_CFG"):
|
| 709 |
+
config = os.getenv(env_key, None)
|
| 710 |
+
if config is not None and os.path.exists(config):
|
| 711 |
+
Settings.loggingconf = config
|
| 712 |
+
logging.config.fileConfig(Settings.loggingconf)
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
def safely_run(cmd: List[str], timeout: int) -> None:
|
| 716 |
+
try:
|
| 717 |
+
subprocess.run(cmd, shell=False, timeout=timeout)
|
| 718 |
+
except Exception:
|
| 719 |
+
raise
|
| 720 |
+
|
| 721 |
+
|
| 722 |
+
def safely_run_save_output(cmd: List[str], timeout: int) -> Any:
|
| 723 |
+
try:
|
| 724 |
+
result = subprocess.run(cmd, shell=False, capture_output=True, text=True, timeout=timeout)
|
| 725 |
+
return result
|
| 726 |
+
except Exception:
|
| 727 |
+
raise
|
| 728 |
+
|
| 729 |
+
|
| 730 |
+
def extract_auth(args: List[str]) -> Tuple[Union[str, None], Union[str, None], Union[List[str], None]]:
|
| 731 |
+
username = None
|
| 732 |
+
password = None
|
| 733 |
+
i = 0
|
| 734 |
+
while i < len(args):
|
| 735 |
+
if args[i] == "--email":
|
| 736 |
+
if i + 1 < len(args):
|
| 737 |
+
username = args[i + 1]
|
| 738 |
+
del args[i : i + 2]
|
| 739 |
+
else:
|
| 740 |
+
del args[i]
|
| 741 |
+
continue
|
| 742 |
+
elif args[i] == "--pw":
|
| 743 |
+
if i + 1 < len(args):
|
| 744 |
+
password = args[i + 1]
|
| 745 |
+
del args[i : i + 2]
|
| 746 |
+
else:
|
| 747 |
+
del args[i]
|
| 748 |
+
continue
|
| 749 |
+
i += 1
|
| 750 |
+
return username, password, args
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
def download_installer(base_url: str, installer_filename: str, target_path: Path, timeout: Tuple[float, float]) -> None:
|
| 754 |
+
base_path = f"official_releases/online_installers/{installer_filename}"
|
| 755 |
+
url = f"{base_url}/{base_path}"
|
| 756 |
+
try:
|
| 757 |
+
hash = get_hash(base_path, Settings.hash_algorithm, timeout)
|
| 758 |
+
downloadBinaryFile(url, target_path, Settings.hash_algorithm, hash, timeout=timeout)
|
| 759 |
+
except Exception as e:
|
| 760 |
+
raise RuntimeError(f"Failed to download installer: {e}")
|
| 761 |
+
|
| 762 |
+
|
| 763 |
+
def prepare_installer(installer_path: Path, os_name: str) -> Path:
|
| 764 |
+
"""
|
| 765 |
+
Prepares the installer for execution. This may involve setting the correct permissions or
|
| 766 |
+
extracting the installer if it's packaged. Returns the path to the installer executable.
|
| 767 |
+
"""
|
| 768 |
+
if os_name == "linux":
|
| 769 |
+
os.chmod(installer_path, 0o500)
|
| 770 |
+
return installer_path
|
| 771 |
+
elif os_name == "mac":
|
| 772 |
+
volume_path = Path(f"/Volumes/{str(uuid.uuid4())}")
|
| 773 |
+
subprocess.run(
|
| 774 |
+
["hdiutil", "attach", str(installer_path), "-mountpoint", str(volume_path)],
|
| 775 |
+
stdout=subprocess.DEVNULL,
|
| 776 |
+
check=True,
|
| 777 |
+
)
|
| 778 |
+
try:
|
| 779 |
+
src_app_name = next(volume_path.glob("*.app")).name
|
| 780 |
+
dst_app_path = installer_path.with_suffix(".app")
|
| 781 |
+
shutil.copytree(volume_path / src_app_name, dst_app_path)
|
| 782 |
+
finally:
|
| 783 |
+
subprocess.run(["hdiutil", "detach", str(volume_path), "-force"], stdout=subprocess.DEVNULL, check=True)
|
| 784 |
+
return dst_app_path / "Contents" / "MacOS" / Path(src_app_name).stem
|
| 785 |
+
else:
|
| 786 |
+
return installer_path
|
python/py313/Lib/site-packages/aqt/installer.py
ADDED
|
@@ -0,0 +1,1708 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2018 Linus Jahn <lnj@kaidan.im>
|
| 4 |
+
# Copyright (C) 2019-2025 Hiroshi Miura <miurahr@linux.com>
|
| 5 |
+
# Copyright (C) 2020, Aurélien Gâteau
|
| 6 |
+
#
|
| 7 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 8 |
+
# this software and associated documentation files (the "Software"), to deal in
|
| 9 |
+
# the Software without restriction, including without limitation the rights to
|
| 10 |
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 11 |
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
| 12 |
+
# subject to the following conditions:
|
| 13 |
+
#
|
| 14 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 15 |
+
# copies or substantial portions of the Software.
|
| 16 |
+
#
|
| 17 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 18 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 19 |
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 20 |
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 21 |
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 22 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 23 |
+
|
| 24 |
+
import argparse
|
| 25 |
+
import errno
|
| 26 |
+
import gc
|
| 27 |
+
import multiprocessing
|
| 28 |
+
import os
|
| 29 |
+
import platform
|
| 30 |
+
import posixpath
|
| 31 |
+
import re
|
| 32 |
+
import signal
|
| 33 |
+
import subprocess
|
| 34 |
+
import sys
|
| 35 |
+
import tarfile
|
| 36 |
+
import time
|
| 37 |
+
import zipfile
|
| 38 |
+
from logging import getLogger
|
| 39 |
+
from logging.handlers import QueueHandler
|
| 40 |
+
from pathlib import Path
|
| 41 |
+
from tempfile import TemporaryDirectory
|
| 42 |
+
from typing import List, Optional, Tuple, cast
|
| 43 |
+
|
| 44 |
+
import aqt
|
| 45 |
+
from aqt.archives import QtArchives, QtPackage, SrcDocExamplesArchives, ToolArchives
|
| 46 |
+
from aqt.commercial import CommercialInstaller
|
| 47 |
+
from aqt.exceptions import (
|
| 48 |
+
AqtException,
|
| 49 |
+
ArchiveChecksumError,
|
| 50 |
+
ArchiveDownloadError,
|
| 51 |
+
ArchiveExtractionError,
|
| 52 |
+
ArchiveListError,
|
| 53 |
+
CliInputError,
|
| 54 |
+
CliKeyboardInterrupt,
|
| 55 |
+
DiskAccessNotPermitted,
|
| 56 |
+
OutOfDiskSpace,
|
| 57 |
+
OutOfMemory,
|
| 58 |
+
)
|
| 59 |
+
from aqt.helper import (
|
| 60 |
+
MyQueueListener,
|
| 61 |
+
Settings,
|
| 62 |
+
download_installer,
|
| 63 |
+
downloadBinaryFile,
|
| 64 |
+
extract_auth,
|
| 65 |
+
get_hash,
|
| 66 |
+
get_os_name,
|
| 67 |
+
get_qt_installer_name,
|
| 68 |
+
prepare_installer,
|
| 69 |
+
retry_on_bad_connection,
|
| 70 |
+
retry_on_errors,
|
| 71 |
+
safely_run_save_output,
|
| 72 |
+
setup_logging,
|
| 73 |
+
)
|
| 74 |
+
from aqt.metadata import ArchiveId, MetadataFactory, QtRepoProperty, SimpleSpec, Version, show_list, suggested_follow_up
|
| 75 |
+
from aqt.updater import Updater, dir_for_version
|
| 76 |
+
|
| 77 |
+
try:
|
| 78 |
+
import py7zr
|
| 79 |
+
|
| 80 |
+
EXT7Z = False
|
| 81 |
+
except ImportError:
|
| 82 |
+
EXT7Z = True
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class BaseArgumentParser(argparse.ArgumentParser):
|
| 86 |
+
"""Global options and subcommand trick"""
|
| 87 |
+
|
| 88 |
+
config: Optional[str]
|
| 89 |
+
func: object
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class ListArgumentParser(BaseArgumentParser):
|
| 93 |
+
"""List-* command parser arguments and options"""
|
| 94 |
+
|
| 95 |
+
arch: Optional[str]
|
| 96 |
+
archives: List[str]
|
| 97 |
+
extension: str
|
| 98 |
+
extensions: str
|
| 99 |
+
host: str
|
| 100 |
+
last_version: str
|
| 101 |
+
latest_version: bool
|
| 102 |
+
long: bool
|
| 103 |
+
long_modules: List[str]
|
| 104 |
+
modules: List[str]
|
| 105 |
+
qt_version_spec: str
|
| 106 |
+
spec: str
|
| 107 |
+
target: str
|
| 108 |
+
email: Optional[str]
|
| 109 |
+
pw: Optional[str]
|
| 110 |
+
search_terms: Optional[str]
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class ListToolArgumentParser(ListArgumentParser):
|
| 114 |
+
"""List-tool command options"""
|
| 115 |
+
|
| 116 |
+
tool_name: str
|
| 117 |
+
tool_version: str
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class CommonInstallArgParser(BaseArgumentParser):
|
| 121 |
+
"""Install-*/install common arguments"""
|
| 122 |
+
|
| 123 |
+
target: str
|
| 124 |
+
host: str
|
| 125 |
+
|
| 126 |
+
outputdir: Optional[str]
|
| 127 |
+
base: Optional[str]
|
| 128 |
+
timeout: Optional[float]
|
| 129 |
+
external: Optional[str]
|
| 130 |
+
internal: bool
|
| 131 |
+
keep: bool
|
| 132 |
+
archive_dest: Optional[str]
|
| 133 |
+
dry_run: bool
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
class InstallArgParser(CommonInstallArgParser):
|
| 137 |
+
"""Install-qt arguments and options"""
|
| 138 |
+
|
| 139 |
+
override: Optional[List[str]]
|
| 140 |
+
arch: Optional[str]
|
| 141 |
+
qt_version: str
|
| 142 |
+
qt_version_spec: str
|
| 143 |
+
version: Optional[str]
|
| 144 |
+
email: Optional[str]
|
| 145 |
+
pw: Optional[str]
|
| 146 |
+
operation_does_not_exist_error: str
|
| 147 |
+
overwrite_target_dir: str
|
| 148 |
+
stop_processes_for_updates: str
|
| 149 |
+
installation_error_with_cancel: str
|
| 150 |
+
installation_error_with_ignore: str
|
| 151 |
+
associate_common_filetypes: str
|
| 152 |
+
telemetry: str
|
| 153 |
+
|
| 154 |
+
modules: Optional[List[str]]
|
| 155 |
+
archives: Optional[List[str]]
|
| 156 |
+
noarchives: bool
|
| 157 |
+
autodesktop: bool
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class InstallToolArgParser(CommonInstallArgParser):
|
| 161 |
+
"""Install-tool arguments and options"""
|
| 162 |
+
|
| 163 |
+
tool_name: str
|
| 164 |
+
version: Optional[str]
|
| 165 |
+
tool_variant: Optional[str]
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class Cli:
|
| 169 |
+
"""CLI main class to parse command line argument and launch proper functions."""
|
| 170 |
+
|
| 171 |
+
__slot__ = ["parser", "combinations", "logger"]
|
| 172 |
+
|
| 173 |
+
UNHANDLED_EXCEPTION_CODE = 254
|
| 174 |
+
|
| 175 |
+
def __init__(self) -> None:
|
| 176 |
+
parser = argparse.ArgumentParser(
|
| 177 |
+
prog="aqt",
|
| 178 |
+
description="Another unofficial Qt Installer.\naqt helps you install Qt SDK, tools, examples and others\n",
|
| 179 |
+
formatter_class=argparse.RawTextHelpFormatter,
|
| 180 |
+
add_help=True,
|
| 181 |
+
)
|
| 182 |
+
parser.add_argument(
|
| 183 |
+
"-c",
|
| 184 |
+
"--config",
|
| 185 |
+
type=argparse.FileType("r"),
|
| 186 |
+
help="Configuration ini file.",
|
| 187 |
+
)
|
| 188 |
+
subparsers = parser.add_subparsers(
|
| 189 |
+
title="subcommands",
|
| 190 |
+
description="aqt accepts several subcommands:\n"
|
| 191 |
+
"install-* subcommands are commands that install components\n"
|
| 192 |
+
"list-* subcommands are commands that show available components\n",
|
| 193 |
+
help="Please refer to each help message by using '--help' with each subcommand",
|
| 194 |
+
)
|
| 195 |
+
self._make_all_parsers(subparsers)
|
| 196 |
+
parser.set_defaults(func=self.show_help)
|
| 197 |
+
self.parser = parser
|
| 198 |
+
|
| 199 |
+
def run(self, arg=None) -> int:
|
| 200 |
+
args = self.parser.parse_args(arg)
|
| 201 |
+
self._setup_settings(args)
|
| 202 |
+
try:
|
| 203 |
+
args.func(args)
|
| 204 |
+
return 0
|
| 205 |
+
except AqtException as e:
|
| 206 |
+
self.logger.error(format(e), exc_info=Settings.print_stacktrace_on_error)
|
| 207 |
+
if e.should_show_help:
|
| 208 |
+
self.show_help()
|
| 209 |
+
return 1
|
| 210 |
+
except Exception as e:
|
| 211 |
+
# If we didn't account for it, and wrap it in an AqtException, it's a bug.
|
| 212 |
+
self.logger.exception(e) # Print stack trace
|
| 213 |
+
self.logger.error(
|
| 214 |
+
f"{self._format_aqt_version()}\n"
|
| 215 |
+
f"Working dir: `{os.getcwd()}`\n"
|
| 216 |
+
f"Arguments: `{sys.argv}` Host: `{platform.uname()}`\n"
|
| 217 |
+
"===========================PLEASE FILE A BUG REPORT===========================\n"
|
| 218 |
+
"You have discovered a bug in aqt.\n"
|
| 219 |
+
"Please file a bug report at https://github.com/miurahr/aqtinstall/issues\n"
|
| 220 |
+
"Please remember to include a copy of this program's output in your report."
|
| 221 |
+
)
|
| 222 |
+
return Cli.UNHANDLED_EXCEPTION_CODE
|
| 223 |
+
|
| 224 |
+
def _set_sevenzip(self, external: Optional[str]) -> Optional[str]:
|
| 225 |
+
sevenzip = external
|
| 226 |
+
fallback = Settings.zipcmd
|
| 227 |
+
if sevenzip is None:
|
| 228 |
+
if EXT7Z:
|
| 229 |
+
self.logger.warning(f"The py7zr module failed to load. Falling back to '{fallback}' for .7z extraction.")
|
| 230 |
+
self.logger.warning("You can use the '--external | -E' flags to select your own extraction tool.")
|
| 231 |
+
sevenzip = fallback
|
| 232 |
+
else:
|
| 233 |
+
# Just use py7zr
|
| 234 |
+
return None
|
| 235 |
+
try:
|
| 236 |
+
subprocess.run(
|
| 237 |
+
[sevenzip, "--help"],
|
| 238 |
+
stdout=subprocess.DEVNULL,
|
| 239 |
+
stderr=subprocess.DEVNULL,
|
| 240 |
+
)
|
| 241 |
+
return sevenzip
|
| 242 |
+
except FileNotFoundError as e:
|
| 243 |
+
qualifier = "Specified" if sevenzip == external else "Fallback"
|
| 244 |
+
raise CliInputError(f"{qualifier} 7zip command executable does not exist: '{sevenzip}'") from e
|
| 245 |
+
|
| 246 |
+
@staticmethod
|
| 247 |
+
def _set_arch(arch: Optional[str], os_name: str, target: str, qt_version_or_spec: str) -> str:
|
| 248 |
+
"""Choose a default architecture, if one can be determined"""
|
| 249 |
+
if arch is not None and arch != "":
|
| 250 |
+
return arch
|
| 251 |
+
if os_name == "linux" and target == "desktop":
|
| 252 |
+
try:
|
| 253 |
+
if Version(qt_version_or_spec) >= Version("6.7.0"):
|
| 254 |
+
return "linux_gcc_64"
|
| 255 |
+
else:
|
| 256 |
+
return "gcc_64"
|
| 257 |
+
except ValueError:
|
| 258 |
+
return "gcc_64"
|
| 259 |
+
elif os_name == "linux_arm64" and target == "desktop":
|
| 260 |
+
return "linux_gcc_arm64"
|
| 261 |
+
elif os_name == "mac" and target == "desktop":
|
| 262 |
+
return "clang_64"
|
| 263 |
+
elif os_name == "mac" and target == "ios":
|
| 264 |
+
return "ios"
|
| 265 |
+
elif target == "android":
|
| 266 |
+
try:
|
| 267 |
+
if Version(qt_version_or_spec) >= Version("5.14.0"):
|
| 268 |
+
return "android"
|
| 269 |
+
except ValueError:
|
| 270 |
+
pass
|
| 271 |
+
elif os_name == "windows_arm64" and target == "desktop":
|
| 272 |
+
return "windows_msvc2022_arm64"
|
| 273 |
+
raise CliInputError("Please supply a target architecture.", should_show_help=True)
|
| 274 |
+
|
| 275 |
+
def _check_mirror(self, mirror):
|
| 276 |
+
if mirror is None:
|
| 277 |
+
pass
|
| 278 |
+
elif mirror.startswith("http://") or mirror.startswith("https://") or mirror.startswith("ftp://"):
|
| 279 |
+
pass
|
| 280 |
+
else:
|
| 281 |
+
return False
|
| 282 |
+
return True
|
| 283 |
+
|
| 284 |
+
@staticmethod
|
| 285 |
+
def _determine_qt_version(
|
| 286 |
+
qt_version_or_spec: str, host: str, target: str, arch: str, base_url: str = Settings.baseurl
|
| 287 |
+
) -> Version:
|
| 288 |
+
def choose_highest(x: Optional[Version], y: Optional[Version]) -> Optional[Version]:
|
| 289 |
+
if x and y:
|
| 290 |
+
return max(x, y)
|
| 291 |
+
return x or y
|
| 292 |
+
|
| 293 |
+
def opt_version_for_spec(ext: str, _spec: SimpleSpec) -> Optional[Version]:
|
| 294 |
+
try:
|
| 295 |
+
meta = MetadataFactory(ArchiveId("qt", host, target), spec=_spec, base_url=base_url)
|
| 296 |
+
return meta.fetch_latest_version(ext)
|
| 297 |
+
except AqtException:
|
| 298 |
+
return None
|
| 299 |
+
|
| 300 |
+
try:
|
| 301 |
+
return Version(qt_version_or_spec)
|
| 302 |
+
except ValueError:
|
| 303 |
+
pass
|
| 304 |
+
try:
|
| 305 |
+
spec = SimpleSpec(qt_version_or_spec)
|
| 306 |
+
except ValueError as e:
|
| 307 |
+
raise CliInputError(f"Invalid version or SimpleSpec: '{qt_version_or_spec}'\n" + SimpleSpec.usage()) from e
|
| 308 |
+
else:
|
| 309 |
+
version: Optional[Version] = None
|
| 310 |
+
for ext in QtRepoProperty.possible_extensions_for_arch(arch):
|
| 311 |
+
version = choose_highest(version, opt_version_for_spec(ext, spec))
|
| 312 |
+
if not version:
|
| 313 |
+
raise CliInputError(
|
| 314 |
+
f"No versions of Qt exist for spec={spec} with host={host}, target={target}, arch={arch}"
|
| 315 |
+
)
|
| 316 |
+
getLogger("aqt.installer").info(f"Resolved spec '{qt_version_or_spec}' to {version}")
|
| 317 |
+
return version
|
| 318 |
+
|
| 319 |
+
@staticmethod
|
| 320 |
+
def choose_archive_dest(archive_dest: Optional[str], keep: bool, temp_dir: str) -> Path:
|
| 321 |
+
"""
|
| 322 |
+
Choose archive download destination, based on context.
|
| 323 |
+
|
| 324 |
+
There are three potential behaviors here:
|
| 325 |
+
1. By default, return a temp directory that will be removed on program exit.
|
| 326 |
+
2. If the user has asked to keep archives, but has not specified a destination,
|
| 327 |
+
we return Settings.archive_download_location ("." by default).
|
| 328 |
+
3. If the user has asked to keep archives and specified a destination,
|
| 329 |
+
we create the destination dir if it doesn't exist, and return that directory.
|
| 330 |
+
"""
|
| 331 |
+
if not archive_dest:
|
| 332 |
+
return Path(Settings.archive_download_location if keep else temp_dir)
|
| 333 |
+
dest = Path(archive_dest)
|
| 334 |
+
dest.mkdir(parents=True, exist_ok=True)
|
| 335 |
+
return dest
|
| 336 |
+
|
| 337 |
+
def run_install_qt(self, args: InstallArgParser):
|
| 338 |
+
"""Run install subcommand"""
|
| 339 |
+
start_time = time.perf_counter()
|
| 340 |
+
self.show_aqt_version()
|
| 341 |
+
target: str = args.target
|
| 342 |
+
os_name: str = args.host
|
| 343 |
+
effective_os_name: str = Cli._get_effective_os_name(os_name)
|
| 344 |
+
qt_version_or_spec: str = getattr(args, "qt_version", getattr(args, "qt_version_spec", ""))
|
| 345 |
+
arch: str = self._set_arch(args.arch, os_name, target, qt_version_or_spec)
|
| 346 |
+
keep: bool = args.keep or Settings.always_keep_archives
|
| 347 |
+
archive_dest: Optional[str] = args.archive_dest
|
| 348 |
+
dry_run: bool = args.dry_run
|
| 349 |
+
output_dir = args.outputdir
|
| 350 |
+
if output_dir is None:
|
| 351 |
+
base_dir = os.getcwd()
|
| 352 |
+
else:
|
| 353 |
+
base_dir = output_dir
|
| 354 |
+
if args.timeout is not None:
|
| 355 |
+
timeout = (args.timeout, args.timeout)
|
| 356 |
+
else:
|
| 357 |
+
timeout = (Settings.connection_timeout, Settings.response_timeout)
|
| 358 |
+
modules = args.modules
|
| 359 |
+
sevenzip = self._set_sevenzip(args.external)
|
| 360 |
+
if args.base is not None:
|
| 361 |
+
if not self._check_mirror(args.base):
|
| 362 |
+
raise CliInputError(
|
| 363 |
+
"The `--base` option requires a url where the path `online/qtsdkrepository` exists.",
|
| 364 |
+
should_show_help=True,
|
| 365 |
+
)
|
| 366 |
+
base = args.base
|
| 367 |
+
else:
|
| 368 |
+
base = Settings.baseurl
|
| 369 |
+
if hasattr(args, "qt_version_spec"):
|
| 370 |
+
qt_version: str = str(Cli._determine_qt_version(args.qt_version_spec, os_name, target, arch, base_url=base))
|
| 371 |
+
else:
|
| 372 |
+
qt_version = args.qt_version
|
| 373 |
+
Cli._validate_version_str(qt_version)
|
| 374 |
+
|
| 375 |
+
if qt_version != qt_version_or_spec:
|
| 376 |
+
arch = self._set_arch(args.arch, os_name, target, qt_version)
|
| 377 |
+
|
| 378 |
+
if hasattr(args, "use_official_installer") and args.use_official_installer is not None:
|
| 379 |
+
|
| 380 |
+
if len(args.use_official_installer) not in [0, 2]:
|
| 381 |
+
raise CliInputError(
|
| 382 |
+
"When providing arguments to --use-official-installer, exactly 2 arguments are required: "
|
| 383 |
+
"--use-official-installer email password"
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
self.logger.info("Using official Qt installer")
|
| 387 |
+
|
| 388 |
+
commercial_args = InstallArgParser()
|
| 389 |
+
|
| 390 |
+
# Core parameters required by install-qt-official
|
| 391 |
+
commercial_args.target = args.target
|
| 392 |
+
commercial_args.arch = self._set_arch(
|
| 393 |
+
args.arch, args.host, args.target, getattr(args, "qt_version", getattr(args, "qt_version_spec", ""))
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
commercial_args.version = qt_version
|
| 397 |
+
|
| 398 |
+
email = None
|
| 399 |
+
password = None
|
| 400 |
+
if len(args.use_official_installer) == 2:
|
| 401 |
+
email, password = args.use_official_installer
|
| 402 |
+
self.logger.info("Using credentials provided with --use-official-installer")
|
| 403 |
+
|
| 404 |
+
# Optional parameters
|
| 405 |
+
commercial_args.email = email or getattr(args, "email", None)
|
| 406 |
+
commercial_args.pw = password or getattr(args, "pw", None)
|
| 407 |
+
commercial_args.outputdir = args.outputdir
|
| 408 |
+
commercial_args.modules = args.modules
|
| 409 |
+
commercial_args.base = getattr(args, "base", None)
|
| 410 |
+
commercial_args.dry_run = getattr(args, "dry_run", False)
|
| 411 |
+
commercial_args.override = None
|
| 412 |
+
|
| 413 |
+
ignored_options = []
|
| 414 |
+
if getattr(args, "noarchives", False):
|
| 415 |
+
ignored_options.append("--noarchives")
|
| 416 |
+
if getattr(args, "autodesktop", False):
|
| 417 |
+
ignored_options.append("--autodesktop")
|
| 418 |
+
if getattr(args, "archives", None):
|
| 419 |
+
ignored_options.append("--archives")
|
| 420 |
+
if getattr(args, "timeout", False):
|
| 421 |
+
ignored_options.append("--timeout")
|
| 422 |
+
if getattr(args, "keep", False):
|
| 423 |
+
ignored_options.append("--keep")
|
| 424 |
+
if getattr(args, "archive_dest", False):
|
| 425 |
+
ignored_options.append("--archive_dest")
|
| 426 |
+
|
| 427 |
+
if ignored_options:
|
| 428 |
+
self.logger.warning("Options ignored because you requested the official installer:")
|
| 429 |
+
self.logger.warning(", ".join(ignored_options))
|
| 430 |
+
|
| 431 |
+
return self.run_install_qt_commercial(commercial_args, print_version=False)
|
| 432 |
+
|
| 433 |
+
archives = args.archives
|
| 434 |
+
if args.noarchives:
|
| 435 |
+
if modules is None:
|
| 436 |
+
raise CliInputError("When `--noarchives` is set, the `--modules` option is mandatory.")
|
| 437 |
+
if archives is not None:
|
| 438 |
+
raise CliInputError("Options `--archives` and `--noarchives` are mutually exclusive.")
|
| 439 |
+
else:
|
| 440 |
+
if modules is not None and archives is not None:
|
| 441 |
+
archives.extend(modules)
|
| 442 |
+
nopatch = args.noarchives or (archives is not None and "qtbase" not in archives) # type: bool
|
| 443 |
+
should_autoinstall: bool = args.autodesktop
|
| 444 |
+
_version = Version(qt_version)
|
| 445 |
+
base_path = Path(base_dir)
|
| 446 |
+
|
| 447 |
+
# Determine if 'all' extra modules should be included
|
| 448 |
+
all_extra = True if modules is not None and "all" in modules else False
|
| 449 |
+
|
| 450 |
+
expect_desktop_archdir, autodesk_arch = self._get_autodesktop_dir_and_arch(
|
| 451 |
+
should_autoinstall, os_name, target, base_path, _version, arch
|
| 452 |
+
)
|
| 453 |
+
|
| 454 |
+
# Main installation
|
| 455 |
+
qt_archives: QtArchives = retry_on_bad_connection(
|
| 456 |
+
lambda base_url: QtArchives(
|
| 457 |
+
os_name,
|
| 458 |
+
target,
|
| 459 |
+
qt_version,
|
| 460 |
+
arch,
|
| 461 |
+
base=base_url,
|
| 462 |
+
subarchives=archives,
|
| 463 |
+
modules=modules,
|
| 464 |
+
all_extra=all_extra,
|
| 465 |
+
is_include_base_package=not args.noarchives,
|
| 466 |
+
timeout=timeout,
|
| 467 |
+
),
|
| 468 |
+
base,
|
| 469 |
+
)
|
| 470 |
+
|
| 471 |
+
target_config = qt_archives.get_target_config()
|
| 472 |
+
target_config.os_name = effective_os_name
|
| 473 |
+
|
| 474 |
+
with TemporaryDirectory() as temp_dir:
|
| 475 |
+
_archive_dest = Cli.choose_archive_dest(archive_dest, keep, temp_dir)
|
| 476 |
+
run_installer(qt_archives.get_packages(), base_dir, sevenzip, keep, _archive_dest, dry_run=dry_run)
|
| 477 |
+
|
| 478 |
+
if dry_run:
|
| 479 |
+
return
|
| 480 |
+
|
| 481 |
+
if not nopatch:
|
| 482 |
+
Updater.update(target_config, base_path, expect_desktop_archdir)
|
| 483 |
+
|
| 484 |
+
# If autodesktop is enabled and we need a desktop installation, do it first
|
| 485 |
+
if should_autoinstall and autodesk_arch is not None:
|
| 486 |
+
is_wasm = arch.startswith("wasm")
|
| 487 |
+
is_msvc = "msvc" in arch
|
| 488 |
+
is_win_desktop_msvc_arm64 = (
|
| 489 |
+
effective_os_name == "windows"
|
| 490 |
+
and target == "desktop"
|
| 491 |
+
and is_msvc
|
| 492 |
+
and arch.endswith(("arm64", "arm64_cross_compiled"))
|
| 493 |
+
)
|
| 494 |
+
if is_win_desktop_msvc_arm64:
|
| 495 |
+
qt_type = "MSVC Arm64"
|
| 496 |
+
elif is_wasm:
|
| 497 |
+
qt_type = "Qt6-WASM"
|
| 498 |
+
else:
|
| 499 |
+
qt_type = target
|
| 500 |
+
|
| 501 |
+
# Create new args for desktop installation
|
| 502 |
+
self.logger.info("")
|
| 503 |
+
self.logger.info(
|
| 504 |
+
f"Autodesktop will now install {effective_os_name} desktop "
|
| 505 |
+
f"{qt_version} {autodesk_arch} as required by {qt_type}"
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
desktop_args = args
|
| 509 |
+
args.autodesktop = False
|
| 510 |
+
args.host = effective_os_name
|
| 511 |
+
args.target = "desktop"
|
| 512 |
+
args.arch = autodesk_arch
|
| 513 |
+
|
| 514 |
+
# Run desktop installation first
|
| 515 |
+
self.run_install_qt(desktop_args)
|
| 516 |
+
|
| 517 |
+
else:
|
| 518 |
+
self.logger.info("Finished installation")
|
| 519 |
+
self.logger.info("Time elapsed: {time:.8f} second".format(time=time.perf_counter() - start_time))
|
| 520 |
+
|
| 521 |
+
def _run_src_doc_examples(self, flavor, args, cmd_name: Optional[str] = None):
|
| 522 |
+
self.show_aqt_version()
|
| 523 |
+
if getattr(args, "target", None) is not None:
|
| 524 |
+
self._warn_on_deprecated_parameter("target", args.target)
|
| 525 |
+
target = "desktop" # The only valid target for src/doc/examples is "desktop"
|
| 526 |
+
os_name = args.host
|
| 527 |
+
output_dir = args.outputdir
|
| 528 |
+
if output_dir is None:
|
| 529 |
+
base_dir = os.getcwd()
|
| 530 |
+
else:
|
| 531 |
+
base_dir = output_dir
|
| 532 |
+
keep: bool = args.keep or Settings.always_keep_archives
|
| 533 |
+
archive_dest: Optional[str] = args.archive_dest
|
| 534 |
+
if args.base is not None:
|
| 535 |
+
base = args.base
|
| 536 |
+
else:
|
| 537 |
+
base = Settings.baseurl
|
| 538 |
+
if hasattr(args, "qt_version_spec"):
|
| 539 |
+
qt_version = str(Cli._determine_qt_version(args.qt_version_spec, os_name, target, arch="", base_url=base))
|
| 540 |
+
else:
|
| 541 |
+
qt_version = args.qt_version
|
| 542 |
+
Cli._validate_version_str(qt_version)
|
| 543 |
+
# Override target/os for recent Qt
|
| 544 |
+
if Version(qt_version) in SimpleSpec(">=6.7.0"):
|
| 545 |
+
target = "qt"
|
| 546 |
+
os_name = "all_os"
|
| 547 |
+
if args.timeout is not None:
|
| 548 |
+
timeout = (args.timeout, args.timeout)
|
| 549 |
+
else:
|
| 550 |
+
timeout = (Settings.connection_timeout, Settings.response_timeout)
|
| 551 |
+
sevenzip = self._set_sevenzip(args.external)
|
| 552 |
+
modules = getattr(args, "modules", None) # `--modules` is invalid for `install-src`
|
| 553 |
+
archives = args.archives
|
| 554 |
+
all_extra = True if modules is not None and "all" in modules else False
|
| 555 |
+
|
| 556 |
+
srcdocexamples_archives: SrcDocExamplesArchives = retry_on_bad_connection(
|
| 557 |
+
lambda base_url: SrcDocExamplesArchives(
|
| 558 |
+
flavor,
|
| 559 |
+
os_name,
|
| 560 |
+
target,
|
| 561 |
+
qt_version,
|
| 562 |
+
base=base_url,
|
| 563 |
+
subarchives=archives,
|
| 564 |
+
modules=modules,
|
| 565 |
+
all_extra=all_extra,
|
| 566 |
+
timeout=timeout,
|
| 567 |
+
),
|
| 568 |
+
base,
|
| 569 |
+
)
|
| 570 |
+
with TemporaryDirectory() as temp_dir:
|
| 571 |
+
_archive_dest = Cli.choose_archive_dest(archive_dest, keep, temp_dir)
|
| 572 |
+
run_installer(
|
| 573 |
+
srcdocexamples_archives.get_packages(), base_dir, sevenzip, keep, _archive_dest, dry_run=args.dry_run
|
| 574 |
+
)
|
| 575 |
+
self.logger.info("Finished installation")
|
| 576 |
+
|
| 577 |
+
def run_install_src(self, args):
|
| 578 |
+
"""Run src subcommand"""
|
| 579 |
+
if not hasattr(args, "qt_version"):
|
| 580 |
+
base = args.base if hasattr(args, "base") else Settings.baseurl
|
| 581 |
+
args.qt_version = str(
|
| 582 |
+
Cli._determine_qt_version(args.qt_version_spec, args.host, args.target, arch="", base_url=base)
|
| 583 |
+
)
|
| 584 |
+
if args.kde and args.qt_version != "5.15.2":
|
| 585 |
+
raise CliInputError("KDE patch: unsupported version!!")
|
| 586 |
+
start_time = time.perf_counter()
|
| 587 |
+
self._run_src_doc_examples("src", args)
|
| 588 |
+
if args.kde:
|
| 589 |
+
if args.outputdir is None:
|
| 590 |
+
target_dir = os.path.join(os.getcwd(), args.qt_version, "Src")
|
| 591 |
+
else:
|
| 592 |
+
target_dir = os.path.join(args.outputdir, args.qt_version, "Src")
|
| 593 |
+
Updater.patch_kde(target_dir)
|
| 594 |
+
self.logger.info("Time elapsed: {time:.8f} second".format(time=time.perf_counter() - start_time))
|
| 595 |
+
|
| 596 |
+
def run_install_example(self, args):
|
| 597 |
+
"""Run example subcommand"""
|
| 598 |
+
start_time = time.perf_counter()
|
| 599 |
+
self._run_src_doc_examples("examples", args, cmd_name="example")
|
| 600 |
+
self.logger.info("Time elapsed: {time:.8f} second".format(time=time.perf_counter() - start_time))
|
| 601 |
+
|
| 602 |
+
def run_install_doc(self, args):
|
| 603 |
+
"""Run doc subcommand"""
|
| 604 |
+
start_time = time.perf_counter()
|
| 605 |
+
self._run_src_doc_examples("doc", args)
|
| 606 |
+
self.logger.info("Time elapsed: {time:.8f} second".format(time=time.perf_counter() - start_time))
|
| 607 |
+
|
| 608 |
+
def run_install_tool(self, args: InstallToolArgParser):
|
| 609 |
+
"""Run tool subcommand"""
|
| 610 |
+
start_time = time.perf_counter()
|
| 611 |
+
self.show_aqt_version()
|
| 612 |
+
tool_name = args.tool_name # such as tools_openssl_x64
|
| 613 |
+
os_name = args.host # windows, linux and mac
|
| 614 |
+
target = args.target # desktop, android and ios
|
| 615 |
+
output_dir = args.outputdir
|
| 616 |
+
if output_dir is None:
|
| 617 |
+
base_dir = os.getcwd()
|
| 618 |
+
else:
|
| 619 |
+
base_dir = output_dir
|
| 620 |
+
sevenzip = self._set_sevenzip(args.external)
|
| 621 |
+
version = getattr(args, "version", None)
|
| 622 |
+
if version is not None:
|
| 623 |
+
Cli._validate_version_str(version, allow_minus=True)
|
| 624 |
+
keep: bool = args.keep or Settings.always_keep_archives
|
| 625 |
+
archive_dest: Optional[str] = args.archive_dest
|
| 626 |
+
if args.base is not None:
|
| 627 |
+
base = args.base
|
| 628 |
+
else:
|
| 629 |
+
base = Settings.baseurl
|
| 630 |
+
if args.timeout is not None:
|
| 631 |
+
timeout = (args.timeout, args.timeout)
|
| 632 |
+
else:
|
| 633 |
+
timeout = (Settings.connection_timeout, Settings.response_timeout)
|
| 634 |
+
if args.tool_variant is None:
|
| 635 |
+
archive_id = ArchiveId("tools", os_name, target)
|
| 636 |
+
meta = MetadataFactory(archive_id, base_url=base, is_latest_version=True, tool_name=tool_name)
|
| 637 |
+
try:
|
| 638 |
+
archs: List[str] = cast(list, meta.getList())
|
| 639 |
+
except ArchiveDownloadError as e:
|
| 640 |
+
msg = f"Failed to locate XML data for the tool '{tool_name}'."
|
| 641 |
+
raise ArchiveListError(msg, suggested_action=suggested_follow_up(meta)) from e
|
| 642 |
+
|
| 643 |
+
else:
|
| 644 |
+
archs = [args.tool_variant]
|
| 645 |
+
|
| 646 |
+
for arch in archs:
|
| 647 |
+
tool_archives: ToolArchives = retry_on_bad_connection(
|
| 648 |
+
lambda base_url: ToolArchives(
|
| 649 |
+
os_name=os_name,
|
| 650 |
+
tool_name=tool_name,
|
| 651 |
+
target=target,
|
| 652 |
+
base=base_url,
|
| 653 |
+
version_str=version,
|
| 654 |
+
arch=arch,
|
| 655 |
+
timeout=timeout,
|
| 656 |
+
),
|
| 657 |
+
base,
|
| 658 |
+
)
|
| 659 |
+
with TemporaryDirectory() as temp_dir:
|
| 660 |
+
_archive_dest = Cli.choose_archive_dest(archive_dest, keep, temp_dir)
|
| 661 |
+
run_installer(tool_archives.get_packages(), base_dir, sevenzip, keep, _archive_dest, dry_run=args.dry_run)
|
| 662 |
+
self.logger.info("Finished installation")
|
| 663 |
+
self.logger.info("Time elapsed: {time:.8f} second".format(time=time.perf_counter() - start_time))
|
| 664 |
+
|
| 665 |
+
def run_list_qt(self, args: ListArgumentParser):
|
| 666 |
+
"""Print versions of Qt, extensions, modules, architectures"""
|
| 667 |
+
|
| 668 |
+
if hasattr(args, "use_official_installer") and args.use_official_installer is not None:
|
| 669 |
+
|
| 670 |
+
if len(args.use_official_installer) not in [0, 2]:
|
| 671 |
+
raise CliInputError(
|
| 672 |
+
"When providing arguments to --use-official-installer, exactly 2 arguments are required: "
|
| 673 |
+
"--use-official-installer email password"
|
| 674 |
+
)
|
| 675 |
+
|
| 676 |
+
self.logger.info("Using official Qt installer for search")
|
| 677 |
+
|
| 678 |
+
commercial_search_args = ListArgumentParser()
|
| 679 |
+
|
| 680 |
+
email = None
|
| 681 |
+
password = None
|
| 682 |
+
if len(args.use_official_installer) == 2:
|
| 683 |
+
email, password = args.use_official_installer
|
| 684 |
+
self.logger.info("Using credentials provided with --use-official-installer")
|
| 685 |
+
|
| 686 |
+
commercial_search_args.email = email or getattr(args, "email", None)
|
| 687 |
+
commercial_search_args.pw = password or getattr(args, "pw", None)
|
| 688 |
+
|
| 689 |
+
target_str = ""
|
| 690 |
+
version_str = ""
|
| 691 |
+
if hasattr(args, "target") and args.target is not None:
|
| 692 |
+
target_str = args.target
|
| 693 |
+
if hasattr(args, "arch") and args.arch is not None:
|
| 694 |
+
try:
|
| 695 |
+
version = Version(args.arch)
|
| 696 |
+
version_str = f"{version.major}{version.minor}{version.patch}"
|
| 697 |
+
except Exception as e:
|
| 698 |
+
self.logger.warning(f"{e}. Ignoring 'arch' value")
|
| 699 |
+
|
| 700 |
+
commercial_search_args.search_terms = [rf"^.*{re.escape(version_str)}\.{re.escape(target_str)}.*$"]
|
| 701 |
+
|
| 702 |
+
ignored_options = []
|
| 703 |
+
if getattr(args, "extensions", False):
|
| 704 |
+
ignored_options.append("--extensions")
|
| 705 |
+
if getattr(args, "extension", False):
|
| 706 |
+
ignored_options.append("--extension")
|
| 707 |
+
if getattr(args, "modules", None):
|
| 708 |
+
ignored_options.append("--modules")
|
| 709 |
+
if getattr(args, "long_modules", False):
|
| 710 |
+
ignored_options.append("--long_modules")
|
| 711 |
+
if getattr(args, "spec", False):
|
| 712 |
+
ignored_options.append("--spec")
|
| 713 |
+
if getattr(args, "archives", False):
|
| 714 |
+
ignored_options.append("--archives")
|
| 715 |
+
if getattr(args, "latest-version", False):
|
| 716 |
+
ignored_options.append("--latest-version")
|
| 717 |
+
|
| 718 |
+
if ignored_options:
|
| 719 |
+
self.logger.warning("Options ignored because you requested the official installer:")
|
| 720 |
+
self.logger.warning(", ".join(ignored_options))
|
| 721 |
+
|
| 722 |
+
return self.run_list_qt_commercial(commercial_search_args, print_version=False)
|
| 723 |
+
|
| 724 |
+
if args.extensions:
|
| 725 |
+
self._warn_on_deprecated_parameter("extensions", args.extensions)
|
| 726 |
+
self.logger.warning(
|
| 727 |
+
"The '--extensions' flag will always return an empty list, "
|
| 728 |
+
"because there are no useful arguments for the '--extension' flag."
|
| 729 |
+
)
|
| 730 |
+
print("")
|
| 731 |
+
return
|
| 732 |
+
if args.extension:
|
| 733 |
+
self._warn_on_deprecated_parameter("extension", args.extension)
|
| 734 |
+
self.logger.warning("The '--extension' flag will be ignored.")
|
| 735 |
+
|
| 736 |
+
if not args.target:
|
| 737 |
+
print(" ".join(ArchiveId.TARGETS_FOR_HOST[args.host]))
|
| 738 |
+
return
|
| 739 |
+
if args.target not in ArchiveId.TARGETS_FOR_HOST[args.host]:
|
| 740 |
+
raise CliInputError("'{0.target}' is not a valid target for host '{0.host}'".format(args))
|
| 741 |
+
if args.modules:
|
| 742 |
+
assert len(args.modules) == 2, "broken argument parser for list-qt"
|
| 743 |
+
modules_query = MetadataFactory.ModulesQuery(args.modules[0], args.modules[1])
|
| 744 |
+
modules_ver, is_long = args.modules[0], False
|
| 745 |
+
elif args.long_modules:
|
| 746 |
+
assert args.long_modules and len(args.long_modules) == 2, "broken argument parser for list-qt"
|
| 747 |
+
modules_query = MetadataFactory.ModulesQuery(args.long_modules[0], args.long_modules[1])
|
| 748 |
+
modules_ver, is_long = args.long_modules[0], True
|
| 749 |
+
else:
|
| 750 |
+
modules_ver, modules_query, is_long = None, None, False
|
| 751 |
+
|
| 752 |
+
for version_str in (modules_ver, args.arch, args.archives[0] if args.archives else None):
|
| 753 |
+
Cli._validate_version_str(version_str, allow_latest=True, allow_empty=True)
|
| 754 |
+
|
| 755 |
+
spec = None
|
| 756 |
+
try:
|
| 757 |
+
if args.spec is not None:
|
| 758 |
+
spec = SimpleSpec(args.spec)
|
| 759 |
+
except ValueError as e:
|
| 760 |
+
raise CliInputError(f"Invalid version specification: '{args.spec}'.\n" + SimpleSpec.usage()) from e
|
| 761 |
+
|
| 762 |
+
meta = MetadataFactory(
|
| 763 |
+
archive_id=ArchiveId("qt", args.host, args.target),
|
| 764 |
+
spec=spec,
|
| 765 |
+
is_latest_version=args.latest_version,
|
| 766 |
+
modules_query=modules_query,
|
| 767 |
+
is_long_listing=is_long,
|
| 768 |
+
architectures_ver=args.arch,
|
| 769 |
+
archives_query=args.archives,
|
| 770 |
+
)
|
| 771 |
+
show_list(meta)
|
| 772 |
+
|
| 773 |
+
def run_list_tool(self, args: ListToolArgumentParser):
|
| 774 |
+
"""Print tools"""
|
| 775 |
+
|
| 776 |
+
if not args.target:
|
| 777 |
+
print(" ".join(ArchiveId.TARGETS_FOR_HOST[args.host]))
|
| 778 |
+
return
|
| 779 |
+
if args.target not in ArchiveId.TARGETS_FOR_HOST[args.host]:
|
| 780 |
+
raise CliInputError("'{0.target}' is not a valid target for host '{0.host}'".format(args))
|
| 781 |
+
|
| 782 |
+
meta = MetadataFactory(
|
| 783 |
+
archive_id=ArchiveId("tools", args.host, args.target),
|
| 784 |
+
tool_name=args.tool_name,
|
| 785 |
+
is_long_listing=args.long,
|
| 786 |
+
)
|
| 787 |
+
show_list(meta)
|
| 788 |
+
|
| 789 |
+
def run_list_src_doc_examples(self, args: ListArgumentParser, cmd_type: str):
|
| 790 |
+
target = "desktop"
|
| 791 |
+
version = Cli._determine_qt_version(args.qt_version_spec, args.host, target, arch="")
|
| 792 |
+
if version >= Version("6.7.0"):
|
| 793 |
+
target = "qt"
|
| 794 |
+
host = "all_os"
|
| 795 |
+
else:
|
| 796 |
+
host = args.host
|
| 797 |
+
is_fetch_modules: bool = getattr(args, "modules", False)
|
| 798 |
+
meta = MetadataFactory(
|
| 799 |
+
archive_id=ArchiveId("qt", host, target),
|
| 800 |
+
src_doc_examples_query=MetadataFactory.SrcDocExamplesQuery(cmd_type, version, is_fetch_modules),
|
| 801 |
+
)
|
| 802 |
+
show_list(meta)
|
| 803 |
+
|
| 804 |
+
def run_install_qt_commercial(self, args: InstallArgParser, print_version: Optional[bool] = True) -> None:
|
| 805 |
+
"""Execute commercial Qt installation"""
|
| 806 |
+
if print_version:
|
| 807 |
+
self.show_aqt_version()
|
| 808 |
+
|
| 809 |
+
try:
|
| 810 |
+
if args.override:
|
| 811 |
+
username, password, override_args = extract_auth(args.override)
|
| 812 |
+
commercial_installer = CommercialInstaller(
|
| 813 |
+
target="", # Empty string as placeholder
|
| 814 |
+
arch="",
|
| 815 |
+
version=None,
|
| 816 |
+
logger=self.logger,
|
| 817 |
+
base_url=args.base if args.base is not None else Settings.baseurl,
|
| 818 |
+
override=override_args,
|
| 819 |
+
no_unattended=not Settings.qt_installer_unattended,
|
| 820 |
+
username=username or args.email,
|
| 821 |
+
password=password or args.pw,
|
| 822 |
+
dry_run=args.dry_run,
|
| 823 |
+
)
|
| 824 |
+
else:
|
| 825 |
+
if not all([args.target, args.arch, args.version]):
|
| 826 |
+
raise CliInputError("target, arch, and version are required")
|
| 827 |
+
|
| 828 |
+
commercial_installer = CommercialInstaller(
|
| 829 |
+
target=args.target,
|
| 830 |
+
arch=args.arch,
|
| 831 |
+
version=args.version,
|
| 832 |
+
username=args.email,
|
| 833 |
+
password=args.pw,
|
| 834 |
+
output_dir=args.outputdir,
|
| 835 |
+
logger=self.logger,
|
| 836 |
+
base_url=args.base if args.base is not None else Settings.baseurl,
|
| 837 |
+
no_unattended=not Settings.qt_installer_unattended,
|
| 838 |
+
modules=args.modules,
|
| 839 |
+
dry_run=args.dry_run,
|
| 840 |
+
)
|
| 841 |
+
|
| 842 |
+
commercial_installer.install()
|
| 843 |
+
Settings.qt_installer_cleanup()
|
| 844 |
+
except Exception as e:
|
| 845 |
+
self.logger.error(f"Error installing official installer: {str(e)}")
|
| 846 |
+
finally:
|
| 847 |
+
self.logger.info("Done")
|
| 848 |
+
|
| 849 |
+
def show_help(self, args=None):
|
| 850 |
+
"""Display help message"""
|
| 851 |
+
self.parser.print_help()
|
| 852 |
+
|
| 853 |
+
def _format_aqt_version(self) -> str:
|
| 854 |
+
py_version = platform.python_version()
|
| 855 |
+
py_impl = platform.python_implementation()
|
| 856 |
+
py_build = platform.python_compiler()
|
| 857 |
+
return f"aqtinstall(aqt) v{aqt.__version__} on Python {py_version} [{py_impl} {py_build}]"
|
| 858 |
+
|
| 859 |
+
def show_aqt_version(self, args: Optional[list[str]] = None) -> None:
|
| 860 |
+
"""Display version information"""
|
| 861 |
+
self.logger.info(self._format_aqt_version())
|
| 862 |
+
|
| 863 |
+
def _set_install_qt_parser(self, install_qt_parser):
|
| 864 |
+
install_qt_parser.set_defaults(func=self.run_install_qt)
|
| 865 |
+
install_qt_parser.add_argument(
|
| 866 |
+
"host",
|
| 867 |
+
choices=["linux", "linux_arm64", "mac", "windows", "windows_arm64", "all_os"],
|
| 868 |
+
help="host os name",
|
| 869 |
+
)
|
| 870 |
+
install_qt_parser.add_argument(
|
| 871 |
+
"target",
|
| 872 |
+
choices=["desktop", "winrt", "android", "ios", "wasm", "qt"],
|
| 873 |
+
help="Target SDK",
|
| 874 |
+
)
|
| 875 |
+
install_qt_parser.add_argument(
|
| 876 |
+
"qt_version_spec",
|
| 877 |
+
metavar="(VERSION | SPECIFICATION)",
|
| 878 |
+
help='Qt version in the format of "5.X.Y" or SimpleSpec like "5.X" or "<6.X"',
|
| 879 |
+
)
|
| 880 |
+
install_qt_parser.add_argument(
|
| 881 |
+
"arch",
|
| 882 |
+
nargs="?",
|
| 883 |
+
help="\ntarget linux/desktop: linux_gcc_64, gcc_64, wasm_32"
|
| 884 |
+
"\ntarget mac/desktop: clang_64, wasm_32"
|
| 885 |
+
"\ntarget mac/ios: ios"
|
| 886 |
+
"\nwindows/desktop: win64_msvc2022_64"
|
| 887 |
+
"\n win64_msvc2019_64, win32_msvc2019"
|
| 888 |
+
"\n win64_msvc2017_64, win32_msvc2017"
|
| 889 |
+
"\n win64_msvc2015_64, win32_msvc2015"
|
| 890 |
+
"\n win64_mingw81, win32_mingw81"
|
| 891 |
+
"\n win64_mingw73, win32_mingw73"
|
| 892 |
+
"\n win32_mingw53"
|
| 893 |
+
"\n wasm_32"
|
| 894 |
+
"\nwindows/winrt: win64_msvc2019_winrt_x64, win64_msvc2019_winrt_x86"
|
| 895 |
+
"\n win64_msvc2017_winrt_x64, win64_msvc2017_winrt_x86"
|
| 896 |
+
"\n win64_msvc2019_winrt_armv7"
|
| 897 |
+
"\n win64_msvc2017_winrt_armv7"
|
| 898 |
+
"\nandroid: Qt 5.14: android (optional)"
|
| 899 |
+
"\n Qt 5.13 or below: android_x86_64, android_arm64_v8a"
|
| 900 |
+
"\n android_x86, android_armv7"
|
| 901 |
+
"\nall_os/wasm: wasm_singlethread, wasm_multithread",
|
| 902 |
+
)
|
| 903 |
+
self._set_common_options(install_qt_parser)
|
| 904 |
+
self._set_module_options(install_qt_parser)
|
| 905 |
+
self._set_archive_options(install_qt_parser)
|
| 906 |
+
install_qt_parser.add_argument(
|
| 907 |
+
"--noarchives",
|
| 908 |
+
action="store_true",
|
| 909 |
+
help="No base packages; allow mod amendment with --modules option.",
|
| 910 |
+
)
|
| 911 |
+
install_qt_parser.add_argument(
|
| 912 |
+
"--autodesktop",
|
| 913 |
+
action="store_true",
|
| 914 |
+
help="For Qt6 android, ios, wasm, and msvc_arm64 installations, an additional desktop Qt installation is "
|
| 915 |
+
"required. When enabled, this option installs the required desktop version automatically. "
|
| 916 |
+
"It has no effect when the desktop installation is not required.",
|
| 917 |
+
)
|
| 918 |
+
install_qt_parser.add_argument(
|
| 919 |
+
"--use-official-installer",
|
| 920 |
+
nargs="*",
|
| 921 |
+
default=None,
|
| 922 |
+
metavar=("EMAIL", "PASSWORD"),
|
| 923 |
+
help="Use the official Qt installer for installation instead of the aqt downloader. "
|
| 924 |
+
"Can be used without arguments or with email and password: --use-official-installer email password. "
|
| 925 |
+
"This redirects to install-qt-official. "
|
| 926 |
+
"Arguments not compatible with the official installer will be ignored.",
|
| 927 |
+
)
|
| 928 |
+
|
| 929 |
+
def _set_install_tool_parser(self, install_tool_parser):
|
| 930 |
+
install_tool_parser.set_defaults(func=self.run_install_tool)
|
| 931 |
+
install_tool_parser.add_argument(
|
| 932 |
+
"host",
|
| 933 |
+
choices=["linux", "linux_arm64", "mac", "windows", "windows_arm64", "all_os"],
|
| 934 |
+
help="host os name",
|
| 935 |
+
)
|
| 936 |
+
install_tool_parser.add_argument(
|
| 937 |
+
"target",
|
| 938 |
+
default=None,
|
| 939 |
+
choices=["desktop", "winrt", "android", "ios", "wasm", "qt"],
|
| 940 |
+
help="Target SDK.",
|
| 941 |
+
)
|
| 942 |
+
install_tool_parser.add_argument("tool_name", help="Name of tool such as tools_ifw, tools_mingw")
|
| 943 |
+
|
| 944 |
+
tool_variant_opts = {"nargs": "?", "default": None}
|
| 945 |
+
install_tool_parser.add_argument(
|
| 946 |
+
"tool_variant",
|
| 947 |
+
**tool_variant_opts,
|
| 948 |
+
help="Name of tool variant, such as qt.tools.ifw.41. "
|
| 949 |
+
"Please use 'aqt list-tool' to list acceptable values for this parameter.",
|
| 950 |
+
)
|
| 951 |
+
self._set_common_options(install_tool_parser)
|
| 952 |
+
|
| 953 |
+
def _set_install_qt_commercial_parser(self, install_qt_commercial_parser: argparse.ArgumentParser) -> None:
|
| 954 |
+
install_qt_commercial_parser.set_defaults(func=self.run_install_qt_commercial)
|
| 955 |
+
|
| 956 |
+
# Create mutually exclusive group for override vs standard parameters
|
| 957 |
+
exclusive_group = install_qt_commercial_parser.add_mutually_exclusive_group()
|
| 958 |
+
exclusive_group.add_argument(
|
| 959 |
+
"--override",
|
| 960 |
+
nargs=argparse.REMAINDER,
|
| 961 |
+
help="Will ignore all other parameters and use everything after this parameter as "
|
| 962 |
+
"input for the official Qt installer",
|
| 963 |
+
)
|
| 964 |
+
|
| 965 |
+
# Make standard arguments optional when override is used by adding a custom action
|
| 966 |
+
class ConditionalRequiredAction(argparse.Action):
|
| 967 |
+
def __call__(self, parser, namespace, values, option_string=None) -> None:
|
| 968 |
+
if not hasattr(namespace, "override") or not namespace.override:
|
| 969 |
+
setattr(namespace, self.dest, values)
|
| 970 |
+
|
| 971 |
+
install_qt_commercial_parser.add_argument(
|
| 972 |
+
"target",
|
| 973 |
+
nargs="?",
|
| 974 |
+
choices=["desktop", "android", "ios"],
|
| 975 |
+
help="Target platform",
|
| 976 |
+
action=ConditionalRequiredAction,
|
| 977 |
+
)
|
| 978 |
+
install_qt_commercial_parser.add_argument(
|
| 979 |
+
"arch", nargs="?", help="Target architecture", action=ConditionalRequiredAction
|
| 980 |
+
)
|
| 981 |
+
install_qt_commercial_parser.add_argument("version", nargs="?", help="Qt version", action=ConditionalRequiredAction)
|
| 982 |
+
|
| 983 |
+
install_qt_commercial_parser.add_argument(
|
| 984 |
+
"--email",
|
| 985 |
+
help="Qt account email",
|
| 986 |
+
)
|
| 987 |
+
install_qt_commercial_parser.add_argument(
|
| 988 |
+
"--pw",
|
| 989 |
+
help="Qt account password",
|
| 990 |
+
)
|
| 991 |
+
install_qt_commercial_parser.add_argument(
|
| 992 |
+
"-m",
|
| 993 |
+
"--modules",
|
| 994 |
+
nargs="*",
|
| 995 |
+
help="Add modules",
|
| 996 |
+
)
|
| 997 |
+
self._set_common_options(install_qt_commercial_parser)
|
| 998 |
+
|
| 999 |
+
def _set_list_qt_commercial_parser(self, list_qt_commercial_parser: argparse.ArgumentParser) -> None:
|
| 1000 |
+
"""Configure parser for list-qt-official command with flexible argument handling."""
|
| 1001 |
+
list_qt_commercial_parser.set_defaults(func=self.run_list_qt_commercial)
|
| 1002 |
+
|
| 1003 |
+
list_qt_commercial_parser.add_argument(
|
| 1004 |
+
"--email",
|
| 1005 |
+
help="Qt account email",
|
| 1006 |
+
)
|
| 1007 |
+
list_qt_commercial_parser.add_argument(
|
| 1008 |
+
"--pw",
|
| 1009 |
+
help="Qt account password",
|
| 1010 |
+
)
|
| 1011 |
+
|
| 1012 |
+
# Capture all remaining arguments as search terms
|
| 1013 |
+
list_qt_commercial_parser.add_argument(
|
| 1014 |
+
"search_terms",
|
| 1015 |
+
nargs="*", # Zero or more arguments
|
| 1016 |
+
help="Search terms (all non-option arguments are treated as search terms)",
|
| 1017 |
+
)
|
| 1018 |
+
|
| 1019 |
+
def run_list_qt_commercial(self, args: ListArgumentParser, print_version: Optional[bool] = True) -> None:
|
| 1020 |
+
"""Execute Qt commercial package listing."""
|
| 1021 |
+
if print_version:
|
| 1022 |
+
self.show_aqt_version()
|
| 1023 |
+
|
| 1024 |
+
# Create temporary directory for installer
|
| 1025 |
+
temp_dir = Settings.qt_installer_temp_path
|
| 1026 |
+
temp_path = Path(temp_dir)
|
| 1027 |
+
if not temp_path.exists():
|
| 1028 |
+
temp_path.mkdir(parents=True, exist_ok=True)
|
| 1029 |
+
else:
|
| 1030 |
+
Settings.qt_installer_cleanup()
|
| 1031 |
+
|
| 1032 |
+
# Get installer based on OS
|
| 1033 |
+
installer_filename = get_qt_installer_name()
|
| 1034 |
+
installer_path = temp_path / installer_filename
|
| 1035 |
+
|
| 1036 |
+
try:
|
| 1037 |
+
# Download installer
|
| 1038 |
+
self.logger.info(f"Downloading Qt installer to {installer_path}")
|
| 1039 |
+
timeout = (Settings.connection_timeout, Settings.response_timeout)
|
| 1040 |
+
download_installer(Settings.baseurl, installer_filename, installer_path, timeout)
|
| 1041 |
+
installer_path = prepare_installer(installer_path, get_os_name())
|
| 1042 |
+
|
| 1043 |
+
# Build command
|
| 1044 |
+
cmd = [str(installer_path), "--accept-licenses", "--accept-obligations", "--confirm-command"]
|
| 1045 |
+
|
| 1046 |
+
if args.email and args.pw:
|
| 1047 |
+
cmd.extend(["--email", args.email, "--pw", args.pw])
|
| 1048 |
+
|
| 1049 |
+
cmd.append("search")
|
| 1050 |
+
|
| 1051 |
+
# Add all search terms if present
|
| 1052 |
+
if args.search_terms:
|
| 1053 |
+
cmd.extend(args.search_terms)
|
| 1054 |
+
|
| 1055 |
+
# Run search
|
| 1056 |
+
output = safely_run_save_output(cmd, Settings.qt_installer_timeout)
|
| 1057 |
+
|
| 1058 |
+
if output.stdout:
|
| 1059 |
+
self.logger.info(output.stdout)
|
| 1060 |
+
if output.stderr:
|
| 1061 |
+
for line in output.stderr.splitlines():
|
| 1062 |
+
self.logger.warning(line)
|
| 1063 |
+
|
| 1064 |
+
except Exception as e:
|
| 1065 |
+
self.logger.error(f"Failed to list Qt official packages: {e}")
|
| 1066 |
+
finally:
|
| 1067 |
+
Settings.qt_installer_cleanup()
|
| 1068 |
+
|
| 1069 |
+
def _warn_on_deprecated_command(self, old_name: str, new_name: str) -> None:
|
| 1070 |
+
self.logger.warning(
|
| 1071 |
+
f"The command '{old_name}' is deprecated and marked for removal in a future version of aqt.\n"
|
| 1072 |
+
f"In the future, please use the command '{new_name}' instead."
|
| 1073 |
+
)
|
| 1074 |
+
|
| 1075 |
+
def _warn_on_deprecated_parameter(self, parameter_name: str, value: str):
|
| 1076 |
+
self.logger.warning(
|
| 1077 |
+
f"The parameter '{parameter_name}' with value '{value}' is deprecated and marked for "
|
| 1078 |
+
f"removal in a future version of aqt.\n"
|
| 1079 |
+
f"In the future, please omit this parameter."
|
| 1080 |
+
)
|
| 1081 |
+
|
| 1082 |
+
def _make_all_parsers(self, subparsers: argparse._SubParsersAction) -> None:
|
| 1083 |
+
"""Creates all command parsers and adds them to the subparsers"""
|
| 1084 |
+
|
| 1085 |
+
def make_parser_it(cmd: str, desc: str, set_parser_cmd, formatter_class):
|
| 1086 |
+
kwargs = {"formatter_class": formatter_class} if formatter_class else {}
|
| 1087 |
+
p = subparsers.add_parser(cmd, description=desc, **kwargs)
|
| 1088 |
+
set_parser_cmd(p)
|
| 1089 |
+
|
| 1090 |
+
def make_parser_sde(cmd: str, desc: str, action, is_add_kde: bool, is_add_modules: bool = True):
|
| 1091 |
+
parser = subparsers.add_parser(cmd, description=desc)
|
| 1092 |
+
parser.set_defaults(func=action)
|
| 1093 |
+
self._set_common_arguments(parser, is_target_deprecated=True)
|
| 1094 |
+
self._set_common_options(parser)
|
| 1095 |
+
if is_add_modules:
|
| 1096 |
+
self._set_module_options(parser)
|
| 1097 |
+
self._set_archive_options(parser)
|
| 1098 |
+
if is_add_kde:
|
| 1099 |
+
parser.add_argument("--kde", action="store_true", help="patching with KDE patch kit.")
|
| 1100 |
+
|
| 1101 |
+
def make_parser_list_sde(cmd: str, desc: str, cmd_type: str):
|
| 1102 |
+
parser = subparsers.add_parser(cmd, description=desc)
|
| 1103 |
+
parser.add_argument(
|
| 1104 |
+
"host",
|
| 1105 |
+
choices=["linux", "linux_arm64", "mac", "windows", "windows_arm64", "all_os"],
|
| 1106 |
+
help="host os name",
|
| 1107 |
+
)
|
| 1108 |
+
parser.add_argument(
|
| 1109 |
+
"qt_version_spec",
|
| 1110 |
+
metavar="(VERSION | SPECIFICATION)",
|
| 1111 |
+
help='Qt version in the format of "5.X.Y" or SimpleSpec like "5.X" or "<6.X"',
|
| 1112 |
+
)
|
| 1113 |
+
parser.set_defaults(func=lambda args: self.run_list_src_doc_examples(args, cmd_type))
|
| 1114 |
+
|
| 1115 |
+
if cmd_type != "src":
|
| 1116 |
+
parser.add_argument("-m", "--modules", action="store_true", help="Print list of available modules")
|
| 1117 |
+
|
| 1118 |
+
# Create install command parsers
|
| 1119 |
+
make_parser_it("install-qt", "Install Qt.", self._set_install_qt_parser, argparse.RawTextHelpFormatter)
|
| 1120 |
+
make_parser_it("install-tool", "Install tools.", self._set_install_tool_parser, None)
|
| 1121 |
+
make_parser_it(
|
| 1122 |
+
"install-qt-official",
|
| 1123 |
+
"Install Qt with official installer.",
|
| 1124 |
+
self._set_install_qt_commercial_parser,
|
| 1125 |
+
argparse.RawTextHelpFormatter,
|
| 1126 |
+
)
|
| 1127 |
+
make_parser_it(
|
| 1128 |
+
"list-qt-official",
|
| 1129 |
+
"Search packages using Qt official installer.",
|
| 1130 |
+
self._set_list_qt_commercial_parser,
|
| 1131 |
+
argparse.RawTextHelpFormatter,
|
| 1132 |
+
)
|
| 1133 |
+
make_parser_sde("install-doc", "Install documentation.", self.run_install_doc, False)
|
| 1134 |
+
make_parser_sde("install-example", "Install examples.", self.run_install_example, False)
|
| 1135 |
+
make_parser_sde("install-src", "Install source.", self.run_install_src, True, is_add_modules=False)
|
| 1136 |
+
|
| 1137 |
+
# Create list command parsers
|
| 1138 |
+
self._make_list_qt_parser(subparsers)
|
| 1139 |
+
self._make_list_tool_parser(subparsers)
|
| 1140 |
+
make_parser_list_sde("list-doc", "List documentation archives available (use with install-doc)", "doc")
|
| 1141 |
+
make_parser_list_sde("list-example", "List example archives available (use with install-example)", "examples")
|
| 1142 |
+
make_parser_list_sde("list-src", "List source archives available (use with install-src)", "src")
|
| 1143 |
+
|
| 1144 |
+
self._make_common_parsers(subparsers)
|
| 1145 |
+
|
| 1146 |
+
def _make_list_qt_parser(self, subparsers: argparse._SubParsersAction):
|
| 1147 |
+
"""Creates a subparser that works with the MetadataFactory, and adds it to the `subparsers` parameter"""
|
| 1148 |
+
list_parser: ListArgumentParser = subparsers.add_parser(
|
| 1149 |
+
"list-qt",
|
| 1150 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 1151 |
+
epilog="Examples:\n"
|
| 1152 |
+
"$ aqt list-qt mac # print all targets for Mac OS\n"
|
| 1153 |
+
"$ aqt list-qt mac desktop # print all versions of Qt 5\n"
|
| 1154 |
+
'$ aqt list-qt mac desktop --spec "5.9" # print all versions of Qt 5.9\n'
|
| 1155 |
+
'$ aqt list-qt mac desktop --spec "5.9" --latest-version # print latest Qt 5.9\n'
|
| 1156 |
+
"$ aqt list-qt mac desktop --modules 5.12.0 clang_64 # print modules for 5.12.0\n"
|
| 1157 |
+
"$ aqt list-qt mac desktop --spec 5.9 --modules latest clang_64 # print modules for latest 5.9\n"
|
| 1158 |
+
"$ aqt list-qt mac desktop --arch 5.9.9 # print architectures for "
|
| 1159 |
+
"5.9.9/mac/desktop\n"
|
| 1160 |
+
"$ aqt list-qt mac desktop --arch latest # print architectures for the "
|
| 1161 |
+
"latest Qt 5\n"
|
| 1162 |
+
"$ aqt list-qt mac desktop --archives 5.9.0 clang_64 # list archives in base Qt "
|
| 1163 |
+
"installation\n"
|
| 1164 |
+
"$ aqt list-qt mac desktop --archives 5.14.0 clang_64 debug_info # list archives in debug_info "
|
| 1165 |
+
"module\n"
|
| 1166 |
+
"$ aqt list-qt all_os wasm --arch 6.8.1 # print architectures for Qt WASM "
|
| 1167 |
+
"6.8.1\n",
|
| 1168 |
+
)
|
| 1169 |
+
list_parser.add_argument(
|
| 1170 |
+
"host",
|
| 1171 |
+
choices=["linux", "linux_arm64", "mac", "windows", "windows_arm64", "all_os"],
|
| 1172 |
+
help="host os name",
|
| 1173 |
+
)
|
| 1174 |
+
list_parser.add_argument(
|
| 1175 |
+
"target",
|
| 1176 |
+
nargs="?",
|
| 1177 |
+
default=None,
|
| 1178 |
+
choices=["desktop", "winrt", "android", "ios", "wasm", "qt"],
|
| 1179 |
+
help="Target SDK. When omitted, this prints all the targets available for a host OS.",
|
| 1180 |
+
)
|
| 1181 |
+
list_parser.add_argument(
|
| 1182 |
+
"--extension",
|
| 1183 |
+
choices=ArchiveId.ALL_EXTENSIONS,
|
| 1184 |
+
help="Deprecated since aqt v3.1.0. Use of this flag will emit a warning, but will otherwise be ignored.",
|
| 1185 |
+
)
|
| 1186 |
+
list_parser.add_argument(
|
| 1187 |
+
"--spec",
|
| 1188 |
+
type=str,
|
| 1189 |
+
metavar="SPECIFICATION",
|
| 1190 |
+
help="Filter output so that only versions that match the specification are printed. "
|
| 1191 |
+
'IE: `aqt list-qt windows desktop --spec "5.12"` prints all versions beginning with 5.12',
|
| 1192 |
+
)
|
| 1193 |
+
list_parser.add_argument(
|
| 1194 |
+
"--use-official-installer",
|
| 1195 |
+
nargs="*",
|
| 1196 |
+
default=None,
|
| 1197 |
+
metavar=("EMAIL", "PASSWORD"),
|
| 1198 |
+
help="Use the official Qt installer for research instead of the aqt researcher. "
|
| 1199 |
+
"Can be used without arguments or with email and password: --use-official-installer email password. "
|
| 1200 |
+
"This redirects to list-qt-official. "
|
| 1201 |
+
"Arguments not compatible with the official installer will be ignored.",
|
| 1202 |
+
)
|
| 1203 |
+
output_modifier_exclusive_group = list_parser.add_mutually_exclusive_group()
|
| 1204 |
+
output_modifier_exclusive_group.add_argument(
|
| 1205 |
+
"--modules",
|
| 1206 |
+
type=str,
|
| 1207 |
+
nargs=2,
|
| 1208 |
+
metavar=("(VERSION | latest)", "ARCHITECTURE"),
|
| 1209 |
+
help='First arg: Qt version in the format of "5.X.Y", or the keyword "latest". '
|
| 1210 |
+
'Second arg: an architecture, which may be printed with the "--arch" flag. '
|
| 1211 |
+
"When set, this prints all the modules available for either Qt 5.X.Y or the latest version of Qt.",
|
| 1212 |
+
)
|
| 1213 |
+
output_modifier_exclusive_group.add_argument(
|
| 1214 |
+
"--long-modules",
|
| 1215 |
+
type=str,
|
| 1216 |
+
nargs=2,
|
| 1217 |
+
metavar=("(VERSION | latest)", "ARCHITECTURE"),
|
| 1218 |
+
help='First arg: Qt version in the format of "5.X.Y", or the keyword "latest". '
|
| 1219 |
+
'Second arg: an architecture, which may be printed with the "--arch" flag. '
|
| 1220 |
+
"When set, this prints a table that describes all the modules available "
|
| 1221 |
+
"for either Qt 5.X.Y or the latest version of Qt.",
|
| 1222 |
+
)
|
| 1223 |
+
output_modifier_exclusive_group.add_argument(
|
| 1224 |
+
"--extensions",
|
| 1225 |
+
type=str,
|
| 1226 |
+
metavar="(VERSION | latest)",
|
| 1227 |
+
help="Deprecated since v3.1.0. Prints a list of valid arguments for the '--extension' flag. "
|
| 1228 |
+
"Since the '--extension' flag is now deprecated, this will always print an empty list.",
|
| 1229 |
+
)
|
| 1230 |
+
output_modifier_exclusive_group.add_argument(
|
| 1231 |
+
"--arch",
|
| 1232 |
+
type=str,
|
| 1233 |
+
metavar="(VERSION | latest)",
|
| 1234 |
+
help='Qt version in the format of "5.X.Y", or the keyword "latest". '
|
| 1235 |
+
"When set, this prints all architectures available for either Qt 5.X.Y or the latest version of Qt.",
|
| 1236 |
+
)
|
| 1237 |
+
output_modifier_exclusive_group.add_argument(
|
| 1238 |
+
"--latest-version",
|
| 1239 |
+
action="store_true",
|
| 1240 |
+
help="print only the newest version available",
|
| 1241 |
+
)
|
| 1242 |
+
output_modifier_exclusive_group.add_argument(
|
| 1243 |
+
"--archives",
|
| 1244 |
+
type=str,
|
| 1245 |
+
nargs="+",
|
| 1246 |
+
help="print the archives available for Qt base or modules. "
|
| 1247 |
+
"If two arguments are provided, the first two arguments must be 'VERSION | latest' and "
|
| 1248 |
+
"'ARCHITECTURE', and this command will print all archives associated with the base Qt package. "
|
| 1249 |
+
"If more than two arguments are provided, the remaining arguments will be interpreted as modules, "
|
| 1250 |
+
"and this command will print all archives associated with those modules. "
|
| 1251 |
+
"At least two arguments are required.",
|
| 1252 |
+
)
|
| 1253 |
+
list_parser.set_defaults(func=self.run_list_qt)
|
| 1254 |
+
|
| 1255 |
+
def _make_list_tool_parser(self, subparsers: argparse._SubParsersAction):
|
| 1256 |
+
"""Creates a subparser that works with the MetadataFactory, and adds it to the `subparsers` parameter"""
|
| 1257 |
+
list_parser: ListArgumentParser = subparsers.add_parser(
|
| 1258 |
+
"list-tool",
|
| 1259 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 1260 |
+
epilog="Examples:\n"
|
| 1261 |
+
"$ aqt list-tool mac desktop # print all tools for mac desktop\n"
|
| 1262 |
+
"$ aqt list-tool mac desktop tools_ifw # print all tool variant names for QtIFW\n"
|
| 1263 |
+
"$ aqt list-tool mac desktop ifw # print all tool variant names for QtIFW\n"
|
| 1264 |
+
"$ aqt list-tool mac desktop tools_ifw --long # print tool variant names with metadata for QtIFW\n"
|
| 1265 |
+
"$ aqt list-tool mac desktop ifw --long # print tool variant names with metadata for QtIFW\n",
|
| 1266 |
+
)
|
| 1267 |
+
list_parser.add_argument(
|
| 1268 |
+
"host",
|
| 1269 |
+
choices=["linux", "linux_arm64", "mac", "windows", "windows_arm64", "all_os"],
|
| 1270 |
+
help="host os name",
|
| 1271 |
+
)
|
| 1272 |
+
list_parser.add_argument(
|
| 1273 |
+
"target",
|
| 1274 |
+
nargs="?",
|
| 1275 |
+
default=None,
|
| 1276 |
+
choices=["desktop", "winrt", "android", "ios", "wasm", "qt"],
|
| 1277 |
+
help="Target SDK. When omitted, this prints all the targets available for a host OS.",
|
| 1278 |
+
)
|
| 1279 |
+
list_parser.add_argument(
|
| 1280 |
+
"tool_name",
|
| 1281 |
+
nargs="?",
|
| 1282 |
+
default=None,
|
| 1283 |
+
help='Name of a tool, ie "tools_mingw" or "tools_ifw". '
|
| 1284 |
+
"When omitted, this prints all the tool names available for a host OS/target SDK combination. "
|
| 1285 |
+
"When present, this prints all the tool variant names available for this tool. ",
|
| 1286 |
+
)
|
| 1287 |
+
list_parser.add_argument(
|
| 1288 |
+
"-l",
|
| 1289 |
+
"--long",
|
| 1290 |
+
action="store_true",
|
| 1291 |
+
help="Long display: shows a table of metadata associated with each tool variant. "
|
| 1292 |
+
"On narrow terminals, it displays tool variant names, versions, and release dates. "
|
| 1293 |
+
"On terminals wider than 95 characters, it also displays descriptions of each tool.",
|
| 1294 |
+
)
|
| 1295 |
+
list_parser.set_defaults(func=self.run_list_tool)
|
| 1296 |
+
|
| 1297 |
+
def _make_common_parsers(self, subparsers: argparse._SubParsersAction) -> None:
|
| 1298 |
+
help_parser = subparsers.add_parser("help")
|
| 1299 |
+
help_parser.set_defaults(func=self.show_help)
|
| 1300 |
+
version_parser = subparsers.add_parser("version")
|
| 1301 |
+
version_parser.set_defaults(func=self.show_aqt_version)
|
| 1302 |
+
|
| 1303 |
+
def _set_common_options(self, subparser: argparse.ArgumentParser) -> None:
|
| 1304 |
+
subparser.add_argument(
|
| 1305 |
+
"-O",
|
| 1306 |
+
"--outputdir",
|
| 1307 |
+
nargs="?",
|
| 1308 |
+
help="Target output directory(default current directory)",
|
| 1309 |
+
)
|
| 1310 |
+
subparser.add_argument(
|
| 1311 |
+
"-b",
|
| 1312 |
+
"--base",
|
| 1313 |
+
nargs="?",
|
| 1314 |
+
help="Specify mirror base url such as http://mirrors.ocf.berkeley.edu/qt/, " "where 'online' folder exist.",
|
| 1315 |
+
)
|
| 1316 |
+
subparser.add_argument(
|
| 1317 |
+
"--timeout",
|
| 1318 |
+
nargs="?",
|
| 1319 |
+
type=float,
|
| 1320 |
+
help="Specify connection timeout for download site.(default: 5 sec)",
|
| 1321 |
+
)
|
| 1322 |
+
subparser.add_argument("-E", "--external", nargs="?", help="Specify external 7zip command path.")
|
| 1323 |
+
subparser.add_argument("--internal", action="store_true", help="Use internal extractor.")
|
| 1324 |
+
subparser.add_argument(
|
| 1325 |
+
"-k",
|
| 1326 |
+
"--keep",
|
| 1327 |
+
action="store_true",
|
| 1328 |
+
help="Keep downloaded archive when specified, otherwise remove after install",
|
| 1329 |
+
)
|
| 1330 |
+
subparser.add_argument(
|
| 1331 |
+
"-d",
|
| 1332 |
+
"--archive-dest",
|
| 1333 |
+
type=str,
|
| 1334 |
+
default=None,
|
| 1335 |
+
help="Set the destination path for downloaded archives (temp directory by default).",
|
| 1336 |
+
)
|
| 1337 |
+
subparser.add_argument(
|
| 1338 |
+
"--dry-run",
|
| 1339 |
+
action="store_true",
|
| 1340 |
+
help="Print what would be downloaded and installed without actually doing it",
|
| 1341 |
+
)
|
| 1342 |
+
subparser.add_argument(
|
| 1343 |
+
"--UNSAFE-ignore-hash",
|
| 1344 |
+
action="store_true",
|
| 1345 |
+
help="UNSAFE: Skip hash verification of downloaded files. Use at your own risk.",
|
| 1346 |
+
)
|
| 1347 |
+
|
| 1348 |
+
def _set_module_options(self, subparser):
|
| 1349 |
+
subparser.add_argument("-m", "--modules", nargs="*", help="Specify extra modules to install")
|
| 1350 |
+
|
| 1351 |
+
def _set_archive_options(self, subparser):
|
| 1352 |
+
subparser.add_argument(
|
| 1353 |
+
"--archives",
|
| 1354 |
+
nargs="*",
|
| 1355 |
+
help="Specify subset of archives to install. Affects the base module and the debug_info module. "
|
| 1356 |
+
"(Default: all archives).",
|
| 1357 |
+
)
|
| 1358 |
+
|
| 1359 |
+
def _set_common_arguments(self, subparser, *, is_target_deprecated: bool = False):
|
| 1360 |
+
"""
|
| 1361 |
+
install-src/doc/example commands do not require a "target" argument anymore, as of 11/22/2021
|
| 1362 |
+
"""
|
| 1363 |
+
subparser.add_argument(
|
| 1364 |
+
"host",
|
| 1365 |
+
choices=["linux", "linux_arm64", "mac", "windows", "windows_arm64", "all_os"],
|
| 1366 |
+
help="host os name",
|
| 1367 |
+
)
|
| 1368 |
+
if is_target_deprecated:
|
| 1369 |
+
subparser.add_argument(
|
| 1370 |
+
"target",
|
| 1371 |
+
choices=["desktop", "winrt", "android", "ios", "wasm", "qt"],
|
| 1372 |
+
nargs="?",
|
| 1373 |
+
help="Ignored. This parameter is deprecated and marked for removal in a future release. "
|
| 1374 |
+
"It is present here for backwards compatibility.",
|
| 1375 |
+
)
|
| 1376 |
+
else:
|
| 1377 |
+
subparser.add_argument(
|
| 1378 |
+
"target",
|
| 1379 |
+
choices=["desktop", "winrt", "android", "ios", "wasm", "qt"],
|
| 1380 |
+
help="target sdk",
|
| 1381 |
+
)
|
| 1382 |
+
subparser.add_argument(
|
| 1383 |
+
"qt_version_spec",
|
| 1384 |
+
metavar="(VERSION | SPECIFICATION)",
|
| 1385 |
+
help='Qt version in the format of "5.X.Y" or SimpleSpec like "5.X" or "<6.X"',
|
| 1386 |
+
)
|
| 1387 |
+
|
| 1388 |
+
def _setup_settings(self, args=None):
|
| 1389 |
+
# setup logging
|
| 1390 |
+
setup_logging()
|
| 1391 |
+
self.logger = getLogger("aqt.main")
|
| 1392 |
+
# setup settings
|
| 1393 |
+
if args is not None and args.config is not None:
|
| 1394 |
+
Settings.load_settings(args.config)
|
| 1395 |
+
else:
|
| 1396 |
+
config = os.getenv("AQT_CONFIG", None)
|
| 1397 |
+
if config is not None and os.path.exists(config):
|
| 1398 |
+
Settings.load_settings(config)
|
| 1399 |
+
self.logger.debug("Load configuration from {}".format(config))
|
| 1400 |
+
else:
|
| 1401 |
+
Settings.load_settings()
|
| 1402 |
+
|
| 1403 |
+
# Set ignore_hash to True if --UNSAFE-ignore-hash flag was passed
|
| 1404 |
+
if args is not None and hasattr(args, "UNSAFE_ignore_hash") and args.UNSAFE_ignore_hash:
|
| 1405 |
+
self.logger.warning(
|
| 1406 |
+
"************************************************************************************************"
|
| 1407 |
+
)
|
| 1408 |
+
self.logger.warning(
|
| 1409 |
+
"Hash verification is disabled. This is UNSAFE and may allow malicious files to be downloaded."
|
| 1410 |
+
)
|
| 1411 |
+
self.logger.warning(
|
| 1412 |
+
"If your install mirror hosts malicious files, you won't be able to know. Use at your own risk."
|
| 1413 |
+
)
|
| 1414 |
+
self.logger.warning(
|
| 1415 |
+
"************************************************************************************************"
|
| 1416 |
+
)
|
| 1417 |
+
Settings.set_ignore_hash_for_session(True)
|
| 1418 |
+
|
| 1419 |
+
@staticmethod
|
| 1420 |
+
def _validate_version_str(
|
| 1421 |
+
version_str: Optional[str],
|
| 1422 |
+
*,
|
| 1423 |
+
allow_latest: bool = False,
|
| 1424 |
+
allow_empty: bool = False,
|
| 1425 |
+
allow_minus: bool = False,
|
| 1426 |
+
) -> None:
|
| 1427 |
+
"""
|
| 1428 |
+
Raise CliInputError if the version is not an acceptable Version.
|
| 1429 |
+
|
| 1430 |
+
:param version_str: The version string to check.
|
| 1431 |
+
:param allow_latest: If true, the string "latest" is acceptable.
|
| 1432 |
+
:param allow_empty: If true, the empty string is acceptable.
|
| 1433 |
+
:param allow_minus: If true, everything after the first '-' in the version will be ignored.
|
| 1434 |
+
This allows acceptance of versions like "1.2.3-0-202101020304"
|
| 1435 |
+
"""
|
| 1436 |
+
if allow_latest and version_str == "latest":
|
| 1437 |
+
return
|
| 1438 |
+
if not version_str:
|
| 1439 |
+
if allow_empty:
|
| 1440 |
+
return
|
| 1441 |
+
else:
|
| 1442 |
+
raise CliInputError("Invalid empty version! Please use the form '5.X.Y'.")
|
| 1443 |
+
try:
|
| 1444 |
+
if "-" in version_str and allow_minus:
|
| 1445 |
+
version_str = version_str[: version_str.find("-")]
|
| 1446 |
+
Version(version_str)
|
| 1447 |
+
except ValueError as e:
|
| 1448 |
+
raise CliInputError(f"Invalid version: '{version_str}'! Please use the form '5.X.Y'.") from e
|
| 1449 |
+
|
| 1450 |
+
def _get_autodesktop_dir_and_arch(
|
| 1451 |
+
self,
|
| 1452 |
+
should_autoinstall: bool,
|
| 1453 |
+
host: str,
|
| 1454 |
+
target: str,
|
| 1455 |
+
base_path: Path,
|
| 1456 |
+
version: Version,
|
| 1457 |
+
arch: str,
|
| 1458 |
+
) -> Tuple[Optional[str], Optional[str]]:
|
| 1459 |
+
"""Returns expected_desktop_arch_dir, desktop_arch_to_install"""
|
| 1460 |
+
is_wasm = arch.startswith("wasm")
|
| 1461 |
+
is_msvc = "msvc" in arch
|
| 1462 |
+
is_win_desktop_msvc_arm64 = (
|
| 1463 |
+
host == "windows" and target == "desktop" and is_msvc and arch.endswith(("arm64", "arm64_cross_compiled"))
|
| 1464 |
+
)
|
| 1465 |
+
if version < Version("6.0.0") or (
|
| 1466 |
+
target not in ["ios", "android", "wasm"] and not is_wasm and not is_win_desktop_msvc_arm64
|
| 1467 |
+
):
|
| 1468 |
+
# We only need to worry about the desktop directory for Qt6 mobile or wasm installs.
|
| 1469 |
+
return None, None
|
| 1470 |
+
|
| 1471 |
+
# For WASM installations on all_os, we need to choose a default desktop host
|
| 1472 |
+
host = Cli._get_effective_os_name(host)
|
| 1473 |
+
|
| 1474 |
+
installed_desktop_arch_dir = QtRepoProperty.find_installed_desktop_qt_dir(host, base_path, version, is_msvc=is_msvc)
|
| 1475 |
+
if installed_desktop_arch_dir:
|
| 1476 |
+
# An acceptable desktop Qt is already installed, so don't do anything.
|
| 1477 |
+
self.logger.info(f"Found installed {host}-desktop Qt at {installed_desktop_arch_dir}")
|
| 1478 |
+
return installed_desktop_arch_dir.name, None
|
| 1479 |
+
|
| 1480 |
+
try:
|
| 1481 |
+
default_desktop_arch = MetadataFactory(ArchiveId("qt", host, "desktop")).fetch_default_desktop_arch(
|
| 1482 |
+
version, is_msvc
|
| 1483 |
+
)
|
| 1484 |
+
except ValueError as e:
|
| 1485 |
+
if "Target 'desktop' is invalid" in str(e):
|
| 1486 |
+
# Special case for all_os host which doesn't support desktop target
|
| 1487 |
+
return None, None
|
| 1488 |
+
raise
|
| 1489 |
+
|
| 1490 |
+
desktop_arch_dir = QtRepoProperty.get_arch_dir_name(host, default_desktop_arch, version)
|
| 1491 |
+
expected_desktop_arch_path = base_path / dir_for_version(version) / desktop_arch_dir
|
| 1492 |
+
|
| 1493 |
+
if is_win_desktop_msvc_arm64:
|
| 1494 |
+
qt_type = "MSVC Arm64"
|
| 1495 |
+
elif is_wasm:
|
| 1496 |
+
qt_type = "Qt6-WASM"
|
| 1497 |
+
else:
|
| 1498 |
+
qt_type = target
|
| 1499 |
+
|
| 1500 |
+
if should_autoinstall:
|
| 1501 |
+
# No desktop Qt is installed, but the user has requested installation. Find out what to install.
|
| 1502 |
+
self.logger.info(f"You are installing the {qt_type} version of Qt")
|
| 1503 |
+
return expected_desktop_arch_path.name, default_desktop_arch
|
| 1504 |
+
else:
|
| 1505 |
+
self.logger.warning(
|
| 1506 |
+
f"You are installing the {qt_type} version of Qt, which requires that the desktop version of Qt "
|
| 1507 |
+
f"is also installed. You can install it with the following command:\n"
|
| 1508 |
+
f" `aqt install-qt {host} desktop {version} {default_desktop_arch}`"
|
| 1509 |
+
)
|
| 1510 |
+
return expected_desktop_arch_path.name, None
|
| 1511 |
+
|
| 1512 |
+
@staticmethod
|
| 1513 |
+
def _get_effective_os_name(host: str) -> str:
|
| 1514 |
+
if host != "all_os":
|
| 1515 |
+
return host
|
| 1516 |
+
elif sys.platform.startswith("linux"):
|
| 1517 |
+
return "linux"
|
| 1518 |
+
elif sys.platform == "darwin":
|
| 1519 |
+
return "mac"
|
| 1520 |
+
else:
|
| 1521 |
+
return "windows"
|
| 1522 |
+
|
| 1523 |
+
|
| 1524 |
+
def is_64bit() -> bool:
|
| 1525 |
+
"""check if running platform is 64bit python."""
|
| 1526 |
+
return sys.maxsize > 1 << 32
|
| 1527 |
+
|
| 1528 |
+
|
| 1529 |
+
def run_installer(
|
| 1530 |
+
archives: List[QtPackage],
|
| 1531 |
+
base_dir: str,
|
| 1532 |
+
sevenzip: Optional[str],
|
| 1533 |
+
keep: bool,
|
| 1534 |
+
archive_dest: Path,
|
| 1535 |
+
dry_run: bool = False,
|
| 1536 |
+
):
|
| 1537 |
+
|
| 1538 |
+
if dry_run:
|
| 1539 |
+
logger = getLogger("aqt.installer")
|
| 1540 |
+
logger.info("DRY RUN: Would download and install the following:")
|
| 1541 |
+
for arc in archives:
|
| 1542 |
+
line_parts = [f" - {arc.name}: {arc.archive_path}"]
|
| 1543 |
+
|
| 1544 |
+
if hasattr(arc, "package_desc") and arc.package_desc:
|
| 1545 |
+
size_match = re.search(r"Size: ([^,]+)", arc.package_desc)
|
| 1546 |
+
if size_match:
|
| 1547 |
+
line_parts.append(f" ({size_match.group(1)})")
|
| 1548 |
+
|
| 1549 |
+
if arc.archive_install_path and arc.archive_install_path.strip():
|
| 1550 |
+
line_parts.append(f" -> {arc.archive_install_path}")
|
| 1551 |
+
|
| 1552 |
+
logger.info("".join(line_parts))
|
| 1553 |
+
|
| 1554 |
+
logger.info(f"Total packages: {len(archives)}")
|
| 1555 |
+
return
|
| 1556 |
+
|
| 1557 |
+
queue = multiprocessing.Manager().Queue(-1)
|
| 1558 |
+
listener = MyQueueListener(queue)
|
| 1559 |
+
listener.start()
|
| 1560 |
+
#
|
| 1561 |
+
tasks = []
|
| 1562 |
+
for arc in archives:
|
| 1563 |
+
tasks.append((arc, base_dir, sevenzip, queue, archive_dest, Settings.configfile, keep))
|
| 1564 |
+
ctx = multiprocessing.get_context("spawn")
|
| 1565 |
+
if is_64bit():
|
| 1566 |
+
pool = ctx.Pool(Settings.concurrency, init_worker_sh, (), 4)
|
| 1567 |
+
else:
|
| 1568 |
+
pool = ctx.Pool(Settings.concurrency, init_worker_sh, (), 1)
|
| 1569 |
+
|
| 1570 |
+
def close_worker_pool_on_exception(exception: BaseException):
|
| 1571 |
+
logger = getLogger("aqt.installer")
|
| 1572 |
+
logger.warning(f"Caught {exception.__class__.__name__}, terminating installer workers")
|
| 1573 |
+
pool.terminate()
|
| 1574 |
+
pool.join()
|
| 1575 |
+
|
| 1576 |
+
try:
|
| 1577 |
+
pool.starmap(installer, tasks)
|
| 1578 |
+
pool.close()
|
| 1579 |
+
pool.join()
|
| 1580 |
+
except PermissionError as e: # subclass of OSError
|
| 1581 |
+
close_worker_pool_on_exception(e)
|
| 1582 |
+
raise DiskAccessNotPermitted(
|
| 1583 |
+
f"Failed to write to base directory at {base_dir}",
|
| 1584 |
+
suggested_action=[
|
| 1585 |
+
"Check that the destination is writable and does not already contain files owned by another user."
|
| 1586 |
+
],
|
| 1587 |
+
) from e
|
| 1588 |
+
except OSError as e:
|
| 1589 |
+
close_worker_pool_on_exception(e)
|
| 1590 |
+
if e.errno == errno.ENOSPC:
|
| 1591 |
+
raise OutOfDiskSpace(
|
| 1592 |
+
"Insufficient disk space to complete installation.",
|
| 1593 |
+
suggested_action=[
|
| 1594 |
+
"Check available disk space.",
|
| 1595 |
+
"Check size requirements for installation.",
|
| 1596 |
+
],
|
| 1597 |
+
) from e
|
| 1598 |
+
else:
|
| 1599 |
+
raise
|
| 1600 |
+
except KeyboardInterrupt as e:
|
| 1601 |
+
close_worker_pool_on_exception(e)
|
| 1602 |
+
raise CliKeyboardInterrupt("Installer halted by keyboard interrupt.") from e
|
| 1603 |
+
except MemoryError as e:
|
| 1604 |
+
close_worker_pool_on_exception(e)
|
| 1605 |
+
alt_extractor_msg = (
|
| 1606 |
+
"Please try using the '--external' flag to specify an alternate 7z extraction tool "
|
| 1607 |
+
"(see https://aqtinstall.readthedocs.io/en/latest/cli.html#cmdoption-list-tool-external)"
|
| 1608 |
+
)
|
| 1609 |
+
if Settings.concurrency > 1:
|
| 1610 |
+
docs_url = "https://aqtinstall.readthedocs.io/en/stable/configuration.html#configuration"
|
| 1611 |
+
raise OutOfMemory(
|
| 1612 |
+
"Out of memory when downloading and extracting archives in parallel.",
|
| 1613 |
+
suggested_action=[
|
| 1614 |
+
f"Please reduce your 'concurrency' setting (see {docs_url})",
|
| 1615 |
+
alt_extractor_msg,
|
| 1616 |
+
],
|
| 1617 |
+
) from e
|
| 1618 |
+
raise OutOfMemory(
|
| 1619 |
+
"Out of memory when downloading and extracting archives.",
|
| 1620 |
+
suggested_action=["Please free up more memory.", alt_extractor_msg],
|
| 1621 |
+
)
|
| 1622 |
+
except Exception as e:
|
| 1623 |
+
close_worker_pool_on_exception(e)
|
| 1624 |
+
raise e from e
|
| 1625 |
+
finally:
|
| 1626 |
+
# all done, close logging service for sub-processes
|
| 1627 |
+
listener.enqueue_sentinel()
|
| 1628 |
+
listener.stop()
|
| 1629 |
+
|
| 1630 |
+
|
| 1631 |
+
def init_worker_sh() -> None:
|
| 1632 |
+
"""Initialize worker signal handling"""
|
| 1633 |
+
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
| 1634 |
+
|
| 1635 |
+
|
| 1636 |
+
def installer(
|
| 1637 |
+
qt_package: QtPackage,
|
| 1638 |
+
base_dir: str,
|
| 1639 |
+
command: Optional[str],
|
| 1640 |
+
queue: multiprocessing.Queue,
|
| 1641 |
+
archive_dest: Path,
|
| 1642 |
+
settings_ini: str,
|
| 1643 |
+
keep: bool,
|
| 1644 |
+
) -> None:
|
| 1645 |
+
"""
|
| 1646 |
+
Installer function to download archive files and extract it.
|
| 1647 |
+
It is called through multiprocessing.Pool()
|
| 1648 |
+
"""
|
| 1649 |
+
name = qt_package.name
|
| 1650 |
+
base_url = qt_package.base_url
|
| 1651 |
+
archive: Path = archive_dest / qt_package.archive
|
| 1652 |
+
base_dir = posixpath.join(base_dir, qt_package.archive_install_path)
|
| 1653 |
+
start_time = time.perf_counter()
|
| 1654 |
+
Settings.load_settings(file=settings_ini)
|
| 1655 |
+
# setup queue logger
|
| 1656 |
+
setup_logging()
|
| 1657 |
+
qh = QueueHandler(queue)
|
| 1658 |
+
logger = getLogger()
|
| 1659 |
+
for handler in logger.handlers:
|
| 1660 |
+
handler.close()
|
| 1661 |
+
logger.removeHandler(handler)
|
| 1662 |
+
logger.addHandler(qh)
|
| 1663 |
+
#
|
| 1664 |
+
timeout = (Settings.connection_timeout, Settings.response_timeout)
|
| 1665 |
+
hash = get_hash(qt_package.archive_path, Settings.hash_algorithm, timeout) if not Settings.ignore_hash else None
|
| 1666 |
+
|
| 1667 |
+
def download_bin(_base_url):
|
| 1668 |
+
url = posixpath.join(_base_url, qt_package.archive_path)
|
| 1669 |
+
logger.debug("Download URL: {}".format(url))
|
| 1670 |
+
return downloadBinaryFile(url, archive, Settings.hash_algorithm, hash, timeout)
|
| 1671 |
+
|
| 1672 |
+
retry_on_errors(
|
| 1673 |
+
action=lambda: retry_on_bad_connection(download_bin, base_url),
|
| 1674 |
+
acceptable_errors=(ArchiveChecksumError,),
|
| 1675 |
+
num_retries=Settings.max_retries_on_checksum_error,
|
| 1676 |
+
name=f"Downloading {name}",
|
| 1677 |
+
)
|
| 1678 |
+
gc.collect()
|
| 1679 |
+
|
| 1680 |
+
if tarfile.is_tarfile(archive):
|
| 1681 |
+
with tarfile.open(archive) as tar_archive:
|
| 1682 |
+
if hasattr(tarfile, "data_filter"):
|
| 1683 |
+
tar_archive.extractall(filter="tar", path=base_dir)
|
| 1684 |
+
else:
|
| 1685 |
+
# remove this when the minimum Python version is 3.12
|
| 1686 |
+
logger.warning("Extracting may be unsafe; consider updating Python to 3.11.4 or greater")
|
| 1687 |
+
tar_archive.extractall(path=base_dir)
|
| 1688 |
+
elif zipfile.is_zipfile(archive):
|
| 1689 |
+
with zipfile.ZipFile(archive) as zip_archive:
|
| 1690 |
+
zip_archive.extractall(path=base_dir)
|
| 1691 |
+
elif command is None:
|
| 1692 |
+
with py7zr.SevenZipFile(archive, "r") as szf:
|
| 1693 |
+
szf.extractall(path=base_dir)
|
| 1694 |
+
else:
|
| 1695 |
+
command_args = [command, "x", "-aoa", "-bd", "-y", "-o{}".format(base_dir), str(archive)]
|
| 1696 |
+
try:
|
| 1697 |
+
proc = subprocess.run(command_args, stdout=subprocess.PIPE, check=True)
|
| 1698 |
+
logger.debug(proc.stdout)
|
| 1699 |
+
except subprocess.CalledProcessError as cpe:
|
| 1700 |
+
msg = "\n".join(filter(None, [f"Extraction error: {cpe.returncode}", cpe.stdout, cpe.stderr]))
|
| 1701 |
+
raise ArchiveExtractionError(msg) from cpe
|
| 1702 |
+
if not keep:
|
| 1703 |
+
os.unlink(archive)
|
| 1704 |
+
logger.info("Finished installation of {} in {:.8f}".format(archive.name, time.perf_counter() - start_time))
|
| 1705 |
+
gc.collect()
|
| 1706 |
+
qh.flush()
|
| 1707 |
+
qh.close()
|
| 1708 |
+
logger.removeHandler(qh)
|
python/py313/Lib/site-packages/aqt/logging.ini
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[loggers]
|
| 2 |
+
keys=root,aqt
|
| 3 |
+
|
| 4 |
+
[logger_root]
|
| 5 |
+
level=NOTSET
|
| 6 |
+
handlers=console
|
| 7 |
+
|
| 8 |
+
[logger_aqt]
|
| 9 |
+
level=DEBUG
|
| 10 |
+
handlers=console,file
|
| 11 |
+
propagate=0
|
| 12 |
+
qualname=aqt
|
| 13 |
+
|
| 14 |
+
[logger_aqt_main]
|
| 15 |
+
level=INFO
|
| 16 |
+
propagate=1
|
| 17 |
+
qualname=aqt.main
|
| 18 |
+
|
| 19 |
+
[logger_aqt_archives]
|
| 20 |
+
level=INFO
|
| 21 |
+
propagate=1
|
| 22 |
+
qualname=aqt.archives
|
| 23 |
+
|
| 24 |
+
[logger_aqt_generate_combos]
|
| 25 |
+
level=INFO
|
| 26 |
+
propagate=1
|
| 27 |
+
qualname=aqt.generate_combos
|
| 28 |
+
|
| 29 |
+
[logger_aqt_helper]
|
| 30 |
+
level=INFO
|
| 31 |
+
propagate=1
|
| 32 |
+
qualname=aqt.helper
|
| 33 |
+
|
| 34 |
+
[logger_aqt_installer]
|
| 35 |
+
level=INFO
|
| 36 |
+
handlers=NOTSET
|
| 37 |
+
propagate=0
|
| 38 |
+
qualname=aqt.installer
|
| 39 |
+
|
| 40 |
+
[logger_aqt_metadata]
|
| 41 |
+
level=INFO
|
| 42 |
+
propagate=1
|
| 43 |
+
qualname=aqt.metadata
|
| 44 |
+
|
| 45 |
+
[logger_aqt_updater]
|
| 46 |
+
level=INFO
|
| 47 |
+
propagate=1
|
| 48 |
+
qualname=aqt.updater
|
| 49 |
+
|
| 50 |
+
[formatters]
|
| 51 |
+
keys=verbose,simple,brief
|
| 52 |
+
|
| 53 |
+
[formatter_verbose]
|
| 54 |
+
format=%(asctime)s - %(name)s - %(levelname)s - %(module)s %(thread)d %(message)s
|
| 55 |
+
class=logging.Formatter
|
| 56 |
+
|
| 57 |
+
[formatter_simple]
|
| 58 |
+
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
| 59 |
+
class=logging.Formatter
|
| 60 |
+
|
| 61 |
+
[formatter_brief]
|
| 62 |
+
format=%(levelname)-8s: %(message)s
|
| 63 |
+
class=logging.Formatter
|
| 64 |
+
|
| 65 |
+
[handlers]
|
| 66 |
+
keys=console,file
|
| 67 |
+
|
| 68 |
+
[handler_console]
|
| 69 |
+
level=INFO
|
| 70 |
+
class=logging.StreamHandler
|
| 71 |
+
formatter=brief
|
| 72 |
+
args=(sys.stderr,)
|
| 73 |
+
|
| 74 |
+
[handler_file]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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2021 David Dalcino
|
| 4 |
+
#
|
| 5 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 6 |
+
# this software and associated documentation files (the "Software"), to deal in
|
| 7 |
+
# the Software without restriction, including without limitation the rights to
|
| 8 |
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 9 |
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
| 10 |
+
# subject to the following conditions:
|
| 11 |
+
#
|
| 12 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
# copies or substantial portions of the Software.
|
| 14 |
+
#
|
| 15 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 17 |
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 18 |
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 19 |
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 20 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
+
import itertools
|
| 22 |
+
import operator
|
| 23 |
+
import os
|
| 24 |
+
import posixpath
|
| 25 |
+
import re
|
| 26 |
+
import secrets as random
|
| 27 |
+
import shutil
|
| 28 |
+
from abc import ABC, abstractmethod
|
| 29 |
+
from functools import reduce
|
| 30 |
+
from logging import getLogger
|
| 31 |
+
from pathlib import Path
|
| 32 |
+
from typing import Callable, Dict, Generator, Iterable, Iterator, List, NamedTuple, Optional, Set, Tuple, Union, cast
|
| 33 |
+
from urllib.parse import ParseResult, urlparse
|
| 34 |
+
from xml.etree.ElementTree import Element
|
| 35 |
+
|
| 36 |
+
import bs4
|
| 37 |
+
from semantic_version import SimpleSpec as SemanticSimpleSpec
|
| 38 |
+
from semantic_version import Version as SemanticVersion
|
| 39 |
+
from texttable import Texttable
|
| 40 |
+
|
| 41 |
+
from aqt.exceptions import (
|
| 42 |
+
ArchiveConnectionError,
|
| 43 |
+
ArchiveDownloadError,
|
| 44 |
+
ArchiveListError,
|
| 45 |
+
ChecksumDownloadFailure,
|
| 46 |
+
CliInputError,
|
| 47 |
+
EmptyMetadata,
|
| 48 |
+
)
|
| 49 |
+
from aqt.helper import Settings, get_hash, getUrl, xml_to_modules
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class SimpleSpec(SemanticSimpleSpec):
|
| 53 |
+
pass
|
| 54 |
+
|
| 55 |
+
@staticmethod
|
| 56 |
+
def usage() -> str:
|
| 57 |
+
return (
|
| 58 |
+
"See documentation at: "
|
| 59 |
+
"https://python-semanticversion.readthedocs.io/en/latest/reference.html#semantic_version.SimpleSpec\n"
|
| 60 |
+
"Examples:\n"
|
| 61 |
+
'* "*": matches everything\n'
|
| 62 |
+
'* "5": matches every version with major=5\n'
|
| 63 |
+
'* "5.6": matches every version beginning with 5.6\n'
|
| 64 |
+
'* "5.*.3": matches versions with major=5 and patch=3'
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class Version(SemanticVersion):
|
| 69 |
+
"""Override semantic_version.Version class
|
| 70 |
+
to accept Qt versions and tools versions
|
| 71 |
+
If the version ends in `-preview`, the version is treated as a preview release.
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
def __init__(
|
| 75 |
+
self,
|
| 76 |
+
version_string=None,
|
| 77 |
+
major=None,
|
| 78 |
+
minor=None,
|
| 79 |
+
patch=None,
|
| 80 |
+
prerelease=None,
|
| 81 |
+
build=None,
|
| 82 |
+
partial=False,
|
| 83 |
+
) -> None:
|
| 84 |
+
if version_string is None:
|
| 85 |
+
super(Version, self).__init__(
|
| 86 |
+
version_string=None,
|
| 87 |
+
major=major,
|
| 88 |
+
minor=minor,
|
| 89 |
+
patch=patch,
|
| 90 |
+
prerelease=prerelease,
|
| 91 |
+
build=build,
|
| 92 |
+
partial=partial,
|
| 93 |
+
)
|
| 94 |
+
return
|
| 95 |
+
# test qt versions
|
| 96 |
+
match = re.match(r"^(\d+)\.(\d+)(\.(\d+)|-preview)$", version_string)
|
| 97 |
+
if not match:
|
| 98 |
+
# bad input
|
| 99 |
+
raise ValueError("Invalid version string: '{}'".format(version_string))
|
| 100 |
+
major, minor, end, patch = match.groups()
|
| 101 |
+
is_preview = end == "-preview"
|
| 102 |
+
super(Version, self).__init__(
|
| 103 |
+
major=int(major),
|
| 104 |
+
minor=int(minor),
|
| 105 |
+
patch=int(patch) if patch else 0,
|
| 106 |
+
prerelease=("preview",) if is_preview else None,
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
def __str__(self):
|
| 110 |
+
if self.prerelease:
|
| 111 |
+
return "{}.{}-preview".format(self.major, self.minor)
|
| 112 |
+
return super(Version, self).__str__()
|
| 113 |
+
|
| 114 |
+
@classmethod
|
| 115 |
+
def permissive(cls, version_string: str):
|
| 116 |
+
"""Converts a version string with dots (5.X.Y, etc) into a semantic version.
|
| 117 |
+
If the version omits either the patch or minor versions, they will be filled in with zeros,
|
| 118 |
+
and the remaining version string becomes part of the prerelease component.
|
| 119 |
+
If the version cannot be converted to a Version, a ValueError is raised.
|
| 120 |
+
|
| 121 |
+
This is intended to be used on Version tags in an Updates.xml file.
|
| 122 |
+
|
| 123 |
+
'1.33.1-202102101246' => Version('1.33.1-202102101246')
|
| 124 |
+
'1.33-202102101246' => Version('1.33.0-202102101246') # tools_conan
|
| 125 |
+
'2020-05-19-1' => Version('2020.0.0-05-19-1') # tools_vcredist
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
match = re.match(r"^(\d+)(\.(\d+)(\.(\d+))?)?(-(.+))?$", version_string)
|
| 129 |
+
if not match:
|
| 130 |
+
raise ValueError("Invalid version string: '{}'".format(version_string))
|
| 131 |
+
major, dot_minor, minor, dot_patch, patch, hyphen_build, build = match.groups()
|
| 132 |
+
return cls(
|
| 133 |
+
major=int(major),
|
| 134 |
+
minor=int(minor) if minor else 0,
|
| 135 |
+
patch=int(patch) if patch else 0,
|
| 136 |
+
build=(build,) if build else None,
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
class Versions:
|
| 141 |
+
def __init__(
|
| 142 |
+
self,
|
| 143 |
+
versions: Union[None, Version, Iterable[Tuple[int, Iterable[Version]]]],
|
| 144 |
+
):
|
| 145 |
+
if versions is None:
|
| 146 |
+
self.versions: List[List[Version]] = list()
|
| 147 |
+
elif isinstance(versions, Version):
|
| 148 |
+
self.versions = [[versions]]
|
| 149 |
+
else:
|
| 150 |
+
self.versions = [list(versions_iterator) for _, versions_iterator in versions]
|
| 151 |
+
|
| 152 |
+
def __str__(self) -> str:
|
| 153 |
+
return str(self.versions)
|
| 154 |
+
|
| 155 |
+
def __format__(self, format_spec) -> str:
|
| 156 |
+
if format_spec == "":
|
| 157 |
+
return "\n".join(" ".join(str(version) for version in minor_list) for minor_list in self.versions)
|
| 158 |
+
elif format_spec == "s":
|
| 159 |
+
return str(self.versions)
|
| 160 |
+
else:
|
| 161 |
+
raise TypeError("Unsupported format.")
|
| 162 |
+
|
| 163 |
+
def __bool__(self):
|
| 164 |
+
return len(self.versions) > 0 and len(self.versions[0]) > 0
|
| 165 |
+
|
| 166 |
+
def latest(self) -> Optional[Version]:
|
| 167 |
+
if not self:
|
| 168 |
+
return None
|
| 169 |
+
return self.versions[-1][-1]
|
| 170 |
+
|
| 171 |
+
def __iter__(self) -> Generator[List[Version], None, None]:
|
| 172 |
+
for item in self.versions:
|
| 173 |
+
yield item
|
| 174 |
+
|
| 175 |
+
def flattened(self) -> List[Version]:
|
| 176 |
+
"""Return a flattened list of all versions"""
|
| 177 |
+
return [version for row in self for version in row]
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def get_semantic_version(qt_ver: str, is_preview: bool) -> Optional[Version]:
|
| 181 |
+
"""Converts a Qt version string (596, 512, 5132, etc) into a semantic version.
|
| 182 |
+
This makes a lot of assumptions based on established patterns:
|
| 183 |
+
If is_preview is True, the number is interpreted as ver[0].ver[1:], with no patch.
|
| 184 |
+
If the version is 3 digits, then major, minor, and patch each get 1 digit.
|
| 185 |
+
If the version is 4 or more digits, then major gets 1 digit, minor gets 2 digits
|
| 186 |
+
and patch gets all the rest.
|
| 187 |
+
As of May 2021, the version strings at https://download.qt.io/online/qtsdkrepository
|
| 188 |
+
conform to this pattern; they are not guaranteed to do so in the future.
|
| 189 |
+
As of December 2024, it can handle version strings like 6_7_3 as well.
|
| 190 |
+
"""
|
| 191 |
+
if not qt_ver:
|
| 192 |
+
return None
|
| 193 |
+
|
| 194 |
+
# Handle versions with underscores (new format)
|
| 195 |
+
if "_" in qt_ver:
|
| 196 |
+
parts = qt_ver.split("_")
|
| 197 |
+
if not (2 <= len(parts) <= 3):
|
| 198 |
+
return None
|
| 199 |
+
|
| 200 |
+
try:
|
| 201 |
+
version_parts = [int(p) for p in parts]
|
| 202 |
+
except ValueError:
|
| 203 |
+
return None
|
| 204 |
+
|
| 205 |
+
major, minor = version_parts[:2]
|
| 206 |
+
patch = version_parts[2] if len(version_parts) > 2 else 0
|
| 207 |
+
|
| 208 |
+
if is_preview:
|
| 209 |
+
minor_patch_combined = int(f"{minor}{patch}") if patch > 0 else minor
|
| 210 |
+
return Version(
|
| 211 |
+
major=major,
|
| 212 |
+
minor=minor_patch_combined,
|
| 213 |
+
patch=0,
|
| 214 |
+
prerelease=("preview",),
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
return Version(
|
| 218 |
+
major=major,
|
| 219 |
+
minor=minor,
|
| 220 |
+
patch=patch,
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
# Handle traditional format (continuous digits)
|
| 224 |
+
if not qt_ver.isdigit():
|
| 225 |
+
return None
|
| 226 |
+
|
| 227 |
+
if is_preview:
|
| 228 |
+
return Version(
|
| 229 |
+
major=int(qt_ver[0]),
|
| 230 |
+
minor=int(qt_ver[1:]),
|
| 231 |
+
patch=0,
|
| 232 |
+
prerelease=("preview",),
|
| 233 |
+
)
|
| 234 |
+
elif len(qt_ver) >= 4:
|
| 235 |
+
return Version(major=int(qt_ver[0]), minor=int(qt_ver[1:3]), patch=int(qt_ver[3:]))
|
| 236 |
+
elif len(qt_ver) == 3:
|
| 237 |
+
return Version(major=int(qt_ver[0]), minor=int(qt_ver[1]), patch=int(qt_ver[2]))
|
| 238 |
+
elif len(qt_ver) == 2:
|
| 239 |
+
return Version(major=int(qt_ver[0]), minor=int(qt_ver[1]), patch=0)
|
| 240 |
+
|
| 241 |
+
raise ValueError("Invalid version string '{}'".format(qt_ver))
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
class ArchiveId:
|
| 245 |
+
CATEGORIES = ("tools", "qt")
|
| 246 |
+
HOSTS = ("windows", "windows_arm64", "mac", "linux", "linux_arm64", "all_os")
|
| 247 |
+
TARGETS_FOR_HOST = {
|
| 248 |
+
"windows": ["android", "desktop", "winrt"],
|
| 249 |
+
"windows_arm64": ["desktop"],
|
| 250 |
+
"mac": ["android", "desktop", "ios"],
|
| 251 |
+
"linux": ["android", "desktop"],
|
| 252 |
+
"linux_arm64": ["desktop"],
|
| 253 |
+
"all_os": ["wasm", "qt", "android"],
|
| 254 |
+
}
|
| 255 |
+
EXTENSIONS_REQUIRED_ANDROID_QT6 = {"x86_64", "x86", "armv7", "arm64_v8a"}
|
| 256 |
+
ALL_EXTENSIONS = {
|
| 257 |
+
"",
|
| 258 |
+
"wasm",
|
| 259 |
+
"src_doc_examples",
|
| 260 |
+
*EXTENSIONS_REQUIRED_ANDROID_QT6,
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
def __init__(self, category: str, host: str, target: str):
|
| 264 |
+
if category not in ArchiveId.CATEGORIES:
|
| 265 |
+
raise ValueError("Category '{}' is invalid".format(category))
|
| 266 |
+
if host not in ArchiveId.HOSTS:
|
| 267 |
+
raise ValueError("Host '{}' is invalid".format(host))
|
| 268 |
+
if target not in ArchiveId.TARGETS_FOR_HOST[host]:
|
| 269 |
+
raise ValueError("Target '{}' is invalid".format(target))
|
| 270 |
+
self.category: str = category
|
| 271 |
+
self.host: str = host
|
| 272 |
+
self.target: str = target
|
| 273 |
+
|
| 274 |
+
def is_preview(self) -> bool:
|
| 275 |
+
return False
|
| 276 |
+
|
| 277 |
+
def is_qt(self) -> bool:
|
| 278 |
+
return self.category == "qt"
|
| 279 |
+
|
| 280 |
+
def is_tools(self) -> bool:
|
| 281 |
+
return self.category == "tools"
|
| 282 |
+
|
| 283 |
+
def to_os_arch(self) -> str:
|
| 284 |
+
if self.host == "all_os":
|
| 285 |
+
return "all_os"
|
| 286 |
+
return "{os}{arch}".format(
|
| 287 |
+
os=self.host,
|
| 288 |
+
arch=(
|
| 289 |
+
"_x86"
|
| 290 |
+
if self.host == "windows"
|
| 291 |
+
else ("" if self.host in ("linux_arm64", "all_os", "windows_arm64") else "_x64")
|
| 292 |
+
),
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
def to_extension_folder(self, module, version, arch) -> str:
|
| 296 |
+
extarch = arch
|
| 297 |
+
if self.host == "windows":
|
| 298 |
+
extarch = arch.replace("win64_", "", 1)
|
| 299 |
+
elif self.host == "linux":
|
| 300 |
+
extarch = "x86_64"
|
| 301 |
+
elif self.host == "linux_arm64":
|
| 302 |
+
extarch = "arm64"
|
| 303 |
+
|
| 304 |
+
return "online/qtsdkrepository/{osarch}/extensions/{ext}/{ver}/{extarch}/".format(
|
| 305 |
+
osarch=self.to_os_arch(),
|
| 306 |
+
ext=module,
|
| 307 |
+
ver=version,
|
| 308 |
+
extarch=extarch,
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
def to_extension_url(self) -> str:
|
| 312 |
+
return "online/qtsdkrepository/{osarch}/extensions/".format(
|
| 313 |
+
osarch=self.to_os_arch(),
|
| 314 |
+
)
|
| 315 |
+
|
| 316 |
+
def to_url(self) -> str:
|
| 317 |
+
return "online/qtsdkrepository/{osarch}/{target}/".format(
|
| 318 |
+
osarch=self.to_os_arch(),
|
| 319 |
+
target=self.target,
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
+
def to_folder(self, version: Version, qt_version_no_dots: str, extension: Optional[str] = None) -> str:
|
| 323 |
+
if version >= Version("6.8.0"):
|
| 324 |
+
if self.target == "wasm":
|
| 325 |
+
# Qt 6.8+ WASM uses a split folder structure
|
| 326 |
+
folder = f"qt{version.major}_{qt_version_no_dots}"
|
| 327 |
+
if extension:
|
| 328 |
+
folder = f"{folder}/{folder}_{extension}"
|
| 329 |
+
return folder
|
| 330 |
+
elif not ((self.host == "all_os") and (self.target == "qt")):
|
| 331 |
+
# Non-WASM, non-all_os/qt case
|
| 332 |
+
return "{category}{major}_{ver}/{category}{major}_{ver}{ext}".format(
|
| 333 |
+
category=self.category,
|
| 334 |
+
major=qt_version_no_dots[0],
|
| 335 |
+
ver=qt_version_no_dots,
|
| 336 |
+
ext="_" + extension if extension else "",
|
| 337 |
+
)
|
| 338 |
+
else:
|
| 339 |
+
# traditional structure, still used by sde.
|
| 340 |
+
return "{category}{major}_{ver}{ext}".format(
|
| 341 |
+
category=self.category,
|
| 342 |
+
major=qt_version_no_dots[0],
|
| 343 |
+
ver=qt_version_no_dots,
|
| 344 |
+
ext="_" + extension if extension else "",
|
| 345 |
+
)
|
| 346 |
+
elif version >= Version("6.5.0") and self.target == "wasm":
|
| 347 |
+
# Qt 6.5-6.7 WASM uses direct wasm_[single|multi]thread folder
|
| 348 |
+
if extension:
|
| 349 |
+
return f"qt{version.major}_{qt_version_no_dots}_{extension}"
|
| 350 |
+
return f"qt{version.major}_{qt_version_no_dots}"
|
| 351 |
+
|
| 352 |
+
# Pre-6.8 structure for non-WASM or pre-6.5 structure
|
| 353 |
+
return "{category}{major}_{ver}{ext}".format(
|
| 354 |
+
category=self.category,
|
| 355 |
+
major=qt_version_no_dots[0],
|
| 356 |
+
ver=qt_version_no_dots,
|
| 357 |
+
ext="_" + extension if extension else "",
|
| 358 |
+
)
|
| 359 |
+
|
| 360 |
+
def all_extensions(self, version: Version) -> List[str]:
|
| 361 |
+
if self.target == "desktop" and QtRepoProperty.is_in_wasm_range(self.host, version):
|
| 362 |
+
return ["", "wasm"]
|
| 363 |
+
elif self.target == "desktop" and QtRepoProperty.is_in_wasm_range_special_65x_66x(self.host, version):
|
| 364 |
+
return ["", "wasm_singlethread", "wasm_multithread"]
|
| 365 |
+
elif self.target == "wasm" and QtRepoProperty.is_in_wasm_threaded_range(version):
|
| 366 |
+
return ["wasm_singlethread", "wasm_multithread"]
|
| 367 |
+
elif self.target == "android" and version >= Version("6.0.0"):
|
| 368 |
+
return list(ArchiveId.EXTENSIONS_REQUIRED_ANDROID_QT6)
|
| 369 |
+
else:
|
| 370 |
+
return [""]
|
| 371 |
+
|
| 372 |
+
def __str__(self) -> str:
|
| 373 |
+
return "{cat}/{host}/{target}".format(
|
| 374 |
+
cat=self.category,
|
| 375 |
+
host=self.host,
|
| 376 |
+
target=self.target,
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
class TableMetadata(ABC):
|
| 381 |
+
"""A data class that holds tool or module details. Can be pretty-printed as a table."""
|
| 382 |
+
|
| 383 |
+
def __init__(self, table_data: Dict[str, Dict[str, str]]):
|
| 384 |
+
self.table_data: Dict[str, Dict[str, str]] = table_data
|
| 385 |
+
self.format_field_for_tty("Description")
|
| 386 |
+
|
| 387 |
+
def format_field_for_tty(self, field: str):
|
| 388 |
+
for key in self.table_data.keys():
|
| 389 |
+
if field in self.table_data[key] and self.table_data[key][field]:
|
| 390 |
+
self.table_data[key][field] = self.table_data[key][field].replace("<br>", "\n")
|
| 391 |
+
|
| 392 |
+
std_keys_to_headings = {
|
| 393 |
+
"ReleaseDate": "Release Date",
|
| 394 |
+
"DisplayName": "Display Name",
|
| 395 |
+
"CompressedSize": "Download Size",
|
| 396 |
+
"UncompressedSize": "Installed Size",
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
@classmethod
|
| 400 |
+
def map_key_to_heading(cls, key: str) -> str:
|
| 401 |
+
return TableMetadata.std_keys_to_headings.get(key, key)
|
| 402 |
+
|
| 403 |
+
@property
|
| 404 |
+
@abstractmethod
|
| 405 |
+
def short_heading_keys(self) -> Iterable[str]: ...
|
| 406 |
+
|
| 407 |
+
@property
|
| 408 |
+
@abstractmethod
|
| 409 |
+
def long_heading_keys(self) -> Iterable[str]: ...
|
| 410 |
+
|
| 411 |
+
@property
|
| 412 |
+
@abstractmethod
|
| 413 |
+
def name_heading(self) -> str: ...
|
| 414 |
+
|
| 415 |
+
def __format__(self, format_spec: str) -> str:
|
| 416 |
+
short = False
|
| 417 |
+
if format_spec == "{:s}":
|
| 418 |
+
return str(self)
|
| 419 |
+
if format_spec == "":
|
| 420 |
+
max_width: int = 0
|
| 421 |
+
elif format_spec == "{:T}":
|
| 422 |
+
short = True
|
| 423 |
+
max_width = 0
|
| 424 |
+
else:
|
| 425 |
+
match = re.match(r"\{?:?(\d+)t\}?", format_spec)
|
| 426 |
+
if match:
|
| 427 |
+
g = match.groups()
|
| 428 |
+
max_width = int(g[0])
|
| 429 |
+
else:
|
| 430 |
+
raise ValueError("Wrong format {}".format(format_spec))
|
| 431 |
+
table = Texttable(max_width=max_width)
|
| 432 |
+
table.set_deco(Texttable.HEADER)
|
| 433 |
+
|
| 434 |
+
heading_keys = self.short_heading_keys if short else self.long_heading_keys
|
| 435 |
+
heading = [self.name_heading, *[self.map_key_to_heading(key) for key in heading_keys]]
|
| 436 |
+
table.header(heading)
|
| 437 |
+
table.add_rows(self._rows(heading_keys), header=False)
|
| 438 |
+
return cast(str, table.draw())
|
| 439 |
+
|
| 440 |
+
def __bool__(self):
|
| 441 |
+
return bool(self.table_data)
|
| 442 |
+
|
| 443 |
+
def _rows(self, keys: Iterable[str]) -> List[List[str]]:
|
| 444 |
+
return [[name, *[content[key] for key in keys]] for name, content in sorted(self.table_data.items())]
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
class ToolData(TableMetadata):
|
| 448 |
+
"""A data class hold tool details."""
|
| 449 |
+
|
| 450 |
+
@property
|
| 451 |
+
def short_heading_keys(self) -> Iterable[str]:
|
| 452 |
+
return "Version", "ReleaseDate"
|
| 453 |
+
|
| 454 |
+
@property
|
| 455 |
+
def long_heading_keys(self) -> Iterable[str]:
|
| 456 |
+
return "Version", "ReleaseDate", "DisplayName", "Description"
|
| 457 |
+
|
| 458 |
+
@property
|
| 459 |
+
def name_heading(self) -> str:
|
| 460 |
+
return "Tool Variant Name"
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
class ModuleData(TableMetadata):
|
| 464 |
+
"""A data class hold module details."""
|
| 465 |
+
|
| 466 |
+
@property
|
| 467 |
+
def short_heading_keys(self) -> Iterable[str]:
|
| 468 |
+
return ("DisplayName",)
|
| 469 |
+
|
| 470 |
+
@property
|
| 471 |
+
def long_heading_keys(self) -> Iterable[str]:
|
| 472 |
+
return "DisplayName", "ReleaseDate", "CompressedSize", "UncompressedSize"
|
| 473 |
+
|
| 474 |
+
@property
|
| 475 |
+
def name_heading(self) -> str:
|
| 476 |
+
return "Module Name"
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
class QtRepoProperty:
|
| 480 |
+
"""
|
| 481 |
+
Describes properties of the Qt repository at https://download.qt.io/online/qtsdkrepository.
|
| 482 |
+
Intended to help decouple the logic of aqt from specific properties of the Qt repository.
|
| 483 |
+
"""
|
| 484 |
+
|
| 485 |
+
@staticmethod
|
| 486 |
+
def dir_for_version(ver: Version) -> str:
|
| 487 |
+
return "5.9" if ver == Version("5.9.0") else f"{ver.major}.{ver.minor}.{ver.patch}"
|
| 488 |
+
|
| 489 |
+
@staticmethod
|
| 490 |
+
def get_arch_dir_name(host: str, arch: str, version: Version) -> str:
|
| 491 |
+
"""
|
| 492 |
+
Determines the architecture directory name based on host, architecture and version.
|
| 493 |
+
Special handling is done for mingw, MSVC and various platform-specific cases.
|
| 494 |
+
"""
|
| 495 |
+
if arch.startswith("win64_mingw"):
|
| 496 |
+
return arch[6:] + "_64"
|
| 497 |
+
elif arch.startswith("win64_llvm"):
|
| 498 |
+
return "llvm-" + arch[11:] + "_64"
|
| 499 |
+
elif arch.startswith("win32_mingw"):
|
| 500 |
+
return arch[6:] + "_32"
|
| 501 |
+
elif arch.startswith("win"):
|
| 502 |
+
m = re.match(r"win\d{2}_(?P<msvc>msvc\d{4})_(?P<winrt>winrt_x\d{2})", arch)
|
| 503 |
+
if m:
|
| 504 |
+
return f"{m.group('winrt')}_{m.group('msvc')}"
|
| 505 |
+
elif arch.endswith("_cross_compiled"):
|
| 506 |
+
return arch[6:-15]
|
| 507 |
+
else:
|
| 508 |
+
return arch[6:]
|
| 509 |
+
elif host == "mac" and arch == "clang_64":
|
| 510 |
+
return QtRepoProperty.default_mac_desktop_arch_dir(version)
|
| 511 |
+
elif host == "linux" and arch in ("gcc_64", "linux_gcc_64"):
|
| 512 |
+
return "gcc_64"
|
| 513 |
+
elif host == "linux_arm64" and arch == "linux_gcc_arm64":
|
| 514 |
+
return "gcc_arm64"
|
| 515 |
+
else:
|
| 516 |
+
return arch
|
| 517 |
+
|
| 518 |
+
@staticmethod
|
| 519 |
+
def default_linux_desktop_arch_dir() -> Tuple[str, str]:
|
| 520 |
+
return ("gcc_64", "gcc_arm64")
|
| 521 |
+
|
| 522 |
+
@staticmethod
|
| 523 |
+
def default_win_msvc_desktop_arch_dir(_version: Version) -> str:
|
| 524 |
+
if _version >= Version("6.8.0"):
|
| 525 |
+
return "msvc2022_64"
|
| 526 |
+
else:
|
| 527 |
+
return "msvc2019_64"
|
| 528 |
+
|
| 529 |
+
@staticmethod
|
| 530 |
+
def default_mac_desktop_arch_dir(version: Version) -> str:
|
| 531 |
+
return "macos" if version in SimpleSpec(">=6.1.2") else "clang_64"
|
| 532 |
+
|
| 533 |
+
@staticmethod
|
| 534 |
+
def extension_for_arch(architecture: str, is_version_ge_6: bool) -> str:
|
| 535 |
+
if architecture == "wasm_32":
|
| 536 |
+
return "wasm"
|
| 537 |
+
elif architecture == "wasm_singlethread":
|
| 538 |
+
return "wasm_singlethread"
|
| 539 |
+
elif architecture == "wasm_multithread":
|
| 540 |
+
return "wasm_multithread"
|
| 541 |
+
elif architecture.startswith("android_") and is_version_ge_6:
|
| 542 |
+
ext = architecture[len("android_") :]
|
| 543 |
+
if ext in ArchiveId.EXTENSIONS_REQUIRED_ANDROID_QT6:
|
| 544 |
+
return ext
|
| 545 |
+
return ""
|
| 546 |
+
|
| 547 |
+
@staticmethod
|
| 548 |
+
def possible_extensions_for_arch(arch: str) -> List[str]:
|
| 549 |
+
"""Assumes no knowledge of the Qt version"""
|
| 550 |
+
|
| 551 |
+
# ext_ge_6: the extension if the version is greater than or equal to 6.0.0
|
| 552 |
+
# ext_lt_6: the extension if the version is less than 6.0.0
|
| 553 |
+
ext_lt_6, ext_ge_6 = [QtRepoProperty.extension_for_arch(arch, is_ge_6) for is_ge_6 in (False, True)]
|
| 554 |
+
if ext_lt_6 == ext_ge_6:
|
| 555 |
+
return [ext_lt_6]
|
| 556 |
+
return [ext_lt_6, ext_ge_6]
|
| 557 |
+
|
| 558 |
+
# Architecture, as reported in Updates.xml
|
| 559 |
+
MINGW_ARCH_PATTERN = re.compile(r"^win(?P<bits>\d+)_mingw(?P<version>\d+)?$")
|
| 560 |
+
# Directory that corresponds to an architecture
|
| 561 |
+
MINGW_DIR_PATTERN = re.compile(r"^mingw(?P<version>\d+)?_(?P<bits>\d+)$")
|
| 562 |
+
|
| 563 |
+
@staticmethod
|
| 564 |
+
def select_default_mingw(mingw_arches: List[str], is_dir: bool) -> Optional[str]:
|
| 565 |
+
"""
|
| 566 |
+
Selects a default architecture from a non-empty list of mingw architectures, matching the pattern
|
| 567 |
+
MetadataFactory.MINGW_ARCH_PATTERN. Meant to be called on a list of installed mingw architectures,
|
| 568 |
+
or a list of architectures available for installation.
|
| 569 |
+
"""
|
| 570 |
+
|
| 571 |
+
ArchBitsVer = Tuple[str, int, Optional[int]]
|
| 572 |
+
pattern = QtRepoProperty.MINGW_DIR_PATTERN if is_dir else QtRepoProperty.MINGW_ARCH_PATTERN
|
| 573 |
+
|
| 574 |
+
def mingw_arch_with_bits_and_version(arch: str) -> Optional[ArchBitsVer]:
|
| 575 |
+
match = pattern.match(arch)
|
| 576 |
+
if not match:
|
| 577 |
+
return None
|
| 578 |
+
bits = int(match.group("bits"))
|
| 579 |
+
ver = None if not match.group("version") else int(match.group("version"))
|
| 580 |
+
return arch, bits, ver
|
| 581 |
+
|
| 582 |
+
def select_superior_arch(lhs: ArchBitsVer, rhs: ArchBitsVer) -> ArchBitsVer:
|
| 583 |
+
_, l_bits, l_ver = lhs
|
| 584 |
+
_, r_bits, r_ver = rhs
|
| 585 |
+
if l_bits != r_bits:
|
| 586 |
+
return lhs if l_bits > r_bits else rhs
|
| 587 |
+
elif r_ver is None:
|
| 588 |
+
return lhs
|
| 589 |
+
elif l_ver is None:
|
| 590 |
+
return rhs
|
| 591 |
+
return lhs if l_ver > r_ver else rhs
|
| 592 |
+
|
| 593 |
+
candidates: List[ArchBitsVer] = list(filter(None, map(mingw_arch_with_bits_and_version, mingw_arches)))
|
| 594 |
+
if len(candidates) == 0:
|
| 595 |
+
return None
|
| 596 |
+
default_arch, _, _ = reduce(select_superior_arch, candidates)
|
| 597 |
+
return default_arch
|
| 598 |
+
|
| 599 |
+
@staticmethod
|
| 600 |
+
def find_installed_desktop_qt_dir(host: str, base_path: Path, version: Version, is_msvc: bool = False) -> Optional[Path]:
|
| 601 |
+
"""
|
| 602 |
+
Locates the default installed desktop qt directory, somewhere in base_path.
|
| 603 |
+
"""
|
| 604 |
+
installed_qt_version_dir = base_path / QtRepoProperty.dir_for_version(version)
|
| 605 |
+
if host == "mac":
|
| 606 |
+
arch_path = installed_qt_version_dir / QtRepoProperty.default_mac_desktop_arch_dir(version)
|
| 607 |
+
return arch_path if (arch_path / "bin/qmake").is_file() else None
|
| 608 |
+
elif host == "linux":
|
| 609 |
+
for arch_dir in QtRepoProperty.default_linux_desktop_arch_dir():
|
| 610 |
+
arch_path = installed_qt_version_dir / arch_dir
|
| 611 |
+
if (arch_path / "bin/qmake").is_file():
|
| 612 |
+
return arch_path
|
| 613 |
+
return None
|
| 614 |
+
elif host == "windows" and is_msvc:
|
| 615 |
+
arch_path = installed_qt_version_dir / QtRepoProperty.default_win_msvc_desktop_arch_dir(version)
|
| 616 |
+
return arch_path if (arch_path / "bin/qmake.exe").is_file() else None
|
| 617 |
+
|
| 618 |
+
def contains_qmake_exe(arch_path: Path) -> bool:
|
| 619 |
+
return (arch_path / "bin/qmake.exe").is_file()
|
| 620 |
+
|
| 621 |
+
paths = [d for d in installed_qt_version_dir.glob("mingw*")]
|
| 622 |
+
directories = list(filter(contains_qmake_exe, paths))
|
| 623 |
+
arch_dirs = [d.name for d in directories]
|
| 624 |
+
selected_dir = QtRepoProperty.select_default_mingw(arch_dirs, is_dir=True)
|
| 625 |
+
return installed_qt_version_dir / selected_dir if selected_dir else None
|
| 626 |
+
|
| 627 |
+
@staticmethod
|
| 628 |
+
def is_in_wasm_range(host: str, version: Version) -> bool:
|
| 629 |
+
return (
|
| 630 |
+
version in SimpleSpec(">=6.2.0,<6.5.0")
|
| 631 |
+
or (host == "linux" and version in SimpleSpec(">=5.13,<6"))
|
| 632 |
+
or version in SimpleSpec(">=5.13.1,<6")
|
| 633 |
+
)
|
| 634 |
+
|
| 635 |
+
@staticmethod
|
| 636 |
+
def is_in_wasm_range_special_65x_66x(host: str, version: Version) -> bool:
|
| 637 |
+
return version in SimpleSpec(">=6.5.0,<6.7.0")
|
| 638 |
+
|
| 639 |
+
@staticmethod
|
| 640 |
+
def is_in_wasm_threaded_range(version: Version) -> bool:
|
| 641 |
+
return version in SimpleSpec(">=6.5.0")
|
| 642 |
+
|
| 643 |
+
@staticmethod
|
| 644 |
+
def known_extensions(version: Version) -> List[str]:
|
| 645 |
+
if version >= Version("6.8.0"):
|
| 646 |
+
return ["qtpdf", "qtwebengine"]
|
| 647 |
+
return []
|
| 648 |
+
|
| 649 |
+
@staticmethod
|
| 650 |
+
def sde_ext(version: Version) -> str:
|
| 651 |
+
if version >= Version("6.8.0"):
|
| 652 |
+
if os.linesep == "\r\n":
|
| 653 |
+
return "windows_line_endings_src"
|
| 654 |
+
else:
|
| 655 |
+
return "unix_line_endings_src"
|
| 656 |
+
else:
|
| 657 |
+
return "src_doc_examples"
|
| 658 |
+
|
| 659 |
+
|
| 660 |
+
class MetadataFactory:
|
| 661 |
+
"""Retrieve metadata of Qt variations, versions, and descriptions from Qt site."""
|
| 662 |
+
|
| 663 |
+
Metadata = Union[List[str], Versions, ToolData, ModuleData]
|
| 664 |
+
Action = Callable[[], Metadata]
|
| 665 |
+
SrcDocExamplesQuery = NamedTuple(
|
| 666 |
+
"SrcDocExamplesQuery", [("cmd_type", str), ("version", Version), ("is_modules_query", bool)]
|
| 667 |
+
)
|
| 668 |
+
ModulesQuery = NamedTuple("ModulesQuery", [("version_str", str), ("arch", str)])
|
| 669 |
+
|
| 670 |
+
def __init__(
|
| 671 |
+
self,
|
| 672 |
+
archive_id: ArchiveId,
|
| 673 |
+
*,
|
| 674 |
+
base_url: Optional[str] = None,
|
| 675 |
+
spec: Optional[SimpleSpec] = None,
|
| 676 |
+
is_latest_version: bool = False,
|
| 677 |
+
modules_query: Optional[ModulesQuery] = None,
|
| 678 |
+
architectures_ver: Optional[str] = None,
|
| 679 |
+
archives_query: Optional[List[str]] = None,
|
| 680 |
+
src_doc_examples_query: Optional[SrcDocExamplesQuery] = None,
|
| 681 |
+
tool_name: Optional[str] = None,
|
| 682 |
+
is_long_listing: bool = False,
|
| 683 |
+
):
|
| 684 |
+
"""
|
| 685 |
+
Construct MetadataFactory.
|
| 686 |
+
|
| 687 |
+
:param spec: When set, the MetadataFactory will filter out all versions of
|
| 688 |
+
Qt that don't fit this SimpleSpec.
|
| 689 |
+
:param is_latest_version: When True, the MetadataFactory will find all versions of Qt
|
| 690 |
+
matching filters, and only print the most recent version
|
| 691 |
+
:param modules_query: [Version of Qt, architecture] for which to list modules
|
| 692 |
+
:param architectures_ver: Version of Qt for which to list architectures
|
| 693 |
+
:param archives_query: [Qt_Version, architecture, *module_names]: used to print list of archives
|
| 694 |
+
:param tool_name: Name of a tool, without architecture, ie "tools_qtcreator" or "tools_ifw"
|
| 695 |
+
:param is_long_listing: If true, long listing is used for tools output
|
| 696 |
+
"""
|
| 697 |
+
self.logger = getLogger("aqt.metadata")
|
| 698 |
+
self.archive_id = archive_id
|
| 699 |
+
self.spec = spec
|
| 700 |
+
self.base_url = base_url or Settings.baseurl
|
| 701 |
+
|
| 702 |
+
if archive_id.is_tools():
|
| 703 |
+
if tool_name is not None:
|
| 704 |
+
if not tool_name.startswith("tools_") and tool_name != "sdktool":
|
| 705 |
+
_tool_name = f"tools_{tool_name}"
|
| 706 |
+
else:
|
| 707 |
+
_tool_name = tool_name
|
| 708 |
+
if is_long_listing:
|
| 709 |
+
self.request_type = "tool long listing"
|
| 710 |
+
self._action: MetadataFactory.Action = lambda: self.fetch_tool_long_listing(_tool_name)
|
| 711 |
+
else:
|
| 712 |
+
self.request_type = "tool variant names"
|
| 713 |
+
self._action = lambda: self.fetch_tool_modules(_tool_name)
|
| 714 |
+
else:
|
| 715 |
+
self.request_type = "tools"
|
| 716 |
+
self._action = self.fetch_tools
|
| 717 |
+
elif is_latest_version:
|
| 718 |
+
self.request_type = "latest version"
|
| 719 |
+
self._action = lambda: Versions(self.fetch_latest_version(ext=""))
|
| 720 |
+
elif modules_query is not None:
|
| 721 |
+
version, arch = modules_query.version_str, modules_query.arch
|
| 722 |
+
if is_long_listing:
|
| 723 |
+
self.request_type = "long modules"
|
| 724 |
+
self._action = lambda: self.fetch_long_modules(self._to_version(version, arch), arch)
|
| 725 |
+
else:
|
| 726 |
+
self.request_type = "modules"
|
| 727 |
+
self._action = lambda: self.fetch_modules(self._to_version(version, arch), arch)
|
| 728 |
+
elif architectures_ver is not None:
|
| 729 |
+
ver_str: str = architectures_ver
|
| 730 |
+
self.request_type = "architectures"
|
| 731 |
+
self._action = lambda: self.fetch_arches(self._to_version(ver_str, None))
|
| 732 |
+
elif archives_query:
|
| 733 |
+
if len(archives_query) < 2:
|
| 734 |
+
raise CliInputError("The '--archives' flag requires a 'QT_VERSION' and an 'ARCHITECTURE' parameter.")
|
| 735 |
+
self.request_type = "archives for modules" if len(archives_query) > 2 else "archives for qt"
|
| 736 |
+
version, arch, modules = archives_query[0], archives_query[1], archives_query[2:]
|
| 737 |
+
self._action = lambda: self.fetch_archives(self._to_version(version, arch), arch, modules)
|
| 738 |
+
elif src_doc_examples_query is not None:
|
| 739 |
+
q: MetadataFactory.SrcDocExamplesQuery = src_doc_examples_query
|
| 740 |
+
if q.is_modules_query:
|
| 741 |
+
self.request_type = f"modules for {q.cmd_type}"
|
| 742 |
+
self._action = lambda: self.fetch_modules_sde(q.cmd_type, q.version)
|
| 743 |
+
else:
|
| 744 |
+
self.request_type = f"archives for {q.cmd_type}"
|
| 745 |
+
self._action = lambda: self.fetch_archives_sde(q.cmd_type, q.version)
|
| 746 |
+
else:
|
| 747 |
+
self.request_type = "versions"
|
| 748 |
+
self._action = self.fetch_versions
|
| 749 |
+
|
| 750 |
+
def getList(self) -> Metadata:
|
| 751 |
+
return self._action()
|
| 752 |
+
|
| 753 |
+
def fetch_arches(self, version: Version) -> List[str]:
|
| 754 |
+
arches = []
|
| 755 |
+
qt_ver_str = self._get_qt_version_str(version)
|
| 756 |
+
for extension in self.archive_id.all_extensions(version):
|
| 757 |
+
modules: Dict[str, Dict[str, str]] = {}
|
| 758 |
+
folder = self.archive_id.to_folder(version, qt_ver_str, extension)
|
| 759 |
+
try:
|
| 760 |
+
modules = self._fetch_module_metadata(folder)
|
| 761 |
+
except ArchiveDownloadError as e:
|
| 762 |
+
if extension == "":
|
| 763 |
+
raise
|
| 764 |
+
else:
|
| 765 |
+
self.logger.debug(e)
|
| 766 |
+
self.logger.debug(
|
| 767 |
+
f"Failed to retrieve arches list with extension `{extension}`. "
|
| 768 |
+
f"Please check that this extension exists for this version of Qt: "
|
| 769 |
+
f"if not, code changes will be necessary."
|
| 770 |
+
)
|
| 771 |
+
# It's ok to swallow this error: we will still print the other available architectures that aqt can
|
| 772 |
+
# install successfully. This is to prevent future errors such as those reported in #643
|
| 773 |
+
|
| 774 |
+
for name in modules.keys():
|
| 775 |
+
ver, arch = name.split(".")[-2:]
|
| 776 |
+
if ver == qt_ver_str:
|
| 777 |
+
arches.append(arch)
|
| 778 |
+
|
| 779 |
+
return arches
|
| 780 |
+
|
| 781 |
+
def fetch_versions(self, extension: str = "") -> Versions:
|
| 782 |
+
def match_any_ext(ver: Version) -> bool:
|
| 783 |
+
return (
|
| 784 |
+
self.archive_id.host == "all_os"
|
| 785 |
+
and self.archive_id.target in ArchiveId.TARGETS_FOR_HOST["all_os"]
|
| 786 |
+
and ver in SimpleSpec("6.7.*")
|
| 787 |
+
)
|
| 788 |
+
|
| 789 |
+
def filter_by(ver: Version, ext: str) -> bool:
|
| 790 |
+
return (self.spec is None or ver in self.spec) and (ext == extension or match_any_ext(ver))
|
| 791 |
+
|
| 792 |
+
versions_extensions = self.get_versions_extensions(
|
| 793 |
+
self.fetch_http(self.archive_id.to_url(), False), self.archive_id.category
|
| 794 |
+
)
|
| 795 |
+
versions = sorted({ver for ver, ext in versions_extensions if ver is not None and filter_by(ver, ext)})
|
| 796 |
+
grouped = cast(Iterable[Tuple[int, Iterable[Version]]], itertools.groupby(versions, lambda version: version.minor))
|
| 797 |
+
|
| 798 |
+
return Versions(grouped)
|
| 799 |
+
|
| 800 |
+
def fetch_latest_version(self, ext: str) -> Optional[Version]:
|
| 801 |
+
return self.fetch_versions(ext).latest()
|
| 802 |
+
|
| 803 |
+
def fetch_extensions(self) -> List[str]:
|
| 804 |
+
html_doc = self.fetch_http(self.archive_id.to_extension_url(), False)
|
| 805 |
+
return list(self.iterate_folders(html_doc, self.base_url))
|
| 806 |
+
|
| 807 |
+
def fetch_tools(self) -> List[str]:
|
| 808 |
+
html_doc = self.fetch_http(self.archive_id.to_url(), False)
|
| 809 |
+
return list(self.iterate_folders(html_doc, self.base_url, filter_category="tools"))
|
| 810 |
+
|
| 811 |
+
def fetch_tool_modules(self, tool_name: str) -> List[str]:
|
| 812 |
+
tool_data = self._fetch_module_metadata(tool_name)
|
| 813 |
+
return list(tool_data.keys())
|
| 814 |
+
|
| 815 |
+
def fetch_tool_by_simple_spec(self, tool_name: str, simple_spec: SimpleSpec) -> Optional[Dict[str, str]]:
|
| 816 |
+
# Get data for all the tool modules
|
| 817 |
+
all_tools_data = self._fetch_module_metadata(tool_name)
|
| 818 |
+
return self.choose_highest_version_in_spec(all_tools_data, simple_spec)
|
| 819 |
+
|
| 820 |
+
def fetch_tool_long_listing(self, tool_name: str) -> ToolData:
|
| 821 |
+
return ToolData(self._fetch_module_metadata(tool_name))
|
| 822 |
+
|
| 823 |
+
@staticmethod
|
| 824 |
+
def choose_highest_version_in_spec(
|
| 825 |
+
all_tools_data: Dict[str, Dict[str, str]], simple_spec: SimpleSpec
|
| 826 |
+
) -> Optional[Dict[str, str]]:
|
| 827 |
+
# Get versions of all modules. Fail if version cannot be determined.
|
| 828 |
+
try:
|
| 829 |
+
tools_versions = [
|
| 830 |
+
(name, tool_data, Version.permissive(tool_data["Version"])) for name, tool_data in all_tools_data.items()
|
| 831 |
+
]
|
| 832 |
+
except ValueError:
|
| 833 |
+
return None
|
| 834 |
+
|
| 835 |
+
# Remove items that don't conform to simple_spec
|
| 836 |
+
tools_versions = [tool_item for tool_item in tools_versions if tool_item[2] in simple_spec]
|
| 837 |
+
|
| 838 |
+
try:
|
| 839 |
+
# Return the conforming item with the highest version.
|
| 840 |
+
# If there are multiple items with the same version, the result will not be predictable.
|
| 841 |
+
return max(tools_versions, key=operator.itemgetter(2))[1]
|
| 842 |
+
except ValueError:
|
| 843 |
+
# There were no tools that fit the simple_spec
|
| 844 |
+
return None
|
| 845 |
+
|
| 846 |
+
def _to_version(self, qt_ver: str, arch: Optional[str]) -> Version:
|
| 847 |
+
"""
|
| 848 |
+
Turns a string in the form of `5.X.Y | latest` into a semantic version.
|
| 849 |
+
If the string does not fit either of these forms, CliInputError will be raised.
|
| 850 |
+
If qt_ver == latest, and no versions exist corresponding to the filters specified,
|
| 851 |
+
then CliInputError will be raised.
|
| 852 |
+
If qt_ver == latest, and an HTTP error occurs, requests.RequestException will be raised.
|
| 853 |
+
|
| 854 |
+
:param qt_ver: Either the literal string `latest`, or a semantic version
|
| 855 |
+
with each part separated with dots.
|
| 856 |
+
"""
|
| 857 |
+
assert qt_ver
|
| 858 |
+
if qt_ver == "latest":
|
| 859 |
+
ext = QtRepoProperty.extension_for_arch(arch, True) if arch else ""
|
| 860 |
+
latest_version = self.fetch_latest_version(ext)
|
| 861 |
+
if not latest_version:
|
| 862 |
+
msg = "There is no latest version of Qt with the criteria '{}'".format(self.describe_filters())
|
| 863 |
+
raise CliInputError(msg)
|
| 864 |
+
return latest_version
|
| 865 |
+
try:
|
| 866 |
+
version = Version(qt_ver)
|
| 867 |
+
except ValueError as e:
|
| 868 |
+
raise CliInputError(e) from e
|
| 869 |
+
return version
|
| 870 |
+
|
| 871 |
+
def fetch_http(self, rest_of_url: str, is_check_hash: bool = True) -> str:
|
| 872 |
+
timeout = (Settings.connection_timeout, Settings.response_timeout)
|
| 873 |
+
expected_hash = get_hash(rest_of_url, Settings.hash_algorithm, timeout) if is_check_hash else None
|
| 874 |
+
base_urls = self.base_url, random.choice(Settings.fallbacks)
|
| 875 |
+
|
| 876 |
+
err: BaseException = AssertionError("unraisable")
|
| 877 |
+
|
| 878 |
+
for i, base_url in enumerate(base_urls):
|
| 879 |
+
try:
|
| 880 |
+
url = posixpath.join(base_url, rest_of_url)
|
| 881 |
+
return getUrl(url=url, timeout=timeout, expected_hash=expected_hash)
|
| 882 |
+
|
| 883 |
+
except (ArchiveDownloadError, ArchiveConnectionError) as e:
|
| 884 |
+
err = e
|
| 885 |
+
if i < len(base_urls) - 1:
|
| 886 |
+
getLogger("aqt.metadata").debug(
|
| 887 |
+
f"Connection to '{base_url}' failed. Retrying with fallback '{base_urls[i + 1]}'."
|
| 888 |
+
)
|
| 889 |
+
raise err from err
|
| 890 |
+
|
| 891 |
+
def iterate_folders(self, html_doc: str, html_url: str, *, filter_category: str = "") -> Generator[str, None, None]:
|
| 892 |
+
def link_to_folder(link: bs4.element.Tag) -> str:
|
| 893 |
+
raw_url: str = str(link.get("href", default=""))
|
| 894 |
+
url: ParseResult = urlparse(raw_url)
|
| 895 |
+
if url.scheme or url.netloc:
|
| 896 |
+
return ""
|
| 897 |
+
url_path: str = posixpath.normpath(url.path)
|
| 898 |
+
if "/" in url_path or url_path == "." or url_path == "..":
|
| 899 |
+
return ""
|
| 900 |
+
return url_path
|
| 901 |
+
|
| 902 |
+
try:
|
| 903 |
+
soup: bs4.BeautifulSoup = bs4.BeautifulSoup(html_doc, "html.parser")
|
| 904 |
+
for link in soup.find_all("a"):
|
| 905 |
+
folder: str = link_to_folder(link)
|
| 906 |
+
if not folder:
|
| 907 |
+
continue
|
| 908 |
+
if folder.startswith(filter_category):
|
| 909 |
+
yield folder
|
| 910 |
+
if filter_category == "tools" and folder == "sdktool":
|
| 911 |
+
yield folder
|
| 912 |
+
except Exception as e:
|
| 913 |
+
raise ArchiveConnectionError(
|
| 914 |
+
f"Failed to retrieve the expected HTML page at {html_url}",
|
| 915 |
+
suggested_action=[
|
| 916 |
+
"Check your network connection.",
|
| 917 |
+
f"Make sure that you can access {html_url} in your web browser.",
|
| 918 |
+
],
|
| 919 |
+
) from e
|
| 920 |
+
|
| 921 |
+
def get_versions_extensions(self, html_doc: str, category: str) -> Iterator[Tuple[Optional[Version], str]]:
|
| 922 |
+
def folder_to_version_extension(folder: str) -> Tuple[Optional[Version], str]:
|
| 923 |
+
|
| 924 |
+
ext = ""
|
| 925 |
+
ver = ""
|
| 926 |
+
|
| 927 |
+
# Special case for Qt6.7 unique format
|
| 928 |
+
if folder.startswith("qt6_7_"):
|
| 929 |
+
# Split the input into version and extension parts
|
| 930 |
+
# For qt6_7_3_arm64_v8a, we want to extract "6_7_3" and "arm64_v8a"
|
| 931 |
+
# Should not be more than qt6_7_3_backup (extension should not have _, but you know...)
|
| 932 |
+
|
| 933 |
+
# Remove the "qt" prefix first
|
| 934 |
+
remainder = folder[2:]
|
| 935 |
+
|
| 936 |
+
# Split the first 3 parts for the version (6_7_3)
|
| 937 |
+
version_parts = remainder.split("_", 3)[:3]
|
| 938 |
+
ver = "_".join(version_parts)
|
| 939 |
+
|
| 940 |
+
# Everything after version is the extension
|
| 941 |
+
if len(remainder.split("_", 3)) > 3:
|
| 942 |
+
ext = remainder.split("_", 3)[3]
|
| 943 |
+
else:
|
| 944 |
+
ext = ""
|
| 945 |
+
else:
|
| 946 |
+
components = folder.split("_", maxsplit=2)
|
| 947 |
+
ext = "" if len(components) < 3 else components[2]
|
| 948 |
+
ver = "" if len(components) < 2 else components[1]
|
| 949 |
+
return (
|
| 950 |
+
get_semantic_version(qt_ver=ver, is_preview="preview" in ext),
|
| 951 |
+
ext,
|
| 952 |
+
)
|
| 953 |
+
|
| 954 |
+
return map(
|
| 955 |
+
folder_to_version_extension,
|
| 956 |
+
self.iterate_folders(html_doc, self.base_url, filter_category=category),
|
| 957 |
+
)
|
| 958 |
+
|
| 959 |
+
@staticmethod
|
| 960 |
+
def _has_nonempty_downloads(element: Element) -> bool:
|
| 961 |
+
"""Returns True if the element has a nonempty '<DownloadableArchives/>' tag"""
|
| 962 |
+
downloads = element.find("DownloadableArchives")
|
| 963 |
+
update_file = element.find("UpdateFile")
|
| 964 |
+
if downloads is None or update_file is None:
|
| 965 |
+
return False
|
| 966 |
+
uncompressed_size = int(update_file.attrib["UncompressedSize"])
|
| 967 |
+
return downloads.text is not None and uncompressed_size >= Settings.min_module_size
|
| 968 |
+
|
| 969 |
+
def _get_qt_version_str(self, version: Version) -> str:
|
| 970 |
+
"""Returns a Qt version, without dots, that works in the Qt repo urls and Updates.xml files"""
|
| 971 |
+
# NOTE: The url at `<base>/<host>/<target>/qt5_590/` does not exist; the real one is `qt5_59`
|
| 972 |
+
patch = (
|
| 973 |
+
""
|
| 974 |
+
if version.prerelease or self.archive_id.is_preview() or version in SimpleSpec("5.9.0")
|
| 975 |
+
else str(version.patch)
|
| 976 |
+
)
|
| 977 |
+
return f"{version.major}{version.minor}{patch}"
|
| 978 |
+
|
| 979 |
+
def _fetch_module_metadata(self, folder: str, predicate: Optional[Callable[[Element], bool]] = None):
|
| 980 |
+
rest_of_url = posixpath.join(self.archive_id.to_url(), folder, "Updates.xml")
|
| 981 |
+
xml = self.fetch_http(rest_of_url) if not Settings.ignore_hash else self.fetch_http(rest_of_url, False)
|
| 982 |
+
return xml_to_modules(
|
| 983 |
+
xml,
|
| 984 |
+
predicate=predicate if predicate else MetadataFactory._has_nonempty_downloads,
|
| 985 |
+
)
|
| 986 |
+
|
| 987 |
+
def _fetch_extension_metadata(self, url: str, predicate: Optional[Callable[[Element], bool]] = None):
|
| 988 |
+
rest_of_url = posixpath.join(url, "Updates.xml")
|
| 989 |
+
xml = self.fetch_http(rest_of_url) if not Settings.ignore_hash else self.fetch_http(rest_of_url, False)
|
| 990 |
+
return xml_to_modules(
|
| 991 |
+
xml,
|
| 992 |
+
predicate=predicate if predicate else MetadataFactory._has_nonempty_downloads,
|
| 993 |
+
)
|
| 994 |
+
|
| 995 |
+
def fetch_modules(self, version: Version, arch: str) -> List[str]:
|
| 996 |
+
"""Returns list of modules"""
|
| 997 |
+
extension = QtRepoProperty.extension_for_arch(arch, version >= Version("6.0.0"))
|
| 998 |
+
qt_ver_str = self._get_qt_version_str(version)
|
| 999 |
+
# Example: re.compile(r"^(preview\.)?qt\.(qt5\.)?590\.(.+)$")
|
| 1000 |
+
pattern = re.compile(r"^(preview\.)?qt\.(qt" + str(version.major) + r"\.)?" + qt_ver_str + r"\.(.+)$")
|
| 1001 |
+
modules_meta = self._fetch_module_metadata(self.archive_id.to_folder(version, qt_ver_str, extension))
|
| 1002 |
+
|
| 1003 |
+
def to_module_arch(name: str) -> Tuple[Optional[str], Optional[str]]:
|
| 1004 |
+
_match = pattern.match(name)
|
| 1005 |
+
if not _match:
|
| 1006 |
+
return None, None
|
| 1007 |
+
module_with_arch = _match.group(3)
|
| 1008 |
+
if "." not in module_with_arch:
|
| 1009 |
+
return module_with_arch, None
|
| 1010 |
+
module, arch = module_with_arch.rsplit(".", 1)
|
| 1011 |
+
if module.startswith("addons."):
|
| 1012 |
+
module = module[len("addons.") :]
|
| 1013 |
+
return module, arch
|
| 1014 |
+
|
| 1015 |
+
modules: Set[str] = set()
|
| 1016 |
+
for name in modules_meta.keys():
|
| 1017 |
+
module, _arch = to_module_arch(name)
|
| 1018 |
+
if _arch == arch:
|
| 1019 |
+
modules.add(cast(str, module))
|
| 1020 |
+
|
| 1021 |
+
ext_pattern = re.compile(r"^extensions\." + r"(?P<module>[^.]+)\." + qt_ver_str + r"\." + arch + r"$")
|
| 1022 |
+
for ext in QtRepoProperty.known_extensions(version):
|
| 1023 |
+
try:
|
| 1024 |
+
ext_meta = self._fetch_extension_metadata(self.archive_id.to_extension_folder(ext, qt_ver_str, arch))
|
| 1025 |
+
for key, value in ext_meta.items():
|
| 1026 |
+
ext_match = ext_pattern.match(key)
|
| 1027 |
+
if ext_match is not None:
|
| 1028 |
+
module = ext_match.group("module")
|
| 1029 |
+
if module is not None:
|
| 1030 |
+
modules.add(ext)
|
| 1031 |
+
except (ChecksumDownloadFailure, ArchiveDownloadError):
|
| 1032 |
+
pass
|
| 1033 |
+
return sorted(modules)
|
| 1034 |
+
|
| 1035 |
+
@staticmethod
|
| 1036 |
+
def require_text(element: Element, key: str) -> str:
|
| 1037 |
+
node = element.find(key)
|
| 1038 |
+
if node is None:
|
| 1039 |
+
raise ArchiveListError(f"Downloaded metadata does not match the expected structure. Missing key: {key}")
|
| 1040 |
+
return node.text or ""
|
| 1041 |
+
|
| 1042 |
+
def fetch_long_modules(self, version: Version, arch: str) -> ModuleData:
|
| 1043 |
+
"""Returns long listing of modules"""
|
| 1044 |
+
extension = QtRepoProperty.extension_for_arch(arch, version >= Version("6.0.0"))
|
| 1045 |
+
qt_ver_str = self._get_qt_version_str(version)
|
| 1046 |
+
# Example: re.compile(r"^(preview\.)?qt\.(qt5\.)?590(\.addons)?\.(?P<module>[^.]+)\.gcc_64$")
|
| 1047 |
+
# qt.qt6.680.addons.qtwebsockets.win64_msvc2022_64
|
| 1048 |
+
# qt.qt6.680.debug_info.win64_msvc2022_64
|
| 1049 |
+
pattern = re.compile(
|
| 1050 |
+
r"^(preview\.)?qt\.(qt"
|
| 1051 |
+
+ str(version.major)
|
| 1052 |
+
+ r"\.)?"
|
| 1053 |
+
+ qt_ver_str
|
| 1054 |
+
+ r"(\.addons)?\.(?P<module>[^.]+)\."
|
| 1055 |
+
+ arch
|
| 1056 |
+
+ r"$"
|
| 1057 |
+
)
|
| 1058 |
+
|
| 1059 |
+
def matches_arch(element: Element) -> bool:
|
| 1060 |
+
return bool(pattern.match(MetadataFactory.require_text(element, "Name")))
|
| 1061 |
+
|
| 1062 |
+
modules_meta = self._fetch_module_metadata(self.archive_id.to_folder(version, qt_ver_str, extension), matches_arch)
|
| 1063 |
+
m: Dict[str, Dict[str, str]] = {}
|
| 1064 |
+
for key, value in modules_meta.items():
|
| 1065 |
+
match = pattern.match(key)
|
| 1066 |
+
if match is not None:
|
| 1067 |
+
module = match.group("module")
|
| 1068 |
+
if module is not None:
|
| 1069 |
+
m[module] = value
|
| 1070 |
+
|
| 1071 |
+
# Examples: extensions.qtwebengine.680.debug_information
|
| 1072 |
+
# extensions.qtwebengine.680.win64_msvc2022_64
|
| 1073 |
+
ext_pattern = re.compile(r"^extensions\." + r"(?P<module>[^.]+)\." + qt_ver_str + r"\." + arch + r"$")
|
| 1074 |
+
for ext in QtRepoProperty.known_extensions(version):
|
| 1075 |
+
try:
|
| 1076 |
+
ext_meta = self._fetch_extension_metadata(self.archive_id.to_extension_folder(ext, qt_ver_str, arch))
|
| 1077 |
+
for key, value in ext_meta.items():
|
| 1078 |
+
ext_match = ext_pattern.match(key)
|
| 1079 |
+
if ext_match is not None:
|
| 1080 |
+
module = ext_match.group("module")
|
| 1081 |
+
if module is not None:
|
| 1082 |
+
m[module] = value
|
| 1083 |
+
except (ChecksumDownloadFailure, ArchiveDownloadError):
|
| 1084 |
+
pass
|
| 1085 |
+
return ModuleData(m)
|
| 1086 |
+
|
| 1087 |
+
def fetch_modules_sde(self, cmd_type: str, version: Version) -> List[str]:
|
| 1088 |
+
"""Returns list of modules for src/doc/examples"""
|
| 1089 |
+
assert cmd_type in ("doc", "examples") and self.archive_id.target in (
|
| 1090 |
+
"desktop",
|
| 1091 |
+
"qt",
|
| 1092 |
+
), "Internal misuse of fetch_modules_sde"
|
| 1093 |
+
qt_ver_str = self._get_qt_version_str(version)
|
| 1094 |
+
modules_meta = self._fetch_module_metadata(
|
| 1095 |
+
self.archive_id.to_folder(version, qt_ver_str, QtRepoProperty.sde_ext(version))
|
| 1096 |
+
)
|
| 1097 |
+
# pattern: Match all names "qt.qt5.12345.doc.(\w+)
|
| 1098 |
+
pattern = re.compile(r"^qt\.(qt" + str(version.major) + r"\.)?" + qt_ver_str + r"\." + cmd_type + r"\.(.+)$")
|
| 1099 |
+
|
| 1100 |
+
modules: List[str] = []
|
| 1101 |
+
for name in modules_meta:
|
| 1102 |
+
_match = pattern.match(name)
|
| 1103 |
+
if _match:
|
| 1104 |
+
modules.append(_match.group(2))
|
| 1105 |
+
return modules
|
| 1106 |
+
|
| 1107 |
+
def fetch_archives_sde(self, cmd_type: str, version: Version) -> List[str]:
|
| 1108 |
+
"""Returns list of archives for src/doc/examples"""
|
| 1109 |
+
assert cmd_type in ("src", "doc", "examples") and self.archive_id.target in (
|
| 1110 |
+
"desktop",
|
| 1111 |
+
"qt",
|
| 1112 |
+
), "Internal misuse of fetch_archives_sde"
|
| 1113 |
+
return self.fetch_archives(version, cmd_type, [], is_sde=True)
|
| 1114 |
+
|
| 1115 |
+
def fetch_archives(self, version: Version, arch: str, modules: List[str], is_sde: bool = False) -> List[str]:
|
| 1116 |
+
extension = (
|
| 1117 |
+
QtRepoProperty.sde_ext(version)
|
| 1118 |
+
if is_sde
|
| 1119 |
+
else QtRepoProperty.extension_for_arch(arch, version >= Version("6.0.0"))
|
| 1120 |
+
)
|
| 1121 |
+
qt_version_str = self._get_qt_version_str(version)
|
| 1122 |
+
nonempty = MetadataFactory._has_nonempty_downloads
|
| 1123 |
+
|
| 1124 |
+
def all_modules(element: Element) -> bool:
|
| 1125 |
+
_module, _arch = MetadataFactory.require_text(element, "Name").split(".")[-2:]
|
| 1126 |
+
return _arch == arch and _module != qt_version_str and nonempty(element)
|
| 1127 |
+
|
| 1128 |
+
def specify_modules(element: Element) -> bool:
|
| 1129 |
+
_module, _arch = MetadataFactory.require_text(element, "Name").split(".")[-2:]
|
| 1130 |
+
return _arch == arch and _module in modules and nonempty(element)
|
| 1131 |
+
|
| 1132 |
+
def no_modules(element: Element) -> bool:
|
| 1133 |
+
name: Optional[str] = getattr(element.find("Name"), "text", None)
|
| 1134 |
+
return name is not None and name.endswith(f".{qt_version_str}.{arch}") and nonempty(element)
|
| 1135 |
+
|
| 1136 |
+
predicate = no_modules if not modules else all_modules if "all" in modules else specify_modules
|
| 1137 |
+
try:
|
| 1138 |
+
mod_metadata = self._fetch_module_metadata(
|
| 1139 |
+
self.archive_id.to_folder(version, qt_version_str, extension), predicate=predicate
|
| 1140 |
+
)
|
| 1141 |
+
except (AttributeError, ValueError) as e:
|
| 1142 |
+
raise ArchiveListError(f"Downloaded metadata is corrupted. {e}") from e
|
| 1143 |
+
|
| 1144 |
+
# Did we find all requested modules?
|
| 1145 |
+
if modules and "all" not in modules:
|
| 1146 |
+
requested_set = set(modules)
|
| 1147 |
+
actual_set = set([_name.split(".")[-2] for _name in mod_metadata.keys()])
|
| 1148 |
+
not_found = sorted(requested_set.difference(actual_set))
|
| 1149 |
+
if not_found:
|
| 1150 |
+
raise CliInputError(
|
| 1151 |
+
f"The requested modules were not located: {not_found}", suggested_action=suggested_follow_up(self)
|
| 1152 |
+
)
|
| 1153 |
+
|
| 1154 |
+
csv_lists = [mod["DownloadableArchives"] for mod in mod_metadata.values()]
|
| 1155 |
+
return sorted(set([arc.split("-")[0] for csv in csv_lists for arc in csv.split(", ")]))
|
| 1156 |
+
|
| 1157 |
+
def describe_filters(self) -> str:
|
| 1158 |
+
if self.spec is None:
|
| 1159 |
+
return str(self.archive_id)
|
| 1160 |
+
return "{} with spec {}".format(self.archive_id, self.spec)
|
| 1161 |
+
|
| 1162 |
+
def fetch_default_desktop_arch(self, version: Version, is_msvc: bool = False) -> str:
|
| 1163 |
+
assert self.archive_id.target == "desktop", "This function is meant to fetch desktop architectures"
|
| 1164 |
+
if self.archive_id.host == "linux":
|
| 1165 |
+
if version >= Version("6.7.0"):
|
| 1166 |
+
return "linux_gcc_64"
|
| 1167 |
+
else:
|
| 1168 |
+
return "gcc_64"
|
| 1169 |
+
elif self.archive_id.host == "linux_arm64":
|
| 1170 |
+
return "linux_gcc_arm64"
|
| 1171 |
+
elif self.archive_id.host == "mac":
|
| 1172 |
+
return "clang_64"
|
| 1173 |
+
elif self.archive_id.host == "windows" and is_msvc:
|
| 1174 |
+
if version >= Version("6.8.0"):
|
| 1175 |
+
return "win64_msvc2022_64"
|
| 1176 |
+
else:
|
| 1177 |
+
return "win64_msvc2019_64"
|
| 1178 |
+
arches = [arch for arch in self.fetch_arches(version) if QtRepoProperty.MINGW_ARCH_PATTERN.match(arch)]
|
| 1179 |
+
selected_arch = QtRepoProperty.select_default_mingw(arches, is_dir=False)
|
| 1180 |
+
if not selected_arch:
|
| 1181 |
+
raise EmptyMetadata("No default desktop architecture available")
|
| 1182 |
+
return selected_arch
|
| 1183 |
+
|
| 1184 |
+
|
| 1185 |
+
def suggested_follow_up(meta: MetadataFactory) -> List[str]:
|
| 1186 |
+
"""Makes an informed guess at what the user got wrong, in the event of an error."""
|
| 1187 |
+
msg = []
|
| 1188 |
+
list_cmd = "list-tool" if meta.archive_id.is_tools() else "list-qt"
|
| 1189 |
+
base_cmd = "aqt {0} {1.host} {1.target}".format(list_cmd, meta.archive_id)
|
| 1190 |
+
versions_msg = f"Please use '{base_cmd}' to show versions of Qt available."
|
| 1191 |
+
arches_msg = f"Please use '{base_cmd} --arch <QT_VERSION>' to show architectures available."
|
| 1192 |
+
|
| 1193 |
+
if meta.archive_id.is_tools() and meta.request_type == "tool variant names":
|
| 1194 |
+
msg.append(f"Please use '{base_cmd}' to check what tools are available.")
|
| 1195 |
+
elif meta.spec is not None:
|
| 1196 |
+
msg.append(
|
| 1197 |
+
f"Please use '{base_cmd}' to check that versions of {meta.archive_id.category} "
|
| 1198 |
+
f"exist within the spec '{meta.spec}'."
|
| 1199 |
+
)
|
| 1200 |
+
elif meta.request_type in ("architectures", "modules", "extensions"):
|
| 1201 |
+
msg.append(f"Please use '{base_cmd}' to show versions of Qt available.")
|
| 1202 |
+
if meta.request_type == "modules":
|
| 1203 |
+
msg.append(f"Please use '{base_cmd} --arch <QT_VERSION>' to list valid architectures.")
|
| 1204 |
+
elif meta.request_type == "archives for modules":
|
| 1205 |
+
msg.extend([versions_msg, arches_msg, f"Please use '{base_cmd} --modules <QT_VERSION>' to show modules available."])
|
| 1206 |
+
elif meta.request_type == "archives for qt":
|
| 1207 |
+
msg.extend([versions_msg, arches_msg])
|
| 1208 |
+
|
| 1209 |
+
return msg
|
| 1210 |
+
|
| 1211 |
+
|
| 1212 |
+
def show_list(meta: MetadataFactory):
|
| 1213 |
+
try:
|
| 1214 |
+
output = meta.getList()
|
| 1215 |
+
if not output:
|
| 1216 |
+
raise EmptyMetadata(
|
| 1217 |
+
f"No {meta.request_type} available for this request.", suggested_action=suggested_follow_up(meta)
|
| 1218 |
+
)
|
| 1219 |
+
if isinstance(output, Versions):
|
| 1220 |
+
print(format(output))
|
| 1221 |
+
elif isinstance(output, TableMetadata):
|
| 1222 |
+
width: int = shutil.get_terminal_size((0, 40)).columns
|
| 1223 |
+
if width == 0: # notty ?
|
| 1224 |
+
print(format(output, "{:0t}"))
|
| 1225 |
+
elif width < 95: # narrow terminal
|
| 1226 |
+
print(format(output, "{:T}"))
|
| 1227 |
+
else:
|
| 1228 |
+
print("{0:{1}t}".format(output, width))
|
| 1229 |
+
elif meta.archive_id.is_tools():
|
| 1230 |
+
print(*output, sep="\n")
|
| 1231 |
+
else:
|
| 1232 |
+
print(*output, sep=" ")
|
| 1233 |
+
except (ArchiveDownloadError, ArchiveConnectionError) as e:
|
| 1234 |
+
e.append_suggested_follow_up(suggested_follow_up(meta))
|
| 1235 |
+
raise e from e
|
python/py313/Lib/site-packages/aqt/settings.ini
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[DEFAULTS]
|
| 2 |
+
|
| 3 |
+
[aqt]
|
| 4 |
+
concurrency : 4
|
| 5 |
+
baseurl : https://download.qt.io
|
| 6 |
+
7zcmd : 7z
|
| 7 |
+
print_stacktrace_on_error : False
|
| 8 |
+
always_keep_archives : False
|
| 9 |
+
archive_download_location : .
|
| 10 |
+
min_module_size : 41
|
| 11 |
+
|
| 12 |
+
[requests]
|
| 13 |
+
connection_timeout : 3.5
|
| 14 |
+
response_timeout : 30
|
| 15 |
+
max_retries_on_connection_error : 5
|
| 16 |
+
retry_backoff : 0.1
|
| 17 |
+
max_retries_on_checksum_error : 5
|
| 18 |
+
max_retries_to_retrieve_hash : 5
|
| 19 |
+
hash_algorithm : sha256
|
| 20 |
+
INSECURE_NOT_FOR_PRODUCTION_ignore_hash : False
|
| 21 |
+
|
| 22 |
+
[qtofficial]
|
| 23 |
+
unattended : True
|
| 24 |
+
installer_timeout : 1800
|
| 25 |
+
operation_does_not_exist_error : Ignore
|
| 26 |
+
overwrite_target_directory : No
|
| 27 |
+
stop_processes_for_updates : Ignore
|
| 28 |
+
installation_error_with_cancel : Ignore
|
| 29 |
+
installation_error_with_ignore : Ignore
|
| 30 |
+
associate_common_filetypes : Yes
|
| 31 |
+
telemetry : No
|
| 32 |
+
cache_path :
|
| 33 |
+
temp_dir :
|
| 34 |
+
|
| 35 |
+
[mirrors]
|
| 36 |
+
trusted_mirrors :
|
| 37 |
+
https://download.qt.io
|
| 38 |
+
blacklist :
|
| 39 |
+
http://mirrors.ocf.berkeley.edu
|
| 40 |
+
http://mirrors.tuna.tsinghua.edu.cn
|
| 41 |
+
http://mirrors.geekpie.club
|
| 42 |
+
fallbacks :
|
| 43 |
+
https://qtproject.mirror.liquidtelecom.com/
|
| 44 |
+
https://mirrors.aliyun.com/qt/
|
| 45 |
+
https://mirrors.ustc.edu.cn/qtproject/
|
| 46 |
+
https://ftp.jaist.ac.jp/pub/qtproject/
|
| 47 |
+
https://ftp.yz.yamagata-u.ac.jp/pub/qtproject/
|
| 48 |
+
https://qt-mirror.dannhauer.de/
|
| 49 |
+
https://ftp.fau.de/qtproject/
|
| 50 |
+
https://mirror.netcologne.de/qtproject/
|
| 51 |
+
https://mirrors.dotsrc.org/qtproject/
|
| 52 |
+
https://www.nic.funet.fi/pub/mirrors/download.qt-project.org/
|
| 53 |
+
https://master.qt.io/
|
| 54 |
+
https://mirrors.ukfast.co.uk/sites/qt.io/
|
| 55 |
+
https://ftp2.nluug.nl/languages/qt/
|
| 56 |
+
https://ftp1.nluug.nl/languages/qt/
|
| 57 |
+
https://qt.mirror.constant.com/
|
| 58 |
+
|
| 59 |
+
[kde_patches]
|
| 60 |
+
patches :
|
| 61 |
+
0001-toolchain.prf-Use-vswhere-to-obtain-VS-installation-.patch
|
| 62 |
+
0002-Fix-allocated-memory-of-QByteArray-returned-by-QIODe.patch
|
| 63 |
+
0003-Update-CLDR-to-v37-adding-Nigerian-Pidgin-as-a-new-l.patch
|
| 64 |
+
0004-QLayout-docs-explain-better-what-the-QWidget-ctor-ar.patch
|
| 65 |
+
0005-QMacStyle-fix-tab-rendering.patch
|
| 66 |
+
0006-QMacStyle-more-pixel-refinements.patch
|
| 67 |
+
0007-Deprecate-ordering-on-QItemSelectionRange.patch
|
| 68 |
+
0008-Deprecate-QLocale-Language-entries-that-no-locale-da.patch
|
| 69 |
+
0009-Deprecate-old-aliases-for-two-countries-and-several-.patch
|
| 70 |
+
0010-QAbstractItemModelTester-don-t-rely-on-hasChildren.patch
|
| 71 |
+
0011-Doc-Remove-mentioning-of-old-macos-versions-from-QSe.patch
|
| 72 |
+
0012-Pass-SameSite-through-QNetworkCookie.patch
|
| 73 |
+
0013-doc-fix-typo-consise-concise.patch
|
| 74 |
+
0014-Selftest-copy-XAUTHORITY-environment-variable.patch
|
| 75 |
+
0015-Fix-delay-first-time-a-font-is-used.patch
|
| 76 |
+
0016-Fix-QScreen-orientation-not-being-updated-when-setti.patch
|
| 77 |
+
0017-Android-Request-cursor-to-be-in-proper-position.patch
|
| 78 |
+
0018-testlib-Let-logger-report-whether-it-is-logging-to-s.patch
|
| 79 |
+
0019-Android-disable-Gradle-caching-by-default.patch
|
| 80 |
+
0020-Android-replace-stacktrace-with-debug-message-in-sea.patch
|
| 81 |
+
0021-Use-void-instead-of-Q_UNUSED.patch
|
| 82 |
+
0022-Don-t-show-QPushButton-as-hovered-unless-the-mouse-i.patch
|
| 83 |
+
0023-MinGW-Fix-assert-in-QCoreApplication-arguments-when-.patch
|
| 84 |
+
0024-QCombobox-propagate-the-palette-to-the-embedded-line.patch
|
| 85 |
+
0025-QMarginsF-document-that-isNull-operator-operator-are.patch
|
| 86 |
+
0026-qmake-vcxproj-Fix-handling-of-extra-compiler-outputs.patch
|
| 87 |
+
0027-Android-fix-documentation-about-ANDROID_EXTRA_LIBS.patch
|
| 88 |
+
0028-Offscreen-QPA-implement-a-native-interface.patch
|
| 89 |
+
0029-DropSite-example-support-markdown.patch
|
| 90 |
+
0030-Do-not-define-dynamic_cast.patch
|
| 91 |
+
0031-Android-fix-crash-by-passing-the-right-Handle-to-dls.patch
|
| 92 |
+
0032-testlib-Add-private-API-to-add-test-logger.patch
|
| 93 |
+
0033-Update-third-party-md4c-to-version-0.4.6.patch
|
| 94 |
+
0034-moc-Handle-include-in-enum-take-2.patch
|
| 95 |
+
0035-InputMethod-should-call-reset-function-when-proxywid.patch
|
| 96 |
+
0036-Add-possibility-to-set-QNX-Screen-pipeline-value.patch
|
| 97 |
+
0037-qglobal-Only-define-QT_ENSURE_STACK_ALIGNED_FOR_SSE-.patch
|
| 98 |
+
0038-macOS-FreeType-fix-crash-with-non-printable-unicode.patch
|
| 99 |
+
0039-Linux-fix-crash-in-AtSpi-adaptor-when-handling-windo.patch
|
| 100 |
+
0040-Add-_MSC_VER-check-to-MSVC-ARM-compiler-workaround.patch
|
| 101 |
+
0041-QMap-suppress-warning-about-strict-aliasing-violatio.patch
|
| 102 |
+
0042-Add-changes-file-for-Qt-5.15.2.patch
|
| 103 |
+
0043-Set-the-url-to-have-the-AtNx-filename-if-one-is-foun.patch
|
| 104 |
+
0044-QMap-don-t-tell-everyone-QMapNode-has-no-friends.patch
|
| 105 |
+
0045-QNAM-Work-around-QObject-finicky-orphan-cleanup-deta.patch
|
| 106 |
+
0046-xcb-ensure-that-available-glx-version-is-greater-tha.patch
|
| 107 |
+
0047-Protect-QImage-colorspace-transform-on-shutdown.patch
|
| 108 |
+
0048-Fix-qstylesheetstyle-clip-border-error.patch
|
| 109 |
+
0049-Correct-processEvents-documentation.patch
|
| 110 |
+
0050-Update-CLDR-to-v38.patch
|
| 111 |
+
0051-Fix-compilation-when-using-no-mimetype-database.patch
|
| 112 |
+
0052-Reduce-memory-reallocations-in-QTextTablePrivate-upd.patch
|
| 113 |
+
0053-Fix-regular-expression-initialize-with-incorrect-fil.patch
|
| 114 |
+
0054-Cocoa-Allow-CMD-H-to-hide-the-application-when-a-too.patch
|
| 115 |
+
0055-Fix-pcre2-feature-conditions.patch
|
| 116 |
+
0056-Q_PRIMITIVE_TYPE-improve-the-documentation.patch
|
| 117 |
+
0057-QAsn1Element-Read-value-in-blocks-to-avoid-oom-at-wr.patch
|
| 118 |
+
0058-Android-Don-t-use-putIfAbsent-as-that-is-not-availab.patch
|
| 119 |
+
0059-QMutex-order-reads-from-QMutexPrivate-waiters-and-QB.patch
|
| 120 |
+
0060-Android-Add-the-QtAndroidBearer.jar-to-the-jar-depen.patch
|
| 121 |
+
0061-Android-Add-the-required-linker-flags-for-unwinding-.patch
|
| 122 |
+
0062-Android-recommend-against-using-ANDROID_ABIS-inside-.patch
|
| 123 |
+
0063-Android-fix-android-java-and-templates-targets-with-.patch
|
| 124 |
+
0064-QCharRef-properly-disable-assignment-from-char.patch
|
| 125 |
+
0065-Android-Treat-ACTION_CANCEL-as-TouchPointReleased.patch
|
| 126 |
+
0066-Fix-misidentification-of-some-shearing-QTransforms-a.patch
|
| 127 |
+
0067-Fix-QGraphicsItem-crash-if-click-right-button-of-mou.patch
|
| 128 |
+
0068-Bump-version.patch
|
| 129 |
+
0069-Android-Ensure-windows-always-have-a-geometry-on-cre.patch
|
| 130 |
+
0070-macOS-Account-for-Big-Sur-always-enabling-layer-back.patch
|
| 131 |
+
0071-Fix-shaping-problems-on-iOS-14-macOS-11.patch
|
| 132 |
+
0072-Link-to-qAlpha-in-qRgb-and-qRgba-docs.patch
|
| 133 |
+
0073-HTTP2-fix-crash-from-assertion.patch
|
| 134 |
+
0074-Fuzzing-Add-a-test-for-QDateTime-fromString.patch
|
| 135 |
+
0075-QSocks5SocketEngine-Fix-out-of-bounds-access-of-QBA.patch
|
| 136 |
+
0076-Use-QTRY_COMPARE-in-an-attempt-to-make-the-test-less.patch
|
| 137 |
+
0077-Doc-Document-QGradient-Preset-enum-values.patch
|
| 138 |
+
0078-Doc-Fix-documentation-warnings-for-Qt-XML.patch
|
| 139 |
+
0079-Doc-Fix-documentation-warnings-in-Qt-Network.patch
|
| 140 |
+
0080-Ensure-that-QMenu-is-polished-before-setting-the-scr.patch
|
| 141 |
+
0081-widgets-Don-t-report-new-focus-object-during-clearFo.patch
|
| 142 |
+
0082-QDtls-remove-redundant-RAII-struct.patch
|
| 143 |
+
0083-macOS-Propagate-device-pixel-ratio-of-system-tray-ic.patch
|
| 144 |
+
0084-tst_qocsp-improve-code-coverage.patch
|
| 145 |
+
0085-Doc-explain-how-to-create-a-test-touch-device-for-us.patch
|
| 146 |
+
0086-macOS-Upgrade-supported-SDK-to-11.0.patch
|
| 147 |
+
0087-Fix-logic-error-in-QString-replace-ch-after-cs.patch
|
| 148 |
+
0088-Be-more-consistent-when-converting-JSON-values-from-.patch
|
| 149 |
+
0089-QCoreApplication-add-more-information-to-processEven.patch
|
| 150 |
+
0090-Fix-QSFPM-not-emitting-dataChanged-when-source-model.patch
|
| 151 |
+
0091-Android-Fix-android-accessibility-not-being-set-acti.patch
|
| 152 |
+
0092-Fix-x-height-name-in-stylesheet-docs.patch
|
| 153 |
+
0093-QMutex-Work-around-ICC-bug-in-dealing-with-constexpr.patch
|
| 154 |
+
0094-wasm-fix-resizing-of-qwidget-windows.patch
|
| 155 |
+
0095-Avoid-integer-overflow-and-division-by-zero.patch
|
| 156 |
+
0096-QPasswordDigestor-improve-code-coverage.patch
|
| 157 |
+
0097-QStackedLayout-fix-a-memory-leak.patch
|
| 158 |
+
0098-Limit-value-in-setFontWeightFromValue.patch
|
| 159 |
+
0099-Doc-Fix-documentation-of-qmake-s-exists-function.patch
|
| 160 |
+
0100-QVLA-do-not-include-QtTest.patch
|
| 161 |
+
0101-Clean-up-docs-of-QCalendar-related-QLocale-toString-.patch
|
| 162 |
+
0102-Change-android-target-SDK-version-to-29.patch
|
| 163 |
+
0103-QVLA-always-use-new-to-create-new-objects.patch
|
| 164 |
+
0104-QPushButton-fix-support-of-style-sheet-rule-for-text.patch
|
| 165 |
+
0105-Limit-pen-width-to-maximal-32767.patch
|
| 166 |
+
0106-Doc-Consistently-use-book-style-capitalization-for-Q.patch
|
| 167 |
+
0107-qstring.h-fix-warnings-about-shortening-qsizetype-to.patch
|
| 168 |
+
0108-Fix-invalid-QSortFilterProxyModel-dataChanged-parame.patch
|
| 169 |
+
0109-Minor-refactor-of-installMetaFile.patch
|
| 170 |
+
0110-Return-a-more-useful-date-time-on-parser-failure-in-.patch
|
| 171 |
+
0111-QCalendar-increase-coverage-by-tests.patch
|
| 172 |
+
0112-Bounds-check-time-zone-offsets-when-parsing.patch
|
| 173 |
+
0113-Network-self-test-make-it-work-with-docker-container.patch
|
| 174 |
+
0114-QSslConfiguration-improve-code-coverage.patch
|
| 175 |
+
0115-Add-new-way-to-mess-up-projects-with-QMAKE_INSTALL_R.patch
|
| 176 |
+
0116-Install-3rd-party-headers-and-meta-for-static-builds.patch
|
| 177 |
+
0117-Create-qtlibjpeg-for-jpeg-image-plugin.patch
|
| 178 |
+
0118-QStandardPaths-Don-t-change-permissions-of-XDG_RUNTI.patch
|
| 179 |
+
0119-tst_QSslCertificate-improve-code-coverage.patch
|
| 180 |
+
0120-Let-QXcbConnection-getTimestamp-properly-exit-when-X.patch
|
| 181 |
+
0121-QDtls-cookie-verifier-make-sure-a-server-can-re-use-.patch
|
| 182 |
+
0122-QMacStyle-remove-vertical-adjustment-for-inactive-ta.patch
|
| 183 |
+
0123-Revert-xcb-add-xcb-util-dependency-for-xcb-image.patch
|
| 184 |
+
0124-Containers-call-constructors-even-for-primitive-type.patch
|
| 185 |
+
0125-Android-print-tailored-warning-if-qml-dependency-pat.patch
|
| 186 |
+
0126-Cosmetic-stroker-avoid-overflows-for-non-finite-coor.patch
|
| 187 |
+
0127-QSslCipher-improve-its-code-coverage-and-auto-tests.patch
|
| 188 |
+
0128-tst_qsslkey-handle-QT_NO_SSL-properly.patch
|
| 189 |
+
0129-Add-the-Qt-6.0-deprecation-macros.patch
|
| 190 |
+
0130-wasm-fix-mouse-double-click.patch
|
| 191 |
+
0131-Android-avoid-reflection-with-ClipData-addItem.patch
|
| 192 |
+
0132-QHeaderView-fix-spurious-sorting.patch
|
| 193 |
+
0133-Fix-exception-with-Android-5.x.patch
|
| 194 |
+
0134-Http2-Remove-errored-out-requests-from-queue.patch
|
| 195 |
+
0135-Http2-don-t-call-ensureConnection-when-there-s-no-re.patch
|
| 196 |
+
0136-Fix-QTranslator-load-search-order-not-following-uiLa.patch
|
| 197 |
+
0137-Avoid-signed-overflow-in-moc.patch
|
| 198 |
+
0138-Android-Kill-calls-to-deprecated-func-in-API-29.patch
|
| 199 |
+
0139-Doc-Improve-_CAST_FROM_ASCII-documentation.patch
|
| 200 |
+
0140-Improve-documented-function-argument-names.patch
|
| 201 |
+
0141-Fix-QImage-setPixelColor-on-RGBA64_Premultiplied.patch
|
| 202 |
+
0142-macOS-Make-sure-that-the-reserved-characters-are-not.patch
|
| 203 |
+
0143-Enable-testing-for-whether-a-calendar-registered-its.patch
|
| 204 |
+
0144-tests-add-a-shortcut-to-quit-app-in-allcursors.patch
|
| 205 |
+
0145-QSslSocket-Don-t-call-transmit-in-unencrypted-mode.patch
|
| 206 |
+
0146-QStringView-operator-operator-operator-currently-Qt6.patch
|
| 207 |
+
0147-QCborStreamReader-move-the-readStringChunk-code-to-t.patch
|
| 208 |
+
0148-Improve-the-documentation-for-QElapsedTimer-restart-.patch
|
| 209 |
+
0149-QSslSocket-verify-do-not-alter-the-default-configura.patch
|
| 210 |
+
0150-Fix-tst_QFontDatabase-aliases-failure-with-ambiguous.patch
|
| 211 |
+
0151-QStyleAnimation-make-sure-the-last-frame-of-animatio.patch
|
| 212 |
+
0152-PCRE-update-to-10.36.patch
|
| 213 |
+
0153-tst_QCborValue-adjust-the-size-of-the-minimum-string.patch
|
| 214 |
+
0154-macOS-Always-allow-interacting-with-popup-windows-du.patch
|
| 215 |
+
0155-macOS-Add-missing-QT_MANGLE_NAMESPACE.patch
|
| 216 |
+
0156-QSplashScreen-draw-pixmap-with-SmoothTransfrom.patch
|
| 217 |
+
0157-Android-Qml-accessibility-fixes.patch
|
| 218 |
+
0158-Http2-set-the-reply-s-error-code-and-string-on-error.patch
|
| 219 |
+
0159-Try-again-to-fix-Clang-s-Wconstant-logical-operand-w.patch
|
| 220 |
+
0160-Revert-Android-print-tailored-warning-if-qml-depende.patch
|
| 221 |
+
0161-QUrl-fix-parsing-of-empty-IPv6-addresses.patch
|
| 222 |
+
0162-tst_QSslError-improve-the-code-coverage-as-pointed-a.patch
|
| 223 |
+
0163-macOS-Disable-WA_QuitOnClose-on-menu-item-widget-con.patch
|
| 224 |
+
0164-QString-fix-count-QRegularExpression.patch
|
| 225 |
+
0165-QString-lastIndexOf-fix-off-by-one-for-zero-length-m.patch
|
| 226 |
+
0166-secureudpclient-a-speculative-fix-for-non-reproducib.patch
|
| 227 |
+
0167-Android-don-t-use-avx-and-avx2-when-building-for-And.patch
|
| 228 |
+
0168-Fuzzing-Provide-link-to-oss-fuzz.patch
|
| 229 |
+
0169-Blacklist-tst_QMdiArea-updateScrollBars-on-macos.patch
|
| 230 |
+
0170-Fix-build-with-GCC-11-include-limits.patch
|
| 231 |
+
0171-Build-fixes-for-GCC-11.patch
|
| 232 |
+
0172-Partially-revert-813a928c7c3cf98670b6043149880ed5c95.patch
|
| 233 |
+
0173-Fix-removing-columns-when-QSortFilterProxyModel-has-.patch
|
| 234 |
+
0174-Fix-get-out-of-bounds-index-in-QSortFilterProxyModel.patch
|
| 235 |
+
0175-Fix-handling-of-surrogates-in-QBidiAlgorithm.patch
|
| 236 |
+
0176-Avoid-undefined-color-values-in-corrupt-xpm-image.patch
|
| 237 |
+
0177-Gracefully-reject-requests-for-absurd-font-sizes.patch
|
| 238 |
+
0178-Don-t-own-unique-name-for-QDBusTrayIcon.patch
|
| 239 |
+
0179-QAbstractItemModelTester-fix-false-positive-when-mod.patch
|
| 240 |
+
0180-Fix-QAbstractItemModelTester-false-positive.patch
|
| 241 |
+
0181-Deprecate-QMutex-in-recursive-mode.patch
|
| 242 |
+
0182-Fix-QAbstractItemModelTester-false-positive.patch
|
| 243 |
+
0183-Fix-crash-on-serializing-default-constructed-QTimeZo.patch
|
| 244 |
+
0184-Fix-QTreeModel-calling-beginRemoveRows-twice.patch
|
| 245 |
+
0185-QConcatenateTablesProxyModel-skip-dataChanged-in-hid.patch
|
| 246 |
+
0186-QComboBox-fix-select-all-columns-in-the-view.patch
|
| 247 |
+
0187-QTableView-honor-spans-when-calculating-height-width.patch
|
| 248 |
+
0188-TableView-Trigger-the-resizing-of-editors-resizing-a.patch
|
| 249 |
+
0189-Fix-no-mapping-for-SysReq-key.patch
|
| 250 |
+
0190-qdbus-add-support-for-aay-QByteArrayList.patch
|
| 251 |
+
0191-QRandom-drop-a-usage-of-std-is_literal_type.patch
|
| 252 |
+
0192-fix-Optimize-the-performance-of-the-inotify-file-sys.patch
|
| 253 |
+
0193-Remove-the-unnecessary-template-parameter-from-the-c.patch
|
| 254 |
+
0194-Fix-memory-leak-when-using-small-caps-font.patch
|
| 255 |
+
0195-Make-sure-_q_printerChanged-is-called-even-if-only-p.patch
|
| 256 |
+
0196-fix-Alt-shortcut-on-non-US-layouts.patch
|
python/py313/Lib/site-packages/aqt/updater.py
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2019-2021 Hiroshi Miura <miurahr@linux.com>
|
| 4 |
+
#
|
| 5 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 6 |
+
# this software and associated documentation files (the "Software"), to deal in
|
| 7 |
+
# the Software without restriction, including without limitation the rights to
|
| 8 |
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 9 |
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
| 10 |
+
# subject to the following conditions:
|
| 11 |
+
#
|
| 12 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
# copies or substantial portions of the Software.
|
| 14 |
+
#
|
| 15 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 17 |
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 18 |
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 19 |
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 20 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
+
import logging
|
| 22 |
+
import os
|
| 23 |
+
import re
|
| 24 |
+
import stat
|
| 25 |
+
import subprocess
|
| 26 |
+
from logging import getLogger
|
| 27 |
+
from pathlib import Path
|
| 28 |
+
from typing import Dict, List, Optional, Union
|
| 29 |
+
|
| 30 |
+
import patch_ng as patch
|
| 31 |
+
|
| 32 |
+
from aqt.archives import TargetConfig
|
| 33 |
+
from aqt.exceptions import UpdaterError
|
| 34 |
+
from aqt.helper import Settings
|
| 35 |
+
from aqt.metadata import ArchiveId, MetadataFactory, QtRepoProperty, SimpleSpec, Version
|
| 36 |
+
|
| 37 |
+
dir_for_version = QtRepoProperty.dir_for_version
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def unpatched_paths() -> List[str]:
|
| 41 |
+
return [
|
| 42 |
+
"/home/qt/work/install/",
|
| 43 |
+
"/Users/qt/work/install/",
|
| 44 |
+
"\\home\\qt\\work\\install\\",
|
| 45 |
+
"\\Users\\qt\\work\\install\\",
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class Updater:
|
| 50 |
+
def __init__(self, prefix: Path, logger) -> None:
|
| 51 |
+
self.logger = logger
|
| 52 |
+
self.prefix = prefix
|
| 53 |
+
self.qmake_path: Optional[Path] = None
|
| 54 |
+
self.qconfigs: Dict[str, str] = {}
|
| 55 |
+
|
| 56 |
+
def _patch_binfile(self, file: Path, key: bytes, newpath: bytes):
|
| 57 |
+
"""Patch binary file with key/value"""
|
| 58 |
+
st = file.stat()
|
| 59 |
+
data = file.read_bytes()
|
| 60 |
+
idx = data.find(key)
|
| 61 |
+
if idx < 0:
|
| 62 |
+
return
|
| 63 |
+
assert len(newpath) < 256, "Qt Prefix path is too long(255)."
|
| 64 |
+
oldlen = data[idx + len(key) :].find(b"\0")
|
| 65 |
+
assert oldlen >= 0
|
| 66 |
+
value = newpath + b"\0" * (oldlen - len(newpath))
|
| 67 |
+
data = data[: idx + len(key)] + value + data[idx + len(key) + len(value) :]
|
| 68 |
+
file.write_bytes(data)
|
| 69 |
+
os.chmod(str(file), st.st_mode)
|
| 70 |
+
|
| 71 |
+
def _append_string(self, file: Path, val: str):
|
| 72 |
+
"""Append string to file"""
|
| 73 |
+
st = file.stat()
|
| 74 |
+
data = file.read_text("UTF-8")
|
| 75 |
+
data += val
|
| 76 |
+
file.write_text(data, "UTF-8")
|
| 77 |
+
os.chmod(str(file), st.st_mode)
|
| 78 |
+
|
| 79 |
+
def _patch_textfile(self, file: Path, old: Union[str, re.Pattern], new: str, *, is_executable: bool = False):
|
| 80 |
+
st = file.stat()
|
| 81 |
+
file_mode = st.st_mode | (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH if is_executable else 0)
|
| 82 |
+
data = file.read_text("UTF-8")
|
| 83 |
+
if isinstance(old, re.Pattern):
|
| 84 |
+
data = old.sub(new, data)
|
| 85 |
+
else:
|
| 86 |
+
data = data.replace(old, new)
|
| 87 |
+
file.write_text(data, "UTF-8")
|
| 88 |
+
os.chmod(str(file), file_mode)
|
| 89 |
+
|
| 90 |
+
def _detect_qmake(self) -> bool:
|
| 91 |
+
"""detect Qt configurations from qmake."""
|
| 92 |
+
for qmake_path in [
|
| 93 |
+
self.prefix.joinpath("bin", "qmake"),
|
| 94 |
+
self.prefix.joinpath("bin", "qmake.exe"),
|
| 95 |
+
]:
|
| 96 |
+
if not qmake_path.exists():
|
| 97 |
+
continue
|
| 98 |
+
try:
|
| 99 |
+
result = subprocess.run([str(qmake_path), "-query"], stdout=subprocess.PIPE)
|
| 100 |
+
except (subprocess.SubprocessError, IOError, OSError):
|
| 101 |
+
return False
|
| 102 |
+
if result.returncode == 0:
|
| 103 |
+
self.qmake_path = qmake_path
|
| 104 |
+
for line in result.stdout.splitlines():
|
| 105 |
+
vals = line.decode("UTF-8").split(":")
|
| 106 |
+
self.qconfigs[vals[0]] = vals[1]
|
| 107 |
+
return True
|
| 108 |
+
return False
|
| 109 |
+
|
| 110 |
+
def patch_prl(self, oldvalue):
|
| 111 |
+
for prlfile in self.prefix.joinpath("lib").glob("*.prl"):
|
| 112 |
+
self.logger.info("Patching {}".format(prlfile))
|
| 113 |
+
self._patch_textfile(prlfile, oldvalue, "$$[QT_INSTALL_LIBS]")
|
| 114 |
+
|
| 115 |
+
def patch_pkgconfig(self, oldvalue, os_name):
|
| 116 |
+
for pcfile in self.prefix.joinpath("lib", "pkgconfig").glob("*.pc"):
|
| 117 |
+
self.logger.info("Patching {}".format(pcfile))
|
| 118 |
+
self._patch_textfile(
|
| 119 |
+
pcfile,
|
| 120 |
+
"prefix={}".format(oldvalue),
|
| 121 |
+
"prefix={}".format(str(self.prefix)),
|
| 122 |
+
)
|
| 123 |
+
if os_name == "mac":
|
| 124 |
+
self._patch_textfile(
|
| 125 |
+
pcfile,
|
| 126 |
+
"-F{}".format(os.path.join(oldvalue, "lib")),
|
| 127 |
+
"-F{}".format(os.path.join(str(self.prefix), "lib")),
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
def patch_libtool(self, oldvalue, os_name):
|
| 131 |
+
for lafile in self.prefix.joinpath("lib").glob("*.la"):
|
| 132 |
+
self.logger.info("Patching {}".format(lafile))
|
| 133 |
+
self._patch_textfile(
|
| 134 |
+
lafile,
|
| 135 |
+
"libdir='={}'".format(oldvalue),
|
| 136 |
+
"libdir='={}'".format(os.path.join(str(self.prefix), "lib")),
|
| 137 |
+
)
|
| 138 |
+
self._patch_textfile(
|
| 139 |
+
lafile,
|
| 140 |
+
"libdir='{}'".format(oldvalue),
|
| 141 |
+
"libdir='{}'".format(os.path.join(str(self.prefix), "lib")),
|
| 142 |
+
)
|
| 143 |
+
self._patch_textfile(
|
| 144 |
+
lafile,
|
| 145 |
+
"-L={}".format(oldvalue),
|
| 146 |
+
"-L={}".format(os.path.join(str(self.prefix), "lib")),
|
| 147 |
+
)
|
| 148 |
+
self._patch_textfile(
|
| 149 |
+
lafile,
|
| 150 |
+
"-L{}".format(oldvalue),
|
| 151 |
+
"-L{}".format(os.path.join(str(self.prefix), "lib")),
|
| 152 |
+
)
|
| 153 |
+
if os_name == "mac":
|
| 154 |
+
self._patch_textfile(
|
| 155 |
+
lafile,
|
| 156 |
+
"-F={}".format(oldvalue),
|
| 157 |
+
"-F={}".format(os.path.join(str(self.prefix), "lib")),
|
| 158 |
+
)
|
| 159 |
+
self._patch_textfile(
|
| 160 |
+
lafile,
|
| 161 |
+
"-F{}".format(oldvalue),
|
| 162 |
+
"-F{}".format(os.path.join(str(self.prefix), "lib")),
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
def patch_qmake(self):
|
| 166 |
+
"""Patch to qmake binary"""
|
| 167 |
+
if self._detect_qmake():
|
| 168 |
+
if self.qmake_path is None:
|
| 169 |
+
return
|
| 170 |
+
self.logger.info("Patching {}".format(str(self.qmake_path)))
|
| 171 |
+
self._patch_binfile(
|
| 172 |
+
self.qmake_path,
|
| 173 |
+
key=b"qt_prfxpath=",
|
| 174 |
+
newpath=bytes(str(self.prefix), "UTF-8"),
|
| 175 |
+
)
|
| 176 |
+
self._patch_binfile(
|
| 177 |
+
self.qmake_path,
|
| 178 |
+
key=b"qt_epfxpath=",
|
| 179 |
+
newpath=bytes(str(self.prefix), "UTF-8"),
|
| 180 |
+
)
|
| 181 |
+
self._patch_binfile(
|
| 182 |
+
self.qmake_path,
|
| 183 |
+
key=b"qt_hpfxpath=",
|
| 184 |
+
newpath=bytes(str(self.prefix), "UTF-8"),
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
def patch_qt_scripts(self, base_dir, version_dir: str, os_name: str, desktop_arch_dir: str, version: Version):
|
| 188 |
+
sep = "\\" if os_name.startswith("windows") else "/"
|
| 189 |
+
patched = sep.join([base_dir, version_dir, desktop_arch_dir, "bin"])
|
| 190 |
+
|
| 191 |
+
def patch_script(script_name):
|
| 192 |
+
script_path = self.prefix / "bin" / (script_name + ".bat" if os_name.startswith("windows") else script_name)
|
| 193 |
+
self.logger.info(f"Patching {script_path}")
|
| 194 |
+
for unpatched in unpatched_paths():
|
| 195 |
+
self._patch_textfile(script_path, f"{unpatched}bin", patched, is_executable=True)
|
| 196 |
+
|
| 197 |
+
patch_script("qmake")
|
| 198 |
+
if version >= Version("6.2.2"):
|
| 199 |
+
patch_script("qtpaths")
|
| 200 |
+
if version >= Version("6.5.0"):
|
| 201 |
+
patch_script("qmake6")
|
| 202 |
+
patch_script("qtpaths6")
|
| 203 |
+
|
| 204 |
+
def patch_qtcore(self, target):
|
| 205 |
+
"""patch to QtCore"""
|
| 206 |
+
if target.os_name == "mac":
|
| 207 |
+
lib_dir = self.prefix.joinpath("lib", "QtCore.framework")
|
| 208 |
+
components = ["QtCore", "QtCore_debug"]
|
| 209 |
+
elif target.os_name == "linux":
|
| 210 |
+
lib_dir = self.prefix.joinpath("lib")
|
| 211 |
+
components = ["libQt5Core.so"]
|
| 212 |
+
elif target.os_name.startswith("windows"):
|
| 213 |
+
lib_dir = self.prefix.joinpath("bin")
|
| 214 |
+
components = ["Qt5Cored.dll", "Qt5Core.dll"]
|
| 215 |
+
else:
|
| 216 |
+
return
|
| 217 |
+
for component in components:
|
| 218 |
+
if lib_dir.joinpath(component).exists():
|
| 219 |
+
qtcore_path = lib_dir.joinpath(component).resolve()
|
| 220 |
+
self.logger.info("Patching {}".format(qtcore_path))
|
| 221 |
+
newpath = bytes(str(self.prefix), "UTF-8")
|
| 222 |
+
self._patch_binfile(qtcore_path, b"qt_prfxpath=", newpath)
|
| 223 |
+
|
| 224 |
+
def make_qtconf(self, base_dir, qt_version, arch_dir):
|
| 225 |
+
"""Prepare qt.conf"""
|
| 226 |
+
with open(os.path.join(base_dir, qt_version, arch_dir, "bin", "qt.conf"), "w") as f:
|
| 227 |
+
f.write("[Paths]\n")
|
| 228 |
+
f.write("Prefix=..\n")
|
| 229 |
+
|
| 230 |
+
def make_qtenv2(self, base_dir, qt_version, arch_dir):
|
| 231 |
+
"""Prepare qtenv2.bat"""
|
| 232 |
+
with open(os.path.join(base_dir, qt_version, arch_dir, "bin", "qtenv2.bat"), "w") as f:
|
| 233 |
+
f.write("@echo off\n")
|
| 234 |
+
f.write("echo Setting up environment for Qt usage...\n")
|
| 235 |
+
f.write("set PATH={};%PATH%\n".format(os.path.join(base_dir, qt_version, arch_dir, "bin")))
|
| 236 |
+
f.write("cd /D {}\n".format(os.path.join(base_dir, qt_version, arch_dir)))
|
| 237 |
+
f.write("echo Remember to call vcvarsall.bat to complete environment setup!\n")
|
| 238 |
+
|
| 239 |
+
def set_license(self, base_dir: str, qt_version: str, arch_dir: str):
|
| 240 |
+
"""Update qconfig.pri as OpenSource"""
|
| 241 |
+
with open(os.path.join(base_dir, qt_version, arch_dir, "mkspecs", "qconfig.pri"), "r+") as f:
|
| 242 |
+
lines = f.readlines()
|
| 243 |
+
f.seek(0)
|
| 244 |
+
f.truncate()
|
| 245 |
+
for line in lines:
|
| 246 |
+
if line.startswith("QT_EDITION ="):
|
| 247 |
+
line = "QT_EDITION = OpenSource\n"
|
| 248 |
+
if line.startswith("QT_LICHECK ="):
|
| 249 |
+
line = "QT_LICHECK =\n"
|
| 250 |
+
f.write(line)
|
| 251 |
+
|
| 252 |
+
def patch_target_qt_conf(self, base_dir: str, qt_version: str, arch_dir: str, os_name: str, desktop_arch_dir: str):
|
| 253 |
+
target_qt_conf = self.prefix / "bin" / "target_qt.conf"
|
| 254 |
+
self.logger.info(f"Patching {target_qt_conf}")
|
| 255 |
+
new_hostprefix = f"HostPrefix=../../{desktop_arch_dir}"
|
| 256 |
+
new_targetprefix = "Prefix={}".format(str(Path(base_dir).joinpath(qt_version, arch_dir, "target")))
|
| 257 |
+
new_hostdata = "HostData=../{}".format(arch_dir)
|
| 258 |
+
new_host_lib_execs = "./bin" if os_name.startswith("windows") else "./libexec"
|
| 259 |
+
old_host_lib_execs = re.compile(r"^HostLibraryExecutables=[^\n]*$", flags=re.MULTILINE)
|
| 260 |
+
|
| 261 |
+
self._patch_textfile(target_qt_conf, old_host_lib_execs, f"HostLibraryExecutables={new_host_lib_execs}")
|
| 262 |
+
for unpatched in unpatched_paths():
|
| 263 |
+
self._patch_textfile(target_qt_conf, f"Prefix={unpatched}target", new_targetprefix)
|
| 264 |
+
self._patch_textfile(target_qt_conf, "HostPrefix=../../", new_hostprefix)
|
| 265 |
+
self._patch_textfile(target_qt_conf, "HostData=target", new_hostdata)
|
| 266 |
+
|
| 267 |
+
def patch_qdevice_file(self, base_dir: str, qt_version: str, arch_dir: str, os_name: str):
|
| 268 |
+
"""Qt 6.4.1+ specific, but it should not hurt anything if `mkspecs/qdevice.pri` does not exist"""
|
| 269 |
+
|
| 270 |
+
qdevice = Path(base_dir) / qt_version / arch_dir / "mkspecs/qdevice.pri"
|
| 271 |
+
if not qdevice.exists():
|
| 272 |
+
return
|
| 273 |
+
|
| 274 |
+
old_line = re.compile(r"^DEFAULT_ANDROID_NDK_HOST =[^\n]*$", flags=re.MULTILINE)
|
| 275 |
+
new_line = f"DEFAULT_ANDROID_NDK_HOST = {'darwin' if os_name == 'mac' else os_name}-x86_64"
|
| 276 |
+
self._patch_textfile(qdevice, old_line, new_line)
|
| 277 |
+
|
| 278 |
+
@classmethod
|
| 279 |
+
def update(cls, target: TargetConfig, base_path: Path, installed_desktop_arch_dir: Optional[str]):
|
| 280 |
+
"""
|
| 281 |
+
Make Qt configuration files, qt.conf and qtconfig.pri.
|
| 282 |
+
And update pkgconfig and patch Qt5Core and qmake
|
| 283 |
+
|
| 284 |
+
:param installed_desktop_arch_dir: This is the path to a desktop Qt installation, like `Qt/6.3.0/mingw_win64`.
|
| 285 |
+
This may or may not contain an actual desktop Qt installation.
|
| 286 |
+
If it does not, the Updater will patch files in a mobile Qt installation
|
| 287 |
+
that point to this directory, and this installation will be non-functional
|
| 288 |
+
until the user installs a desktop Qt in this directory.
|
| 289 |
+
"""
|
| 290 |
+
logger = getLogger("aqt.updater")
|
| 291 |
+
arch = target.arch
|
| 292 |
+
version = Version(target.version)
|
| 293 |
+
os_name = target.os_name
|
| 294 |
+
version_dir = dir_for_version(version)
|
| 295 |
+
arch_dir = QtRepoProperty.get_arch_dir_name(os_name, arch, version)
|
| 296 |
+
base_dir = str(base_path)
|
| 297 |
+
try:
|
| 298 |
+
prefix = base_path / version_dir / arch_dir
|
| 299 |
+
updater = Updater(prefix, logger)
|
| 300 |
+
updater.set_license(base_dir, version_dir, arch_dir)
|
| 301 |
+
if target.arch not in [
|
| 302 |
+
"ios",
|
| 303 |
+
"android",
|
| 304 |
+
"wasm_32",
|
| 305 |
+
"wasm_singlethread",
|
| 306 |
+
"wasm_multithread",
|
| 307 |
+
"android_x86_64",
|
| 308 |
+
"android_arm64_v8a",
|
| 309 |
+
"android_x86",
|
| 310 |
+
"android_armv7",
|
| 311 |
+
"win64_msvc2019_arm64",
|
| 312 |
+
"win64_msvc2022_arm64_cross_compiled",
|
| 313 |
+
]: # desktop version
|
| 314 |
+
updater.make_qtconf(base_dir, version_dir, arch_dir)
|
| 315 |
+
updater.patch_qmake()
|
| 316 |
+
if target.os_name == "linux":
|
| 317 |
+
updater.patch_pkgconfig("/home/qt/work/install", target.os_name)
|
| 318 |
+
updater.patch_libtool("/home/qt/work/install/lib", target.os_name)
|
| 319 |
+
updater.patch_prl("/home/qt/work/install/lib")
|
| 320 |
+
elif target.os_name == "mac":
|
| 321 |
+
updater.patch_pkgconfig("/Users/qt/work/install", target.os_name)
|
| 322 |
+
updater.patch_libtool("/Users/qt/work/install/lib", target.os_name)
|
| 323 |
+
updater.patch_prl("/Users/qt/work/install/lib")
|
| 324 |
+
elif target.os_name.startswith("windows"):
|
| 325 |
+
updater.patch_pkgconfig("c:/Users/qt/work/install", target.os_name)
|
| 326 |
+
updater.patch_prl("c:/Users/qt/work/install/lib")
|
| 327 |
+
updater.make_qtenv2(base_dir, version_dir, arch_dir)
|
| 328 |
+
if version < Version("5.14.0"):
|
| 329 |
+
updater.patch_qtcore(target)
|
| 330 |
+
elif version in SimpleSpec(">=5.0,<6.0"):
|
| 331 |
+
updater.patch_qmake()
|
| 332 |
+
else: # qt6 mobile, wasm, or msvc-arm64
|
| 333 |
+
if installed_desktop_arch_dir is not None:
|
| 334 |
+
desktop_arch_dir = installed_desktop_arch_dir
|
| 335 |
+
else:
|
| 336 |
+
# Use MetadataFactory to check what the default architecture should be
|
| 337 |
+
meta = MetadataFactory(ArchiveId("qt", os_name, "desktop"))
|
| 338 |
+
desktop_arch_dir = meta.fetch_default_desktop_arch(version, is_msvc="msvc" in target.arch)
|
| 339 |
+
|
| 340 |
+
updater.patch_qt_scripts(base_dir, version_dir, target.os_name, desktop_arch_dir, version)
|
| 341 |
+
updater.patch_target_qt_conf(base_dir, version_dir, arch_dir, target.os_name, desktop_arch_dir)
|
| 342 |
+
updater.patch_qdevice_file(base_dir, version_dir, arch_dir, target.os_name)
|
| 343 |
+
except IOError as e:
|
| 344 |
+
raise UpdaterError(f"Updater caused an IO error: {e}") from e
|
| 345 |
+
|
| 346 |
+
@classmethod
|
| 347 |
+
def patch_kde(cls, src_dir):
|
| 348 |
+
logger = logging.getLogger("aqt")
|
| 349 |
+
PATCH_URL_BASE = "https://raw.githubusercontent.com/miurahr/kde-qt-patch/main/patches/"
|
| 350 |
+
for p in Settings.kde_patches:
|
| 351 |
+
logger.info("Apply patch: " + p)
|
| 352 |
+
patchfile = patch.fromurl(PATCH_URL_BASE + p)
|
| 353 |
+
patchfile.apply(strip=True, root=os.path.join(src_dir, "qtbase"))
|
python/py313/Lib/site-packages/aqt/version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__version__ = "3.3.0"
|
python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: aqtinstall
|
| 3 |
+
Version: 3.3.0
|
| 4 |
+
Summary: Another unofficial Qt installer
|
| 5 |
+
Author-email: Hiroshi Miura <miurahr@linux.com>
|
| 6 |
+
License: MIT License
|
| 7 |
+
Project-URL: Documentation, https://aqtinstall.readthedocs.io/
|
| 8 |
+
Project-URL: Bug Tracker, https://github.com/miurahr/aqtinstall/issues
|
| 9 |
+
Project-URL: Wiki, https://github.com/miurahr/aqtinstall/wiki
|
| 10 |
+
Project-URL: Source, https://github.com/miurahr/aqtinstall
|
| 11 |
+
Project-URL: Changelog, https://aqtinstall.readthedocs.io/en/latest/CHANGELOG.html
|
| 12 |
+
Classifier: Development Status :: 4 - Beta
|
| 13 |
+
Classifier: Environment :: Console
|
| 14 |
+
Classifier: Environment :: X11 Applications :: Qt
|
| 15 |
+
Classifier: Intended Audience :: Developers
|
| 16 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 17 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 18 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 19 |
+
Classifier: Operating System :: POSIX
|
| 20 |
+
Classifier: Operating System :: POSIX :: Linux
|
| 21 |
+
Classifier: Programming Language :: Python
|
| 22 |
+
Classifier: Programming Language :: C++
|
| 23 |
+
Classifier: Topic :: Software Development
|
| 24 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 25 |
+
Requires-Python: >=3.9
|
| 26 |
+
Description-Content-Type: text/x-rst
|
| 27 |
+
License-File: LICENSE
|
| 28 |
+
Requires-Dist: bs4
|
| 29 |
+
Requires-Dist: defusedxml
|
| 30 |
+
Requires-Dist: humanize
|
| 31 |
+
Requires-Dist: patch-ng
|
| 32 |
+
Requires-Dist: py7zr>=0.22.0
|
| 33 |
+
Requires-Dist: requests>=2.31.0
|
| 34 |
+
Requires-Dist: semantic-version
|
| 35 |
+
Requires-Dist: texttable
|
| 36 |
+
Provides-Extra: test
|
| 37 |
+
Requires-Dist: pytest>=6.0; extra == "test"
|
| 38 |
+
Requires-Dist: pytest-pep8; extra == "test"
|
| 39 |
+
Requires-Dist: pytest-cov; extra == "test"
|
| 40 |
+
Requires-Dist: pytest-remotedata>=0.4.1; extra == "test"
|
| 41 |
+
Requires-Dist: pytest-socket; extra == "test"
|
| 42 |
+
Requires-Dist: pytest-timeout; extra == "test"
|
| 43 |
+
Requires-Dist: pympler; extra == "test"
|
| 44 |
+
Provides-Extra: check
|
| 45 |
+
Requires-Dist: mypy>=1.10.0; extra == "check"
|
| 46 |
+
Requires-Dist: flake8<8.0.0,>=6.0.0; extra == "check"
|
| 47 |
+
Requires-Dist: flake8-black; extra == "check"
|
| 48 |
+
Requires-Dist: flake8-colors; extra == "check"
|
| 49 |
+
Requires-Dist: flake8-isort<7.0.0,>=6.0.0; extra == "check"
|
| 50 |
+
Requires-Dist: flake8-pyi; extra == "check"
|
| 51 |
+
Requires-Dist: flake8-typing-imports; extra == "check"
|
| 52 |
+
Requires-Dist: docutils; extra == "check"
|
| 53 |
+
Requires-Dist: check-manifest; extra == "check"
|
| 54 |
+
Requires-Dist: readme-renderer; extra == "check"
|
| 55 |
+
Requires-Dist: pygments; extra == "check"
|
| 56 |
+
Requires-Dist: packaging; extra == "check"
|
| 57 |
+
Requires-Dist: pylint; extra == "check"
|
| 58 |
+
Requires-Dist: types-requests; extra == "check"
|
| 59 |
+
Provides-Extra: docs
|
| 60 |
+
Requires-Dist: sphinx>=7.0; extra == "docs"
|
| 61 |
+
Requires-Dist: sphinx_rtd_theme>=1.3; extra == "docs"
|
| 62 |
+
Requires-Dist: sphinx-py3doc-enhanced-theme>=2.4; extra == "docs"
|
| 63 |
+
Provides-Extra: debug
|
| 64 |
+
Requires-Dist: pytest-leaks; extra == "debug"
|
| 65 |
+
Dynamic: license-file
|
| 66 |
+
|
| 67 |
+
Another Qt installer(aqt)
|
| 68 |
+
=========================
|
| 69 |
+
|
| 70 |
+
- Release: |pypi|
|
| 71 |
+
- Documentation: |docs|
|
| 72 |
+
- Test status: |gha| and Coverage: |coveralls|
|
| 73 |
+
- Code Quality: |codacy|
|
| 74 |
+
- Project maturity |Package health|
|
| 75 |
+
|
| 76 |
+
.. |pypi| image:: https://badge.fury.io/py/aqtinstall.svg
|
| 77 |
+
:target: http://badge.fury.io/py/aqtinstall
|
| 78 |
+
.. |docs| image:: https://readthedocs.org/projects/aqtinstall/badge/?version=stable
|
| 79 |
+
:target: https://aqtinstall.readthedocs.io/en/latest/?badge=stable
|
| 80 |
+
.. |gha| image:: https://github.com/miurahr/aqtinstall/workflows/Test%20on%20GH%20actions%20environment/badge.svg
|
| 81 |
+
:target: https://github.com/miurahr/aqtinstall/actions?query=workflow%3A%22Test+on+GH+actions+environment%22
|
| 82 |
+
.. |coveralls| image:: https://coveralls.io/repos/github/miurahr/aqtinstall/badge.svg?branch=master
|
| 83 |
+
:target: https://coveralls.io/github/miurahr/aqtinstall?branch=master
|
| 84 |
+
.. |Package health| image:: https://snyk.io/advisor/python/aqtinstall/badge.svg
|
| 85 |
+
:target: https://snyk.io/advisor/python/aqtinstall
|
| 86 |
+
:alt: aqtinstall
|
| 87 |
+
.. |codacy| image:: https://app.codacy.com/project/badge/Grade/188accbe7f8f406abf61b888773bf5e3
|
| 88 |
+
:target: https://app.codacy.com/gh/miurahr/aqtinstall/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
This is a utility alternative to the official graphical Qt installer, for using in CI environment
|
| 92 |
+
where an interactive UI is not usable, or just on command line.
|
| 93 |
+
|
| 94 |
+
It can automatically download prebuilt Qt binaries, documents and sources for target specified,
|
| 95 |
+
when the versions are on Qt download mirror sites.
|
| 96 |
+
|
| 97 |
+
.. note::
|
| 98 |
+
Because it is an installer utility, it can download from Qt distribution site and its mirror.
|
| 99 |
+
The site is operated by The Qt Company who may remove versions you may want to use that become end of support.
|
| 100 |
+
Please don't blame us.
|
| 101 |
+
|
| 102 |
+
.. warning::
|
| 103 |
+
This is NOT franchised with The Qt Company and The Qt Project. Please don't ask them about aqtinstall.
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
License and copyright
|
| 107 |
+
---------------------
|
| 108 |
+
|
| 109 |
+
This program is distributed under MIT license.
|
| 110 |
+
|
| 111 |
+
Qt SDK and its related files are under its licenses. When using aqtinstall, you are considered
|
| 112 |
+
to agree upon Qt licenses. **aqtinstall installs Qt SDK as of a (L)GPL Free Software.**
|
| 113 |
+
|
| 114 |
+
For details see `Qt Licensing`_ and `Licenses used in Qt6`_
|
| 115 |
+
|
| 116 |
+
.. _`Qt Licensing`: https://doc.qt.io/qt-6/licensing.html
|
| 117 |
+
|
| 118 |
+
.. _`Licenses used in Qt6`: https://doc.qt.io/qt-6/licenses-used-in-qt.html
|
| 119 |
+
|
| 120 |
+
Requirements
|
| 121 |
+
------------
|
| 122 |
+
|
| 123 |
+
- Minimum Python version:
|
| 124 |
+
3.9
|
| 125 |
+
|
| 126 |
+
- Recommended Python version:
|
| 127 |
+
3.13 (frequently tested on)
|
| 128 |
+
|
| 129 |
+
- Dependencies:
|
| 130 |
+
requests
|
| 131 |
+
semantic_version
|
| 132 |
+
patch
|
| 133 |
+
py7zr
|
| 134 |
+
texttable
|
| 135 |
+
bs4
|
| 136 |
+
defusedxml
|
| 137 |
+
|
| 138 |
+
- Operating Systems:
|
| 139 |
+
Linux, macOS, MS Windows
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
Documentation
|
| 143 |
+
-------------
|
| 144 |
+
|
| 145 |
+
There is precise documentation with many examples.
|
| 146 |
+
You are recommended to read the *Getting started* section.
|
| 147 |
+
|
| 148 |
+
- Getting started: https://aqtinstall.readthedocs.io/en/latest/getting_started.html
|
| 149 |
+
- Stable: https://aqtinstall.readthedocs.io/en/stable
|
| 150 |
+
- Latest: https://aqtinstall.readthedocs.io/en/latest
|
| 151 |
+
|
| 152 |
+
Install
|
| 153 |
+
-------
|
| 154 |
+
|
| 155 |
+
Same as usual, it can be installed with ``pip``:
|
| 156 |
+
|
| 157 |
+
.. code-block:: console
|
| 158 |
+
|
| 159 |
+
pip install -U pip
|
| 160 |
+
pip install aqtinstall
|
| 161 |
+
|
| 162 |
+
You are recommended to update pip before installing aqtinstall.
|
| 163 |
+
|
| 164 |
+
.. note::
|
| 165 |
+
|
| 166 |
+
aqtinstall depends several packages, that is required to download files from internet, and extract 7zip archives,
|
| 167 |
+
some of which are precompiled in several platforms.
|
| 168 |
+
Older pip does not handle it expectedly(see #230).
|
| 169 |
+
|
| 170 |
+
.. note::
|
| 171 |
+
|
| 172 |
+
When you want to use it on MSYS2/Mingw64 environment, you need to set environmental variable
|
| 173 |
+
``export SETUPTOOLS_USE_DISTUTILS=stdlib``, because of setuptools package on mingw wrongly
|
| 174 |
+
raise error ``VC6.0 is not supported``
|
| 175 |
+
|
| 176 |
+
.. warning::
|
| 177 |
+
|
| 178 |
+
There is an unrelated package `aqt` in pypi. Please don't confuse with it.
|
| 179 |
+
|
| 180 |
+
It may be difficult to set up some Windows systems with the correct version of Python and all of ``aqt``'s dependencies.
|
| 181 |
+
To get around this problem, ``aqtinstall`` offers ``aqt.exe``, a Windows executable that contains Python and all required dependencies.
|
| 182 |
+
You may access ``aqt.exe`` from the `Releases section`_, under "assets", or via the persistent link to `the continuous build`_ of ``aqt.exe``.
|
| 183 |
+
|
| 184 |
+
.. _`Releases section`: https://github.com/miurahr/aqtinstall/releases
|
| 185 |
+
.. _`the continuous build`: https://github.com/miurahr/aqtinstall/releases/download/Continuous/aqt.exe
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
Example
|
| 189 |
+
--------
|
| 190 |
+
|
| 191 |
+
When installing Qt SDK 6.2.0 for Windows.
|
| 192 |
+
|
| 193 |
+
Check the options that can be used with the ``list-qt`` subcommand, and query available architectures:
|
| 194 |
+
|
| 195 |
+
.. code-block:: console
|
| 196 |
+
|
| 197 |
+
aqt list-qt windows desktop --arch 6.2.0
|
| 198 |
+
|
| 199 |
+
Then you may get candidates: ``win64_mingw81 win64_msvc2019_64 win64_msvc2019_arm64``. You can also query the available modules:
|
| 200 |
+
|
| 201 |
+
.. code-block:: console
|
| 202 |
+
|
| 203 |
+
aqt list-qt windows desktop --modules 6.2.0 win64_mingw81
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
When you decide to install Qt SDK version 6.2.0 for mingw v8.1:
|
| 207 |
+
|
| 208 |
+
.. code-block:: console
|
| 209 |
+
|
| 210 |
+
aqt install-qt windows desktop 6.2.0 win64_mingw81 -m all
|
| 211 |
+
|
| 212 |
+
The optional `-m all` argument installs all the modules available for Qt 6.2.0; you can leave it off if you don't want those modules.
|
| 213 |
+
|
| 214 |
+
To install Qt 6.2.0 with the modules 'qtcharts' and 'qtnetworking', you can use this command (note that the module names are lowercase):
|
| 215 |
+
|
| 216 |
+
.. code-block:: console
|
| 217 |
+
|
| 218 |
+
aqt install-qt windows desktop 6.2.0 win64_mingw81 -m qtcharts qtnetworking
|
| 219 |
+
|
| 220 |
+
When you want to install Qt for android with required desktop toolsets
|
| 221 |
+
|
| 222 |
+
.. code-block:: console
|
| 223 |
+
|
| 224 |
+
aqt install-qt linux android 5.13.2 android_armv7 --autodesktop
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
When aqtinstall downloads and installs packages, it updates package configurations
|
| 228 |
+
such as prefix directory in ``bin/qt.conf``, and ``bin/qconfig.pri``
|
| 229 |
+
to make it working well with installed directory.
|
| 230 |
+
|
| 231 |
+
.. note::
|
| 232 |
+
It is your own task to set some environment variables to fit your platform, such as PATH, QT_PLUGIN_PATH, QML_IMPORT_PATH, and QML2_IMPORT_PATH. aqtinstall will never do it for you, in order not to break the installation of multiple versions.
|
| 233 |
+
|
| 234 |
+
.. warning::
|
| 235 |
+
If you are using aqtinstall to install the ios version of Qt, please be aware that
|
| 236 |
+
there are compatibility issues between XCode 13+ and versions of Qt less than 6.2.4.
|
| 237 |
+
You may use aqtinstall to install older versions of Qt for ios, but the developers of
|
| 238 |
+
aqtinstall cannot guarantee that older versions will work on the most recent versions of MacOS.
|
| 239 |
+
Aqtinstall is tested for ios on MacOS 12 with Qt 6.2.4 and greater.
|
| 240 |
+
All earlier versions of Qt are expected not to function.
|
| 241 |
+
|
| 242 |
+
Testimonies
|
| 243 |
+
-----------
|
| 244 |
+
|
| 245 |
+
Some projects utilize aqtinstall, and there are several articles and discussions
|
| 246 |
+
|
| 247 |
+
* GitHub Actions: `install_qt`_
|
| 248 |
+
|
| 249 |
+
* Docker image: `docker aqtinstall`_
|
| 250 |
+
|
| 251 |
+
* Yet another comic reader: `YACReader`_ utilize on Azure-Pipelines
|
| 252 |
+
|
| 253 |
+
.. _`install_qt`: https://github.com/jurplel/install-qt-action
|
| 254 |
+
.. _`docker aqtinstall`: https://github.com/vslotman/docker-aqtinstall
|
| 255 |
+
.. _`pyqt5-tools`: https://github.com/altendky/pyqt5-tools
|
| 256 |
+
.. _`YACReader`: https://github.com/YACReader/yacreader
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
* Contributor Nelson's blog article: `Fast and lightweight headless Qt Installer from Qt Mirrors - aqtinstall`_
|
| 261 |
+
|
| 262 |
+
* Lostdomain.org blog: `Using Azure DevOps Pipelines with Qt`_
|
| 263 |
+
|
| 264 |
+
* Wincak's Weblog: `Using Azure CI for cross-platform Linux and Windows Qt application builds`_
|
| 265 |
+
|
| 266 |
+
* Qt Forum: `Automatic installation for Travis CI (or any other CI)`_
|
| 267 |
+
|
| 268 |
+
* Qt Forum: `Qt silent, unattended install`_
|
| 269 |
+
|
| 270 |
+
* Reddit: `Qt Maintenance tool now requires you to enter your company name`_
|
| 271 |
+
|
| 272 |
+
* Qt Study group presentation: `Another Qt CLI installer`_
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
.. _`Fast and lightweight headless Qt Installer from Qt Mirrors - aqtinstall`: https://mindflakes.com/posts/2019/06/02/fast-and-lightweight-headless-qt-installer-from-qt-mirrors-aqtinstall/
|
| 276 |
+
.. _`Using Azure DevOps Pipelines with Qt`: https://lostdomain.org/2019/12/27/using-azure-devops-pipelines-with-qt/
|
| 277 |
+
.. _`Using Azure CI for cross-platform Linux and Windows Qt application builds`: https://www.wincak.name/programming/using-azure-ci-for-cross-platform-linux-and-windows-qt-application-builds/
|
| 278 |
+
.. _`Automatic installation for Travis CI (or any other CI)`: https://forum.qt.io/topic/114520/automatic-installation-for-travis-ci-or-any-other-ci/2
|
| 279 |
+
.. _`Qt silent, unattended install`: https://forum.qt.io/topic/122185/qt-silent-unattended-install
|
| 280 |
+
.. _`Qt Maintenance tool now requires you to enter your company name`: https://www.reddit.com/r/QtFramework/comments/grgrux/qt_maintenance_tool_now_requires_you_to_enter/
|
| 281 |
+
.. _`Another Qt CLI installer`: https://www.slideshare.net/miurahr-nttdata/aqt-install-for-qt-tokyo-r-2-20196
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
History
|
| 285 |
+
-------
|
| 286 |
+
|
| 287 |
+
This program is originally shown in Kaidan project as a name `qli-installer`_.
|
| 288 |
+
The ``aqtinstall`` project extend and improve it.
|
| 289 |
+
|
| 290 |
+
.. _`qli-installer`: https://lnj.gitlab.io/post/qli-installer
|
python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../Scripts/aqt.exe,sha256=-cbBVY7-S1tfEASKpHBWKxYzARv4FIHZAT7m6aQB1G8,108340
|
| 2 |
+
aqt/__init__.py,sha256=cb2tw0mJeIB18pjiLmO8JxEg1TSkfW7RieVKuYpe8pw,1581
|
| 3 |
+
aqt/__main__.py,sha256=lceeL2HiWgelq5ERS5UcIudhMXsXCAJUggDqE6AlnUI,1220
|
| 4 |
+
aqt/__pycache__/__init__.cpython-313.pyc,,
|
| 5 |
+
aqt/__pycache__/__main__.cpython-313.pyc,,
|
| 6 |
+
aqt/__pycache__/archives.cpython-313.pyc,,
|
| 7 |
+
aqt/__pycache__/commercial.cpython-313.pyc,,
|
| 8 |
+
aqt/__pycache__/exceptions.cpython-313.pyc,,
|
| 9 |
+
aqt/__pycache__/helper.cpython-313.pyc,,
|
| 10 |
+
aqt/__pycache__/installer.cpython-313.pyc,,
|
| 11 |
+
aqt/__pycache__/metadata.cpython-313.pyc,,
|
| 12 |
+
aqt/__pycache__/updater.cpython-313.pyc,,
|
| 13 |
+
aqt/__pycache__/version.cpython-313.pyc,,
|
| 14 |
+
aqt/archives.py,sha256=2f2A_FqGbdUUnJBokzcR8y_x_297roiT0_SjKiR2TkE,29511
|
| 15 |
+
aqt/commercial.py,sha256=gL9ElyjWz-4rczBhutf1ERDqMOXO2772vECNnnzIhmI,15878
|
| 16 |
+
aqt/exceptions.py,sha256=yvwQNHvEOvoBcZKLqwDEGSMBjZ_v3nM42nBkWNTY2pQ,3593
|
| 17 |
+
aqt/helper.py,sha256=R2Eq5HE9_UXn5mBIiaCcnHGBvHR3GmXKRwVLoUHCW9w,30838
|
| 18 |
+
aqt/installer.py,sha256=-2EQauhkvzpBntVvfkYGAQbG-C1zSLwMbSCyBp0q7_A,72628
|
| 19 |
+
aqt/logging.ini,sha256=uXgPjK-PPDhWtlGYoX-HYiJsgCYl0Nym0yo71mwG5KQ,1210
|
| 20 |
+
aqt/metadata.py,sha256=OTaw2YgNtaUUxyuO84DOGQJVwO8WTlJCantjKJCshME,52353
|
| 21 |
+
aqt/settings.ini,sha256=lWsfChZyuQXnRgDRNJpbc2C-HTfXkJ5hzC1xebdyWq0,13580
|
| 22 |
+
aqt/updater.py,sha256=QhBG8kag3uL3Q-KaGLqbvSwS-SaK9GwLBsZIh9gN2is,16166
|
| 23 |
+
aqt/version.py,sha256=MPSbkJS_-QSkLK7sMlFXFf5iWlbcSL18Dj2ZiMCtS9c,22
|
| 24 |
+
aqtinstall-3.3.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 25 |
+
aqtinstall-3.3.0.dist-info/METADATA,sha256=UDliBF431cstE24cCtu2Dq1FlYrtYqJwzYADk3A1Zqo,11472
|
| 26 |
+
aqtinstall-3.3.0.dist-info/RECORD,,
|
| 27 |
+
aqtinstall-3.3.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 28 |
+
aqtinstall-3.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
| 29 |
+
aqtinstall-3.3.0.dist-info/entry_points.txt,sha256=-rWPqTLjP7z-AclECuPwKqb9N8woXXBTrMGXtyoRkPo,42
|
| 30 |
+
aqtinstall-3.3.0.dist-info/licenses/LICENSE,sha256=aMVou9OYVzJLuLtzbIK562O0TVJZf3az8YBDhObyTGw,1141
|
| 31 |
+
aqtinstall-3.3.0.dist-info/top_level.txt,sha256=4ZbCrra52FYe2xDXU7vB2Svv_pFdR-swV4VwN5Hhl-4,4
|
python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/REQUESTED
ADDED
|
File without changes
|
python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (80.9.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
aqt = aqt.__main__:main
|
python/py313/Lib/site-packages/aqtinstall-3.3.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
aqt
|
python/py313/Lib/site-packages/backports_zstd-1.5.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
python/py313/Lib/site-packages/backports_zstd-1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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: backports.zstd
|
| 3 |
+
Version: 1.5.0
|
| 4 |
+
Summary: Backport of compression.zstd
|
| 5 |
+
Author-email: Rogdham <contact@rogdham.net>
|
| 6 |
+
License-Expression: PSF-2.0
|
| 7 |
+
Project-URL: Homepage, https://github.com/rogdham/backports.zstd
|
| 8 |
+
Project-URL: Source, https://github.com/rogdham/backports.zstd
|
| 9 |
+
Keywords: backport,backports,pep-784,zstd
|
| 10 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 11 |
+
Classifier: Intended Audience :: Developers
|
| 12 |
+
Classifier: Topic :: System :: Archiving :: Compression
|
| 13 |
+
Classifier: Programming Language :: Python
|
| 14 |
+
Classifier: Programming Language :: Python :: 3
|
| 15 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 20 |
+
Requires-Python: <3.14,>=3.10
|
| 21 |
+
Description-Content-Type: text/markdown
|
| 22 |
+
License-File: LICENSE.txt
|
| 23 |
+
License-File: LICENSE_zstd.txt
|
| 24 |
+
Dynamic: license-file
|
| 25 |
+
|
| 26 |
+
<div align="center" size="15px">
|
| 27 |
+
|
| 28 |
+
# backports.zstd
|
| 29 |
+
|
| 30 |
+
Backport of [PEP-784 “adding Zstandard to the standard library”][PEP-784]
|
| 31 |
+
|
| 32 |
+
[](https://github.com/rogdham/backports.zstd/actions?query=branch:master)
|
| 33 |
+
[](https://pypi.org/project/backports.zstd/)
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
[📖 PEP-784][PEP-784] | [📃 Changelog](./CHANGELOG.md)
|
| 38 |
+
|
| 39 |
+
[PEP-784]: https://peps.python.org/pep-0784/
|
| 40 |
+
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## Install
|
| 46 |
+
|
| 47 |
+
Add the following dependency to your project:
|
| 48 |
+
|
| 49 |
+
```
|
| 50 |
+
backports.zstd ; python_version<'3.14'
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
…or just run `pip install backports.zstd`.
|
| 54 |
+
|
| 55 |
+
## Usage
|
| 56 |
+
|
| 57 |
+
When importing a module needing Zstandard support, use a conditional import based on the
|
| 58 |
+
version of Python. See below for examples.
|
| 59 |
+
|
| 60 |
+
### zstd
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
import sys
|
| 64 |
+
|
| 65 |
+
if sys.version_info >= (3, 14):
|
| 66 |
+
from compression import zstd
|
| 67 |
+
else:
|
| 68 |
+
from backports import zstd
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# use the zstd module, for example:
|
| 72 |
+
zstd.compress(b"Hello, world!")
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
Refer to the [official Python documentation][doc-zstd] for usage of the module.
|
| 76 |
+
|
| 77 |
+
[doc-zstd]: https://docs.python.org/3.14/library/compression.zstd.html
|
| 78 |
+
|
| 79 |
+
### tarfile
|
| 80 |
+
|
| 81 |
+
```python
|
| 82 |
+
import sys
|
| 83 |
+
|
| 84 |
+
if sys.version_info >= (3, 14):
|
| 85 |
+
import tarfile
|
| 86 |
+
else:
|
| 87 |
+
from backports.zstd import tarfile
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
# use the tarfile module, for example:
|
| 91 |
+
with tarfile.open("archive.tar.zst") as tar:
|
| 92 |
+
tar.list()
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
This `tarfile` modules is backported from Python 3.14 and includes Zstandard-specific
|
| 96 |
+
features such as: explicit modes for opening files (e.g. `r:zstd`), specific arguments
|
| 97 |
+
(e.g. `zstd_dict`)… refer to the [official Python documentation][doc-tarfile] for more
|
| 98 |
+
info.
|
| 99 |
+
|
| 100 |
+
[doc-tarfile]: https://docs.python.org/3.14/library/tarfile.html
|
| 101 |
+
|
| 102 |
+
Moreover, the CLI is available as well: `python -m backports.zstd.tarfile`.
|
| 103 |
+
|
| 104 |
+
### zipfile
|
| 105 |
+
|
| 106 |
+
```python
|
| 107 |
+
import sys
|
| 108 |
+
|
| 109 |
+
if sys.version_info >= (3, 14):
|
| 110 |
+
import zipfile
|
| 111 |
+
else:
|
| 112 |
+
from backports.zstd import zipfile
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
# use the zipfile module, for example:
|
| 116 |
+
with zipfile.ZipFile("archive.zip", "w") as zf:
|
| 117 |
+
zf.writestr("hello.txt", "Hi!", zipfile.ZIP_ZSTANDARD)
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
This `zipfile` modules is backported from Python 3.14 and includes Zstandard-specific
|
| 121 |
+
features such as the constant `ZIP_ZSTANDARD` to be used for `compress_type`… refer to
|
| 122 |
+
the [official Python documentation][doc-zipfile] for more info.
|
| 123 |
+
|
| 124 |
+
[doc-zipfile]: https://docs.python.org/3.14/library/zipfile.html
|
| 125 |
+
|
| 126 |
+
Moreover, the CLI is available as well: `python -m backports.zstd.zipfile`.
|
| 127 |
+
|
| 128 |
+
### shutil
|
| 129 |
+
|
| 130 |
+
```python
|
| 131 |
+
import shutil
|
| 132 |
+
import sys
|
| 133 |
+
|
| 134 |
+
if sys.version_info < (3, 14):
|
| 135 |
+
from backports.zstd import register_shutil
|
| 136 |
+
register_shutil()
|
| 137 |
+
|
| 138 |
+
# use the shutil module, for example
|
| 139 |
+
shutil.unpack_archive('archive.tar.zst')
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
Calling the `register_shutil` function allows to create zstd'ed tar files using the
|
| 143 |
+
`"zstdtar"` format, as well as unpack them.
|
| 144 |
+
|
| 145 |
+
It also overrides support for unpacking zip files, enabling the unpacking of zip
|
| 146 |
+
archives that use Zstandard for compression.
|
| 147 |
+
|
| 148 |
+
Alternatively, call `register_shutil(tar=False)` or `register_shutil(zip=False)` to
|
| 149 |
+
choose which archiving support to register.
|
| 150 |
+
|
| 151 |
+
## FAQ
|
| 152 |
+
|
| 153 |
+
### Who are you?
|
| 154 |
+
|
| 155 |
+
This project is created and maintained by [Rogdham](https://github.com/rogdham)
|
| 156 |
+
(maintainer of [`pyzstd`](https://github.com/rogdham/pyzstd), who helped with [PEP-784]
|
| 157 |
+
and integration of Zstandard into the standard library), with help from
|
| 158 |
+
[Emma Smith](https://github.com/emmatyping) (author of [PEP-784], who did most of the
|
| 159 |
+
work of porting `pyzstd` into the standard library).
|
| 160 |
+
|
| 161 |
+
### How is this backport constructed?
|
| 162 |
+
|
| 163 |
+
The aim is to be as close as possible to the upstream code of
|
| 164 |
+
[CPython](https://github.com/python/cpython).
|
| 165 |
+
|
| 166 |
+
The runtime code comes from CPython 3.14, with minor changes to support older versions
|
| 167 |
+
of Python. For PyPy users, the C code has been ported to CFFI.
|
| 168 |
+
|
| 169 |
+
During the build phase, the project uses [`zstd`](https://github.com/facebook/zstd)
|
| 170 |
+
(canonical implementation of Zstandard) as well as
|
| 171 |
+
[`pythoncapi-compat`](https://github.com/python/pythoncapi-compat) (which handles some
|
| 172 |
+
of the compatibility with older Python versions).
|
| 173 |
+
|
| 174 |
+
Tests come from CPython 3.14, with minor changes to support older versions of Python.
|
| 175 |
+
Additional tests have been written specifically for `backports.zstd`.
|
| 176 |
+
|
| 177 |
+
The type hints for the standard library have been contributed to
|
| 178 |
+
[`typeshed`](https://github.com/python/typeshed) and also backported to
|
| 179 |
+
`backports.zstd`.
|
| 180 |
+
|
| 181 |
+
### Why can this library not be installed with Python 3.14?
|
| 182 |
+
|
| 183 |
+
This is [on purpose](https://github.com/Rogdham/backports.zstd/issues/50). For Python
|
| 184 |
+
3.14 and later, use the `compression.zstd` module from the standard library.
|
| 185 |
+
|
| 186 |
+
If you want your code to be compatible with multiple Python versions, condition the
|
| 187 |
+
usage of this library based on the Python version:
|
| 188 |
+
|
| 189 |
+
- [During install](#install);
|
| 190 |
+
- [When importing at runtime](#usage).
|
| 191 |
+
|
| 192 |
+
### Can I use the libzstd version installed on my system?
|
| 193 |
+
|
| 194 |
+
The wheels distributed on PyPI include a static version of `libzstd` for ease of
|
| 195 |
+
installation and reproducibility.
|
| 196 |
+
|
| 197 |
+
If you want to use `libzstd` installed on your system, pass the `--system-zstd` argument
|
| 198 |
+
to the build backend. For example:
|
| 199 |
+
|
| 200 |
+
```sh
|
| 201 |
+
python -m pip install --config-settings=--build-option=--system-zstd ...
|
| 202 |
+
python -m build --wheel --config-setting=--build-option=--system-zstd ...
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
If you run the test suite, set the environment variable
|
| 206 |
+
`BACKPORTSZSTD_SKIP_EXTENSION_TEST=1` to skip tests that may fail when using the system
|
| 207 |
+
library.
|
| 208 |
+
|
| 209 |
+
### I found a bug
|
| 210 |
+
|
| 211 |
+
If you encounter any issues, please open a
|
| 212 |
+
[GitHub issue](https://github.com/Rogdham/backports.zstd/issues/new) with a minimal
|
| 213 |
+
reproducible example.
|
| 214 |
+
|
| 215 |
+
We will check if the issue is with `backports.zstd` or CPython. We have already reported
|
| 216 |
+
and fixed a few issues in CPython this way!
|
python/py313/Lib/site-packages/backports_zstd-1.5.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
backports/zstd/__init__.py,sha256=2iCNo6g7ZVOZuTlQuo0ewjey2ZGx-g6TGMI4s9rGQ9Y,9328
|
| 2 |
+
backports/zstd/__init__.pyi,sha256=x5flabz3W08WQk6tzFAwITWCVWbU73uVvC2XVmP9x-o,8257
|
| 3 |
+
backports/zstd/__pycache__/__init__.cpython-313.pyc,,
|
| 4 |
+
backports/zstd/__pycache__/_compat.cpython-313.pyc,,
|
| 5 |
+
backports/zstd/__pycache__/_shutil.cpython-313.pyc,,
|
| 6 |
+
backports/zstd/__pycache__/_streams.cpython-313.pyc,,
|
| 7 |
+
backports/zstd/__pycache__/_zstd.cpython-313.pyc,,
|
| 8 |
+
backports/zstd/__pycache__/_zstdfile.cpython-313.pyc,,
|
| 9 |
+
backports/zstd/__pycache__/tarfile.cpython-313.pyc,,
|
| 10 |
+
backports/zstd/_cffi/__init__.py,sha256=JUi0NOFda-S3t0pDBTY5CUEHksMe1QvKMTrtGFLcNl8,8190
|
| 11 |
+
backports/zstd/_cffi/__pycache__/__init__.cpython-313.pyc,,
|
| 12 |
+
backports/zstd/_cffi/__pycache__/_blocks_output_buffer.cpython-313.pyc,,
|
| 13 |
+
backports/zstd/_cffi/__pycache__/_common.cpython-313.pyc,,
|
| 14 |
+
backports/zstd/_cffi/__pycache__/buffer.cpython-313.pyc,,
|
| 15 |
+
backports/zstd/_cffi/__pycache__/compressor.cpython-313.pyc,,
|
| 16 |
+
backports/zstd/_cffi/__pycache__/decompressor.cpython-313.pyc,,
|
| 17 |
+
backports/zstd/_cffi/__pycache__/zstddict.cpython-313.pyc,,
|
| 18 |
+
backports/zstd/_cffi/_blocks_output_buffer.py,sha256=Rmn70vPTg2GNEdvi2QKYPSsFCdhT_OyNp5u86mNpebo,3403
|
| 19 |
+
backports/zstd/_cffi/_common.py,sha256=ka4zctVtUyWqoqxIBxLLInUqiCEOG2AuW2W-6LR9-pc,4866
|
| 20 |
+
backports/zstd/_cffi/buffer.py,sha256=EU9EerxO1qYcROrU6Cchy4dCfRtdYkLWRvNhZqU5VSw,797
|
| 21 |
+
backports/zstd/_cffi/compressor.py,sha256=clrbW-HC_i190HD81b7O9OUKvYg5fBRdKA8RtqbSo9s,13635
|
| 22 |
+
backports/zstd/_cffi/decompressor.py,sha256=a-0X8aoHAWjwYW0JWbUpLmOEcQPal6tis7ZeOz3NGRQ,13230
|
| 23 |
+
backports/zstd/_cffi/zstddict.py,sha256=nMb9aSC_Nz0qQx50yFIAAkhrZ6Y5J108aBdMbqBbmJs,6288
|
| 24 |
+
backports/zstd/_compat.py,sha256=NTvC5dwiMfLZJF8Di0NeJ765nEqsBE31vNTzBdA8cbM,2682
|
| 25 |
+
backports/zstd/_shutil.py,sha256=rlFOZoEl13_1H7aP2MtbQg5-DgZ4OFFlHoJdxFzHZXY,4903
|
| 26 |
+
backports/zstd/_streams.py,sha256=i46UOBXHSNAw5UCgI0AMuH-xP3XC8GFaY-xC758VbJI,5670
|
| 27 |
+
backports/zstd/_zstd.cp313-win_amd64.pyd,sha256=xnJ26dxIshOnOu38GPoiuOAw8eljUyGkg8NxtPt0YZo,582144
|
| 28 |
+
backports/zstd/_zstd.py,sha256=YxW09D9QPnZgzRmqVIDcIkGC01oTlCGOpD0tCoCZ9tU,1039
|
| 29 |
+
backports/zstd/_zstdfile.py,sha256=NrvrWVrdAy7WbReZ8NIB5vQqr1G7Ck0VgDVQcXm1SHc,12296
|
| 30 |
+
backports/zstd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 31 |
+
backports/zstd/tarfile.py,sha256=oN6qru-9GyxCaItKSkGks92s3yoQ_J4DooFcNMrg6yM,118076
|
| 32 |
+
backports/zstd/tarfile.pyi,sha256=JxmS3vz9pUzU6Rsy7b2xSgOZMGvMl1xFbSNtAJIHXIY,27836
|
| 33 |
+
backports/zstd/zipfile/__init__.py,sha256=iNK65tEjOSycOJUcZAXDxf5FWzb3JnsW3jvQHmPd79c,92853
|
| 34 |
+
backports/zstd/zipfile/__init__.pyi,sha256=mLhU8KG0bYdFl_3vN30d3jF0FML_SOTbruFTF5uXinY,8777
|
| 35 |
+
backports/zstd/zipfile/__main__.py,sha256=5BjNuyet8AY-POwoF5rGt722rHQ7tJ0Vf0UFUfzzi-I,58
|
| 36 |
+
backports/zstd/zipfile/__pycache__/__init__.cpython-313.pyc,,
|
| 37 |
+
backports/zstd/zipfile/__pycache__/__main__.cpython-313.pyc,,
|
| 38 |
+
backports/zstd/zipfile/_path/__init__.py,sha256=ClCtgJbX21snmJCTMdVtN5krzHra9UYiQ7N7sd_HsLA,11973
|
| 39 |
+
backports/zstd/zipfile/_path/__init__.pyi,sha256=wxw3UwdzWQLNE1Vx-HsJ3VDgnBeE2wfHluYdtLc0w_U,2715
|
| 40 |
+
backports/zstd/zipfile/_path/__pycache__/__init__.cpython-313.pyc,,
|
| 41 |
+
backports/zstd/zipfile/_path/__pycache__/glob.cpython-313.pyc,,
|
| 42 |
+
backports/zstd/zipfile/_path/glob.py,sha256=7e_qY48lC54BFSYUHYOyIqBkZqaONXtteAqLQXPYAvc,3314
|
| 43 |
+
backports/zstd/zipfile/_path/glob.pyi,sha256=6PXA7uH5307e7sWPOHy50m1VqGA82yVzaoDJJkgHH40,671
|
| 44 |
+
backports_zstd-1.5.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 45 |
+
backports_zstd-1.5.0.dist-info/METADATA,sha256=TSgRjK0dao04YOLPt5puJJ3wUOTNSQtZoS0MNgr7IpU,7036
|
| 46 |
+
backports_zstd-1.5.0.dist-info/RECORD,,
|
| 47 |
+
backports_zstd-1.5.0.dist-info/WHEEL,sha256=x5Wpw_tLx5PQKiWdxpqvs0e7Sg-SO0mTWdEADYDGPGA,101
|
| 48 |
+
backports_zstd-1.5.0.dist-info/licenses/LICENSE.txt,sha256=sOJaeM_7Q_TZLei2HM-h8fmOy8IjMLVLUlHntroBAjE,13804
|
| 49 |
+
backports_zstd-1.5.0.dist-info/licenses/LICENSE_zstd.txt,sha256=g2y9qXL3QmGhK3Bq2qfHPa6lNuqWQMmg3Ld7aBBb4FE,1761
|
| 50 |
+
backports_zstd-1.5.0.dist-info/top_level.txt,sha256=cGjaLMOoBR1FK0ApojtzWVmViTtJ7JGIK_HwXiEsvtU,10
|
python/py313/Lib/site-packages/backports_zstd-1.5.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (82.0.1)
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp313-cp313-win_amd64
|
| 5 |
+
|
python/py313/Lib/site-packages/backports_zstd-1.5.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
backports
|
python/py313/Lib/site-packages/bcj/__init__.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PyBcj library.
|
| 2 |
+
# Copyright 2020-2022 Hiroshi Miura
|
| 3 |
+
# SPDX-License-Identifier: LGPL-2.1-or-later
|
| 4 |
+
#
|
| 5 |
+
try:
|
| 6 |
+
from importlib.metadata import PackageNotFoundError # type: ignore
|
| 7 |
+
from importlib.metadata import version # type: ignore
|
| 8 |
+
except ImportError:
|
| 9 |
+
from importlib_metadata import PackageNotFoundError # type: ignore
|
| 10 |
+
from importlib_metadata import version # type: ignore
|
| 11 |
+
try:
|
| 12 |
+
from ._bcj import (
|
| 13 |
+
ARMDecoder,
|
| 14 |
+
ARMEncoder,
|
| 15 |
+
ARMTDecoder,
|
| 16 |
+
ARMTEncoder,
|
| 17 |
+
BCJDecoder,
|
| 18 |
+
BCJEncoder,
|
| 19 |
+
IA64Decoder,
|
| 20 |
+
IA64Encoder,
|
| 21 |
+
PPCDecoder,
|
| 22 |
+
PPCEncoder,
|
| 23 |
+
SparcDecoder,
|
| 24 |
+
SparcEncoder,
|
| 25 |
+
)
|
| 26 |
+
except ImportError:
|
| 27 |
+
try:
|
| 28 |
+
from ._bcjfilter import (
|
| 29 |
+
ARMDecoder,
|
| 30 |
+
ARMEncoder,
|
| 31 |
+
ARMTDecoder,
|
| 32 |
+
ARMTEncoder,
|
| 33 |
+
BCJDecoder,
|
| 34 |
+
BCJEncoder,
|
| 35 |
+
IA64Decoder,
|
| 36 |
+
IA64Encoder,
|
| 37 |
+
PPCDecoder,
|
| 38 |
+
PPCEncoder,
|
| 39 |
+
SparcDecoder,
|
| 40 |
+
SparcEncoder,
|
| 41 |
+
)
|
| 42 |
+
except ImportError:
|
| 43 |
+
msg = "pybcj module: Neither C implementation nor Python implementation can be imported."
|
| 44 |
+
raise ImportError(msg)
|
| 45 |
+
|
| 46 |
+
__all__ = (
|
| 47 |
+
ARMDecoder,
|
| 48 |
+
ARMEncoder,
|
| 49 |
+
ARMTDecoder,
|
| 50 |
+
ARMTEncoder,
|
| 51 |
+
BCJDecoder,
|
| 52 |
+
BCJEncoder,
|
| 53 |
+
IA64Decoder,
|
| 54 |
+
IA64Encoder,
|
| 55 |
+
PPCDecoder,
|
| 56 |
+
PPCEncoder,
|
| 57 |
+
SparcDecoder,
|
| 58 |
+
SparcEncoder,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
__copyright__ = "Copyright (C) 2021 Hiroshi Miura"
|
| 62 |
+
|
| 63 |
+
try:
|
| 64 |
+
__version__ = version(__name__)
|
| 65 |
+
except PackageNotFoundError: # pragma: no-cover
|
| 66 |
+
# package is not installed
|
| 67 |
+
__version__ = "unknown"
|
| 68 |
+
|
| 69 |
+
__doc__ = """\
|
| 70 |
+
Python bindings to BCJ filter library.
|
| 71 |
+
|
| 72 |
+
Documentation: https://pybcj.readthedocs.io
|
| 73 |
+
Github: https://github.com/miurahr/pybcj
|
| 74 |
+
PyPI: https://pypi.org/project/pybcj"""
|
python/py313/Lib/site-packages/bcj/_bcj.cp313-win_amd64.pyd
ADDED
|
Binary file (23 kB). View file
|
|
|
python/py313/Lib/site-packages/bcj/_bcjfilter.py
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PyBcj library.
|
| 2 |
+
# Copyright (c) 2019,2020,2022 Hiroshi Miura <miurahr@linux.com>
|
| 3 |
+
# SPDX-License-Identifier: LGPL-2.1-or-later
|
| 4 |
+
#
|
| 5 |
+
import struct
|
| 6 |
+
from typing import Union
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class BCJFilter:
|
| 10 |
+
|
| 11 |
+
_mask_to_allowed_number = [0, 1, 2, 4, 8, 9, 10, 12]
|
| 12 |
+
_mask_to_bit_number = [0, 1, 2, 2, 3, 3, 3, 3]
|
| 13 |
+
|
| 14 |
+
def __init__(self, func, readahead: int, is_encoder: bool, stream_size: int = 0):
|
| 15 |
+
self.is_encoder: bool = is_encoder
|
| 16 |
+
#
|
| 17 |
+
self.prev_mask: int = 0
|
| 18 |
+
self.prev_pos: int = -5
|
| 19 |
+
self.current_position: int = 0
|
| 20 |
+
self.stream_size: int = stream_size # should initialize in child class
|
| 21 |
+
self.buffer = bytearray()
|
| 22 |
+
#
|
| 23 |
+
self._method = func
|
| 24 |
+
self._readahead = readahead
|
| 25 |
+
|
| 26 |
+
def sparc_code(self) -> int:
|
| 27 |
+
limit: int = len(self.buffer) - 4
|
| 28 |
+
i: int = 0
|
| 29 |
+
while i <= limit:
|
| 30 |
+
if (self.buffer[i], self.buffer[i + 1] & 0xC0) in [
|
| 31 |
+
(0x40, 0x00),
|
| 32 |
+
(0x7F, 0xC0),
|
| 33 |
+
]:
|
| 34 |
+
src = struct.unpack(">L", self.buffer[i : i + 4])[0] << 2
|
| 35 |
+
distance: int = self.current_position + i
|
| 36 |
+
if self.is_encoder:
|
| 37 |
+
dest = (src + distance) >> 2
|
| 38 |
+
else:
|
| 39 |
+
dest = (src - distance) >> 2
|
| 40 |
+
dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000
|
| 41 |
+
self.buffer[i : i + 4] = struct.pack(">L", dest)
|
| 42 |
+
i += 4
|
| 43 |
+
self.current_position = i
|
| 44 |
+
return i
|
| 45 |
+
|
| 46 |
+
def ppc_code(self) -> int:
|
| 47 |
+
limit: int = len(self.buffer) - 4
|
| 48 |
+
i: int = 0
|
| 49 |
+
while i <= limit:
|
| 50 |
+
# PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link)
|
| 51 |
+
distance: int = self.current_position + i
|
| 52 |
+
if self.buffer[i] & 0xFC == 0x48 and self.buffer[i + 3] & 0x03 == 1:
|
| 53 |
+
src = struct.unpack(">L", self.buffer[i : i + 4])[0] & 0x3FFFFFC
|
| 54 |
+
if self.is_encoder:
|
| 55 |
+
dest = src + distance
|
| 56 |
+
else:
|
| 57 |
+
dest = src - distance
|
| 58 |
+
# lsb = int(self.buffer[i + 3]) & 0x03 == 1
|
| 59 |
+
dest = (0x48 << 24) | (dest & 0x03FFFFFF) | 1
|
| 60 |
+
self.buffer[i : i + 4] = struct.pack(">L", dest)
|
| 61 |
+
i += 4
|
| 62 |
+
self.current_position = i
|
| 63 |
+
return i
|
| 64 |
+
|
| 65 |
+
def _unpack_thumb(self, b: Union[bytearray, bytes, memoryview]) -> int:
|
| 66 |
+
return ((b[1] & 0x07) << 19) | (b[0] << 11) | ((b[3] & 0x07) << 8) | b[2]
|
| 67 |
+
|
| 68 |
+
def _pack_thumb(self, val: int) -> bytes:
|
| 69 |
+
b = bytes(
|
| 70 |
+
[
|
| 71 |
+
(val >> 11) & 0xFF,
|
| 72 |
+
0xF0 | ((val >> 19) & 0x07),
|
| 73 |
+
val & 0xFF,
|
| 74 |
+
0xF8 | ((val >> 8) & 0x07),
|
| 75 |
+
]
|
| 76 |
+
)
|
| 77 |
+
return b
|
| 78 |
+
|
| 79 |
+
def armt_code(self) -> int:
|
| 80 |
+
limit: int = len(self.buffer) - 4
|
| 81 |
+
i: int = 0
|
| 82 |
+
while i <= limit:
|
| 83 |
+
if self.buffer[i + 1] & 0xF8 == 0xF0 and self.buffer[i + 3] & 0xF8 == 0xF8:
|
| 84 |
+
src = self._unpack_thumb(self.buffer[i : i + 4]) << 1
|
| 85 |
+
distance: int = self.current_position + i + 4
|
| 86 |
+
if self.is_encoder:
|
| 87 |
+
dest = src + distance
|
| 88 |
+
else:
|
| 89 |
+
dest = src - distance
|
| 90 |
+
dest >>= 1
|
| 91 |
+
self.buffer[i : i + 4] = self._pack_thumb(dest)
|
| 92 |
+
i += 2
|
| 93 |
+
i += 2
|
| 94 |
+
self.current_position += i
|
| 95 |
+
return i
|
| 96 |
+
|
| 97 |
+
def arm_code(self) -> int:
|
| 98 |
+
limit = len(self.buffer) - 4
|
| 99 |
+
i = 0
|
| 100 |
+
while i <= limit:
|
| 101 |
+
if self.buffer[i + 3] == 0xEB:
|
| 102 |
+
src = struct.unpack("<L", self.buffer[i : i + 3] + b"\x00")[0] << 2
|
| 103 |
+
distance = self.current_position + i + 8
|
| 104 |
+
if self.is_encoder:
|
| 105 |
+
dest = (src + distance) >> 2
|
| 106 |
+
else:
|
| 107 |
+
dest = (src - distance) >> 2
|
| 108 |
+
self.buffer[i : i + 3] = struct.pack("<L", dest & 0xFFFFFF)[:3]
|
| 109 |
+
i += 4
|
| 110 |
+
self.current_position += i
|
| 111 |
+
return i
|
| 112 |
+
|
| 113 |
+
def x86_code(self) -> int:
|
| 114 |
+
"""
|
| 115 |
+
The code algorithm from liblzma/simple/x86.c
|
| 116 |
+
It is slightly different from LZMA-SDK's bra86.c
|
| 117 |
+
:return: buffer position
|
| 118 |
+
"""
|
| 119 |
+
size: int = len(self.buffer)
|
| 120 |
+
if size < 5:
|
| 121 |
+
return 0
|
| 122 |
+
if self.current_position - self.prev_pos > 5:
|
| 123 |
+
self.prev_pos = self.current_position - 5
|
| 124 |
+
view = memoryview(self.buffer)
|
| 125 |
+
limit: int = size - 5
|
| 126 |
+
buffer_pos: int = 0
|
| 127 |
+
pos1: int = 0
|
| 128 |
+
pos2: int = 0
|
| 129 |
+
while buffer_pos <= limit:
|
| 130 |
+
# --
|
| 131 |
+
# The following is pythonic way as same as
|
| 132 |
+
# if self.buffer[buffer_pos] not in [0xe9, 0xe8]:
|
| 133 |
+
# buffer_pos += 1
|
| 134 |
+
# continue
|
| 135 |
+
# --
|
| 136 |
+
if pos1 >= 0:
|
| 137 |
+
pos1 = self.buffer.find(0xE9, buffer_pos, limit)
|
| 138 |
+
if pos2 >= 0:
|
| 139 |
+
pos2 = self.buffer.find(0xE8, buffer_pos, limit)
|
| 140 |
+
if pos1 < 0 and pos2 < 0:
|
| 141 |
+
buffer_pos = limit + 1
|
| 142 |
+
break
|
| 143 |
+
elif pos1 < 0:
|
| 144 |
+
buffer_pos = pos2
|
| 145 |
+
elif pos2 < 0:
|
| 146 |
+
buffer_pos = pos1
|
| 147 |
+
else:
|
| 148 |
+
buffer_pos = min(pos1, pos2)
|
| 149 |
+
# --
|
| 150 |
+
offset = self.current_position + buffer_pos - self.prev_pos
|
| 151 |
+
self.prev_pos = self.current_position + buffer_pos
|
| 152 |
+
if offset > 5:
|
| 153 |
+
self.prev_mask = 0
|
| 154 |
+
else:
|
| 155 |
+
for i in range(offset):
|
| 156 |
+
self.prev_mask &= 0x77
|
| 157 |
+
self.prev_mask <<= 1
|
| 158 |
+
# note:
|
| 159 |
+
# condition (self.prev_mask >> 1) in [0, 1, 2, 4, 8, 9, 10, 12]
|
| 160 |
+
# is as same as
|
| 161 |
+
# condition _mask_to_allowed_status[(self.prev_mask >> 1) & 0x7] and (self.prev_mask >> 1) < 0x10:
|
| 162 |
+
# when _mask_to_allowed_status = [True, True, True, False, True, False, False, False]
|
| 163 |
+
#
|
| 164 |
+
if view[buffer_pos + 4] in [0, 0xFF] and (self.prev_mask >> 1) in self._mask_to_allowed_number:
|
| 165 |
+
jump_target = self.buffer[buffer_pos + 1 : buffer_pos + 5]
|
| 166 |
+
src = struct.unpack("<L", jump_target)[0]
|
| 167 |
+
distance = self.current_position + buffer_pos + 5
|
| 168 |
+
idx = self._mask_to_bit_number[self.prev_mask >> 1]
|
| 169 |
+
while True:
|
| 170 |
+
if self.is_encoder:
|
| 171 |
+
dest = (src + distance) & 0xFFFFFFFF # uint32 behavior
|
| 172 |
+
else:
|
| 173 |
+
dest = (src - distance) & 0xFFFFFFFF
|
| 174 |
+
if self.prev_mask == 0:
|
| 175 |
+
break
|
| 176 |
+
b = 0xFF & (dest >> (24 - idx * 8))
|
| 177 |
+
if not (b == 0 or b == 0xFF):
|
| 178 |
+
break
|
| 179 |
+
src = dest ^ ((1 << (32 - idx * 8)) - 1) & 0xFFFFFFFF
|
| 180 |
+
write_view = view[buffer_pos + 1 : buffer_pos + 5]
|
| 181 |
+
write_view[0:3] = (dest & 0xFFFFFF).to_bytes(3, "little")
|
| 182 |
+
write_view[3:4] = [b"\x00", b"\xff"][(dest >> 24) & 1] # (~(((dest >> 24) & 1) - 1)) & 0xFF
|
| 183 |
+
buffer_pos += 5
|
| 184 |
+
self.prev_mask = 0
|
| 185 |
+
else:
|
| 186 |
+
buffer_pos += 1
|
| 187 |
+
self.prev_mask |= 1
|
| 188 |
+
if self.buffer[buffer_pos + 3] in [0, 0xFF]:
|
| 189 |
+
self.prev_mask |= 0x10
|
| 190 |
+
self.current_position += buffer_pos
|
| 191 |
+
return buffer_pos
|
| 192 |
+
|
| 193 |
+
def decode(self, data: Union[bytes, bytearray, memoryview], max_length: int = -1) -> bytes:
|
| 194 |
+
self.buffer.extend(data)
|
| 195 |
+
pos: int = self._method()
|
| 196 |
+
if self.current_position > self.stream_size - self._readahead:
|
| 197 |
+
offset: int = self.stream_size - self.current_position
|
| 198 |
+
tmp = bytes(self.buffer[: pos + offset])
|
| 199 |
+
self.current_position = self.stream_size
|
| 200 |
+
self.buffer = bytearray()
|
| 201 |
+
else:
|
| 202 |
+
tmp = bytes(self.buffer[:pos])
|
| 203 |
+
self.buffer = self.buffer[pos:]
|
| 204 |
+
return tmp
|
| 205 |
+
|
| 206 |
+
def encode(self, data: Union[bytes, bytearray, memoryview]) -> bytes:
|
| 207 |
+
self.buffer.extend(data)
|
| 208 |
+
pos: int = self._method()
|
| 209 |
+
tmp = bytes(self.buffer[:pos])
|
| 210 |
+
self.buffer = self.buffer[pos:]
|
| 211 |
+
return tmp
|
| 212 |
+
|
| 213 |
+
def flush(self) -> bytes:
|
| 214 |
+
return bytes(self.buffer)
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
class BCJDecoder(BCJFilter):
|
| 218 |
+
def __init__(self, size: int):
|
| 219 |
+
super().__init__(self.x86_code, 5, False, size)
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
class BCJEncoder(BCJFilter):
|
| 223 |
+
def __init__(self):
|
| 224 |
+
super().__init__(self.x86_code, 5, True)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
class SparcDecoder(BCJFilter):
|
| 228 |
+
def __init__(self, size: int):
|
| 229 |
+
super().__init__(self.sparc_code, 4, False, size)
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
class SparcEncoder(BCJFilter):
|
| 233 |
+
def __init__(self):
|
| 234 |
+
super().__init__(self.sparc_code, 4, True)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
class PPCDecoder(BCJFilter):
|
| 238 |
+
def __init__(self, size: int):
|
| 239 |
+
super().__init__(self.ppc_code, 4, False, size)
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
class PPCEncoder(BCJFilter):
|
| 243 |
+
def __init__(self):
|
| 244 |
+
super().__init__(self.ppc_code, 4, True)
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
class ARMTDecoder(BCJFilter):
|
| 248 |
+
def __init__(self, size: int):
|
| 249 |
+
super().__init__(self.armt_code, 4, False, size)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
class ARMTEncoder(BCJFilter):
|
| 253 |
+
def __init__(self):
|
| 254 |
+
super().__init__(self.armt_code, 4, True)
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
class ARMDecoder(BCJFilter):
|
| 258 |
+
def __init__(self, size: int):
|
| 259 |
+
super().__init__(self.arm_code, 4, False, size)
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
class ARMEncoder(BCJFilter):
|
| 263 |
+
def __init__(self):
|
| 264 |
+
super().__init__(self.arm_code, 4, True)
|
python/py313/Lib/site-packages/bcj/py.typed
ADDED
|
File without changes
|
python/py313/Lib/site-packages/beautifulsoup4-4.14.3.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
python/py313/Lib/site-packages/beautifulsoup4-4.14.3.dist-info/METADATA
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: beautifulsoup4
|
| 3 |
+
Version: 4.14.3
|
| 4 |
+
Summary: Screen-scraping library
|
| 5 |
+
Project-URL: Download, https://www.crummy.com/software/BeautifulSoup/bs4/download/
|
| 6 |
+
Project-URL: Homepage, https://www.crummy.com/software/BeautifulSoup/bs4/
|
| 7 |
+
Author-email: Leonard Richardson <leonardr@segfault.org>
|
| 8 |
+
License: MIT License
|
| 9 |
+
License-File: AUTHORS
|
| 10 |
+
License-File: LICENSE
|
| 11 |
+
Keywords: HTML,XML,parse,soup
|
| 12 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 13 |
+
Classifier: Intended Audience :: Developers
|
| 14 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 15 |
+
Classifier: Programming Language :: Python
|
| 16 |
+
Classifier: Programming Language :: Python :: 3
|
| 17 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 18 |
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
| 19 |
+
Classifier: Topic :: Text Processing :: Markup :: SGML
|
| 20 |
+
Classifier: Topic :: Text Processing :: Markup :: XML
|
| 21 |
+
Requires-Python: >=3.7.0
|
| 22 |
+
Requires-Dist: soupsieve>=1.6.1
|
| 23 |
+
Requires-Dist: typing-extensions>=4.0.0
|
| 24 |
+
Provides-Extra: cchardet
|
| 25 |
+
Requires-Dist: cchardet; extra == 'cchardet'
|
| 26 |
+
Provides-Extra: chardet
|
| 27 |
+
Requires-Dist: chardet; extra == 'chardet'
|
| 28 |
+
Provides-Extra: charset-normalizer
|
| 29 |
+
Requires-Dist: charset-normalizer; extra == 'charset-normalizer'
|
| 30 |
+
Provides-Extra: html5lib
|
| 31 |
+
Requires-Dist: html5lib; extra == 'html5lib'
|
| 32 |
+
Provides-Extra: lxml
|
| 33 |
+
Requires-Dist: lxml; extra == 'lxml'
|
| 34 |
+
Description-Content-Type: text/markdown
|
| 35 |
+
|
| 36 |
+
Beautiful Soup is a library that makes it easy to scrape information
|
| 37 |
+
from web pages. It sits atop an HTML or XML parser, providing Pythonic
|
| 38 |
+
idioms for iterating, searching, and modifying the parse tree.
|
| 39 |
+
|
| 40 |
+
# Quick start
|
| 41 |
+
|
| 42 |
+
```
|
| 43 |
+
>>> from bs4 import BeautifulSoup
|
| 44 |
+
>>> soup = BeautifulSoup("<p>Some<b>bad<i>HTML")
|
| 45 |
+
>>> print(soup.prettify())
|
| 46 |
+
<html>
|
| 47 |
+
<body>
|
| 48 |
+
<p>
|
| 49 |
+
Some
|
| 50 |
+
<b>
|
| 51 |
+
bad
|
| 52 |
+
<i>
|
| 53 |
+
HTML
|
| 54 |
+
</i>
|
| 55 |
+
</b>
|
| 56 |
+
</p>
|
| 57 |
+
</body>
|
| 58 |
+
</html>
|
| 59 |
+
>>> soup.find(string="bad")
|
| 60 |
+
'bad'
|
| 61 |
+
>>> soup.i
|
| 62 |
+
<i>HTML</i>
|
| 63 |
+
#
|
| 64 |
+
>>> soup = BeautifulSoup("<tag1>Some<tag2/>bad<tag3>XML", "xml")
|
| 65 |
+
#
|
| 66 |
+
>>> print(soup.prettify())
|
| 67 |
+
<?xml version="1.0" encoding="utf-8"?>
|
| 68 |
+
<tag1>
|
| 69 |
+
Some
|
| 70 |
+
<tag2/>
|
| 71 |
+
bad
|
| 72 |
+
<tag3>
|
| 73 |
+
XML
|
| 74 |
+
</tag3>
|
| 75 |
+
</tag1>
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
To go beyond the basics, [comprehensive documentation is available](https://www.crummy.com/software/BeautifulSoup/bs4/doc/).
|
| 79 |
+
|
| 80 |
+
# Links
|
| 81 |
+
|
| 82 |
+
* [Homepage](https://www.crummy.com/software/BeautifulSoup/bs4/)
|
| 83 |
+
* [Documentation](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)
|
| 84 |
+
* [Discussion group](https://groups.google.com/group/beautifulsoup/)
|
| 85 |
+
* [Development](https://code.launchpad.net/beautifulsoup/)
|
| 86 |
+
* [Bug tracker](https://bugs.launchpad.net/beautifulsoup/)
|
| 87 |
+
* [Complete changelog](https://git.launchpad.net/beautifulsoup/tree/CHANGELOG)
|
| 88 |
+
|
| 89 |
+
# Note on Python 2 sunsetting
|
| 90 |
+
|
| 91 |
+
Beautiful Soup's support for Python 2 was discontinued on December 31,
|
| 92 |
+
2020: one year after the sunset date for Python 2 itself. From this
|
| 93 |
+
point onward, new Beautiful Soup development will exclusively target
|
| 94 |
+
Python 3. The final release of Beautiful Soup 4 to support Python 2
|
| 95 |
+
was 4.9.3.
|
| 96 |
+
|
| 97 |
+
# Supporting the project
|
| 98 |
+
|
| 99 |
+
If you use Beautiful Soup as part of your professional work, please consider a
|
| 100 |
+
[Tidelift subscription](https://tidelift.com/subscription/pkg/pypi-beautifulsoup4?utm_source=pypi-beautifulsoup4&utm_medium=referral&utm_campaign=readme).
|
| 101 |
+
This will support many of the free software projects your organization
|
| 102 |
+
depends on, not just Beautiful Soup.
|
| 103 |
+
|
| 104 |
+
If you use Beautiful Soup for personal projects, the best way to say
|
| 105 |
+
thank you is to read
|
| 106 |
+
[Tool Safety](https://www.crummy.com/software/BeautifulSoup/zine/), a zine I
|
| 107 |
+
wrote about what Beautiful Soup has taught me about software
|
| 108 |
+
development.
|
| 109 |
+
|
| 110 |
+
# Building the documentation
|
| 111 |
+
|
| 112 |
+
The bs4/doc/ directory contains full documentation in Sphinx
|
| 113 |
+
format. Run `make html` in that directory to create HTML
|
| 114 |
+
documentation.
|
| 115 |
+
|
| 116 |
+
# Running the unit tests
|
| 117 |
+
|
| 118 |
+
Beautiful Soup supports unit test discovery using Pytest:
|
| 119 |
+
|
| 120 |
+
```
|
| 121 |
+
$ pytest
|
| 122 |
+
```
|
| 123 |
+
|
python/py313/Lib/site-packages/beautifulsoup4-4.14.3.dist-info/RECORD
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
beautifulsoup4-4.14.3.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
beautifulsoup4-4.14.3.dist-info/METADATA,sha256=Ac93vA8Xp9FtgOcKXFM8ESfVdztimUfJ3WUpVlhKtsY,3812
|
| 3 |
+
beautifulsoup4-4.14.3.dist-info/RECORD,,
|
| 4 |
+
beautifulsoup4-4.14.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
| 5 |
+
beautifulsoup4-4.14.3.dist-info/licenses/AUTHORS,sha256=uYkjiRjh_aweRnF8tAW2PpJJeickE68NmJwd9siry28,2201
|
| 6 |
+
beautifulsoup4-4.14.3.dist-info/licenses/LICENSE,sha256=VbTY1LHlvIbRDvrJG3TIe8t3UmsPW57a-LnNKtxzl7I,1441
|
| 7 |
+
bs4/__init__.py,sha256=E7wiVp7oQK0JhdAYxpehZa8drv3W_sJv5oeTFiBfR5o,44386
|
| 8 |
+
bs4/__pycache__/__init__.cpython-313.pyc,,
|
| 9 |
+
bs4/__pycache__/_deprecation.cpython-313.pyc,,
|
| 10 |
+
bs4/__pycache__/_typing.cpython-313.pyc,,
|
| 11 |
+
bs4/__pycache__/_warnings.cpython-313.pyc,,
|
| 12 |
+
bs4/__pycache__/css.cpython-313.pyc,,
|
| 13 |
+
bs4/__pycache__/dammit.cpython-313.pyc,,
|
| 14 |
+
bs4/__pycache__/diagnose.cpython-313.pyc,,
|
| 15 |
+
bs4/__pycache__/element.cpython-313.pyc,,
|
| 16 |
+
bs4/__pycache__/exceptions.cpython-313.pyc,,
|
| 17 |
+
bs4/__pycache__/filter.cpython-313.pyc,,
|
| 18 |
+
bs4/__pycache__/formatter.cpython-313.pyc,,
|
| 19 |
+
bs4/_deprecation.py,sha256=niHJCk37APg8KEuFOa57ZXaxLdBmc_2V6uuaJqu7r30,2408
|
| 20 |
+
bs4/_typing.py,sha256=zNcx7R1yCTK8WwtumP28hc7CJ3pMyZXj_VAeYaNXMZA,7549
|
| 21 |
+
bs4/_warnings.py,sha256=ZuOETgcnEbZgw2N0nnNXn6wvtrn2ut7AF0d98bvkMFc,4711
|
| 22 |
+
bs4/builder/__init__.py,sha256=Rl4qjOXvdyyyjayOFqbkgoUoo81IgoyKD-RwWeVK59g,31194
|
| 23 |
+
bs4/builder/__pycache__/__init__.cpython-313.pyc,,
|
| 24 |
+
bs4/builder/__pycache__/_html5lib.cpython-313.pyc,,
|
| 25 |
+
bs4/builder/__pycache__/_htmlparser.cpython-313.pyc,,
|
| 26 |
+
bs4/builder/__pycache__/_lxml.cpython-313.pyc,,
|
| 27 |
+
bs4/builder/_html5lib.py,sha256=hL6xUk4_I2i5CMguFoYFlrI26cY4Dut7fOEQrUctHIM,23607
|
| 28 |
+
bs4/builder/_htmlparser.py,sha256=CnULPQV2rm4vLojJABpQ7Xm9diddnEZx2Wcz_VTC1Mg,17445
|
| 29 |
+
bs4/builder/_lxml.py,sha256=ks1e8boA_nOA2oomAhxeudccR6ThbEE-EllFqHRoPLA,18969
|
| 30 |
+
bs4/css.py,sha256=_m_l_4SGWHnY620VJ21j_qQH1RX3p91sYVemgKxaLsM,12713
|
| 31 |
+
bs4/dammit.py,sha256=ZJWa9K32X6N2imFHleqUq0ekf592weU1lvULN_WYWYk,57024
|
| 32 |
+
bs4/diagnose.py,sha256=at98iuxyOrqec4V8iwkTIbNUqBCsq9Lr3fDAQx2129Y,7846
|
| 33 |
+
bs4/element.py,sha256=oXmj7LG_2NpsDK90mq73q0PMK0FjFBIGSeTTJLVwwTc,120237
|
| 34 |
+
bs4/exceptions.py,sha256=Q9FOadNe8QRvzDMaKSXe2Wtl8JK_oAZW7mbFZBVP_GE,951
|
| 35 |
+
bs4/filter.py,sha256=rw8ZNhTDLEJVCEiSifou5tZR_3zBLeuvAyouY82qU_E,29201
|
| 36 |
+
bs4/formatter.py,sha256=uBT0k6W8O5kJ9PCuJYjra97yoUqC-dlM9D_v-oRM0r8,10478
|
| 37 |
+
bs4/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
python/py313/Lib/site-packages/beautifulsoup4-4.14.3.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: hatchling 1.27.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
python/py313/Lib/site-packages/brotli-1.2.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
python/py313/Lib/site-packages/brotli-1.2.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: brotli
|
| 3 |
+
Version: 1.2.0
|
| 4 |
+
Summary: Python bindings for the Brotli compression library
|
| 5 |
+
Home-page: https://github.com/google/brotli
|
| 6 |
+
Author: The Brotli Authors
|
| 7 |
+
License: MIT
|
| 8 |
+
Platform: Posix
|
| 9 |
+
Platform: MacOS X
|
| 10 |
+
Platform: Windows
|
| 11 |
+
Classifier: Development Status :: 4 - Beta
|
| 12 |
+
Classifier: Environment :: Console
|
| 13 |
+
Classifier: Intended Audience :: Developers
|
| 14 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 15 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 16 |
+
Classifier: Operating System :: POSIX :: Linux
|
| 17 |
+
Classifier: Programming Language :: C
|
| 18 |
+
Classifier: Programming Language :: C++
|
| 19 |
+
Classifier: Programming Language :: Python
|
| 20 |
+
Classifier: Programming Language :: Python :: 2
|
| 21 |
+
Classifier: Programming Language :: Python :: 2.7
|
| 22 |
+
Classifier: Programming Language :: Python :: 3
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.3
|
| 24 |
+
Classifier: Programming Language :: Python :: 3.4
|
| 25 |
+
Classifier: Programming Language :: Python :: 3.5
|
| 26 |
+
Classifier: Programming Language :: Unix Shell
|
| 27 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 28 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 29 |
+
Classifier: Topic :: System :: Archiving
|
| 30 |
+
Classifier: Topic :: System :: Archiving :: Compression
|
| 31 |
+
Classifier: Topic :: Text Processing :: Fonts
|
| 32 |
+
Classifier: Topic :: Utilities
|
| 33 |
+
Description-Content-Type: text/markdown
|
| 34 |
+
License-File: LICENSE
|
| 35 |
+
Dynamic: author
|
| 36 |
+
Dynamic: classifier
|
| 37 |
+
Dynamic: description
|
| 38 |
+
Dynamic: description-content-type
|
| 39 |
+
Dynamic: home-page
|
| 40 |
+
Dynamic: license
|
| 41 |
+
Dynamic: license-file
|
| 42 |
+
Dynamic: platform
|
| 43 |
+
Dynamic: summary
|
| 44 |
+
|
| 45 |
+
<p align="center">
|
| 46 |
+
<img src="https://github.com/google/brotli/actions/workflows/build_test.yml/badge.svg" alt="GitHub Actions Build Status" href="https://github.com/google/brotli/actions?query=branch%3Amaster">
|
| 47 |
+
<img src="https://oss-fuzz-build-logs.storage.googleapis.com/badges/brotli.svg" alt="Fuzzing Status" href="https://oss-fuzz-build-logs.storage.googleapis.com/index.html#brotli">
|
| 48 |
+
</p>
|
| 49 |
+
<p align="center"><img src="https://brotli.org/brotli.svg" alt="Brotli" width="64"></p>
|
| 50 |
+
|
| 51 |
+
### Introduction
|
| 52 |
+
|
| 53 |
+
Brotli is a generic-purpose lossless compression algorithm that compresses data
|
| 54 |
+
using a combination of a modern variant of the LZ77 algorithm, Huffman coding
|
| 55 |
+
and 2nd order context modeling, with a compression ratio comparable to the best
|
| 56 |
+
currently available general-purpose compression methods. It is similar in speed
|
| 57 |
+
with deflate but offers more dense compression.
|
| 58 |
+
|
| 59 |
+
The specification of the Brotli Compressed Data Format is defined in
|
| 60 |
+
[RFC 7932](https://datatracker.ietf.org/doc/html/rfc7932).
|
| 61 |
+
|
| 62 |
+
Brotli is open-sourced under the MIT License, see the LICENSE file.
|
| 63 |
+
|
| 64 |
+
> **Please note:** brotli is a "stream" format; it does not contain
|
| 65 |
+
> meta-information, like checksums or uncompressed data length. It is possible
|
| 66 |
+
> to modify "raw" ranges of the compressed stream and the decoder will not
|
| 67 |
+
> notice that.
|
| 68 |
+
|
| 69 |
+
### Installation
|
| 70 |
+
|
| 71 |
+
In most Linux distributions, installing `brotli` is just a matter of using
|
| 72 |
+
the package management system. For example in Debian-based distributions:
|
| 73 |
+
`apt install brotli` will install `brotli`. On MacOS, you can use
|
| 74 |
+
[Homebrew](https://brew.sh/): `brew install brotli`.
|
| 75 |
+
|
| 76 |
+
[](https://repology.org/project/brotli/versions)
|
| 77 |
+
|
| 78 |
+
Of course you can also build brotli from sources.
|
| 79 |
+
|
| 80 |
+
### Build instructions
|
| 81 |
+
|
| 82 |
+
#### Vcpkg
|
| 83 |
+
|
| 84 |
+
You can download and install brotli using the
|
| 85 |
+
[vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
|
| 86 |
+
|
| 87 |
+
git clone https://github.com/Microsoft/vcpkg.git
|
| 88 |
+
cd vcpkg
|
| 89 |
+
./bootstrap-vcpkg.sh
|
| 90 |
+
./vcpkg integrate install
|
| 91 |
+
./vcpkg install brotli
|
| 92 |
+
|
| 93 |
+
The brotli port in vcpkg is kept up to date by Microsoft team members and
|
| 94 |
+
community contributors. If the version is out of date, please [create an issue
|
| 95 |
+
or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
| 96 |
+
|
| 97 |
+
#### Bazel
|
| 98 |
+
|
| 99 |
+
See [Bazel](https://www.bazel.build/)
|
| 100 |
+
|
| 101 |
+
#### CMake
|
| 102 |
+
|
| 103 |
+
The basic commands to build and install brotli are:
|
| 104 |
+
|
| 105 |
+
$ mkdir out && cd out
|
| 106 |
+
$ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./installed ..
|
| 107 |
+
$ cmake --build . --config Release --target install
|
| 108 |
+
|
| 109 |
+
You can use other [CMake](https://cmake.org/) configuration.
|
| 110 |
+
|
| 111 |
+
#### Python
|
| 112 |
+
|
| 113 |
+
To install the latest release of the Python module, run the following:
|
| 114 |
+
|
| 115 |
+
$ pip install brotli
|
| 116 |
+
|
| 117 |
+
To install the tip-of-the-tree version, run:
|
| 118 |
+
|
| 119 |
+
$ pip install --upgrade git+https://github.com/google/brotli
|
| 120 |
+
|
| 121 |
+
See the [Python readme](python/README.md) for more details on installing
|
| 122 |
+
from source, development, and testing.
|
| 123 |
+
|
| 124 |
+
### Contributing
|
| 125 |
+
|
| 126 |
+
We glad to answer/library related questions in
|
| 127 |
+
[brotli mailing list](https://groups.google.com/g/brotli).
|
| 128 |
+
|
| 129 |
+
Regular issues / feature requests should be reported in
|
| 130 |
+
[issue tracker](https://github.com/google/brotli/issues).
|
| 131 |
+
|
| 132 |
+
For reporting vulnerability please read [SECURITY](SECURITY.md).
|
| 133 |
+
|
| 134 |
+
For contributing changes please read [CONTRIBUTING](CONTRIBUTING.md).
|
| 135 |
+
|
| 136 |
+
### Benchmarks
|
| 137 |
+
* [Squash Compression Benchmark](https://quixdb.github.io/squash-benchmark/) / [Unstable Squash Compression Benchmark](https://quixdb.github.io/squash-benchmark/unstable/)
|
| 138 |
+
* [Large Text Compression Benchmark](https://mattmahoney.net/dc/text.html)
|
| 139 |
+
* [Lzturbo Benchmark](https://sites.google.com/site/powturbo/home/benchmark)
|
| 140 |
+
|
| 141 |
+
### Related projects
|
| 142 |
+
> **Disclaimer:** Brotli authors take no responsibility for the third party projects mentioned in this section.
|
| 143 |
+
|
| 144 |
+
Independent [decoder](https://github.com/madler/brotli) implementation
|
| 145 |
+
by Mark Adler, based entirely on format specification.
|
| 146 |
+
|
| 147 |
+
JavaScript port of brotli [decoder](https://github.com/devongovett/brotli.js).
|
| 148 |
+
Could be used directly via `npm install brotli`
|
| 149 |
+
|
| 150 |
+
Hand ported [decoder / encoder](https://github.com/dominikhlbg/BrotliHaxe)
|
| 151 |
+
in haxe by Dominik Homberger.
|
| 152 |
+
Output source code: JavaScript, PHP, Python, Java and C#
|
| 153 |
+
|
| 154 |
+
7Zip [plugin](https://github.com/mcmilk/7-Zip-Zstd)
|
| 155 |
+
|
| 156 |
+
Dart compression framework with
|
| 157 |
+
[fast FFI-based Brotli implementation](https://pub.dev/documentation/es_compression/latest/brotli/)
|
| 158 |
+
with ready-to-use prebuilt binaries for Win/Linux/Mac
|
python/py313/Lib/site-packages/brotli-1.2.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/brotli.cpython-313.pyc,,
|
| 2 |
+
_brotli.cp313-win_amd64.pyd,sha256=p_gwhqmZoB2wyoy6bUdrSqdOwvliks9OF0Rt0wwIXGE,856576
|
| 3 |
+
brotli-1.2.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 4 |
+
brotli-1.2.0.dist-info/METADATA,sha256=dLzObyHAQu_lsd37HPc2cDB_IdeFaA1feDjHkiJvkdE,6274
|
| 5 |
+
brotli-1.2.0.dist-info/RECORD,,
|
| 6 |
+
brotli-1.2.0.dist-info/WHEEL,sha256=qV0EIPljj1XC_vuSatRWjn02nZIz3N1t8jsZz7HBr2U,101
|
| 7 |
+
brotli-1.2.0.dist-info/licenses/LICENSE,sha256=YK4PE-dswuqqEIZ37vpM4Wtkf2u-jPChrJQp2C7Kckg,1103
|
| 8 |
+
brotli-1.2.0.dist-info/top_level.txt,sha256=gsS54HrhO3ZveFxeMrKo_7qH4Sm4TbQ7jGLVBEqJ4NI,15
|
| 9 |
+
brotli.py,sha256=_i8MubwH-A-oO0fza84xahZ_OxtujMLp3AEXy0pMxTU,2027
|
python/py313/Lib/site-packages/brotli-1.2.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (80.9.0)
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp313-cp313-win_amd64
|
| 5 |
+
|
python/py313/Lib/site-packages/brotli-1.2.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
_brotli
|
| 2 |
+
brotli
|
python/py313/Lib/site-packages/brotli.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2016 The Brotli Authors. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Distributed under MIT license.
|
| 4 |
+
# See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
| 5 |
+
|
| 6 |
+
"""Functions to compress and decompress data using the Brotli library."""
|
| 7 |
+
|
| 8 |
+
import _brotli
|
| 9 |
+
|
| 10 |
+
# The library version.
|
| 11 |
+
version = __version__ = _brotli.__version__
|
| 12 |
+
|
| 13 |
+
# The compression mode.
|
| 14 |
+
MODE_GENERIC = _brotli.MODE_GENERIC
|
| 15 |
+
MODE_TEXT = _brotli.MODE_TEXT
|
| 16 |
+
MODE_FONT = _brotli.MODE_FONT
|
| 17 |
+
|
| 18 |
+
# The Compressor object.
|
| 19 |
+
Compressor = _brotli.Compressor
|
| 20 |
+
|
| 21 |
+
# The Decompressor object.
|
| 22 |
+
Decompressor = _brotli.Decompressor
|
| 23 |
+
|
| 24 |
+
# Compress a byte string.
|
| 25 |
+
def compress(string, mode=MODE_GENERIC, quality=11, lgwin=22, lgblock=0):
|
| 26 |
+
"""Compress a byte string.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
string (bytes): The input data.
|
| 30 |
+
mode (int, optional): The compression mode; value 0 should be used for
|
| 31 |
+
generic input (MODE_GENERIC); value 1 might be beneficial for UTF-8 text
|
| 32 |
+
input (MODE_TEXT); value 2 tunes encoder for WOFF 2.0 data (MODE_FONT).
|
| 33 |
+
Defaults to 0.
|
| 34 |
+
quality (int, optional): Controls the compression-speed vs compression-
|
| 35 |
+
density tradeoff. The higher the quality, the slower the compression.
|
| 36 |
+
Range is 0 to 11. Defaults to 11.
|
| 37 |
+
lgwin (int, optional): Base 2 logarithm of the sliding window size. Range
|
| 38 |
+
is 10 to 24. Defaults to 22.
|
| 39 |
+
lgblock (int, optional): Base 2 logarithm of the maximum input block size.
|
| 40 |
+
Range is 16 to 24. If set to 0, the value will be set based on the
|
| 41 |
+
quality. Defaults to 0.
|
| 42 |
+
|
| 43 |
+
Returns:
|
| 44 |
+
The compressed byte string.
|
| 45 |
+
|
| 46 |
+
Raises:
|
| 47 |
+
brotli.error: If arguments are invalid, or compressor fails.
|
| 48 |
+
"""
|
| 49 |
+
compressor = Compressor(mode=mode, quality=quality, lgwin=lgwin,
|
| 50 |
+
lgblock=lgblock)
|
| 51 |
+
return compressor.process(string) + compressor.finish()
|
| 52 |
+
|
| 53 |
+
# Decompress a compressed byte string.
|
| 54 |
+
decompress = _brotli.decompress
|
| 55 |
+
|
| 56 |
+
# Raised if compression or decompression fails.
|
| 57 |
+
error = _brotli.error
|
python/py313/Lib/site-packages/bs4-0.0.2.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
python/py313/Lib/site-packages/bs4-0.0.2.dist-info/METADATA
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: bs4
|
| 3 |
+
Version: 0.0.2
|
| 4 |
+
Summary: Dummy package for Beautiful Soup (beautifulsoup4)
|
| 5 |
+
Author-email: Leonard Richardson <leonardr@segfault.org>
|
| 6 |
+
License: MIT License
|
| 7 |
+
Requires-Dist: beautifulsoup4
|
| 8 |
+
Description-Content-Type: text/x-rst
|
| 9 |
+
|
| 10 |
+
This is a dummy package designed to prevent namesquatting on PyPI. You should install `beautifulsoup4 <https://pypi.python.org/pypi/beautifulsoup4>`_ instead.
|
python/py313/Lib/site-packages/bs4-0.0.2.dist-info/RECORD
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
README.rst,sha256=KMs4D-t40JC-oge8vGS3O5gueksurGqAIFxPtHZAMXQ,159
|
| 2 |
+
bs4-0.0.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 3 |
+
bs4-0.0.2.dist-info/METADATA,sha256=GEwOSFCOYLu11XQR3O2dMO7ZTpKFZpGoIUG0gkFVgA8,411
|
| 4 |
+
bs4-0.0.2.dist-info/RECORD,,
|
| 5 |
+
bs4-0.0.2.dist-info/WHEEL,sha256=VYAwk8D_V6zmIA2XKK-k7Fem_KAtVk3hugaRru3yjGc,105
|
python/py313/Lib/site-packages/bs4-0.0.2.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: hatchling 1.21.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py2-none-any
|
| 5 |
+
Tag: py3-none-any
|
python/py313/Lib/site-packages/bs4/__init__.py
ADDED
|
@@ -0,0 +1,1174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Beautiful Soup Elixir and Tonic - "The Screen-Scraper's Friend".
|
| 2 |
+
|
| 3 |
+
http://www.crummy.com/software/BeautifulSoup/
|
| 4 |
+
|
| 5 |
+
Beautiful Soup uses a pluggable XML or HTML parser to parse a
|
| 6 |
+
(possibly invalid) document into a tree representation. Beautiful Soup
|
| 7 |
+
provides methods and Pythonic idioms that make it easy to navigate,
|
| 8 |
+
search, and modify the parse tree.
|
| 9 |
+
|
| 10 |
+
Beautiful Soup works with Python 3.7 and up. It works better if lxml
|
| 11 |
+
and/or html5lib is installed, but they are not required.
|
| 12 |
+
|
| 13 |
+
For more than you ever wanted to know about Beautiful Soup, see the
|
| 14 |
+
documentation: http://www.crummy.com/software/BeautifulSoup/bs4/doc/
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
__author__ = "Leonard Richardson (leonardr@segfault.org)"
|
| 18 |
+
__version__ = "4.14.3"
|
| 19 |
+
__copyright__ = "Copyright (c) 2004-2025 Leonard Richardson"
|
| 20 |
+
# Use of this source code is governed by the MIT license.
|
| 21 |
+
__license__ = "MIT"
|
| 22 |
+
|
| 23 |
+
__all__ = [
|
| 24 |
+
"AttributeResemblesVariableWarning",
|
| 25 |
+
"BeautifulSoup",
|
| 26 |
+
"Comment",
|
| 27 |
+
"Declaration",
|
| 28 |
+
"ProcessingInstruction",
|
| 29 |
+
"ResultSet",
|
| 30 |
+
"CSS",
|
| 31 |
+
"Script",
|
| 32 |
+
"Stylesheet",
|
| 33 |
+
"Tag",
|
| 34 |
+
"TemplateString",
|
| 35 |
+
"ElementFilter",
|
| 36 |
+
"UnicodeDammit",
|
| 37 |
+
"CData",
|
| 38 |
+
"Doctype",
|
| 39 |
+
|
| 40 |
+
# Exceptions
|
| 41 |
+
"FeatureNotFound",
|
| 42 |
+
"ParserRejectedMarkup",
|
| 43 |
+
"StopParsing",
|
| 44 |
+
|
| 45 |
+
# Warnings
|
| 46 |
+
"AttributeResemblesVariableWarning",
|
| 47 |
+
"GuessedAtParserWarning",
|
| 48 |
+
"MarkupResemblesLocatorWarning",
|
| 49 |
+
"UnusualUsageWarning",
|
| 50 |
+
"XMLParsedAsHTMLWarning",
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
from collections import Counter
|
| 54 |
+
import io
|
| 55 |
+
import sys
|
| 56 |
+
import warnings
|
| 57 |
+
|
| 58 |
+
# The very first thing we do is give a useful error if someone is
|
| 59 |
+
# running this code under Python 2.
|
| 60 |
+
if sys.version_info.major < 3:
|
| 61 |
+
raise ImportError(
|
| 62 |
+
"You are trying to use a Python 3-specific version of Beautiful Soup under Python 2. This will not work. The final version of Beautiful Soup to support Python 2 was 4.9.3."
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
from .builder import (
|
| 66 |
+
builder_registry,
|
| 67 |
+
TreeBuilder,
|
| 68 |
+
)
|
| 69 |
+
from .builder._htmlparser import HTMLParserTreeBuilder
|
| 70 |
+
from .dammit import UnicodeDammit
|
| 71 |
+
from .css import CSS
|
| 72 |
+
from ._deprecation import (
|
| 73 |
+
_deprecated,
|
| 74 |
+
)
|
| 75 |
+
from .element import (
|
| 76 |
+
CData,
|
| 77 |
+
Comment,
|
| 78 |
+
DEFAULT_OUTPUT_ENCODING,
|
| 79 |
+
Declaration,
|
| 80 |
+
Doctype,
|
| 81 |
+
NavigableString,
|
| 82 |
+
PageElement,
|
| 83 |
+
ProcessingInstruction,
|
| 84 |
+
PYTHON_SPECIFIC_ENCODINGS,
|
| 85 |
+
ResultSet,
|
| 86 |
+
Script,
|
| 87 |
+
Stylesheet,
|
| 88 |
+
Tag,
|
| 89 |
+
TemplateString,
|
| 90 |
+
)
|
| 91 |
+
from .formatter import Formatter
|
| 92 |
+
from .filter import (
|
| 93 |
+
ElementFilter,
|
| 94 |
+
SoupStrainer,
|
| 95 |
+
)
|
| 96 |
+
from typing import (
|
| 97 |
+
Any,
|
| 98 |
+
cast,
|
| 99 |
+
Counter as CounterType,
|
| 100 |
+
Dict,
|
| 101 |
+
Iterator,
|
| 102 |
+
List,
|
| 103 |
+
Sequence,
|
| 104 |
+
Sized,
|
| 105 |
+
Optional,
|
| 106 |
+
Type,
|
| 107 |
+
Union,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
from bs4._typing import (
|
| 111 |
+
_Encoding,
|
| 112 |
+
_Encodings,
|
| 113 |
+
_IncomingMarkup,
|
| 114 |
+
_InsertableElement,
|
| 115 |
+
_RawAttributeValue,
|
| 116 |
+
_RawAttributeValues,
|
| 117 |
+
_RawMarkup,
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
# Import all warnings and exceptions into the main package.
|
| 121 |
+
from bs4.exceptions import (
|
| 122 |
+
FeatureNotFound,
|
| 123 |
+
ParserRejectedMarkup,
|
| 124 |
+
StopParsing,
|
| 125 |
+
)
|
| 126 |
+
from bs4._warnings import (
|
| 127 |
+
AttributeResemblesVariableWarning,
|
| 128 |
+
GuessedAtParserWarning,
|
| 129 |
+
MarkupResemblesLocatorWarning,
|
| 130 |
+
UnusualUsageWarning,
|
| 131 |
+
XMLParsedAsHTMLWarning,
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class BeautifulSoup(Tag):
|
| 136 |
+
"""A data structure representing a parsed HTML or XML document.
|
| 137 |
+
|
| 138 |
+
Most of the methods you'll call on a BeautifulSoup object are inherited from
|
| 139 |
+
PageElement or Tag.
|
| 140 |
+
|
| 141 |
+
Internally, this class defines the basic interface called by the
|
| 142 |
+
tree builders when converting an HTML/XML document into a data
|
| 143 |
+
structure. The interface abstracts away the differences between
|
| 144 |
+
parsers. To write a new tree builder, you'll need to understand
|
| 145 |
+
these methods as a whole.
|
| 146 |
+
|
| 147 |
+
These methods will be called by the BeautifulSoup constructor:
|
| 148 |
+
* reset()
|
| 149 |
+
* feed(markup)
|
| 150 |
+
|
| 151 |
+
The tree builder may call these methods from its feed() implementation:
|
| 152 |
+
* handle_starttag(name, attrs) # See note about return value
|
| 153 |
+
* handle_endtag(name)
|
| 154 |
+
* handle_data(data) # Appends to the current data node
|
| 155 |
+
* endData(containerClass) # Ends the current data node
|
| 156 |
+
|
| 157 |
+
No matter how complicated the underlying parser is, you should be
|
| 158 |
+
able to build a tree using 'start tag' events, 'end tag' events,
|
| 159 |
+
'data' events, and "done with data" events.
|
| 160 |
+
|
| 161 |
+
If you encounter an empty-element tag (aka a self-closing tag,
|
| 162 |
+
like HTML's <br> tag), call handle_starttag and then
|
| 163 |
+
handle_endtag.
|
| 164 |
+
"""
|
| 165 |
+
|
| 166 |
+
#: Since `BeautifulSoup` subclasses `Tag`, it's possible to treat it as
|
| 167 |
+
#: a `Tag` with a `Tag.name`. Hoever, this name makes it clear the
|
| 168 |
+
#: `BeautifulSoup` object isn't a real markup tag.
|
| 169 |
+
ROOT_TAG_NAME: str = "[document]"
|
| 170 |
+
|
| 171 |
+
#: If the end-user gives no indication which tree builder they
|
| 172 |
+
#: want, look for one with these features.
|
| 173 |
+
DEFAULT_BUILDER_FEATURES: Sequence[str] = ["html", "fast"]
|
| 174 |
+
|
| 175 |
+
#: A string containing all ASCII whitespace characters, used in
|
| 176 |
+
#: during parsing to detect data chunks that seem 'empty'.
|
| 177 |
+
ASCII_SPACES: str = "\x20\x0a\x09\x0c\x0d"
|
| 178 |
+
|
| 179 |
+
# FUTURE PYTHON:
|
| 180 |
+
element_classes: Dict[Type[PageElement], Type[PageElement]] #: :meta private:
|
| 181 |
+
builder: TreeBuilder #: :meta private:
|
| 182 |
+
is_xml: bool
|
| 183 |
+
known_xml: Optional[bool]
|
| 184 |
+
parse_only: Optional[SoupStrainer] #: :meta private:
|
| 185 |
+
|
| 186 |
+
# These members are only used while parsing markup.
|
| 187 |
+
markup: Optional[_RawMarkup] #: :meta private:
|
| 188 |
+
current_data: List[str] #: :meta private:
|
| 189 |
+
currentTag: Optional[Tag] #: :meta private:
|
| 190 |
+
tagStack: List[Tag] #: :meta private:
|
| 191 |
+
open_tag_counter: CounterType[str] #: :meta private:
|
| 192 |
+
preserve_whitespace_tag_stack: List[Tag] #: :meta private:
|
| 193 |
+
string_container_stack: List[Tag] #: :meta private:
|
| 194 |
+
_most_recent_element: Optional[PageElement] #: :meta private:
|
| 195 |
+
|
| 196 |
+
#: Beautiful Soup's best guess as to the character encoding of the
|
| 197 |
+
#: original document.
|
| 198 |
+
original_encoding: Optional[_Encoding]
|
| 199 |
+
|
| 200 |
+
#: The character encoding, if any, that was explicitly defined
|
| 201 |
+
#: in the original document. This may or may not match
|
| 202 |
+
#: `BeautifulSoup.original_encoding`.
|
| 203 |
+
declared_html_encoding: Optional[_Encoding]
|
| 204 |
+
|
| 205 |
+
#: This is True if the markup that was parsed contains
|
| 206 |
+
#: U+FFFD REPLACEMENT_CHARACTER characters which were not present
|
| 207 |
+
#: in the original markup. These mark character sequences that
|
| 208 |
+
#: could not be represented in Unicode.
|
| 209 |
+
contains_replacement_characters: bool
|
| 210 |
+
|
| 211 |
+
def __init__(
|
| 212 |
+
self,
|
| 213 |
+
markup: _IncomingMarkup = "",
|
| 214 |
+
features: Optional[Union[str, Sequence[str]]] = None,
|
| 215 |
+
builder: Optional[Union[TreeBuilder, Type[TreeBuilder]]] = None,
|
| 216 |
+
parse_only: Optional[SoupStrainer] = None,
|
| 217 |
+
from_encoding: Optional[_Encoding] = None,
|
| 218 |
+
exclude_encodings: Optional[_Encodings] = None,
|
| 219 |
+
element_classes: Optional[Dict[Type[PageElement], Type[PageElement]]] = None,
|
| 220 |
+
**kwargs: Any,
|
| 221 |
+
):
|
| 222 |
+
"""Constructor.
|
| 223 |
+
|
| 224 |
+
:param markup: A string or a file-like object representing
|
| 225 |
+
markup to be parsed.
|
| 226 |
+
|
| 227 |
+
:param features: Desirable features of the parser to be
|
| 228 |
+
used. This may be the name of a specific parser ("lxml",
|
| 229 |
+
"lxml-xml", "html.parser", or "html5lib") or it may be the
|
| 230 |
+
type of markup to be used ("html", "html5", "xml"). It's
|
| 231 |
+
recommended that you name a specific parser, so that
|
| 232 |
+
Beautiful Soup gives you the same results across platforms
|
| 233 |
+
and virtual environments.
|
| 234 |
+
|
| 235 |
+
:param builder: A TreeBuilder subclass to instantiate (or
|
| 236 |
+
instance to use) instead of looking one up based on
|
| 237 |
+
`features`. You only need to use this if you've implemented a
|
| 238 |
+
custom TreeBuilder.
|
| 239 |
+
|
| 240 |
+
:param parse_only: A SoupStrainer. Only parts of the document
|
| 241 |
+
matching the SoupStrainer will be considered. This is useful
|
| 242 |
+
when parsing part of a document that would otherwise be too
|
| 243 |
+
large to fit into memory.
|
| 244 |
+
|
| 245 |
+
:param from_encoding: A string indicating the encoding of the
|
| 246 |
+
document to be parsed. Pass this in if Beautiful Soup is
|
| 247 |
+
guessing wrongly about the document's encoding.
|
| 248 |
+
|
| 249 |
+
:param exclude_encodings: A list of strings indicating
|
| 250 |
+
encodings known to be wrong. Pass this in if you don't know
|
| 251 |
+
the document's encoding but you know Beautiful Soup's guess is
|
| 252 |
+
wrong.
|
| 253 |
+
|
| 254 |
+
:param element_classes: A dictionary mapping BeautifulSoup
|
| 255 |
+
classes like Tag and NavigableString, to other classes you'd
|
| 256 |
+
like to be instantiated instead as the parse tree is
|
| 257 |
+
built. This is useful for subclassing Tag or NavigableString
|
| 258 |
+
to modify default behavior.
|
| 259 |
+
|
| 260 |
+
:param kwargs: For backwards compatibility purposes, the
|
| 261 |
+
constructor accepts certain keyword arguments used in
|
| 262 |
+
Beautiful Soup 3. None of these arguments do anything in
|
| 263 |
+
Beautiful Soup 4; they will result in a warning and then be
|
| 264 |
+
ignored.
|
| 265 |
+
|
| 266 |
+
Apart from this, any keyword arguments passed into the
|
| 267 |
+
BeautifulSoup constructor are propagated to the TreeBuilder
|
| 268 |
+
constructor. This makes it possible to configure a
|
| 269 |
+
TreeBuilder by passing in arguments, not just by saying which
|
| 270 |
+
one to use.
|
| 271 |
+
"""
|
| 272 |
+
if "convertEntities" in kwargs:
|
| 273 |
+
del kwargs["convertEntities"]
|
| 274 |
+
warnings.warn(
|
| 275 |
+
"BS4 does not respect the convertEntities argument to the "
|
| 276 |
+
"BeautifulSoup constructor. Entities are always converted "
|
| 277 |
+
"to Unicode characters."
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
if "markupMassage" in kwargs:
|
| 281 |
+
del kwargs["markupMassage"]
|
| 282 |
+
warnings.warn(
|
| 283 |
+
"BS4 does not respect the markupMassage argument to the "
|
| 284 |
+
"BeautifulSoup constructor. The tree builder is responsible "
|
| 285 |
+
"for any necessary markup massage."
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
if "smartQuotesTo" in kwargs:
|
| 289 |
+
del kwargs["smartQuotesTo"]
|
| 290 |
+
warnings.warn(
|
| 291 |
+
"BS4 does not respect the smartQuotesTo argument to the "
|
| 292 |
+
"BeautifulSoup constructor. Smart quotes are always converted "
|
| 293 |
+
"to Unicode characters."
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
if "selfClosingTags" in kwargs:
|
| 297 |
+
del kwargs["selfClosingTags"]
|
| 298 |
+
warnings.warn(
|
| 299 |
+
"Beautiful Soup 4 does not respect the selfClosingTags argument to the "
|
| 300 |
+
"BeautifulSoup constructor. The tree builder is responsible "
|
| 301 |
+
"for understanding self-closing tags."
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
if "isHTML" in kwargs:
|
| 305 |
+
del kwargs["isHTML"]
|
| 306 |
+
warnings.warn(
|
| 307 |
+
"Beautiful Soup 4 does not respect the isHTML argument to the "
|
| 308 |
+
"BeautifulSoup constructor. Suggest you use "
|
| 309 |
+
"features='lxml' for HTML and features='lxml-xml' for "
|
| 310 |
+
"XML."
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
def deprecated_argument(old_name: str, new_name: str) -> Optional[Any]:
|
| 314 |
+
if old_name in kwargs:
|
| 315 |
+
warnings.warn(
|
| 316 |
+
'The "%s" argument to the BeautifulSoup constructor '
|
| 317 |
+
'was renamed to "%s" in Beautiful Soup 4.0.0'
|
| 318 |
+
% (old_name, new_name),
|
| 319 |
+
DeprecationWarning,
|
| 320 |
+
stacklevel=3,
|
| 321 |
+
)
|
| 322 |
+
return kwargs.pop(old_name)
|
| 323 |
+
return None
|
| 324 |
+
|
| 325 |
+
parse_only = parse_only or deprecated_argument("parseOnlyThese", "parse_only")
|
| 326 |
+
if parse_only is not None:
|
| 327 |
+
# Issue a warning if we can tell in advance that
|
| 328 |
+
# parse_only will exclude the entire tree.
|
| 329 |
+
if parse_only.excludes_everything:
|
| 330 |
+
warnings.warn(
|
| 331 |
+
f"The given value for parse_only will exclude everything: {parse_only}",
|
| 332 |
+
UserWarning,
|
| 333 |
+
stacklevel=3,
|
| 334 |
+
)
|
| 335 |
+
|
| 336 |
+
from_encoding = from_encoding or deprecated_argument(
|
| 337 |
+
"fromEncoding", "from_encoding"
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
if from_encoding and isinstance(markup, str):
|
| 341 |
+
warnings.warn(
|
| 342 |
+
"You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored."
|
| 343 |
+
)
|
| 344 |
+
from_encoding = None
|
| 345 |
+
|
| 346 |
+
self.element_classes = element_classes or dict()
|
| 347 |
+
|
| 348 |
+
# We need this information to track whether or not the builder
|
| 349 |
+
# was specified well enough that we can omit the 'you need to
|
| 350 |
+
# specify a parser' warning.
|
| 351 |
+
original_builder = builder
|
| 352 |
+
original_features = features
|
| 353 |
+
|
| 354 |
+
builder_class: Optional[Type[TreeBuilder]] = None
|
| 355 |
+
if isinstance(builder, type):
|
| 356 |
+
# A builder class was passed in; it needs to be instantiated.
|
| 357 |
+
builder_class = builder
|
| 358 |
+
builder = None
|
| 359 |
+
elif builder is None:
|
| 360 |
+
if isinstance(features, str):
|
| 361 |
+
features = [features]
|
| 362 |
+
if features is None or len(features) == 0:
|
| 363 |
+
features = self.DEFAULT_BUILDER_FEATURES
|
| 364 |
+
possible_builder_class = builder_registry.lookup(*features)
|
| 365 |
+
if possible_builder_class is None:
|
| 366 |
+
raise FeatureNotFound(
|
| 367 |
+
"Couldn't find a tree builder with the features you "
|
| 368 |
+
"requested: %s. Do you need to install a parser library?"
|
| 369 |
+
% ",".join(features)
|
| 370 |
+
)
|
| 371 |
+
builder_class = possible_builder_class
|
| 372 |
+
|
| 373 |
+
# At this point either we have a TreeBuilder instance in
|
| 374 |
+
# builder, or we have a builder_class that we can instantiate
|
| 375 |
+
# with the remaining **kwargs.
|
| 376 |
+
if builder is None:
|
| 377 |
+
assert builder_class is not None
|
| 378 |
+
builder = builder_class(**kwargs)
|
| 379 |
+
if (
|
| 380 |
+
not original_builder
|
| 381 |
+
and not (
|
| 382 |
+
original_features == builder.NAME
|
| 383 |
+
or (
|
| 384 |
+
isinstance(original_features, str)
|
| 385 |
+
and original_features in builder.ALTERNATE_NAMES
|
| 386 |
+
)
|
| 387 |
+
)
|
| 388 |
+
and markup
|
| 389 |
+
):
|
| 390 |
+
# The user did not tell us which TreeBuilder to use,
|
| 391 |
+
# and we had to guess. Issue a warning.
|
| 392 |
+
if builder.is_xml:
|
| 393 |
+
markup_type = "XML"
|
| 394 |
+
else:
|
| 395 |
+
markup_type = "HTML"
|
| 396 |
+
|
| 397 |
+
# This code adapted from warnings.py so that we get the same line
|
| 398 |
+
# of code as our warnings.warn() call gets, even if the answer is wrong
|
| 399 |
+
# (as it may be in a multithreading situation).
|
| 400 |
+
caller = None
|
| 401 |
+
try:
|
| 402 |
+
caller = sys._getframe(1)
|
| 403 |
+
except ValueError:
|
| 404 |
+
pass
|
| 405 |
+
if caller:
|
| 406 |
+
globals = caller.f_globals
|
| 407 |
+
line_number = caller.f_lineno
|
| 408 |
+
else:
|
| 409 |
+
globals = sys.__dict__
|
| 410 |
+
line_number = 1
|
| 411 |
+
filename = globals.get("__file__")
|
| 412 |
+
if filename:
|
| 413 |
+
fnl = filename.lower()
|
| 414 |
+
if fnl.endswith((".pyc", ".pyo")):
|
| 415 |
+
filename = filename[:-1]
|
| 416 |
+
if filename:
|
| 417 |
+
# If there is no filename at all, the user is most likely in a REPL,
|
| 418 |
+
# and the warning is not necessary.
|
| 419 |
+
values = dict(
|
| 420 |
+
filename=filename,
|
| 421 |
+
line_number=line_number,
|
| 422 |
+
parser=builder.NAME,
|
| 423 |
+
markup_type=markup_type,
|
| 424 |
+
)
|
| 425 |
+
warnings.warn(
|
| 426 |
+
GuessedAtParserWarning.MESSAGE % values,
|
| 427 |
+
GuessedAtParserWarning,
|
| 428 |
+
stacklevel=2,
|
| 429 |
+
)
|
| 430 |
+
else:
|
| 431 |
+
if kwargs:
|
| 432 |
+
warnings.warn(
|
| 433 |
+
"Keyword arguments to the BeautifulSoup constructor will be ignored. These would normally be passed into the TreeBuilder constructor, but a TreeBuilder instance was passed in as `builder`."
|
| 434 |
+
)
|
| 435 |
+
|
| 436 |
+
self.builder = builder
|
| 437 |
+
self.is_xml = builder.is_xml
|
| 438 |
+
self.known_xml = self.is_xml
|
| 439 |
+
self._namespaces = dict()
|
| 440 |
+
self.parse_only = parse_only
|
| 441 |
+
|
| 442 |
+
if hasattr(markup, "read"): # It's a file-type object.
|
| 443 |
+
markup = cast(io.IOBase, markup).read()
|
| 444 |
+
elif not isinstance(markup, (bytes, str)) and not hasattr(markup, "__len__"):
|
| 445 |
+
raise TypeError(
|
| 446 |
+
f"Incoming markup is of an invalid type: {markup!r}. Markup must be a string, a bytestring, or an open filehandle."
|
| 447 |
+
)
|
| 448 |
+
elif isinstance(markup, Sized) and len(markup) <= 256 and (
|
| 449 |
+
(isinstance(markup, bytes) and b"<" not in markup and b"\n" not in markup)
|
| 450 |
+
or (isinstance(markup, str) and "<" not in markup and "\n" not in markup)
|
| 451 |
+
):
|
| 452 |
+
# Issue warnings for a couple beginner problems
|
| 453 |
+
# involving passing non-markup to Beautiful Soup.
|
| 454 |
+
# Beautiful Soup will still parse the input as markup,
|
| 455 |
+
# since that is sometimes the intended behavior.
|
| 456 |
+
if not self._markup_is_url(markup):
|
| 457 |
+
self._markup_resembles_filename(markup)
|
| 458 |
+
|
| 459 |
+
# At this point we know markup is a string or bytestring. If
|
| 460 |
+
# it was a file-type object, we've read from it.
|
| 461 |
+
markup = cast(_RawMarkup, markup)
|
| 462 |
+
|
| 463 |
+
rejections = []
|
| 464 |
+
success = False
|
| 465 |
+
for (
|
| 466 |
+
self.markup,
|
| 467 |
+
self.original_encoding,
|
| 468 |
+
self.declared_html_encoding,
|
| 469 |
+
self.contains_replacement_characters,
|
| 470 |
+
) in self.builder.prepare_markup(
|
| 471 |
+
markup, from_encoding, exclude_encodings=exclude_encodings
|
| 472 |
+
):
|
| 473 |
+
self.reset()
|
| 474 |
+
self.builder.initialize_soup(self)
|
| 475 |
+
try:
|
| 476 |
+
self._feed()
|
| 477 |
+
success = True
|
| 478 |
+
break
|
| 479 |
+
except ParserRejectedMarkup as e:
|
| 480 |
+
rejections.append(e)
|
| 481 |
+
pass
|
| 482 |
+
|
| 483 |
+
if not success:
|
| 484 |
+
other_exceptions = [str(e) for e in rejections]
|
| 485 |
+
raise ParserRejectedMarkup(
|
| 486 |
+
"The markup you provided was rejected by the parser. Trying a different parser or a different encoding may help.\n\nOriginal exception(s) from parser:\n "
|
| 487 |
+
+ "\n ".join(other_exceptions)
|
| 488 |
+
)
|
| 489 |
+
|
| 490 |
+
# Clear out the markup and remove the builder's circular
|
| 491 |
+
# reference to this object.
|
| 492 |
+
self.markup = None
|
| 493 |
+
self.builder.soup = None
|
| 494 |
+
|
| 495 |
+
def copy_self(self) -> "BeautifulSoup":
|
| 496 |
+
"""Create a new BeautifulSoup object with the same TreeBuilder,
|
| 497 |
+
but not associated with any markup.
|
| 498 |
+
|
| 499 |
+
This is the first step of the deepcopy process.
|
| 500 |
+
"""
|
| 501 |
+
clone = type(self)("", None, self.builder)
|
| 502 |
+
|
| 503 |
+
# Keep track of the encoding of the original document,
|
| 504 |
+
# since we won't be parsing it again.
|
| 505 |
+
clone.original_encoding = self.original_encoding
|
| 506 |
+
return clone
|
| 507 |
+
|
| 508 |
+
def __getstate__(self) -> Dict[str, Any]:
|
| 509 |
+
# Frequently a tree builder can't be pickled.
|
| 510 |
+
d = dict(self.__dict__)
|
| 511 |
+
if "builder" in d and d["builder"] is not None and not self.builder.picklable:
|
| 512 |
+
d["builder"] = type(self.builder)
|
| 513 |
+
# Store the contents as a Unicode string.
|
| 514 |
+
d["contents"] = []
|
| 515 |
+
d["markup"] = self.decode()
|
| 516 |
+
|
| 517 |
+
# If _most_recent_element is present, it's a Tag object left
|
| 518 |
+
# over from initial parse. It might not be picklable and we
|
| 519 |
+
# don't need it.
|
| 520 |
+
if "_most_recent_element" in d:
|
| 521 |
+
del d["_most_recent_element"]
|
| 522 |
+
return d
|
| 523 |
+
|
| 524 |
+
def __setstate__(self, state: Dict[str, Any]) -> None:
|
| 525 |
+
# If necessary, restore the TreeBuilder by looking it up.
|
| 526 |
+
self.__dict__ = state
|
| 527 |
+
if isinstance(self.builder, type):
|
| 528 |
+
self.builder = self.builder()
|
| 529 |
+
elif not self.builder:
|
| 530 |
+
# We don't know which builder was used to build this
|
| 531 |
+
# parse tree, so use a default we know is always available.
|
| 532 |
+
self.builder = HTMLParserTreeBuilder()
|
| 533 |
+
self.builder.soup = self
|
| 534 |
+
self.reset()
|
| 535 |
+
self._feed()
|
| 536 |
+
|
| 537 |
+
@classmethod
|
| 538 |
+
@_deprecated(
|
| 539 |
+
replaced_by="nothing (private method, will be removed)", version="4.13.0"
|
| 540 |
+
)
|
| 541 |
+
def _decode_markup(cls, markup: _RawMarkup) -> str:
|
| 542 |
+
"""Ensure `markup` is Unicode so it's safe to send into warnings.warn.
|
| 543 |
+
|
| 544 |
+
warnings.warn had this problem back in 2010 but fortunately
|
| 545 |
+
not anymore. This has not been used for a long time; I just
|
| 546 |
+
noticed that fact while working on 4.13.0.
|
| 547 |
+
"""
|
| 548 |
+
if isinstance(markup, bytes):
|
| 549 |
+
decoded = markup.decode("utf-8", "replace")
|
| 550 |
+
else:
|
| 551 |
+
decoded = markup
|
| 552 |
+
return decoded
|
| 553 |
+
|
| 554 |
+
@classmethod
|
| 555 |
+
def _markup_is_url(cls, markup: _RawMarkup) -> bool:
|
| 556 |
+
"""Error-handling method to raise a warning if incoming markup looks
|
| 557 |
+
like a URL.
|
| 558 |
+
|
| 559 |
+
:param markup: A string of markup.
|
| 560 |
+
:return: Whether or not the markup resembled a URL
|
| 561 |
+
closely enough to justify issuing a warning.
|
| 562 |
+
"""
|
| 563 |
+
problem: bool = False
|
| 564 |
+
if isinstance(markup, bytes):
|
| 565 |
+
problem = (
|
| 566 |
+
any(markup.startswith(prefix) for prefix in (b"http:", b"https:"))
|
| 567 |
+
and b" " not in markup
|
| 568 |
+
)
|
| 569 |
+
elif isinstance(markup, str):
|
| 570 |
+
problem = (
|
| 571 |
+
any(markup.startswith(prefix) for prefix in ("http:", "https:"))
|
| 572 |
+
and " " not in markup
|
| 573 |
+
)
|
| 574 |
+
else:
|
| 575 |
+
return False
|
| 576 |
+
|
| 577 |
+
if not problem:
|
| 578 |
+
return False
|
| 579 |
+
warnings.warn(
|
| 580 |
+
MarkupResemblesLocatorWarning.URL_MESSAGE % dict(what="URL"),
|
| 581 |
+
MarkupResemblesLocatorWarning,
|
| 582 |
+
stacklevel=3,
|
| 583 |
+
)
|
| 584 |
+
return True
|
| 585 |
+
|
| 586 |
+
@classmethod
|
| 587 |
+
def _markup_resembles_filename(cls, markup: _RawMarkup) -> bool:
|
| 588 |
+
"""Error-handling method to issue a warning if incoming markup
|
| 589 |
+
resembles a filename.
|
| 590 |
+
|
| 591 |
+
:param markup: A string of markup.
|
| 592 |
+
:return: Whether or not the markup resembled a filename
|
| 593 |
+
closely enough to justify issuing a warning.
|
| 594 |
+
"""
|
| 595 |
+
markup_b: bytes
|
| 596 |
+
|
| 597 |
+
# We're only checking ASCII characters, so rather than write
|
| 598 |
+
# the same tests twice, convert Unicode to a bytestring and
|
| 599 |
+
# operate on the bytestring.
|
| 600 |
+
if isinstance(markup, str):
|
| 601 |
+
markup_b = markup.encode("utf8")
|
| 602 |
+
else:
|
| 603 |
+
markup_b = markup
|
| 604 |
+
|
| 605 |
+
# Step 1: does it end with a common textual file extension?
|
| 606 |
+
filelike = False
|
| 607 |
+
lower = markup_b.lower()
|
| 608 |
+
extensions = [b".html", b".htm", b".xml", b".xhtml", b".txt"]
|
| 609 |
+
if any(lower.endswith(ext) for ext in extensions):
|
| 610 |
+
filelike = True
|
| 611 |
+
if not filelike:
|
| 612 |
+
return False
|
| 613 |
+
|
| 614 |
+
# Step 2: it _might_ be a file, but there are a few things
|
| 615 |
+
# we can look for that aren't very common in filenames.
|
| 616 |
+
|
| 617 |
+
# Characters that have special meaning to Unix shells. (< was
|
| 618 |
+
# excluded before this method was called.)
|
| 619 |
+
#
|
| 620 |
+
# Many of these are also reserved characters that cannot
|
| 621 |
+
# appear in Windows filenames.
|
| 622 |
+
for byte in markup_b:
|
| 623 |
+
if byte in b"?*#&;>$|":
|
| 624 |
+
return False
|
| 625 |
+
|
| 626 |
+
# Two consecutive forward slashes (as seen in a URL) or two
|
| 627 |
+
# consecutive spaces (as seen in fixed-width data).
|
| 628 |
+
#
|
| 629 |
+
# (Paths to Windows network shares contain consecutive
|
| 630 |
+
# backslashes, so checking that doesn't seem as helpful.)
|
| 631 |
+
if b"//" in markup_b:
|
| 632 |
+
return False
|
| 633 |
+
if b" " in markup_b:
|
| 634 |
+
return False
|
| 635 |
+
|
| 636 |
+
# A colon in any position other than position 1 (e.g. after a
|
| 637 |
+
# Windows drive letter).
|
| 638 |
+
if markup_b.startswith(b":"):
|
| 639 |
+
return False
|
| 640 |
+
colon_i = markup_b.rfind(b":")
|
| 641 |
+
if colon_i not in (-1, 1):
|
| 642 |
+
return False
|
| 643 |
+
|
| 644 |
+
# Step 3: If it survived all of those checks, it's similar
|
| 645 |
+
# enough to a file to justify issuing a warning.
|
| 646 |
+
warnings.warn(
|
| 647 |
+
MarkupResemblesLocatorWarning.FILENAME_MESSAGE % dict(what="filename"),
|
| 648 |
+
MarkupResemblesLocatorWarning,
|
| 649 |
+
stacklevel=3,
|
| 650 |
+
)
|
| 651 |
+
return True
|
| 652 |
+
|
| 653 |
+
def _feed(self) -> None:
|
| 654 |
+
"""Internal method that parses previously set markup, creating a large
|
| 655 |
+
number of Tag and NavigableString objects.
|
| 656 |
+
"""
|
| 657 |
+
# Convert the document to Unicode.
|
| 658 |
+
self.builder.reset()
|
| 659 |
+
|
| 660 |
+
if self.markup is not None:
|
| 661 |
+
self.builder.feed(self.markup)
|
| 662 |
+
# Close out any unfinished strings and close all the open tags.
|
| 663 |
+
self.endData()
|
| 664 |
+
while (
|
| 665 |
+
self.currentTag is not None and self.currentTag.name != self.ROOT_TAG_NAME
|
| 666 |
+
):
|
| 667 |
+
self.popTag()
|
| 668 |
+
|
| 669 |
+
def reset(self) -> None:
|
| 670 |
+
"""Reset this object to a state as though it had never parsed any
|
| 671 |
+
markup.
|
| 672 |
+
"""
|
| 673 |
+
Tag.__init__(self, self, self.builder, self.ROOT_TAG_NAME)
|
| 674 |
+
self.hidden = True
|
| 675 |
+
self.builder.reset()
|
| 676 |
+
self.current_data = []
|
| 677 |
+
self.currentTag = None
|
| 678 |
+
self.tagStack = []
|
| 679 |
+
self.open_tag_counter = Counter()
|
| 680 |
+
self.preserve_whitespace_tag_stack = []
|
| 681 |
+
self.string_container_stack = []
|
| 682 |
+
self._most_recent_element = None
|
| 683 |
+
self.pushTag(self)
|
| 684 |
+
|
| 685 |
+
def new_tag(
|
| 686 |
+
self,
|
| 687 |
+
name: str,
|
| 688 |
+
namespace: Optional[str] = None,
|
| 689 |
+
nsprefix: Optional[str] = None,
|
| 690 |
+
attrs: Optional[_RawAttributeValues] = None,
|
| 691 |
+
sourceline: Optional[int] = None,
|
| 692 |
+
sourcepos: Optional[int] = None,
|
| 693 |
+
string: Optional[str] = None,
|
| 694 |
+
**kwattrs: _RawAttributeValue,
|
| 695 |
+
) -> Tag:
|
| 696 |
+
"""Create a new Tag associated with this BeautifulSoup object.
|
| 697 |
+
|
| 698 |
+
:param name: The name of the new Tag.
|
| 699 |
+
:param namespace: The URI of the new Tag's XML namespace, if any.
|
| 700 |
+
:param prefix: The prefix for the new Tag's XML namespace, if any.
|
| 701 |
+
:param attrs: A dictionary of this Tag's attribute values; can
|
| 702 |
+
be used instead of ``kwattrs`` for attributes like 'class'
|
| 703 |
+
that are reserved words in Python.
|
| 704 |
+
:param sourceline: The line number where this tag was
|
| 705 |
+
(purportedly) found in its source document.
|
| 706 |
+
:param sourcepos: The character position within ``sourceline`` where this
|
| 707 |
+
tag was (purportedly) found.
|
| 708 |
+
:param string: String content for the new Tag, if any.
|
| 709 |
+
:param kwattrs: Keyword arguments for the new Tag's attribute values.
|
| 710 |
+
|
| 711 |
+
"""
|
| 712 |
+
attr_container = self.builder.attribute_dict_class(**kwattrs)
|
| 713 |
+
if attrs is not None:
|
| 714 |
+
attr_container.update(attrs)
|
| 715 |
+
tag_class = self.element_classes.get(Tag, Tag)
|
| 716 |
+
|
| 717 |
+
# Assume that this is either Tag or a subclass of Tag. If not,
|
| 718 |
+
# the user brought type-unsafety upon themselves.
|
| 719 |
+
tag_class = cast(Type[Tag], tag_class)
|
| 720 |
+
tag = tag_class(
|
| 721 |
+
None,
|
| 722 |
+
self.builder,
|
| 723 |
+
name,
|
| 724 |
+
namespace,
|
| 725 |
+
nsprefix,
|
| 726 |
+
attr_container,
|
| 727 |
+
sourceline=sourceline,
|
| 728 |
+
sourcepos=sourcepos,
|
| 729 |
+
)
|
| 730 |
+
|
| 731 |
+
if string is not None:
|
| 732 |
+
tag.string = string
|
| 733 |
+
return tag
|
| 734 |
+
|
| 735 |
+
def string_container(
|
| 736 |
+
self, base_class: Optional[Type[NavigableString]] = None
|
| 737 |
+
) -> Type[NavigableString]:
|
| 738 |
+
"""Find the class that should be instantiated to hold a given kind of
|
| 739 |
+
string.
|
| 740 |
+
|
| 741 |
+
This may be a built-in Beautiful Soup class or a custom class passed
|
| 742 |
+
in to the BeautifulSoup constructor.
|
| 743 |
+
"""
|
| 744 |
+
container = base_class or NavigableString
|
| 745 |
+
|
| 746 |
+
# The user may want us to use some other class (hopefully a
|
| 747 |
+
# custom subclass) instead of the one we'd use normally.
|
| 748 |
+
container = cast(
|
| 749 |
+
Type[NavigableString], self.element_classes.get(container, container)
|
| 750 |
+
)
|
| 751 |
+
|
| 752 |
+
# On top of that, we may be inside a tag that needs a special
|
| 753 |
+
# container class.
|
| 754 |
+
if self.string_container_stack and container is NavigableString:
|
| 755 |
+
container = self.builder.string_containers.get(
|
| 756 |
+
self.string_container_stack[-1].name, container
|
| 757 |
+
)
|
| 758 |
+
return container
|
| 759 |
+
|
| 760 |
+
def new_string(
|
| 761 |
+
self, s: str, subclass: Optional[Type[NavigableString]] = None
|
| 762 |
+
) -> NavigableString:
|
| 763 |
+
"""Create a new `NavigableString` associated with this `BeautifulSoup`
|
| 764 |
+
object.
|
| 765 |
+
|
| 766 |
+
:param s: The string content of the `NavigableString`
|
| 767 |
+
:param subclass: The subclass of `NavigableString`, if any, to
|
| 768 |
+
use. If a document is being processed, an appropriate
|
| 769 |
+
subclass for the current location in the document will
|
| 770 |
+
be determined automatically.
|
| 771 |
+
"""
|
| 772 |
+
container = self.string_container(subclass)
|
| 773 |
+
return container(s)
|
| 774 |
+
|
| 775 |
+
def insert_before(self, *args: _InsertableElement) -> List[PageElement]:
|
| 776 |
+
"""This method is part of the PageElement API, but `BeautifulSoup` doesn't implement
|
| 777 |
+
it because there is nothing before or after it in the parse tree.
|
| 778 |
+
"""
|
| 779 |
+
raise NotImplementedError(
|
| 780 |
+
"BeautifulSoup objects don't support insert_before()."
|
| 781 |
+
)
|
| 782 |
+
|
| 783 |
+
def insert_after(self, *args: _InsertableElement) -> List[PageElement]:
|
| 784 |
+
"""This method is part of the PageElement API, but `BeautifulSoup` doesn't implement
|
| 785 |
+
it because there is nothing before or after it in the parse tree.
|
| 786 |
+
"""
|
| 787 |
+
raise NotImplementedError("BeautifulSoup objects don't support insert_after().")
|
| 788 |
+
|
| 789 |
+
def popTag(self) -> Optional[Tag]:
|
| 790 |
+
"""Internal method called by _popToTag when a tag is closed.
|
| 791 |
+
|
| 792 |
+
:meta private:
|
| 793 |
+
"""
|
| 794 |
+
if not self.tagStack:
|
| 795 |
+
# Nothing to pop. This shouldn't happen.
|
| 796 |
+
return None
|
| 797 |
+
tag = self.tagStack.pop()
|
| 798 |
+
if tag.name in self.open_tag_counter:
|
| 799 |
+
self.open_tag_counter[tag.name] -= 1
|
| 800 |
+
if (
|
| 801 |
+
self.preserve_whitespace_tag_stack
|
| 802 |
+
and tag == self.preserve_whitespace_tag_stack[-1]
|
| 803 |
+
):
|
| 804 |
+
self.preserve_whitespace_tag_stack.pop()
|
| 805 |
+
if self.string_container_stack and tag == self.string_container_stack[-1]:
|
| 806 |
+
self.string_container_stack.pop()
|
| 807 |
+
# print("Pop", tag.name)
|
| 808 |
+
if self.tagStack:
|
| 809 |
+
self.currentTag = self.tagStack[-1]
|
| 810 |
+
return self.currentTag
|
| 811 |
+
|
| 812 |
+
def pushTag(self, tag: Tag) -> None:
|
| 813 |
+
"""Internal method called by handle_starttag when a tag is opened.
|
| 814 |
+
|
| 815 |
+
:meta private:
|
| 816 |
+
"""
|
| 817 |
+
# print("Push", tag.name)
|
| 818 |
+
if self.currentTag is not None:
|
| 819 |
+
self.currentTag.contents.append(tag)
|
| 820 |
+
self.tagStack.append(tag)
|
| 821 |
+
self.currentTag = self.tagStack[-1]
|
| 822 |
+
if tag.name != self.ROOT_TAG_NAME:
|
| 823 |
+
self.open_tag_counter[tag.name] += 1
|
| 824 |
+
if tag.name in self.builder.preserve_whitespace_tags:
|
| 825 |
+
self.preserve_whitespace_tag_stack.append(tag)
|
| 826 |
+
if tag.name in self.builder.string_containers:
|
| 827 |
+
self.string_container_stack.append(tag)
|
| 828 |
+
|
| 829 |
+
def endData(self, containerClass: Optional[Type[NavigableString]] = None) -> None:
|
| 830 |
+
"""Method called by the TreeBuilder when the end of a data segment
|
| 831 |
+
occurs.
|
| 832 |
+
|
| 833 |
+
:param containerClass: The class to use when incorporating the
|
| 834 |
+
data segment into the parse tree.
|
| 835 |
+
|
| 836 |
+
:meta private:
|
| 837 |
+
"""
|
| 838 |
+
if self.current_data:
|
| 839 |
+
current_data = "".join(self.current_data)
|
| 840 |
+
# If whitespace is not preserved, and this string contains
|
| 841 |
+
# nothing but ASCII spaces, replace it with a single space
|
| 842 |
+
# or newline.
|
| 843 |
+
if not self.preserve_whitespace_tag_stack:
|
| 844 |
+
strippable = True
|
| 845 |
+
for i in current_data:
|
| 846 |
+
if i not in self.ASCII_SPACES:
|
| 847 |
+
strippable = False
|
| 848 |
+
break
|
| 849 |
+
if strippable:
|
| 850 |
+
if "\n" in current_data:
|
| 851 |
+
current_data = "\n"
|
| 852 |
+
else:
|
| 853 |
+
current_data = " "
|
| 854 |
+
|
| 855 |
+
# Reset the data collector.
|
| 856 |
+
self.current_data = []
|
| 857 |
+
|
| 858 |
+
# Should we add this string to the tree at all?
|
| 859 |
+
if (
|
| 860 |
+
self.parse_only
|
| 861 |
+
and len(self.tagStack) <= 1
|
| 862 |
+
and (not self.parse_only.allow_string_creation(current_data))
|
| 863 |
+
):
|
| 864 |
+
return
|
| 865 |
+
|
| 866 |
+
containerClass = self.string_container(containerClass)
|
| 867 |
+
o = containerClass(current_data)
|
| 868 |
+
self.object_was_parsed(o)
|
| 869 |
+
|
| 870 |
+
def object_was_parsed(
|
| 871 |
+
self,
|
| 872 |
+
o: PageElement,
|
| 873 |
+
parent: Optional[Tag] = None,
|
| 874 |
+
most_recent_element: Optional[PageElement] = None,
|
| 875 |
+
) -> None:
|
| 876 |
+
"""Method called by the TreeBuilder to integrate an object into the
|
| 877 |
+
parse tree.
|
| 878 |
+
|
| 879 |
+
:meta private:
|
| 880 |
+
"""
|
| 881 |
+
if parent is None:
|
| 882 |
+
parent = self.currentTag
|
| 883 |
+
assert parent is not None
|
| 884 |
+
previous_element: Optional[PageElement]
|
| 885 |
+
if most_recent_element is not None:
|
| 886 |
+
previous_element = most_recent_element
|
| 887 |
+
else:
|
| 888 |
+
previous_element = self._most_recent_element
|
| 889 |
+
|
| 890 |
+
next_element = previous_sibling = next_sibling = None
|
| 891 |
+
if isinstance(o, Tag):
|
| 892 |
+
next_element = o.next_element
|
| 893 |
+
next_sibling = o.next_sibling
|
| 894 |
+
previous_sibling = o.previous_sibling
|
| 895 |
+
if previous_element is None:
|
| 896 |
+
previous_element = o.previous_element
|
| 897 |
+
|
| 898 |
+
fix = parent.next_element is not None
|
| 899 |
+
|
| 900 |
+
o.setup(parent, previous_element, next_element, previous_sibling, next_sibling)
|
| 901 |
+
|
| 902 |
+
self._most_recent_element = o
|
| 903 |
+
parent.contents.append(o)
|
| 904 |
+
|
| 905 |
+
# Check if we are inserting into an already parsed node.
|
| 906 |
+
if fix:
|
| 907 |
+
self._linkage_fixer(parent)
|
| 908 |
+
|
| 909 |
+
def _linkage_fixer(self, el: Tag) -> None:
|
| 910 |
+
"""Make sure linkage of this fragment is sound."""
|
| 911 |
+
|
| 912 |
+
first = el.contents[0]
|
| 913 |
+
child = el.contents[-1]
|
| 914 |
+
descendant: PageElement = child
|
| 915 |
+
|
| 916 |
+
if child is first and el.parent is not None:
|
| 917 |
+
# Parent should be linked to first child
|
| 918 |
+
el.next_element = child
|
| 919 |
+
# We are no longer linked to whatever this element is
|
| 920 |
+
prev_el = child.previous_element
|
| 921 |
+
if prev_el is not None and prev_el is not el:
|
| 922 |
+
prev_el.next_element = None
|
| 923 |
+
# First child should be linked to the parent, and no previous siblings.
|
| 924 |
+
child.previous_element = el
|
| 925 |
+
child.previous_sibling = None
|
| 926 |
+
|
| 927 |
+
# We have no sibling as we've been appended as the last.
|
| 928 |
+
child.next_sibling = None
|
| 929 |
+
|
| 930 |
+
# This index is a tag, dig deeper for a "last descendant"
|
| 931 |
+
if isinstance(child, Tag) and child.contents:
|
| 932 |
+
# _last_decendant is typed as returning Optional[PageElement],
|
| 933 |
+
# but the value can't be None here, because el is a Tag
|
| 934 |
+
# which we know has contents.
|
| 935 |
+
descendant = cast(PageElement, child._last_descendant(False))
|
| 936 |
+
|
| 937 |
+
# As the final step, link last descendant. It should be linked
|
| 938 |
+
# to the parent's next sibling (if found), else walk up the chain
|
| 939 |
+
# and find a parent with a sibling. It should have no next sibling.
|
| 940 |
+
descendant.next_element = None
|
| 941 |
+
descendant.next_sibling = None
|
| 942 |
+
|
| 943 |
+
target: Optional[Tag] = el
|
| 944 |
+
while True:
|
| 945 |
+
if target is None:
|
| 946 |
+
break
|
| 947 |
+
elif target.next_sibling is not None:
|
| 948 |
+
descendant.next_element = target.next_sibling
|
| 949 |
+
target.next_sibling.previous_element = child
|
| 950 |
+
break
|
| 951 |
+
target = target.parent
|
| 952 |
+
|
| 953 |
+
def _popToTag(
|
| 954 |
+
self, name: str, nsprefix: Optional[str] = None, inclusivePop: bool = True
|
| 955 |
+
) -> Optional[Tag]:
|
| 956 |
+
"""Pops the tag stack up to and including the most recent
|
| 957 |
+
instance of the given tag.
|
| 958 |
+
|
| 959 |
+
If there are no open tags with the given name, nothing will be
|
| 960 |
+
popped.
|
| 961 |
+
|
| 962 |
+
:param name: Pop up to the most recent tag with this name.
|
| 963 |
+
:param nsprefix: The namespace prefix that goes with `name`.
|
| 964 |
+
:param inclusivePop: It this is false, pops the tag stack up
|
| 965 |
+
to but *not* including the most recent instqance of the
|
| 966 |
+
given tag.
|
| 967 |
+
|
| 968 |
+
:meta private:
|
| 969 |
+
"""
|
| 970 |
+
# print("Popping to %s" % name)
|
| 971 |
+
if name == self.ROOT_TAG_NAME:
|
| 972 |
+
# The BeautifulSoup object itself can never be popped.
|
| 973 |
+
return None
|
| 974 |
+
|
| 975 |
+
most_recently_popped = None
|
| 976 |
+
|
| 977 |
+
stack_size = len(self.tagStack)
|
| 978 |
+
for i in range(stack_size - 1, 0, -1):
|
| 979 |
+
if not self.open_tag_counter.get(name):
|
| 980 |
+
break
|
| 981 |
+
t = self.tagStack[i]
|
| 982 |
+
if name == t.name and nsprefix == t.prefix:
|
| 983 |
+
if inclusivePop:
|
| 984 |
+
most_recently_popped = self.popTag()
|
| 985 |
+
break
|
| 986 |
+
most_recently_popped = self.popTag()
|
| 987 |
+
|
| 988 |
+
return most_recently_popped
|
| 989 |
+
|
| 990 |
+
def handle_starttag(
|
| 991 |
+
self,
|
| 992 |
+
name: str,
|
| 993 |
+
namespace: Optional[str],
|
| 994 |
+
nsprefix: Optional[str],
|
| 995 |
+
attrs: _RawAttributeValues,
|
| 996 |
+
sourceline: Optional[int] = None,
|
| 997 |
+
sourcepos: Optional[int] = None,
|
| 998 |
+
namespaces: Optional[Dict[str, str]] = None,
|
| 999 |
+
) -> Optional[Tag]:
|
| 1000 |
+
"""Called by the tree builder when a new tag is encountered.
|
| 1001 |
+
|
| 1002 |
+
:param name: Name of the tag.
|
| 1003 |
+
:param nsprefix: Namespace prefix for the tag.
|
| 1004 |
+
:param attrs: A dictionary of attribute values. Note that
|
| 1005 |
+
attribute values are expected to be simple strings; processing
|
| 1006 |
+
of multi-valued attributes such as "class" comes later.
|
| 1007 |
+
:param sourceline: The line number where this tag was found in its
|
| 1008 |
+
source document.
|
| 1009 |
+
:param sourcepos: The character position within `sourceline` where this
|
| 1010 |
+
tag was found.
|
| 1011 |
+
:param namespaces: A dictionary of all namespace prefix mappings
|
| 1012 |
+
currently in scope in the document.
|
| 1013 |
+
|
| 1014 |
+
If this method returns None, the tag was rejected by an active
|
| 1015 |
+
`ElementFilter`. You should proceed as if the tag had not occurred
|
| 1016 |
+
in the document. For instance, if this was a self-closing tag,
|
| 1017 |
+
don't call handle_endtag.
|
| 1018 |
+
|
| 1019 |
+
:meta private:
|
| 1020 |
+
"""
|
| 1021 |
+
# print("Start tag %s: %s" % (name, attrs))
|
| 1022 |
+
self.endData()
|
| 1023 |
+
|
| 1024 |
+
if (
|
| 1025 |
+
self.parse_only
|
| 1026 |
+
and len(self.tagStack) <= 1
|
| 1027 |
+
and not self.parse_only.allow_tag_creation(nsprefix, name, attrs)
|
| 1028 |
+
):
|
| 1029 |
+
return None
|
| 1030 |
+
|
| 1031 |
+
tag_class = self.element_classes.get(Tag, Tag)
|
| 1032 |
+
# Assume that this is either Tag or a subclass of Tag. If not,
|
| 1033 |
+
# the user brought type-unsafety upon themselves.
|
| 1034 |
+
tag_class = cast(Type[Tag], tag_class)
|
| 1035 |
+
tag = tag_class(
|
| 1036 |
+
self,
|
| 1037 |
+
self.builder,
|
| 1038 |
+
name,
|
| 1039 |
+
namespace,
|
| 1040 |
+
nsprefix,
|
| 1041 |
+
attrs,
|
| 1042 |
+
self.currentTag,
|
| 1043 |
+
self._most_recent_element,
|
| 1044 |
+
sourceline=sourceline,
|
| 1045 |
+
sourcepos=sourcepos,
|
| 1046 |
+
namespaces=namespaces,
|
| 1047 |
+
)
|
| 1048 |
+
if tag is None:
|
| 1049 |
+
return tag
|
| 1050 |
+
if self._most_recent_element is not None:
|
| 1051 |
+
self._most_recent_element.next_element = tag
|
| 1052 |
+
self._most_recent_element = tag
|
| 1053 |
+
self.pushTag(tag)
|
| 1054 |
+
return tag
|
| 1055 |
+
|
| 1056 |
+
def handle_endtag(self, name: str, nsprefix: Optional[str] = None) -> None:
|
| 1057 |
+
"""Called by the tree builder when an ending tag is encountered.
|
| 1058 |
+
|
| 1059 |
+
:param name: Name of the tag.
|
| 1060 |
+
:param nsprefix: Namespace prefix for the tag.
|
| 1061 |
+
|
| 1062 |
+
:meta private:
|
| 1063 |
+
"""
|
| 1064 |
+
# print("End tag: " + name)
|
| 1065 |
+
self.endData()
|
| 1066 |
+
self._popToTag(name, nsprefix)
|
| 1067 |
+
|
| 1068 |
+
def handle_data(self, data: str) -> None:
|
| 1069 |
+
"""Called by the tree builder when a chunk of textual data is
|
| 1070 |
+
encountered.
|
| 1071 |
+
|
| 1072 |
+
:meta private:
|
| 1073 |
+
"""
|
| 1074 |
+
self.current_data.append(data)
|
| 1075 |
+
|
| 1076 |
+
def decode(
|
| 1077 |
+
self,
|
| 1078 |
+
indent_level: Optional[int] = None,
|
| 1079 |
+
eventual_encoding: _Encoding = DEFAULT_OUTPUT_ENCODING,
|
| 1080 |
+
formatter: Union[Formatter, str] = "minimal",
|
| 1081 |
+
iterator: Optional[Iterator[PageElement]] = None,
|
| 1082 |
+
**kwargs: Any,
|
| 1083 |
+
) -> str:
|
| 1084 |
+
"""Returns a string representation of the parse tree
|
| 1085 |
+
as a full HTML or XML document.
|
| 1086 |
+
|
| 1087 |
+
:param indent_level: Each line of the rendering will be
|
| 1088 |
+
indented this many levels. (The ``formatter`` decides what a
|
| 1089 |
+
'level' means, in terms of spaces or other characters
|
| 1090 |
+
output.) This is used internally in recursive calls while
|
| 1091 |
+
pretty-printing.
|
| 1092 |
+
:param eventual_encoding: The encoding of the final document.
|
| 1093 |
+
If this is None, the document will be a Unicode string.
|
| 1094 |
+
:param formatter: Either a `Formatter` object, or a string naming one of
|
| 1095 |
+
the standard formatters.
|
| 1096 |
+
:param iterator: The iterator to use when navigating over the
|
| 1097 |
+
parse tree. This is only used by `Tag.decode_contents` and
|
| 1098 |
+
you probably won't need to use it.
|
| 1099 |
+
"""
|
| 1100 |
+
if self.is_xml:
|
| 1101 |
+
# Print the XML declaration
|
| 1102 |
+
encoding_part = ""
|
| 1103 |
+
declared_encoding: Optional[str] = eventual_encoding
|
| 1104 |
+
if eventual_encoding in PYTHON_SPECIFIC_ENCODINGS:
|
| 1105 |
+
# This is a special Python encoding; it can't actually
|
| 1106 |
+
# go into an XML document because it means nothing
|
| 1107 |
+
# outside of Python.
|
| 1108 |
+
declared_encoding = None
|
| 1109 |
+
if declared_encoding is not None:
|
| 1110 |
+
encoding_part = ' encoding="%s"' % declared_encoding
|
| 1111 |
+
prefix = '<?xml version="1.0"%s?>\n' % encoding_part
|
| 1112 |
+
else:
|
| 1113 |
+
prefix = ""
|
| 1114 |
+
|
| 1115 |
+
# Prior to 4.13.0, the first argument to this method was a
|
| 1116 |
+
# bool called pretty_print, which gave the method a different
|
| 1117 |
+
# signature from its superclass implementation, Tag.decode.
|
| 1118 |
+
#
|
| 1119 |
+
# The signatures of the two methods now match, but just in
|
| 1120 |
+
# case someone is still passing a boolean in as the first
|
| 1121 |
+
# argument to this method (or a keyword argument with the old
|
| 1122 |
+
# name), we can handle it and put out a DeprecationWarning.
|
| 1123 |
+
warning: Optional[str] = None
|
| 1124 |
+
pretty_print: Optional[bool] = None
|
| 1125 |
+
if isinstance(indent_level, bool):
|
| 1126 |
+
if indent_level is True:
|
| 1127 |
+
indent_level = 0
|
| 1128 |
+
elif indent_level is False:
|
| 1129 |
+
indent_level = None
|
| 1130 |
+
warning = f"As of 4.13.0, the first argument to BeautifulSoup.decode has been changed from bool to int, to match Tag.decode. Pass in a value of {indent_level} instead."
|
| 1131 |
+
else:
|
| 1132 |
+
pretty_print = kwargs.pop("pretty_print", None)
|
| 1133 |
+
assert not kwargs
|
| 1134 |
+
if pretty_print is not None:
|
| 1135 |
+
if pretty_print is True:
|
| 1136 |
+
indent_level = 0
|
| 1137 |
+
elif pretty_print is False:
|
| 1138 |
+
indent_level = None
|
| 1139 |
+
warning = f"As of 4.13.0, the pretty_print argument to BeautifulSoup.decode has been removed, to match Tag.decode. Pass in a value of indent_level={indent_level} instead."
|
| 1140 |
+
|
| 1141 |
+
if warning:
|
| 1142 |
+
warnings.warn(warning, DeprecationWarning, stacklevel=2)
|
| 1143 |
+
elif indent_level is False or pretty_print is False:
|
| 1144 |
+
indent_level = None
|
| 1145 |
+
return prefix + super(BeautifulSoup, self).decode(
|
| 1146 |
+
indent_level, eventual_encoding, formatter, iterator
|
| 1147 |
+
)
|
| 1148 |
+
|
| 1149 |
+
|
| 1150 |
+
# Aliases to make it easier to get started quickly, e.g. 'from bs4 import _soup'
|
| 1151 |
+
_s = BeautifulSoup
|
| 1152 |
+
_soup = BeautifulSoup
|
| 1153 |
+
|
| 1154 |
+
|
| 1155 |
+
class BeautifulStoneSoup(BeautifulSoup):
|
| 1156 |
+
"""Deprecated interface to an XML parser."""
|
| 1157 |
+
|
| 1158 |
+
def __init__(self, *args: Any, **kwargs: Any):
|
| 1159 |
+
kwargs["features"] = "xml"
|
| 1160 |
+
warnings.warn(
|
| 1161 |
+
"The BeautifulStoneSoup class was deprecated in version 4.0.0. Instead of using "
|
| 1162 |
+
'it, pass features="xml" into the BeautifulSoup constructor.',
|
| 1163 |
+
DeprecationWarning,
|
| 1164 |
+
stacklevel=2,
|
| 1165 |
+
)
|
| 1166 |
+
super(BeautifulStoneSoup, self).__init__(*args, **kwargs)
|
| 1167 |
+
|
| 1168 |
+
|
| 1169 |
+
# If this file is run as a script, act as an HTML pretty-printer.
|
| 1170 |
+
if __name__ == "__main__":
|
| 1171 |
+
import sys
|
| 1172 |
+
|
| 1173 |
+
soup = BeautifulSoup(sys.stdin)
|
| 1174 |
+
print((soup.prettify()))
|