From 496a2be06b02c12db65e91100d2d0eb37eafeed1 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 May 2024 20:39:38 +0300 Subject: [PATCH] Added config for delete sources --- ChangeLog.txt | 3 ++- configs/slpkg.toml | 6 +++++- slpkg/binaries/install.py | 4 +++- slpkg/configs.py | 2 ++ slpkg/dialog_configs.py | 2 ++ slpkg/sbos/slackbuild.py | 42 +++++++++++++++++++++------------------ 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 06de595b..6145e530 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,9 +1,10 @@ ## slpkg - ChangeLog -### 5.0.9 - 12/05/2024 +### 5.0.9 - 23/05/2024 - Added: * Inform message for invalid package version with the upgrade command + * Config to delete sources after build or install packages ### 5.0.8 - 10/05/2024 diff --git a/configs/slpkg.toml b/configs/slpkg.toml index 09dedafa..fbfa28b6 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -1,6 +1,6 @@ # This is the general configuration file of slpkg: # /etc/slpkg/slpkg.toml -# Updated: 12/05/2024, Version: 5.0.9 +# Updated: 23/05/2024, Version: 5.0.9 [CONFIGS] @@ -37,6 +37,10 @@ DIALOG = true # Default is true. [true/false] VIEW_MISSING_DEPS = true +# Delete downloaded sources after build or install packages. +# Default is false. [true/false] +DELETE_SOURCES = false + # Choose ascii printable characters. # If true, it uses the extended characters, otherwise the basic ones. # Default is true. [true/false]. diff --git a/slpkg/binaries/install.py b/slpkg/binaries/install.py index 18faa575..a4e7e715 100644 --- a/slpkg/binaries/install.py +++ b/slpkg/binaries/install.py @@ -140,7 +140,6 @@ class Packages(Configs): # pylint: disable=[R0902] asc_files.append(asc_file) self.binary_packages.append(package) - self.utils.remove_file_if_exists(self.tmp_slpkg, package) self.view_process.done() self.download_the_binary_packages(packages) @@ -183,6 +182,9 @@ class Packages(Configs): # pylint: disable=[R0902] name: str = self.utils.split_package(package)['name'] self.write_deps_log(name) + if self.delete_sources: + self.utils.remove_file_if_exists(self.tmp_slpkg, package) + def write_deps_log(self, name: str) -> None: """Create log file with installed packages with dependencies. diff --git a/slpkg/configs.py b/slpkg/configs.py index dd969f97..1172647f 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -46,6 +46,7 @@ class Configs: # pylint: disable=[R0902] checksum_md5: bool = True dialog: bool = True view_missing_deps: bool = True + delete_sources: bool = False downloader: str = 'wget' wget_options: str = '--c -q --progress=bar:force:noscroll --show-progress' curl_options: str = '' @@ -93,6 +94,7 @@ class Configs: # pylint: disable=[R0902] checksum_md5: bool = config['checksum_md5'] dialog: bool = config['dialog'] view_missing_deps: bool = config['view_missing_deps'] + delete_sources: bool = config['delete_sources'] downloader: str = config['downloader'] wget_options: str = config['wget_options'] curl_options: str = config['curl_options'] diff --git a/slpkg/dialog_configs.py b/slpkg/dialog_configs.py index e9d8184f..fa09c7b2 100644 --- a/slpkg/dialog_configs.py +++ b/slpkg/dialog_configs.py @@ -76,6 +76,7 @@ class FormConfigs(Configs): 'COLORS', 'DIALOG', 'VIEW_MISSING_DEPS', + 'DELETE_SOURCES', 'SILENT_MODE', 'ASCII_CHARACTERS', 'ASK_QUESTION', @@ -127,6 +128,7 @@ class FormConfigs(Configs): ('COLORS =', 'DIALOG =', 'VIEW_MISSING_DEPS =', + 'DELETE_SOURCES =', 'SILENT_MODE =', 'ASCII_CHARACTERS =', 'ASK_QUESTION =', diff --git a/slpkg/sbos/slackbuild.py b/slpkg/sbos/slackbuild.py index 94168b96..0685bf91 100644 --- a/slpkg/sbos/slackbuild.py +++ b/slpkg/sbos/slackbuild.py @@ -52,7 +52,7 @@ class Slackbuilds(Configs): # pylint: disable=[R0902,R0904] self.bar_process = None self.sources: dict = {} - self.install_order: list = [] + self.build_order: list = [] self.dependencies: list = [] self.skipped_packages: list = [] self.asc_files: list = [] @@ -80,7 +80,7 @@ class Slackbuilds(Configs): # pylint: disable=[R0902,R0904] self.check_for_skipped() self.view_slackbuilds_before_build() - self.view.missing_dependencies(self.install_order) + self.view.missing_dependencies(self.build_order) self.view.question() start: float = time.time() @@ -105,7 +105,7 @@ class Slackbuilds(Configs): # pylint: disable=[R0902,R0904] def add_dependencies_to_install_order(self) -> None: """Add the dependency list in order for install.""" - self.install_order.extend(self.dependencies) + self.build_order.extend(self.dependencies) def clean_the_main_slackbuilds(self) -> None: """Remove main packages if they already added as dependency.""" @@ -115,18 +115,18 @@ class Slackbuilds(Configs): # pylint: disable=[R0902,R0904] def add_main_packages_to_install_order(self) -> None: """Add the main packages to order for install.""" - self.install_order.extend(self.slackbuilds) + self.build_order.extend(self.slackbuilds) def check_for_skipped(self) -> None: """Check packages for skipped.""" if self.option_for_skip_installed: - for name in self.install_order: + for name in self.build_order: installed: str = self.utils.is_package_installed(name) if installed: self.skipped_packages.append(name) # Remove packages from skipped packages. - self.install_order: list = [pkg for pkg in self.install_order if pkg not in self.skipped_packages] + self.build_order: list = [pkg for pkg in self.build_order if pkg not in self.skipped_packages] def view_slackbuilds_before_build(self) -> None: """View packages before build.""" @@ -137,25 +137,26 @@ class Slackbuilds(Configs): # pylint: disable=[R0902,R0904] def prepare_slackbuilds_for_build(self) -> None: """Prepare slackbuilds for build.""" - if self.install_order: + if self.build_order: self.view_process.message('Prepare sources for downloading') - for sbo in self.install_order: + for sbo in self.build_order: build_path: Path = Path(self.build_path, sbo) - self.utils.remove_folder_if_exists(build_path) + # self.utils.remove_folder_if_exists(build_path) location: str = self.data[sbo]['location'] slackbuild: Path = Path(self.build_path, sbo, f'{sbo}.SlackBuild') # Copy slackbuilds to the build folder. - path_repo_package: Path = Path(self.repos.repositories[self.repository]['path'], location, sbo) - shutil.copytree(path_repo_package, build_path) + repo_package: Path = Path(self.repos.repositories[self.repository]['path'], location, sbo) + + shutil.copytree(repo_package, build_path, dirs_exist_ok=True) os.chmod(slackbuild, 0o775) if self.os_arch == 'x86_64' and self.data[sbo]['download64']: sources: tuple = self.data[sbo]['download64'] else: - sources: tuple = self.data[sbo]['download'] # type: ignore[no-redef] + sources: tuple = self.data[sbo]['download'] if self.gpg_verification and self.repository == self.repos.sbo_repo_name: asc_file: Path = Path(self.repos.repositories_path, self.repos.sbo_repo_name, @@ -177,7 +178,7 @@ class Slackbuilds(Configs): # pylint: disable=[R0902,R0904] def checksum_downloaded_sources(self) -> None: """Checksum the sources.""" - for sbo in self.install_order: + for sbo in self.build_order: path: Path = Path(self.build_path, sbo) if self.os_arch == 'x86_64' and self.data[sbo]['md5sum64']: @@ -191,24 +192,27 @@ class Slackbuilds(Configs): # pylint: disable=[R0902,R0904] self.check_md5.md5sum(path, source, checksum) def build_and_install_the_slackbuilds(self) -> None: - """Build an install the slackbuilds.""" - # Remove old slpkg.log file. - if self.slpkg_log_file.is_file(): + """Build or install the slackbuilds.""" + if self.slpkg_log_file.is_file(): # Remove old slpkg.log file. self.slpkg_log_file.unlink() if self.gpg_verification and self.repository == self.repos.sbo_repo_name: self.gpg.verify(self.asc_files) - if self.install_order: - print(f'Started the processing of ({self.cyan}{len(self.install_order)}{self.endc}) packages:\n') + if self.build_order: + print(f'Started the processing of ({self.cyan}{len(self.build_order)}{self.endc}) packages:\n') - for sbo in self.install_order: + for sbo in self.build_order: self.patch_slackbuild_tag(sbo) self.build_the_script(self.build_path, sbo) if self.mode in ('install', 'upgrade'): self.install_package(sbo) + if self.delete_sources: + sbo_build_folder: Path = Path(self.build_path, sbo) + self.utils.remove_folder_if_exists(sbo_build_folder) + def patch_slackbuild_tag(self, sbo: str) -> None: """Patch the slackbuild tag.