slpkg/slpkg/download_only.py
Dimitris Zlatanidis 87910b945b Updated for extend
2023-05-06 22:17:37 +03:00

81 lines
2.7 KiB
Python

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import time
import shutil
from pathlib import Path
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.downloader import Downloader
from slpkg.views.views import ViewMessage
from slpkg.repositories import Repositories
from slpkg.models.models import session as Session
class Download(Configs):
""" Download the slackbuilds with the sources only. """
def __init__(self, directory: Path, flags: list, data: dict, repository: str):
super(Configs, self).__init__()
self.directory: Path = directory
self.flags: list = flags
self.data: dict = data
self.repository: str = repository
self.view = ViewMessage(flags, repository, data)
self.repos = Repositories()
self.utils = Utilities()
self.session = Session
self.is_binary: bool = self.utils.is_binary_repo(repository)
self.option_for_directory: bool = self.utils.is_option(
['-z', '--directory='], flags)
def packages(self, packages: list) -> None:
""" Download the package only. """
urls: list = []
sbo_repo: dict = {
self.repos.sbo_repo_name: self.repos.sbo_repo_path,
self.repos.ponce_repo_name: self.repos.ponce_repo_path
}
packages: list = self.utils.apply_package_pattern(self.data, packages)
self.view.download_packages(packages, self.directory)
self.view.question()
download_path: Path = self.download_only_path
if self.option_for_directory:
download_path: Path = self.directory
start: float = time.time()
for pkg in packages:
if self.is_binary:
package: str = self.data[pkg][1]
mirror: str = self.data[pkg][2]
location: str = self.data[pkg][3]
urls.append(f'{mirror}{location}/{package}')
else:
location: str = self.data[pkg][0]
if self.os_arch == 'x86_64' and self.data[pkg][4]:
sources = self.data[pkg][4].split()
else:
sources = self.data[pkg][3].split()
urls.extend(sources)
repo_path_package: Path = Path(sbo_repo[self.repository], location, pkg)
if not Path(download_path, pkg).is_dir():
shutil.copytree(repo_path_package, Path(download_path, pkg))
print(f"{self.byellow}Copying{self.endc}: {repo_path_package} -> {Path(download_path, pkg)}")
down = Downloader(download_path, urls, self.flags)
down.download()
elapsed_time: float = time.time() - start
self.utils.finished_time(elapsed_time)