Updated for download only

This commit is contained in:
Dimitris Zlatanidis 2023-05-09 17:52:21 +03:00
parent 39bf5db2ff
commit cbb7a16d7a

View file

@ -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()