Skip to content

Commit

Permalink
Merge pull request miurahr#316 from miurahr/patch-refactoring-installer
Browse files Browse the repository at this point in the history
Refactoring call_instaler/installer
  • Loading branch information
miurahr authored Jul 15, 2021
2 parents 6aeac16 + 62d8ed3 commit 0d7c3ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
4 changes: 2 additions & 2 deletions aqt/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import xml.etree.ElementTree as ElementTree
from dataclasses import dataclass, field
from logging import getLogger
from typing import Optional, Tuple
from typing import List, Optional, Tuple

from aqt.exceptions import ArchiveListError, NoPackageFound
from aqt.helper import Settings, getUrl
Expand Down Expand Up @@ -216,7 +216,7 @@ def _parse_update_xml(self, archive_url, target_packages):
)
raise NoPackageFound

def get_archives(self):
def get_packages(self) -> List[QtPackage]:
"""
It returns an archive package list.
Expand Down
57 changes: 34 additions & 23 deletions aqt/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
import time
from logging import getLogger
from logging.handlers import QueueHandler
from typing import List, Optional

import aqt
from aqt.archives import QtArchives, SrcDocExamplesArchives, ToolArchives
from aqt.archives import QtArchives, QtPackage, SrcDocExamplesArchives, ToolArchives
from aqt.exceptions import (
ArchiveConnectionError,
ArchiveDownloadError,
Expand Down Expand Up @@ -283,7 +284,7 @@ def run_install(self, args):
except ArchiveDownloadError or ArchiveListError or NoPackageFound:
exit(1)
target_config = qt_archives.get_target_config()
self.call_installer(qt_archives, base_dir, sevenzip, keep)
run_installer(qt_archives.get_packages(), base_dir, sevenzip, keep)
if not nopatch:
Updater.update(target_config, base_dir)
self.logger.info("Finished installation")
Expand Down Expand Up @@ -361,7 +362,7 @@ def _run_src_doc_examples(self, flavor, args):
exit(1)
except ArchiveDownloadError or ArchiveListError:
exit(1)
self.call_installer(srcdocexamples_archives, base_dir, sevenzip, keep)
run_installer(srcdocexamples_archives.get_packages(), base_dir, sevenzip, keep)
self.logger.info("Finished installation")

def run_src(self, args):
Expand Down Expand Up @@ -464,7 +465,7 @@ def run_tool(self, args):
exit(1)
except ArchiveDownloadError or ArchiveListError:
exit(1)
self.call_installer(tool_archives, base_dir, sevenzip, keep)
run_installer(tool_archives.get_packages(), base_dir, sevenzip, keep)
self.logger.info("Finished installation")
self.logger.info(
"Time elapsed: {time:.8f} second".format(
Expand Down Expand Up @@ -800,24 +801,6 @@ def run(self, arg=None):
result = args.func(args)
return result

def call_installer(self, qt_archives, base_dir, sevenzip, keep):
queue = multiprocessing.Manager().Queue(-1)
listener = MyQueueListener(queue)
listener.start()
#
tasks = []
for arc in qt_archives.get_archives():
tasks.append((arc, base_dir, sevenzip, queue, keep))
ctx = multiprocessing.get_context("spawn")
pool = ctx.Pool(Settings.concurrency)
pool.starmap(installer, tasks)
#
pool.close()
pool.join()
# all done, close logging service for sub-processes
listener.enqueue_sentinel()
listener.stop()

@staticmethod
def _is_valid_version_str(
version_str: str, *, allow_latest: bool = False, allow_empty: bool = False
Expand All @@ -833,7 +816,35 @@ def _is_valid_version_str(
return False


def installer(qt_archive, base_dir, command, queue, keep=False, response_timeout=None):
def run_installer(
archives: List[QtPackage], base_dir: str, sevenzip: Optional[str], keep: bool
):
queue = multiprocessing.Manager().Queue(-1)
listener = MyQueueListener(queue)
listener.start()
#
tasks = []
for arc in archives:
tasks.append((arc, base_dir, sevenzip, queue, keep))
ctx = multiprocessing.get_context("spawn")
pool = ctx.Pool(Settings.concurrency)
pool.starmap(installer, tasks)
#
pool.close()
pool.join()
# all done, close logging service for sub-processes
listener.enqueue_sentinel()
listener.stop()


def installer(
qt_archive: QtPackage,
base_dir: str,
command: Optional[str],
queue: multiprocessing.Queue,
keep: bool = False,
response_timeout: Optional[int] = None,
):
"""
Installer function to download archive files and extract it.
It is called through multiprocessing.Pool()
Expand Down

0 comments on commit 0d7c3ee

Please sign in to comment.