mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-29 20:34:22 +01:00
Updated for error messages
This commit is contained in:
parent
f683d8cf6c
commit
bf3591ef63
6 changed files with 22 additions and 30 deletions
|
@ -31,7 +31,7 @@ class Blacklist(Configs):
|
|||
with open(self.blacklist_file_toml, 'rb') as black:
|
||||
return tomli.load(black)['BLACKLIST']['PACKAGES']
|
||||
except (tomli.TOMLDecodeError, KeyError) as error:
|
||||
raise SystemExit(f"\n[{self.bred}Error{self.endc}]: {error}: in the configuration file "
|
||||
raise SystemExit(f"\n{self.prog_name} {self.bred}Error{self.endc}: {error}: in the configuration file "
|
||||
f"'/etc/slpkg/blacklist.toml'.\n"
|
||||
f"\nIf you have upgraded the '{self.prog_name}' probably you need to run:\n"
|
||||
f"'mv {self.etc_path}/blacklist.toml.new {self.etc_path}/blacklist.toml'.\n"
|
||||
|
|
|
@ -43,8 +43,7 @@ class Check(Configs):
|
|||
not_packages.append(sbo)
|
||||
|
||||
if not_packages:
|
||||
raise SystemExit(f"\n[{self.bred}Error{self.endc}]: Packages "
|
||||
f"'{self.cyan}{', '.join(not_packages)}{self.endc}' does not exists.\n")
|
||||
self.utils.raise_error_message(f"Packages '{', '.join(not_packages)}' does not exists")
|
||||
|
||||
def is_package_unsupported(self, slackbuilds: list) -> None:
|
||||
""" Checking for unsupported slackbuilds. """
|
||||
|
@ -52,8 +51,7 @@ class Check(Configs):
|
|||
sources = SBoQueries(sbo).sources()
|
||||
|
||||
if 'UNSUPPORTED' in sources:
|
||||
raise SystemExit(f"\n[{self.bred}Error{self.endc}]: Package "
|
||||
f"'{self.cyan}{sbo}{self.endc}' unsupported by arch.\n")
|
||||
self.utils.raise_error_message(f"Package '{sbo}' unsupported by arch")
|
||||
|
||||
def is_installed(self, slackbuilds: list, file_pattern: str) -> None:
|
||||
""" Checking for installed packages. """
|
||||
|
@ -65,8 +63,7 @@ class Check(Configs):
|
|||
not_found.append(sbo)
|
||||
|
||||
if not_found:
|
||||
raise SystemExit(f'\n[{self.bred}Error{self.endc}]: Not found \'{", ".join(not_found)}\' '
|
||||
'installed packages.\n')
|
||||
self.utils.raise_error_message(f'Not found \'{", ".join(not_found)}\' installed packages')
|
||||
|
||||
def is_blacklist(self, slackbuilds: list) -> None:
|
||||
""" Checking if the packages are blacklisted. """
|
||||
|
|
|
@ -25,7 +25,7 @@ class Load:
|
|||
with open(config_path_file, 'rb') as conf:
|
||||
return tomli.load(conf)
|
||||
except tomli.TOMLDecodeError as error:
|
||||
raise SystemExit(f"\n[{self.bred}Error{self.endc}]: {error}: in the configuration file "
|
||||
raise SystemExit(f"\nslpkg: {self.bred}Error{self.endc}: {error}: in the configuration file "
|
||||
"'/etc/slpkg/slpkg.toml'\n")
|
||||
|
||||
|
||||
|
@ -216,7 +216,7 @@ class Configs:
|
|||
spinner_color: str = config['SPINNER_COLOR']
|
||||
|
||||
except KeyError as error:
|
||||
raise SystemExit(f"\n[{color['bold']}{color['red']}Error{color['endc']}]: "
|
||||
raise SystemExit(f"\n{prog_name}: {color['bold']}{color['red']}Error{color['endc']}: "
|
||||
f"{error}: in the configuration file '/etc/slpkg/slpkg.toml'.\n"
|
||||
f"\nIf you have upgraded the '{prog_name}' probably you need to run:\n"
|
||||
f"'mv {etc_path}/{prog_name}.toml.new {etc_path}/{prog_name}.toml'.\n"
|
||||
|
|
|
@ -18,14 +18,8 @@ class Downloader(Configs):
|
|||
self.urls: list = urls
|
||||
self.flags: list = flags
|
||||
|
||||
self.color = self.colour()
|
||||
self.utils = Utilities()
|
||||
|
||||
self.bold: str = self.color['bold']
|
||||
self.cyan: str = self.color['cyan']
|
||||
self.red: str = self.color['red']
|
||||
self.endc: str = self.color['endc']
|
||||
self.bred: str = f'{self.bold}{self.red}'
|
||||
self.flag_parallel: list = ['-P', '--parallel']
|
||||
|
||||
def download(self):
|
||||
|
@ -46,6 +40,7 @@ class Downloader(Configs):
|
|||
|
||||
def tools(self, url: str) -> None:
|
||||
""" Downloader tools wget, curl and lftp. """
|
||||
command: str = ''
|
||||
filename: str = url.split('/')[-1]
|
||||
|
||||
if self.downloader == 'wget':
|
||||
|
@ -58,7 +53,7 @@ class Downloader(Configs):
|
|||
command: str = f'lftp {self.lftp_get_options} {url} -o {self.path}'
|
||||
|
||||
else:
|
||||
raise SystemExit(f"{self.red}Error:{self.endc} Downloader '{self.downloader}' not supported.\n")
|
||||
self.utils.raise_error_message(f"Downloader '{self.downloader}' not supported")
|
||||
|
||||
self.utils.process(command)
|
||||
self.check_if_downloaded(url)
|
||||
|
@ -70,5 +65,4 @@ class Downloader(Configs):
|
|||
path_file = Path(self.path, file)
|
||||
|
||||
if not path_file.exists():
|
||||
raise SystemExit(f"\n[{self.bred}FAILED{self.endc}]: Download the '{self.cyan}{file}{self.endc}' "
|
||||
f"file.\n")
|
||||
self.utils.raise_error_message(f"Download the '{file}' file")
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from slpkg.configs import Configs
|
||||
from slpkg.configs import Load
|
||||
from slpkg.configs import Configs
|
||||
from slpkg.utilities import Utilities
|
||||
from slpkg.dialog_box import DialogBox
|
||||
|
||||
|
||||
|
@ -15,21 +16,16 @@ class FormConfigs(Configs):
|
|||
super(Configs).__init__()
|
||||
self.load_configs = Load()
|
||||
self.dialogbox = DialogBox()
|
||||
self.color = self.colour()
|
||||
self.utils = Utilities()
|
||||
|
||||
self.orig_configs: list = []
|
||||
self.config_file = Path(self.etc_path, f'{self.prog_name}.toml')
|
||||
|
||||
self.bold: str = self.color['bold']
|
||||
self.red: str = self.color['red']
|
||||
self.endc: str = self.color['endc']
|
||||
self.bred: str = f'{self.bold}{self.red}'
|
||||
|
||||
def is_dialog_enabled(self):
|
||||
""" Checking if the dialog box is enabled by the user. """
|
||||
if not self.dialog:
|
||||
raise SystemExit(f"\n[{self.bred}Error{self.endc}]: You should enable the dialog "
|
||||
"in the '/etc/slpkg/slpkg.toml' file.\n")
|
||||
self.utils.raise_error_message(f"You should enable the dialog "
|
||||
f"in the '{self.etc_path}/{self.prog_name}.toml' file")
|
||||
|
||||
def edit(self) -> None:
|
||||
""" Read and write the configuration file. """
|
||||
|
|
|
@ -23,9 +23,12 @@ class Utilities:
|
|||
self.color = self.colors()
|
||||
self.black = Blacklist()
|
||||
|
||||
self.bold: str = self.color['bold']
|
||||
self.yellow: str = self.color['yellow']
|
||||
self.cyan: str = self.color['cyan']
|
||||
self.endc: str = self.color['endc']
|
||||
self.red: str = self.color['red']
|
||||
self.bred: str = f'{self.bold}{self.red}'
|
||||
|
||||
def is_package_installed(self, name: str, pattern: str) -> str:
|
||||
""" Returns the installed package name. """
|
||||
|
@ -143,8 +146,7 @@ class Utilities:
|
|||
""" Checking for flags. """
|
||||
return [f for f in flag if f in flags]
|
||||
|
||||
@staticmethod
|
||||
def read_packages_from_file(file: Path) -> Generator:
|
||||
def read_packages_from_file(self, file: Path) -> Generator:
|
||||
""" Reads packages from file and split these to list. """
|
||||
try:
|
||||
|
||||
|
@ -159,7 +161,7 @@ class Utilities:
|
|||
yield package
|
||||
|
||||
except FileNotFoundError as err:
|
||||
raise SystemExit(f'Error: {err}')
|
||||
self.raise_error_message(str(err))
|
||||
|
||||
@staticmethod
|
||||
def read_file(file: Union[str, Path]) -> list:
|
||||
|
@ -176,3 +178,6 @@ class Utilities:
|
|||
raise SystemExit(output)
|
||||
except KeyboardInterrupt:
|
||||
raise SystemExit(1)
|
||||
|
||||
def raise_error_message(self, message: str) -> None:
|
||||
raise SystemExit(f"\n{self.configs.prog_name}: {self.bred}Error{self.endc}: {message}.\n")
|
||||
|
|
Loading…
Add table
Reference in a new issue