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