diff --git a/pungi/linker.py b/pungi/linker.py index 936f6f1f..d90c4fc0 100644 --- a/pungi/linker.py +++ b/pungi/linker.py @@ -31,6 +31,13 @@ class LinkerPool(ThreadPool): self.link_type = link_type self.linker = Linker() + @classmethod + def with_workers(cls, num_workers, *args, **kwargs): + pool = cls(*args, **kwargs) + for _ in range(num_workers): + pool.add(LinkerThread(pool)) + return pool + class LinkerThread(WorkerThread): def process(self, item, num): diff --git a/pungi/phases/gather/link.py b/pungi/phases/gather/link.py index 29921654..4931c6cd 100644 --- a/pungi/phases/gather/link.py +++ b/pungi/phases/gather/link.py @@ -18,7 +18,7 @@ import os import kobo.rpmlib -from pungi.linker import LinkerThread, LinkerPool +from pungi.linker import LinkerPool # TODO: global Linker instance - to keep hardlinks on dest? @@ -61,9 +61,7 @@ def link_files(compose, arch, variant, pkg_map, pkg_sets, manifest, srpm_map={}) compose.log_info("[BEGIN] %s" % msg) link_type = compose.conf["link_type"] - pool = LinkerPool(link_type, logger=compose._logger) - for i in range(10): - pool.add(LinkerThread(pool)) + pool = LinkerPool.with_workers(10, link_type, logger=compose._logger) hashed_directories = compose.conf["hashed_directories"] diff --git a/pungi/phases/pkgset/sources/source_repos.py b/pungi/phases/pkgset/sources/source_repos.py index 55aab529..50edb7f5 100644 --- a/pungi/phases/pkgset/sources/source_repos.py +++ b/pungi/phases/pkgset/sources/source_repos.py @@ -30,7 +30,7 @@ from pungi.phases.pkgset.common import (run_create_global_repo, create_arch_repos, populate_arch_pkgsets) from pungi.phases.gather import get_prepopulate_packages, get_packages_to_gather -from pungi.linker import LinkerThread, LinkerPool +from pungi.linker import LinkerPool import pungi.phases.pkgset.source @@ -52,9 +52,7 @@ def get_pkgset_from_repos(compose): profiler = compose.conf["gather_profiler"] link_type = compose.conf["link_type"] - pool = LinkerPool(link_type, logger=compose._logger) - for i in range(10): - pool.add(LinkerThread(pool)) + pool = LinkerPool.with_workers(10, link_type, logger=compose._logger) path_prefix = os.path.join(compose.paths.work.topdir(arch="global"), "download") + "/" makedirs(path_prefix)