mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-18 10:26:29 +01:00
Added maximum parallel
This commit is contained in:
parent
a8c8aaa689
commit
cac4ef49c1
5 changed files with 16 additions and 1 deletions
|
@ -1,5 +1,9 @@
|
||||||
## slpkg - ChangeLog
|
## slpkg - ChangeLog
|
||||||
|
|
||||||
|
### 5.0.5 - 06/04/2024
|
||||||
|
- Added:
|
||||||
|
* Added maximum parallel for downloading in the config file
|
||||||
|
|
||||||
### 5.0.4 - 04/04/2024
|
### 5.0.4 - 04/04/2024
|
||||||
- Updated:
|
- Updated:
|
||||||
* Updated to ignore blacklist installed packages
|
* Updated to ignore blacklist installed packages
|
||||||
|
|
|
@ -56,6 +56,9 @@ ASK_QUESTION = true
|
||||||
# Alternatively, you can use the option '--parallel'.
|
# Alternatively, you can use the option '--parallel'.
|
||||||
PARALLEL_DOWNLOADS = false
|
PARALLEL_DOWNLOADS = false
|
||||||
|
|
||||||
|
# Specifies number of concurrent download streams. Default is 5.
|
||||||
|
MAXIMUM_PARALLEL = 5
|
||||||
|
|
||||||
# If progress bar is true, it does not print the commands as they
|
# If progress bar is true, it does not print the commands as they
|
||||||
# are executed. Default is false. [true/false]
|
# are executed. Default is false. [true/false]
|
||||||
PROGRESS_BAR = false
|
PROGRESS_BAR = false
|
||||||
|
|
|
@ -54,6 +54,7 @@ class Configs:
|
||||||
ascii_characters: bool = True
|
ascii_characters: bool = True
|
||||||
ask_question: bool = True
|
ask_question: bool = True
|
||||||
parallel_downloads: bool = False
|
parallel_downloads: bool = False
|
||||||
|
maximum_parallel: int = 5
|
||||||
progress_bar: bool = False
|
progress_bar: bool = False
|
||||||
progress_spinner: str = 'pixel'
|
progress_spinner: str = 'pixel'
|
||||||
spinner_color: str = 'green'
|
spinner_color: str = 'green'
|
||||||
|
@ -100,6 +101,7 @@ class Configs:
|
||||||
ascii_characters: bool = config['ASCII_CHARACTERS']
|
ascii_characters: bool = config['ASCII_CHARACTERS']
|
||||||
file_list_suffix: str = config['FILE_LIST_SUFFIX']
|
file_list_suffix: str = config['FILE_LIST_SUFFIX']
|
||||||
parallel_downloads: bool = config['PARALLEL_DOWNLOADS']
|
parallel_downloads: bool = config['PARALLEL_DOWNLOADS']
|
||||||
|
maximum_parallel: int = config['MAXIMUM_PARALLEL']
|
||||||
progress_bar: str = config['PROGRESS_BAR']
|
progress_bar: str = config['PROGRESS_BAR']
|
||||||
progress_spinner: str = config['PROGRESS_SPINNER']
|
progress_spinner: str = config['PROGRESS_SPINNER']
|
||||||
spinner_color: str = config['SPINNER_COLOR']
|
spinner_color: str = config['SPINNER_COLOR']
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process, Semaphore
|
||||||
from urllib.parse import unquote, urlparse
|
from urllib.parse import unquote, urlparse
|
||||||
|
|
||||||
from slpkg.configs import Configs
|
from slpkg.configs import Configs
|
||||||
|
@ -33,6 +33,9 @@ class Downloader(Configs):
|
||||||
'curl': self.set_curl_downloader,
|
'curl': self.set_curl_downloader,
|
||||||
'lftp': self.set_lftp_downloader
|
'lftp': self.set_lftp_downloader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.semaphore = Semaphore(self.maximum_parallel)
|
||||||
|
|
||||||
self.option_for_parallel: bool = self.utils.is_option(
|
self.option_for_parallel: bool = self.utils.is_option(
|
||||||
('-P', '--parallel'), flags)
|
('-P', '--parallel'), flags)
|
||||||
|
|
||||||
|
@ -62,6 +65,7 @@ class Downloader(Configs):
|
||||||
self.tools(url, path)
|
self.tools(url, path)
|
||||||
|
|
||||||
def tools(self, url: str, path: Path) -> None:
|
def tools(self, url: str, path: Path) -> None:
|
||||||
|
self.semaphore.acquire()
|
||||||
url_parse: str = urlparse(url).path
|
url_parse: str = urlparse(url).path
|
||||||
self.filename: str = unquote(Path(url_parse).name)
|
self.filename: str = unquote(Path(url_parse).name)
|
||||||
|
|
||||||
|
@ -75,6 +79,7 @@ class Downloader(Configs):
|
||||||
|
|
||||||
self.multi_process.process(self.downloader_command)
|
self.multi_process.process(self.downloader_command)
|
||||||
self.check_if_downloaded(url, path)
|
self.check_if_downloaded(url, path)
|
||||||
|
self.semaphore.release()
|
||||||
|
|
||||||
def copy_local_binary_file(self, url: str) -> None:
|
def copy_local_binary_file(self, url: str) -> None:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -44,6 +44,7 @@ class TestConfigs(unittest.TestCase):
|
||||||
self.assertEqual(True, self.configs.ascii_characters)
|
self.assertEqual(True, self.configs.ascii_characters)
|
||||||
self.assertEqual(True, self.configs.ask_question)
|
self.assertEqual(True, self.configs.ask_question)
|
||||||
self.assertEqual(False, self.configs.parallel_downloads)
|
self.assertEqual(False, self.configs.parallel_downloads)
|
||||||
|
self.assertEqual(5, self.configs.maximum_parallel)
|
||||||
self.assertEqual(True, self.configs.progress_bar)
|
self.assertEqual(True, self.configs.progress_bar)
|
||||||
self.assertEqual('pixel', self.configs.progress_spinner)
|
self.assertEqual('pixel', self.configs.progress_spinner)
|
||||||
self.assertEqual('green', self.configs.spinner_color)
|
self.assertEqual('green', self.configs.spinner_color)
|
||||||
|
|
Loading…
Reference in a new issue