mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-19 10:27:07 +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
|
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
|
@dataclass
|
||||||
class Configs:
|
class Configs:
|
||||||
""" Default configurations. """
|
""" Default configurations. """
|
||||||
|
@ -68,11 +51,14 @@ class Configs:
|
||||||
proxy_username: str = ''
|
proxy_username: str = ''
|
||||||
proxy_password: str = ''
|
proxy_password: str = ''
|
||||||
|
|
||||||
load = Load()
|
try:
|
||||||
configs = load.config_file(etc_path, prog_name)
|
config_path_file = Path(etc_path, f'{prog_name}.toml')
|
||||||
|
|
||||||
if configs:
|
if config_path_file.exists():
|
||||||
try:
|
with open(config_path_file, 'rb') as conf:
|
||||||
|
configs = tomli.load(conf)
|
||||||
|
|
||||||
|
if configs:
|
||||||
config = configs['CONFIGS']
|
config = configs['CONFIGS']
|
||||||
|
|
||||||
os_arch: str = config['OS_ARCH']
|
os_arch: str = config['OS_ARCH']
|
||||||
|
@ -99,8 +85,8 @@ class Configs:
|
||||||
proxy_username: str = config['PROXY_USERNAME']
|
proxy_username: str = config['PROXY_USERNAME']
|
||||||
proxy_password: str = config['PROXY_PASSWORD']
|
proxy_password: str = config['PROXY_PASSWORD']
|
||||||
|
|
||||||
except KeyError as error:
|
except (KeyError, tomli.TOMLDecodeError) as error:
|
||||||
errors.raise_toml_error_message(error, toml_file='/etc/slpkg/slpkg.toml')
|
errors.raise_toml_error_message(error, toml_file='/etc/slpkg/slpkg.toml')
|
||||||
|
|
||||||
# Creating the paths if not exists
|
# Creating the paths if not exists
|
||||||
paths = [
|
paths = [
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from slpkg.configs import Load
|
|
||||||
from slpkg.configs import Configs
|
from slpkg.configs import Configs
|
||||||
from slpkg.utilities import Utilities
|
from slpkg.utilities import Utilities
|
||||||
from slpkg.dialog_box import DialogBox
|
from slpkg.dialog_box import DialogBox
|
||||||
|
@ -15,7 +14,6 @@ class FormConfigs(Configs):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Configs).__init__()
|
super(Configs).__init__()
|
||||||
self.load_configs = Load()
|
|
||||||
self.dialogbox = DialogBox()
|
self.dialogbox = DialogBox()
|
||||||
self.errors = Errors()
|
self.errors = Errors()
|
||||||
self.utils = Utilities()
|
self.utils = Utilities()
|
||||||
|
|
Loading…
Reference in a new issue