From 531d9e8b662fdaa645e1daa6454f646ea5ed0c53 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Mon, 13 Mar 2023 10:35:08 +0200 Subject: [PATCH] Added parallel to the configs --- configs/slpkg.toml | 2 ++ slpkg/configs.py | 6 ++++++ slpkg/downloader.py | 16 ++++++++++------ slpkg/form_configs.py | 6 ++++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/configs/slpkg.toml b/configs/slpkg.toml index fb8a1a06..39fb4a73 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -28,6 +28,8 @@ # Set false to all the questions. If set false option --yes will not work. # Default is true. [true/false]. ASK_QUESTION = true + # Download parallel multi-sources. Default is true. [true/false]. + PARALLEL_DOWNLOADS = true # Pass your file pattern here, instead, you can use '--file-pattern=' option. FILE_PATTERN = "" diff --git a/slpkg/configs.py b/slpkg/configs.py index 589354bd..619dff40 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -119,6 +119,9 @@ class Configs: # Set false to all the questions. ask_question: bool = True + # Download parallel multi-sources. + parallel_downloads: bool = True + # Pass the file pattern here. file_pattern_conf: str = "" @@ -194,6 +197,9 @@ class Configs: # File suffix for list packages. file_list_suffix: str = config['FILE_LIST_SUFFIX'] + # Download parallel multi-sources. + parallel_downloads: bool = config['PARALLEL_DOWNLOADS'] + # Pass the file pattern here. file_pattern_conf: str = config['FILE_PATTERN'] diff --git a/slpkg/downloader.py b/slpkg/downloader.py index b52c81e3..d8f2d72b 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -33,13 +33,17 @@ class Downloader(Configs, Utilities): """ Starting the processing for downloading. """ process: list = [] - for url in self.urls: - p1 = Process(target=self.tools, args=(url,)) - process.append(p1) - p1.start() + if self.parallel_downloads: + for url in self.urls: + p1 = Process(target=self.tools, args=(url,)) + process.append(p1) + p1.start() - for proc in process: - proc.join() + for proc in process: + proc.join() + else: + for url in self.urls: + self.tools(url) def tools(self, url: str) -> None: """ Downloader tools wget, curl and lftp. """ diff --git a/slpkg/form_configs.py b/slpkg/form_configs.py index cac348d9..4e02f114 100644 --- a/slpkg/form_configs.py +++ b/slpkg/form_configs.py @@ -73,7 +73,8 @@ class FormConfigs(Configs): def check_configs(self, tags: list) -> bool: """ Check for true of false values. """ - keys: list = ['COLORS', 'DIALOG', 'SILENT_MODE', 'ASCII_CHARACTERS', 'PONCE_REPO', 'ASK_QUESTION'] + keys: list = ['COLORS', 'DIALOG', 'SILENT_MODE', 'ASCII_CHARACTERS', + 'PONCE_REPO', 'ASK_QUESTION', 'PARALLEL_DOWNLOADS'] values: list = ['true', 'false'] for key, value in zip(self.configs['CONFIGS'].keys(), tags): @@ -106,7 +107,8 @@ class FormConfigs(Configs): line = f' {key} = "{value}"\n' if line.lstrip().startswith(('COLORS =', 'DIALOG =', 'SILENT_MODE =', - 'ASCII_CHARACTERS =', 'PONCE_REPO =', 'ASK_QUESTION =')): + 'ASCII_CHARACTERS =', 'PONCE_REPO =', + 'ASK_QUESTION =', 'PARALLEL_DOWNLOADS =')): line = line.replace('"', '') patch_toml.write(line)