19
19
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
20
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
21
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
-
22
+ import binascii
23
23
import posixpath
24
24
import xml .etree .ElementTree as ElementTree
25
25
from dataclasses import dataclass , field
26
26
from logging import getLogger
27
27
from typing import Dict , Iterable , List , Optional , Tuple
28
28
29
- from aqt .exceptions import ArchiveDownloadError , ArchiveListError , NoPackageFound
30
- from aqt .helper import Settings , getUrl , ssplit
29
+ from aqt .exceptions import ArchiveDownloadError , ArchiveListError , ChecksumDownloadFailure , NoPackageFound
30
+ from aqt .helper import Settings , get_hash , getUrl , ssplit
31
31
from aqt .metadata import QtRepoProperty , Version
32
32
33
33
@@ -45,10 +45,10 @@ def __post_init__(self):
45
45
@dataclass
46
46
class QtPackage :
47
47
name : str
48
- archive_url : str
48
+ base_url : str
49
+ archive_path : str
49
50
archive : str
50
51
package_desc : str
51
- hashurl : str
52
52
pkg_update_name : str
53
53
version : Optional [Version ] = field (default = None )
54
54
@@ -59,9 +59,9 @@ def __repr__(self):
59
59
def __str__ (self ):
60
60
v_info = f", version={ self .version } " if self .version else ""
61
61
return (
62
- f"QtPackage(name={ self .name } , url={ self .archive_url } , "
62
+ f"QtPackage(name={ self .name } , url={ self .archive_path } , "
63
63
f"archive={ self .archive } , desc={ self .package_desc } "
64
- f"hashurl= { self . hashurl } { v_info } )"
64
+ f"{ v_info } )"
65
65
)
66
66
67
67
@@ -140,7 +140,7 @@ def __init__(
140
140
self .os_name : str = os_name
141
141
self .all_extra : bool = all_extra
142
142
self .arch_list : List [str ] = [item .get ("arch" ) for item in Settings .qt_combinations ]
143
- self .base : str = posixpath . join ( base , "online/qtsdkrepository" )
143
+ self .base : str = base
144
144
self .logger = getLogger ("aqt.archives" )
145
145
self .archives : List [QtPackage ] = []
146
146
self .subarchives : Optional [Iterable [str ]] = subarchives
@@ -217,22 +217,26 @@ def _target_packages(self) -> ModuleToPackage:
217
217
def _get_archives (self ):
218
218
# Get packages index
219
219
220
- # archive_path: windows_x86/desktop/qt5_59_src_doc_examples
221
- archive_path = posixpath .join (
220
+ # os_target_folder: online/qtsdkrepository/windows_x86/desktop/qt5_59_src_doc_examples
221
+ os_target_folder = posixpath .join (
222
+ "online/qtsdkrepository" ,
222
223
self .os_name + ("_x86" if self .os_name == "windows" else "_x64" ),
223
224
self .target ,
224
225
f"qt{ self .version .major } _{ self ._version_str ()} { self ._arch_ext ()} " ,
225
226
)
226
- update_xml_url = posixpath .join (self .base , archive_path , "Updates.xml" )
227
- archive_url = posixpath .join (self .base , archive_path )
228
- self ._download_update_xml (update_xml_url )
229
- self ._parse_update_xml (archive_url , self ._target_packages ())
227
+ update_xml_path = posixpath .join (os_target_folder , "Updates.xml" )
228
+ self ._download_update_xml (update_xml_path )
229
+ self ._parse_update_xml (os_target_folder , self ._target_packages ())
230
230
231
- def _download_update_xml (self , update_xml_url ):
231
+ def _download_update_xml (self , update_xml_path ):
232
232
"""Hook for unit test."""
233
- self .update_xml_text = getUrl (update_xml_url , self .timeout )
233
+ xml_hash = binascii .unhexlify (get_hash (update_xml_path , "sha256" , self .timeout ))
234
+ if xml_hash == "" :
235
+ raise ChecksumDownloadFailure (f"Checksum for '{ update_xml_path } ' is empty" )
236
+ update_xml_text = getUrl (posixpath .join (self .base , update_xml_path ), self .timeout , xml_hash )
237
+ self .update_xml_text = update_xml_text
234
238
235
- def _parse_update_xml (self , archive_url , target_packages : Optional [ModuleToPackage ]):
239
+ def _parse_update_xml (self , os_target_folder , target_packages : Optional [ModuleToPackage ]):
236
240
if not target_packages :
237
241
target_packages = ModuleToPackage ({})
238
242
try :
@@ -270,22 +274,21 @@ def _parse_update_xml(self, archive_url, target_packages: Optional[ModuleToPacka
270
274
archive_name = archive .split ("-" , maxsplit = 1 )[0 ]
271
275
if should_filter_archives and archive_name not in self .subarchives :
272
276
continue
273
- package_url = posixpath .join (
274
- # https://download.qt.io/ online/qtsdkrepository/linux_x64/desktop/qt5_5150/
275
- archive_url ,
277
+ archive_path = posixpath .join (
278
+ # online/qtsdkrepository/linux_x64/desktop/qt5_5150/
279
+ os_target_folder ,
276
280
# qt.qt5.5150.gcc_64/
277
281
pkg_name ,
278
282
# 5.15.0-0-202005140804qtbase-Linux-RHEL_7_6-GCC-Linux-RHEL_7_6-X86_64.7z
279
283
full_version + archive ,
280
284
)
281
- hashurl = package_url + ".sha1"
282
285
self .archives .append (
283
286
QtPackage (
284
287
name = archive_name ,
285
- archive_url = package_url ,
288
+ base_url = self .base ,
289
+ archive_path = archive_path ,
286
290
archive = archive ,
287
291
package_desc = package_desc ,
288
- hashurl = hashurl ,
289
292
pkg_update_name = pkg_name , # For testing purposes
290
293
)
291
294
)
@@ -431,25 +434,20 @@ def handle_missing_updates_xml(self, e: ArchiveDownloadError):
431
434
raise ArchiveListError (msg , suggested_action = [help_msg ]) from e
432
435
433
436
def _get_archives (self ):
434
- _a = "_x64"
435
- if self .os_name == "windows" :
436
- _a = "_x86"
437
-
438
- archive_url = posixpath .join (
439
- # https://download.qt.io/online/qtsdkrepository/
440
- self .base ,
437
+ os_target_folder = posixpath .join (
438
+ "online/qtsdkrepository" ,
441
439
# linux_x64/
442
- self .os_name + _a ,
440
+ self .os_name + ( "_x86" if self . os_name == "windows" else "_x64" ) ,
443
441
# desktop/
444
442
self .target ,
445
443
# tools_ifw/
446
444
self .tool_name ,
447
445
)
448
- update_xml_url = posixpath .join (archive_url , "Updates.xml" )
446
+ update_xml_url = posixpath .join (os_target_folder , "Updates.xml" )
449
447
self ._download_update_xml (update_xml_url ) # call super method.
450
- self ._parse_update_xml (archive_url , None )
448
+ self ._parse_update_xml (os_target_folder , None )
451
449
452
- def _parse_update_xml (self , archive_url , * ignored ):
450
+ def _parse_update_xml (self , os_target_folder , * ignored ):
453
451
try :
454
452
self .update_xml = ElementTree .fromstring (self .update_xml_text )
455
453
except ElementTree .ParseError as perror :
@@ -472,22 +470,21 @@ def _parse_update_xml(self, archive_url, *ignored):
472
470
message = f"The package '{ self .arch } ' contains no downloadable archives!"
473
471
raise NoPackageFound (message )
474
472
for archive in ssplit (downloadable_archives ):
475
- package_url = posixpath .join (
476
- # https://download.qt.io/ online/qtsdkrepository/linux_x64/desktop/tools_ifw/
477
- archive_url ,
473
+ archive_path = posixpath .join (
474
+ # online/qtsdkrepository/linux_x64/desktop/tools_ifw/
475
+ os_target_folder ,
478
476
# qt.tools.ifw.41/
479
477
name ,
480
478
# 4.1.1-202105261130ifw-linux-x64.7z
481
479
f"{ named_version } { archive } " ,
482
480
)
483
- hashurl = package_url + ".sha1"
484
481
self .archives .append (
485
482
QtPackage (
486
483
name = name ,
487
- archive_url = package_url ,
484
+ base_url = self .base ,
485
+ archive_path = archive_path ,
488
486
archive = archive ,
489
487
package_desc = package_desc ,
490
- hashurl = hashurl ,
491
488
pkg_update_name = name , # Redundant
492
489
)
493
490
)
0 commit comments