Skip to content

Commit

Permalink
CLI: Add --archives option
Browse files Browse the repository at this point in the history
when specify '--archive qtbase qttools' then
aqt installs these subset of installation.

There is no gurantee it works, and it is an advanced
option.

Implemented #126

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed May 19, 2020
1 parent ea6407f commit fcb5b45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
9 changes: 7 additions & 2 deletions aqt/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ class QtArchives:

BASE_URL = 'https://download.qt.io/online/qtsdkrepository/'

def __init__(self, os_name, target, version, arch, modules=None, mirror=None, logging=None, all_extra=False):
def __init__(self, os_name, target, version, arch, subarchives=None,
modules=None, mirror=None, logging=None, all_extra=False):
self.version = version
self.target = target
self.arch = arch
self.mirror = mirror
self.os_name = os_name
self.all_extra = all_extra
all_archives = (subarchives is None)
if mirror is not None:
self.has_mirror = True
self.base = mirror + '/online/qtsdkrepository/'
Expand All @@ -78,6 +80,8 @@ def __init__(self, os_name, target, version, arch, modules=None, mirror=None, lo
self.mod_list.append("qt.qt5.{}.{}.{}".format(qt_ver_num, m, arch))
self.mod_list.append("qt.{}.{}.{}".format(qt_ver_num, m, arch))
self._get_archives(qt_ver_num)
if not all_archives:
self.archives = list(filter(lambda a: a.name in subarchives, self.archives))

def _get_archives(self, qt_ver_num):
# Get packages index
Expand Down Expand Up @@ -124,8 +128,9 @@ def _parse_update_xml(self, target_packages, archive_url):
full_version = packageupdate.find("Version").text
package_desc = packageupdate.find("Description").text
for archive in downloadable_archives:
archive_name = archive.split('-', maxsplit=1)[0]
package_url = archive_url + name + "/" + full_version + archive
self.archives.append(QtPackage(name, package_url, archive, package_desc,
self.archives.append(QtPackage(archive_name, package_url, archive, package_desc,
has_mirror=self.has_mirror))
if len(self.archives) == 0:
self.logger.error("Error while parsing package information!")
Expand Down
7 changes: 5 additions & 2 deletions aqt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def run_install(self, args):
modules = args.modules
sevenzip = self._set_sevenzip(args)
mirror = args.base
archives = args.archives
self.show_aqt_version()
if output_dir is not None:
output_dir = os.path.normpath(output_dir)
Expand All @@ -141,8 +142,8 @@ def run_install(self, args):
if not all_extra and not self._check_modules_arg(qt_version, modules):
self.logger.warning("Some of specified modules are unknown.")
try:
qt_archives = QtArchives(os_name, target, qt_version, arch, modules=modules, mirror=mirror,
logging=self.logger, all_extra=all_extra)
qt_archives = QtArchives(os_name, target, qt_version, arch, subarchives=archives, modules=modules,
mirror=mirror, logging=self.logger, all_extra=all_extra)
except ArchiveDownloadError or ArchiveListError:
exit(1)
else:
Expand Down Expand Up @@ -213,6 +214,8 @@ def _create_parser(self):
"\n Qt 5.13 or below: android_x86_64, android_arm64_v8a"
"\n android_x86, android_armv7")
install_parser.add_argument('-m', '--modules', nargs='*', help="Specify extra modules to install")
install_parser.add_argument('--archives', nargs='*',
help="Specify subset modules to install(Default: all standard modules).")
install_parser.add_argument('-O', '--outputdir', nargs='?',
help='Target output directory(default current directory)')
install_parser.add_argument('-b', '--base', nargs='?',
Expand Down
6 changes: 4 additions & 2 deletions aqt/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ def __init__(self, qt_archives, logging=None, command=None, target_dir=None):
def retrieve_archive(self, package: QtPackage):
archive = package.archive
url = package.url
name = package.name
start_time = time.perf_counter()
self.logger.info("Downloading {}...".format(url))
self.logger.info("Downloading {}...".format(name))
self.logger.debug("Download URL: {}".format(url))
session = requests.Session()
retry = Retry(connect=5, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
Expand All @@ -72,7 +74,7 @@ def retrieve_archive(self, package: QtPackage):
r = session.get(url, allow_redirects=False, stream=True)
if r.status_code == 302:
newurl = altlink(r.url, r.headers['Location'], logger=self.logger)
self.logger.info('Redirected to new URL: {}'.format(newurl))
self.logger.info('Redirected URL: {}'.format(newurl))
r = session.get(newurl, stream=True)
except requests.exceptions.ConnectionError as e:
self.logger.error("Connection error: %s" % e.args)
Expand Down

0 comments on commit fcb5b45

Please sign in to comment.