mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-18 10:26:29 +01:00
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
import tomli
|
|
from pathlib import Path
|
|
|
|
from slpkg.configs import Configs
|
|
from slpkg.models.models import session as Session
|
|
|
|
|
|
class Repositories(Configs):
|
|
|
|
def __init__(self):
|
|
super(Configs, self).__init__()
|
|
self.session = Session
|
|
|
|
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')
|
|
|
|
def configs(self) -> dict:
|
|
""" Reads the repositories file. """
|
|
|
|
if self.repositories_file_toml.is_file():
|
|
try:
|
|
with open(self.repositories_file_toml, 'rb') as repo:
|
|
return 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")
|
|
return []
|