-
Notifications
You must be signed in to change notification settings - Fork 4
/
fetchers.py
128 lines (87 loc) · 3.54 KB
/
fetchers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from dataclasses import dataclass
from typing import List
from collections import defaultdict
import requests
import logging
import re
import xmltodict
from .helpers import check
from .helpers import split_version
def fetch_versions():
url = requests.get('https://api.github.com/repos/qt/qtdoc/git/refs/tags')
regx = re.compile('\d\.\d+\.\d')
matches = regx.findall(url.text)
versions = sorted(set(matches))
return versions
def fetch_archive_xml(os: str, platform: str, version: str):
major, minor, patch = split_version(version)
arch = "_x86" if os == "windows" else "_x64"
stub = f'{major}{minor}{patch}'
if (major, minor, patch) == (5, 9, 0):
# note(will.brennan) - Qt changed their naming pattern
stub = f'59'
base_url = f'https://download.qt.io/online/qtsdkrepository/{os}{arch}/{platform}/qt{major}_{stub}'
xml_url = f'{base_url}/Updates.xml'
r = requests.get(xml_url)
if r.ok:
return base_url, xmltodict.parse(r.text)
else:
return base_url, None
@dataclass
class Package:
name: str
module: str
description: str
dependencies: List[str]
archive_urls: List[str]
sha1: str
def archive_urls_from_package(base_url: str, package_update) -> List[str]:
archives = package_update['DownloadableArchives']
if archives is None:
return []
name = package_update['Name']
version = package_update['Version']
urls = []
for archive in archives.split(', '):
url = f'{base_url}/{name}/{version}{archive}'
urls.append(url)
return urls
def fetch_package_infos(base_url: str, xml, modules: List[str]) -> List[Package]:
logging.info(f'finding packages download paths for modules - {modules}')
all_packages = {}
all_modules = defaultdict(list)
logging.debug('parsing xml into packages')
for package_update in xml['Updates']['PackageUpdate']:
name = package_update['Name']
# note(will.brennan) - we remove addons because of qt6
module = name.replace('.addons', '').split('.')[3]
description = package_update['Description']
dependencies = package_update.get('Dependencies', '')
dependencies = dependencies.split(', ')
archive_urls = archive_urls_from_package(base_url, package_update)
sha1 = package_update['SHA1']
package = Package(name, module, description, dependencies, archive_urls, sha1)
all_packages[name] = package
all_modules[module].append(package)
logging.debug('adding packages for modules')
packages = {}
for module in modules:
check(module in all_modules, f'module {module} is not supported; available modules: {list(all_modules.keys())}')
module_packages = all_modules[module]
for package in module_packages:
packages[package.name] = package
logging.debug('recursively adding dependencies for selected modules')
packages_to_scan = list(packages.values())
while len(packages_to_scan) != 0:
package = packages_to_scan.pop(-1)
for dependency in package.dependencies:
if dependency.startswith('qt.tools'):
continue
dependency_type = dependency.split('.')[3]
if dependency_type in ('doc', 'examples'):
continue
if dependency not in packages:
dependency_package = all_packages[dependency]
packages[dependency_package.name] = dependency_package
packages_to_scan.append(dependency_package)
return list(packages.values())