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.
.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
.P
Configuration file in the /etc/slpkg/slpkg.toml file.

View file

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

View file

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

View file

@ -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. """

View file

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

View file

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

View file

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

View file

@ -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. """