From cbb7a16d7abc10bfe2b29a7de442af2571cff804 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 9 May 2023 17:52:21 +0300 Subject: [PATCH] Updated for download only --- slpkg/download_only.py | 76 +++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/slpkg/download_only.py b/slpkg/download_only.py index 04f01778..b7b5a572 100644 --- a/slpkg/download_only.py +++ b/slpkg/download_only.py @@ -27,55 +27,61 @@ class Download(Configs): self.repos = Repositories() self.utils = Utilities() self.session = Session + self.urls: list = [] + self.download_path: Path = Path() + + self.sbo_repo: dict = { + self.repos.sbo_repo_name: self.repos.sbo_repo_path, + self.repos.ponce_repo_name: self.repos.ponce_repo_path + } 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 - + self.set_download_path() 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}') + self.save_binary_sources(pkg) 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() + self.save_slackbuild_sources(pkg) + self.copy_slackbuild_scripts(pkg) + self.download_the_sources() elapsed_time: float = time.time() - start self.utils.finished_time(elapsed_time) + + def set_download_path(self) -> None: + self.download_path: Path = self.download_only_path + if self.option_for_directory: + self.download_path: Path = self.directory + + def save_binary_sources(self, pkg: str) -> None: + package: str = self.data[pkg][1] + mirror: str = self.data[pkg][2] + location: str = self.data[pkg][3] + self.urls.append(f'{mirror}{location}/{package}') + + def save_slackbuild_sources(self, pkg: str) -> None: + if self.os_arch == 'x86_64' and self.data[pkg][4]: + sources: list = self.data[pkg][4].split() + else: + sources: list = self.data[pkg][3].split() + self.urls.extend(sources) + + def copy_slackbuild_scripts(self, pkg: str) -> None: + repo_path_package: Path = Path(self.sbo_repo[self.repository], self.data[pkg][0], pkg) + if not Path(self.download_path, pkg).is_dir(): + shutil.copytree(repo_path_package, Path(self.download_path, pkg)) + print(f"{self.byellow}Copying{self.endc}: {repo_path_package} -> {Path(self.download_path, pkg)}") + + def download_the_sources(self) -> None: + down = Downloader(self.download_path, self.urls, self.flags) + down.download()