diff --git a/man/slpkg.1 b/man/slpkg.1 index 83f32bd3..a043213e 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -242,6 +242,16 @@ Command clean-data, removes the local repository data and the database data. Note: There is currently no function to indicate the packages if the colors are disabled. .RE +.SH EXIT STATUS +.P +0 Successful slpkg execution. +.P +1 Something wrong happened. +.P +20 No package found to be downloaded, installed, reinstalled, upā€graded, or removed. +.P +30 Md5sum checksum failed. +.RE .SH CONFIGURATION FILES .P Configuration file in the /etc/slpkg/slpkg.toml file. diff --git a/slpkg/checks.py b/slpkg/checks.py index faa4b2cc..0f1475f9 100644 --- a/slpkg/checks.py +++ b/slpkg/checks.py @@ -51,7 +51,7 @@ class Check(Configs): not_packages.append(pkg) if not_packages: - self.errors.raise_error_message(f"Packages '{', '.join(not_packages)}' does not exists") + self.errors.raise_error_message(f"Packages '{', '.join(not_packages)}' does not exists", exit_status=20) def is_package_unsupported(self, slackbuilds: list) -> None: """ Checking for unsupported slackbuilds. """ @@ -63,7 +63,7 @@ class Check(Configs): sources: list = self.data[sbo][3].split() if 'UNSUPPORTED' in sources: - self.errors.raise_error_message(f"Package '{sbo}' unsupported by arch") + self.errors.raise_error_message(f"Package '{sbo}' unsupported by arch", exit_status=1) def is_installed(self, packages: list) -> None: """ Checking for installed packages. """ @@ -75,7 +75,7 @@ class Check(Configs): not_found.append(pkg) if not_found: - self.errors.raise_error_message(f'Not found \'{", ".join(not_found)}\' installed packages') + self.errors.raise_error_message(f'Not found \'{", ".join(not_found)}\' installed packages', exit_status=20) def is_empty_database(self, repo: str) -> None: """ Checking for empty table and database file. """ @@ -89,4 +89,4 @@ class Check(Configs): if not self.session.query(self.repo_table).first() or not db.is_file() or count == 0: self.errors.raise_error_message("You need to update the package lists first, run:\n\n" " $ 'slpkg update'\n" - " $ 'slpkg update --bin-repo='*' for binaries") + " $ 'slpkg update --bin-repo='*' for binaries", exit_status=1) diff --git a/slpkg/checksum.py b/slpkg/checksum.py index d0cf3b4a..3163ce62 100644 --- a/slpkg/checksum.py +++ b/slpkg/checksum.py @@ -45,4 +45,4 @@ class Md5sum: with open(filename, 'rb') as f: return f.read() except FileNotFoundError: - self.errors.raise_error_message(f"No such file or directory: '{filename}'") + self.errors.raise_error_message(f"No such file or directory: '{filename}'", exit_status=20) diff --git a/slpkg/dialog_configs.py b/slpkg/dialog_configs.py index 0a1dee6b..2530ff83 100644 --- a/slpkg/dialog_configs.py +++ b/slpkg/dialog_configs.py @@ -25,7 +25,7 @@ class FormConfigs(Configs): """ Checking if the dialog box is enabled by the user. """ if not self.dialog: self.errors.raise_error_message(f"You should enable the dialog in the " - f"'{self.etc_path}/{self.prog_name}.toml' file") + f"'{self.etc_path}/{self.prog_name}.toml' file", exit_status=1) def edit(self) -> None: """ Read and write the configuration file. """ diff --git a/slpkg/downloader.py b/slpkg/downloader.py index 294cb178..adfee40c 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -61,7 +61,7 @@ class Downloader(Configs): command: str = f'{self.downloader} {self.lftp_get_options} {url} -o {self.path}' else: - self.errors.raise_error_message(f"Downloader '{self.downloader}' not supported") + self.errors.raise_error_message(f"Downloader '{self.downloader}' not supported", exit_status=1) self.utils.process(command) self.check_if_downloaded(url) @@ -73,4 +73,4 @@ class Downloader(Configs): path_file: Path = Path(self.path, file) if not path_file.exists(): - self.errors.raise_error_message(f"Download the '{file}' file") + self.errors.raise_error_message(f"Download the '{file}' file", exit_status=20) diff --git a/slpkg/error_messages.py b/slpkg/error_messages.py index 25395ee1..760c8d38 100644 --- a/slpkg/error_messages.py +++ b/slpkg/error_messages.py @@ -10,6 +10,7 @@ class Errors(Configs): def __init__(self): super(Configs, self).__init__() - def raise_error_message(self, message: str) -> None: + def raise_error_message(self, message: str, exit_status: int) -> None: """ A general method to raise an error message and exit. """ - raise SystemExit(f"\n{self.prog_name}: {self.bred}Error{self.endc}: {message}.\n") + print(f"\n{self.prog_name}: {self.bred}Error{self.endc}: {message}.\n") + raise SystemExit(exit_status) diff --git a/slpkg/sbos/slackbuild.py b/slpkg/sbos/slackbuild.py index 3be6c043..37bf3416 100644 --- a/slpkg/sbos/slackbuild.py +++ b/slpkg/sbos/slackbuild.py @@ -298,7 +298,7 @@ class Slackbuilds(Configs): try: package: str = max(packages) except ValueError: - self.errors.raise_error_message(f"Package '{name}' not found for install") + self.errors.raise_error_message(f"Package '{name}' not found for install", exit_status=20) return package diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 00fd693c..02cd672c 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -131,7 +131,7 @@ class Utilities(Configs): yield package except FileNotFoundError: - self.errors.raise_error_message(f"No such file or directory: '{file}'") + self.errors.raise_error_message(f"No such file or directory: '{file}'", exit_status=20) @staticmethod def read_file(file: Union[str, Path]) -> list: @@ -139,16 +139,16 @@ class Utilities(Configs): with open(file, 'r', encoding='utf-8', errors='replace') as f: return f.readlines() - @staticmethod - def process(command: str, stderr=None, stdout=None) -> None: + def process(self, command: str, stderr=None, stdout=None) -> None: """ Handle the processes. """ + output: int = 0 try: output = subprocess.call(command, shell=True, stderr=stderr, stdout=stdout) except (KeyboardInterrupt, subprocess.CalledProcessError) as err: - raise SystemExit(err) + self.errors.raise_error_message(err, exit_status=20) if output != 0: - raise SystemExit(output) + self.errors.raise_error_message(f"Command {command} failed", exit_status=20) def get_file_size(self, file: Path) -> str: """ Get the local file size and converted to units. """