Updated for dataclass

This commit is contained in:
Dimitris Zlatanidis 2023-03-21 17:35:28 +02:00
parent 87f58a0fba
commit aa57091b42

View file

@ -4,86 +4,93 @@
import tomli
from pathlib import Path
from dataclasses import dataclass
from slpkg.configs import Configs
from slpkg.models.models import session as Session
class Repositories(Configs):
@dataclass
class Repositories:
config = Configs
color = config.colour()
bold: str = color['bold']
red: str = color['red']
cyan: str = color['cyan']
endc: str = color['endc']
bred: str = f'{bold}{red}'
repositories_file_toml = Path(config.etc_path, 'repositories.toml')
def __init__(self):
super(Configs, self).__init__()
self.session = Session
repos = {}
self.color = self.colour()
self.bold: str = self.color['bold']
self.red: str = self.color['red']
self.cyan: str = self.color['cyan']
self.endc: str = self.color['endc']
self.bred: str = f'{self.bold}{self.red}'
self.repositories_file_toml = Path(self.etc_path, 'repositories.toml')
sbo_repo_name: str = 'sbo'
sbo_repo_path: Path = Path(config.lib_path, 'repositories', sbo_repo_name)
sbo_repo_url: str = "https://slackbuilds.org/slackbuilds/15.0/"
sbo_repo_txt: str = "SLACKBUILDS.TXT"
sbo_repo_chglog_txt: str = "ChangeLog.txt"
sbo_repo_tar_suffix: str = ".tar.gz"
sbo_repo_tag: str = "_SBo"
self.repos: dict = {}
ponce_repo_name: str = 'ponce'
ponce_repo: bool = False
ponce_repo_path: Path = Path(config.lib_path, 'repositories', ponce_repo_name)
ponce_repo_url: str = "https://cgit.ponce.cc/slackbuilds/plain/"
ponce_repo_txt: str = "SLACKBUILDS.TXT"
ponce_repo_chglog_txt: str = "ChangeLog.txt"
ponce_repo_tag: str = "_SBo"
self.sbo_repo_name: str = 'sbo'
self.sbo_repo_path: Path = Path(self.lib_path, 'repositories', 'sbo')
self.sbo_repo_url: str = "https://slackbuilds.org/slackbuilds/15.0/"
self.sbo_repo_txt: str = "SLACKBUILDS.TXT"
self.sbo_repo_chglog_txt: str = "ChangeLog.txt"
self.sbo_repo_tar_suffix: str = ".tar.gz"
self.sbo_repo_tag: str = "_SBo"
gnome_repo_name: str = 'gnome'
gnome_repo: bool = True
gnome_repo_path: Path = Path(config.lib_path, 'repositories', gnome_repo_name)
gnome_repo_url: str = "https://reddoglinux.ddns.net/linux/gnome/43.x/x86_64/"
gnome_repo_pkg_txt: str = "PACKAGES.TXT"
gnome_repo_chglog_pkg_txt: str = "ChangeLog.txt"
self.ponce_repo_name: str = 'ponce'
self.ponce_repo: bool = False
self.ponce_repo_path: Path = Path(self.lib_path, 'repositories', 'ponce')
self.ponce_repo_url: str = "https://cgit.ponce.cc/slackbuilds/plain/"
self.ponce_repo_txt: str = "SLACKBUILDS.TXT"
self.ponce_repo_chglog_txt: str = "ChangeLog.txt"
self.ponce_repo_tag: str = "_SBo"
conraid_repo_name: str = 'conraid'
conraid_repo: bool = True
conraid_repo_path: Path = Path(config.lib_path, 'repositories', conraid_repo_name)
conraid_repo_url: str = "https://reddoglinux.ddns.net/linux/conraid_43.x/x86_64/"
conraid_repo_pkg_txt: str = "PACKAGES.TXT"
conraid_repo_chglog_pkg_txt: str = "ChangeLog.txt"
self.gnome_repo_name: str = 'gnome'
self.gnome_repo: bool = True
self.gnome_repo_path: Path = Path(self.lib_path, 'repositories', 'gnome')
self.gnome_repo_url: str = "https://reddoglinux.ddns.net/linux/gnome/43.x/x86_64/"
self.gnome_repo_pkg_txt: str = "PACKAGES.TXT"
self.gnome_repo_chglog_pkg_txt: str = "ChangeLog.txt"
repo_tag: str = sbo_repo_tag
self.repo_tag: str = self.sbo_repo_tag
try:
if repositories_file_toml.is_file():
with open(repositories_file_toml, 'rb') as repo:
repos = tomli.load(repo)['REPOSITORIES']
def configs(self) -> None:
""" The repositories.toml configurations file. """
sbo_repo_name: str = repos['SBO_REPO_NAME']
sbo_repo_url: str = repos['SBO_REPO_URL']
sbo_repo_txt: str = repos['SBO_REPO_TXT']
sbo_repo_chglog_txt: str = repos['SBO_REPO_CHGLOG_TXT']
sbo_repo_tar_suffix: str = repos['SBO_REPO_TAR_SUFFIX']
sbo_repo_tag: str = repos['SBO_REPO_TAG']
try:
if self.repositories_file_toml.is_file():
with open(self.repositories_file_toml, 'rb') as repo:
self.repos: dict = tomli.load(repo)['REPOSITORIES']
ponce_repo_name: str = repos['PONCE_REPO_NAME']
ponce_repo: bool = repos['PONCE_REPO']
ponce_repo_url: str = repos['PONCE_REPO_URL']
ponce_repo_txt: str = repos['PONCE_REPO_TXT']
ponce_repo_chglog_txt: str = repos['PONCE_REPO_CHGLOG_TXT']
ponce_repo_tag: str = repos['PONCE_REPO_TAG']
self.sbo_repo_name: str = self.repos['SBO_REPO_NAME']
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']
gnome_repo_name: str = repos['GNOME_REPO_NAME']
gnome_repo: bool = repos['GNOME_REPO']
gnome_repo_url: str = repos['GNOME_REPO_URL']
gnome_repo_pkg_txt: str = repos['GNOME_REPO_PKG_TXT']
gnome_repo_chglog_pkg_txt: str = repos['GNOME_REPO_CHGLOG_TXT']
self.ponce_repo_name: str = self.repos['PONCE_REPO_NAME']
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']
conraid_repo_name: str = repos['CONRAID_REPO_NAME']
conraid_repo: bool = repos['CONRAID_REPO']
conraid_repo_url: str = repos['CONRAID_REPO_URL']
conraid_repo_pkg_txt: str = repos['CONRAID_REPO_PKG_TXT']
conraid_repo_chglog_pkg_txt: str = repos['CONRAID_REPO_CHGLOG_TXT']
self.gnome_repo_name: str = self.repos['GNOME_REPO_NAME']
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{config.prog_name} {bred}Error{endc}: {error}: in the configuration file "
f"'{repositories_file_toml}'.\n"
f"\nIf you have upgraded the '{config.prog_name}' probably you need to run:\n"
f"'mv {repositories_file_toml}.new {repositories_file_toml}'.\n"
f"or '{cyan}slpkg_new-configs{endc}' command.\n")
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
if ponce_repo:
repo_tag: str = ponce_repo_tag