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