mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-18 10:26:29 +01:00
Updated for load configs
This commit is contained in:
parent
2dd818078a
commit
e821febc9c
2 changed files with 9 additions and 25 deletions
|
@ -11,23 +11,6 @@ from slpkg.errors_messages import Errors
|
|||
from slpkg.logging_config import LoggingConfig
|
||||
|
||||
|
||||
class Load:
|
||||
|
||||
def __init__(self):
|
||||
self.errors = Errors()
|
||||
|
||||
def config_file(self, path: Path, file: str) -> dict: # type: ignore
|
||||
try:
|
||||
""" Load the configs from the file. """
|
||||
config_path_file = Path(path, f'{file}.toml')
|
||||
if config_path_file.exists():
|
||||
with open(config_path_file, 'rb') as conf:
|
||||
return tomli.load(conf)
|
||||
except tomli.TOMLDecodeError as error:
|
||||
pass
|
||||
self.errors.raise_toml_error_message(error, toml_file='/etc/slpkg/slpkg.toml')
|
||||
|
||||
|
||||
@dataclass
|
||||
class Configs:
|
||||
""" Default configurations. """
|
||||
|
@ -68,11 +51,14 @@ class Configs:
|
|||
proxy_username: str = ''
|
||||
proxy_password: str = ''
|
||||
|
||||
load = Load()
|
||||
configs = load.config_file(etc_path, prog_name)
|
||||
try:
|
||||
config_path_file = Path(etc_path, f'{prog_name}.toml')
|
||||
|
||||
if configs:
|
||||
try:
|
||||
if config_path_file.exists():
|
||||
with open(config_path_file, 'rb') as conf:
|
||||
configs = tomli.load(conf)
|
||||
|
||||
if configs:
|
||||
config = configs['CONFIGS']
|
||||
|
||||
os_arch: str = config['OS_ARCH']
|
||||
|
@ -99,8 +85,8 @@ class Configs:
|
|||
proxy_username: str = config['PROXY_USERNAME']
|
||||
proxy_password: str = config['PROXY_PASSWORD']
|
||||
|
||||
except KeyError as error:
|
||||
errors.raise_toml_error_message(error, toml_file='/etc/slpkg/slpkg.toml')
|
||||
except (KeyError, tomli.TOMLDecodeError) as error:
|
||||
errors.raise_toml_error_message(error, toml_file='/etc/slpkg/slpkg.toml')
|
||||
|
||||
# Creating the paths if not exists
|
||||
paths = [
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from slpkg.configs import Load
|
||||
from slpkg.configs import Configs
|
||||
from slpkg.utilities import Utilities
|
||||
from slpkg.dialog_box import DialogBox
|
||||
|
@ -15,7 +14,6 @@ class FormConfigs(Configs):
|
|||
|
||||
def __init__(self):
|
||||
super(Configs).__init__()
|
||||
self.load_configs = Load()
|
||||
self.dialogbox = DialogBox()
|
||||
self.errors = Errors()
|
||||
self.utils = Utilities()
|
||||
|
|
Loading…
Reference in a new issue