Updated for exit status

This commit is contained in:
Dimitris Zlatanidis 2023-04-25 21:15:35 +03:00
parent 7d10401771
commit 398c0c06a2
8 changed files with 27 additions and 16 deletions

View file

@ -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. Note: There is currently no function to indicate the packages if the colors are disabled.
.RE .RE
.SH EXIT STATUS
.P
0 Successful slpkg execution.
.P
1 Something wrong happened.
.P
20 No package found to be downloaded, installed, reinstalled, upgraded, or removed.
.P
30 Md5sum checksum failed.
.RE
.SH CONFIGURATION FILES .SH CONFIGURATION FILES
.P .P
Configuration file in the /etc/slpkg/slpkg.toml file. Configuration file in the /etc/slpkg/slpkg.toml file.

View file

@ -51,7 +51,7 @@ class Check(Configs):
not_packages.append(pkg) not_packages.append(pkg)
if not_packages: 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: def is_package_unsupported(self, slackbuilds: list) -> None:
""" Checking for unsupported slackbuilds. """ """ Checking for unsupported slackbuilds. """
@ -63,7 +63,7 @@ class Check(Configs):
sources: list = self.data[sbo][3].split() sources: list = self.data[sbo][3].split()
if 'UNSUPPORTED' in sources: 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: def is_installed(self, packages: list) -> None:
""" Checking for installed packages. """ """ Checking for installed packages. """
@ -75,7 +75,7 @@ class Check(Configs):
not_found.append(pkg) not_found.append(pkg)
if not_found: 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: def is_empty_database(self, repo: str) -> None:
""" Checking for empty table and database file. """ """ 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: 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" self.errors.raise_error_message("You need to update the package lists first, run:\n\n"
" $ 'slpkg update'\n" " $ 'slpkg update'\n"
" $ 'slpkg update --bin-repo='*' for binaries") " $ 'slpkg update --bin-repo='*' for binaries", exit_status=1)

View file

@ -45,4 +45,4 @@ class Md5sum:
with open(filename, 'rb') as f: with open(filename, 'rb') as f:
return f.read() return f.read()
except FileNotFoundError: 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)

View file

@ -25,7 +25,7 @@ class FormConfigs(Configs):
""" Checking if the dialog box is enabled by the user. """ """ Checking if the dialog box is enabled by the user. """
if not self.dialog: if not self.dialog:
self.errors.raise_error_message(f"You should enable the dialog in the " 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: def edit(self) -> None:
""" Read and write the configuration file. """ """ Read and write the configuration file. """

View file

@ -61,7 +61,7 @@ class Downloader(Configs):
command: str = f'{self.downloader} {self.lftp_get_options} {url} -o {self.path}' command: str = f'{self.downloader} {self.lftp_get_options} {url} -o {self.path}'
else: 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.utils.process(command)
self.check_if_downloaded(url) self.check_if_downloaded(url)
@ -73,4 +73,4 @@ class Downloader(Configs):
path_file: Path = Path(self.path, file) path_file: Path = Path(self.path, file)
if not path_file.exists(): 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)

View file

@ -10,6 +10,7 @@ class Errors(Configs):
def __init__(self): def __init__(self):
super(Configs, self).__init__() 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. """ """ 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)

View file

@ -298,7 +298,7 @@ class Slackbuilds(Configs):
try: try:
package: str = max(packages) package: str = max(packages)
except ValueError: 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 return package

View file

@ -131,7 +131,7 @@ class Utilities(Configs):
yield package yield package
except FileNotFoundError: 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 @staticmethod
def read_file(file: Union[str, Path]) -> list: 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: with open(file, 'r', encoding='utf-8', errors='replace') as f:
return f.readlines() return f.readlines()
@staticmethod def process(self, command: str, stderr=None, stdout=None) -> None:
def process(command: str, stderr=None, stdout=None) -> None:
""" Handle the processes. """ """ Handle the processes. """
output: int = 0
try: try:
output = subprocess.call(command, shell=True, stderr=stderr, stdout=stdout) output = subprocess.call(command, shell=True, stderr=stderr, stdout=stdout)
except (KeyboardInterrupt, subprocess.CalledProcessError) as err: except (KeyboardInterrupt, subprocess.CalledProcessError) as err:
raise SystemExit(err) self.errors.raise_error_message(err, exit_status=20)
if output != 0: 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: def get_file_size(self, file: Path) -> str:
""" Get the local file size and converted to units. """ """ Get the local file size and converted to units. """