Fixed for KeyError

This commit is contained in:
Dimitris Zlatanidis 2023-03-20 21:16:39 +02:00
parent 5dfe1ef6f7
commit 5d76680e0e

View file

@ -50,33 +50,34 @@ class Repositories(Configs):
def configs(self) -> None:
""" The repositories.toml configurations file. """
if self.repositories_file_toml.is_file():
try:
try:
if self.repositories_file_toml.is_file():
with open(self.repositories_file_toml, 'rb') as repo:
self.repos: dict = tomli.load(repo)['REPOSITORIES']
except (tomli.TOMLDecodeError, KeyError) as error:
raise SystemExit(f"\n{self.prog_name} {self.bred}Error{self.endc}: {error}: in the configuration file "
f"'{self.repositories_file_toml}'.\n"
f"\nIf you have upgraded the '{self.prog_name}' probably you need to run:\n"
f"'mv {self.repositories_file_toml}.new {self.repositories_file_toml}'.\n"
f"or '{self.cyan}slpkg_new-configs{self.endc}' command.\n")
self.sbo_repo_url: str = self.repos['SBO_REPO_URL']
self.sbo_repo_txt: str = self.repos['SBO_REPO_TXT']
self.sbo_repo_chglog_txt: str = self.repos['SBO_REPO_CHGLOG_TXT']
self.sbo_repo_tar_suffix: str = self.repos['SBO_REPO_TAR_SUFFIX']
self.sbo_repo_tag: str = self.repos['SBO_REPO_TAG']
self.sbo_repo_url: str = self.repos['SBO_REPO_URL']
self.sbo_repo_txt: str = self.repos['SBO_REPO_TXT']
self.sbo_repo_chglog_txt: str = self.repos['SBO_REPO_CHGLOG_TXT']
self.sbo_repo_tar_suffix: str = self.repos['SBO_REPO_TAR_SUFFIX']
self.sbo_repo_tag: str = self.repos['SBO_REPO_TAG']
self.ponce_repo: bool = self.repos['PONCE_REPO']
self.ponce_repo_url: str = self.repos['PONCE_REPO_URL']
self.ponce_repo_txt: str = self.repos['PONCE_REPO_TXT']
self.ponce_repo_chglog_txt: str = self.repos['PONCE_REPO_CHGLOG_TXT']
self.ponce_repo_tag: str = self.repos['PONCE_REPO_TAG']
self.ponce_repo: bool = self.repos['PONCE_REPO']
self.ponce_repo_url: str = self.repos['PONCE_REPO_URL']
self.ponce_repo_txt: str = self.repos['PONCE_REPO_TXT']
self.ponce_repo_chglog_txt: str = self.repos['PONCE_REPO_CHGLOG_TXT']
self.ponce_repo_tag: str = self.repos['PONCE_REPO_TAG']
self.gnome_repo: bool = self.repos['GNOME_REPO']
self.gnome_repo_url: str = self.repos['GNOME_REPO_URL']
self.gnome_repo_pkg_txt: str = self.repos['GNOME_REPO_PKG_TXT']
self.gnome_repo_chglog_pkg_txt: str = self.repos['GNOME_REPO_CHGLOG_TXT']
self.gnome_repo: bool = self.repos['GNOME_REPO']
self.gnome_repo_url: str = self.repos['GNOME_REPO_URL']
self.gnome_repo_pkg_txt: str = self.repos['GNOME_REPO_PKG_TXT']
self.gnome_repo_chglog_pkg_txt: str = self.repos['GNOME_REPO_CHGLOG_TXT']
except (tomli.TOMLDecodeError, KeyError) as error:
raise SystemExit(f"\n{self.prog_name} {self.bred}Error{self.endc}: {error}: in the configuration file "
f"'{self.repositories_file_toml}'.\n"
f"\nIf you have upgraded the '{self.prog_name}' probably you need to run:\n"
f"'mv {self.repositories_file_toml}.new {self.repositories_file_toml}'.\n"
f"or '{self.cyan}slpkg_new-configs{self.endc}' command.\n")
if self.ponce_repo:
self.repo_tag: str = self.ponce_repo_tag