Updated for dict

This commit is contained in:
Dimitris Zlatanidis 2023-05-24 22:08:25 +03:00
parent 1660366cb8
commit bf1910a7cf
4 changed files with 40 additions and 41 deletions

View file

@ -36,6 +36,7 @@ class Packages(Configs):
self.upgrade = Upgrade(repository, data)
self.view_message = ViewMessage(flags, repository, data)
self.check_md5 = Md5sum(flags)
self.download = Downloader(flags)
self.dependencies: list = []
self.install_order: list = []
@ -100,7 +101,7 @@ class Packages(Configs):
self.install_order.extend(self.packages)
def crating_the_package_urls_list(self) -> None:
package_urls: list = []
packages: dict = {}
for pkg in self.install_order:
if self.continue_to_install(pkg):
@ -108,7 +109,7 @@ class Packages(Configs):
mirror: str = self.data[pkg]['mirror']
location: str = self.data[pkg]['location']
package_urls.append(f'{mirror}{location}/{package}')
packages[f'{mirror}{location}/{package}'] = self.tmp_slpkg
self.binary_packages.append(package)
self.utils.remove_file_if_exists(self.tmp_slpkg, package)
@ -116,13 +117,12 @@ class Packages(Configs):
installed_package: str = self.utils.is_package_installed(pkg)
self.view_message.view_skipping_packages(installed_package)
self.download_the_binary_packages(package_urls)
self.download_the_binary_packages(packages)
def download_the_binary_packages(self, package_urls: list) -> None:
if package_urls:
print(f'Started to download total ({self.cyan}{len(package_urls)}{self.endc}) packages:\n')
down = Downloader(self.tmp_slpkg, package_urls, self.flags)
down.download()
def download_the_binary_packages(self, packages: dict) -> None:
if packages:
print(f'Started to download total ({self.cyan}{len(packages)}{self.endc}) packages:\n')
self.download.download(packages)
print()
def continue_to_install(self, name: str) -> bool:

View file

@ -26,10 +26,11 @@ class DownloadOnly(Configs):
self.repository: str = repository
self.view = ViewMessage(flags, repository, data)
self.download = Downloader(flags)
self.repos = Repositories()
self.utils = Utilities()
self.session = Session
self.urls: list = []
self.urls: dict = {}
self.download_path: Path = Path()
self.sbo_repo: dict = {
@ -69,14 +70,15 @@ class DownloadOnly(Configs):
package: str = self.data[name]['package']
mirror: str = self.data[name]['mirror']
location: str = self.data[name]['location']
self.urls.append(f'{mirror}{location}/{package}')
self.urls[f'{mirror}{location}/{package}'] = self.tmp_slpkg
def save_slackbuild_sources(self, name: str) -> None:
if self.os_arch == 'x86_64' and self.data[name]['download64']:
sources: list = self.data[name]['download64'].split()
else:
sources: list = self.data[name]['download'].split()
self.urls.extend(sources)
for source in sources:
self.urls[source] = Path(self.build_path, name)
def copy_slackbuild_scripts(self, name: str) -> None:
repo_path_package: Path = Path(self.sbo_repo[self.repository], self.data[name]['location'], name)
@ -87,5 +89,4 @@ class DownloadOnly(Configs):
def download_the_sources(self) -> None:
if self.urls:
print(f'\nStarted to download total ({self.cyan}{len(self.urls)}{self.endc}) sources:\n')
down = Downloader(self.download_path, self.urls, self.flags)
down.download()
self.download.download(self.urls)

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
import shutil
from typing import Union
from pathlib import Path
from multiprocessing import Process
from urllib.parse import unquote, urlparse
@ -14,10 +13,8 @@ from slpkg.error_messages import Errors
class Downloader(Configs):
def __init__(self, path: Union[str, Path], urls: list, flags: list):
def __init__(self, flags: list):
super(Configs, self).__init__()
self.path: Path = path
self.urls: list = urls
self.flags: list = flags
self.errors = Errors()
@ -34,36 +31,36 @@ class Downloader(Configs):
self.option_for_parallel: bool = self.utils.is_option(
('-P', '--parallel'), flags)
def download(self) -> None:
def download(self, sources: dict) -> None:
""" Starting the processing for downloading. """
processes: list = []
if self.parallel_downloads or self.option_for_parallel:
for url in self.urls:
proc = Process(target=self.tools, args=(url,))
for url, path in sources.items():
proc = Process(target=self.tools, args=(url, path))
processes.append(proc)
proc.start()
for process in processes:
process.join()
else:
for url in self.urls:
self.tools(url)
for url, path in sources.items():
self.tools(url, path)
def tools(self, url: str) -> None:
path: str = urlparse(url).path
self.filename: str = unquote(Path(path).name)
def tools(self, url: str, path: Path) -> None:
url_parse: str = urlparse(url).path
self.filename: str = unquote(Path(url_parse).name)
if url.startswith('file'):
self.copy_local_binary_file(url)
else:
try:
self.downloader_tools[self.downloader](url)
self.downloader_tools[self.downloader](url, path)
except KeyError:
self.errors.raise_error_message(f"Downloader '{self.downloader}' not supported", exit_status=1)
self.utils.process(self.downloader_command)
self.check_if_downloaded(url)
self.check_if_downloaded(url, path)
def copy_local_binary_file(self, url: str) -> None:
try:
@ -72,17 +69,17 @@ class Downloader(Configs):
except FileNotFoundError as error:
self.errors.raise_error_message(f'{error}', 1)
def wget_downloader(self, url: str) -> None:
self.downloader_command: str = f'{self.downloader} {self.wget_options} --directory-prefix={self.path} "{url}"'
def wget_downloader(self, url: str, path: Path) -> None:
self.downloader_command: str = f'{self.downloader} {self.wget_options} --directory-prefix={path} "{url}"'
def curl_downloader(self, url: str) -> None:
def curl_downloader(self, url: str, path: Path) -> None:
self.downloader_command: str = (f'{self.downloader} {self.curl_options} "{url}" '
f'--output {self.path}/{self.filename}')
f'--output {path}/{self.filename}')
def lftp_downloader(self, url: str) -> None:
self.downloader_command: str = f'{self.downloader} {self.lftp_get_options} {url} -o {self.path}'
def lftp_downloader(self, url: str, path: Path) -> None:
self.downloader_command: str = f'{self.downloader} {self.lftp_get_options} {url} -o {path}'
def check_if_downloaded(self, url: str) -> None:
path_file: Path = Path(self.path, self.filename)
def check_if_downloaded(self, url: str, path: Path) -> None:
path_file: Path = Path(path, self.filename)
if not path_file.exists():
self.errors.raise_error_message(f"Download the '{url}'", exit_status=20)

View file

@ -44,7 +44,8 @@ class Slackbuilds(Configs):
self.logs_deps = LoggingDeps(repository, data)
self.upgrade = Upgrade(repository, data)
self.view_message = ViewMessage(flags, repository, data)
self.check_md5 = Md5sum(self.flags)
self.check_md5 = Md5sum(flags)
self.download = Downloader(flags)
self.sources: dict = {}
self.install_order: list = []
@ -158,16 +159,16 @@ class Slackbuilds(Configs):
os.chmod(slackbuild, 0o775)
if self.os_arch == 'x86_64' and self.data[sbo]['download64']:
self.sources[sbo] = self.data[sbo]['download64'].split()
sources: list = self.data[sbo]['download64'].split()
else:
self.sources[sbo] = self.data[sbo]['download'].split()
sources: list = self.data[sbo]['download'].split()
for source in sources:
self.sources[source] = Path(self.build_path, sbo)
def download_the_sources(self) -> None:
if self.sources:
print(f'Started to download total ({self.cyan}{len(self.sources)}{self.endc}) sources:\n')
for package, sbo_sources in self.sources.items():
down_urls = Downloader(Path(self.build_path, package), sbo_sources, self.flags)
down_urls.download()
self.download.download(self.sources)
print()
self.checksum_downloaded_sources()