2023-03-27 19:40:52 -07:00
|
|
|
|
|
|
|
|
2024-06-09 09:22:48 -07:00
|
|
|
from domain.config.ConfigFile import ConfigFile
|
|
|
|
from domain.config.Scanner import Scanner
|
2023-03-27 19:40:52 -07:00
|
|
|
from domain.Logger import Logger
|
|
|
|
|
2024-06-09 07:50:34 -07:00
|
|
|
|
|
|
|
from pathlib import Path
|
2023-03-27 19:40:52 -07:00
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
2024-06-09 09:22:48 -07:00
|
|
|
def __init__(self, logger: Logger, config_files_paths: [Path]):
|
|
|
|
|
2023-03-27 19:59:45 -07:00
|
|
|
self.__logger = logger
|
2024-06-09 07:50:34 -07:00
|
|
|
|
2024-06-09 09:22:48 -07:00
|
|
|
self.__config_files_paths: [Path] = config_files_paths
|
2024-06-09 09:41:00 -07:00
|
|
|
self.__configs = {}
|
2023-03-27 19:40:52 -07:00
|
|
|
|
2024-06-09 09:22:48 -07:00
|
|
|
self.__scanner = Scanner(
|
|
|
|
logger=self.__logger
|
|
|
|
)
|
2023-03-27 19:40:52 -07:00
|
|
|
|
2024-06-09 09:22:48 -07:00
|
|
|
self._consume_configs()
|
|
|
|
|
2024-06-09 09:41:00 -07:00
|
|
|
def _consume_configs(self):
|
2023-03-27 19:40:52 -07:00
|
|
|
|
2024-06-09 09:41:00 -07:00
|
|
|
config_paths = self.__scanner.gather_valid_config_paths(
|
|
|
|
paths=self.__config_files_paths
|
|
|
|
)
|
2023-03-27 19:40:52 -07:00
|
|
|
|
2024-06-09 09:22:48 -07:00
|
|
|
for config_path in config_paths:
|
2024-06-09 07:50:34 -07:00
|
|
|
|
2024-06-09 09:22:48 -07:00
|
|
|
config = ConfigFile(
|
|
|
|
logger=self.__logger,
|
|
|
|
path=config_path
|
|
|
|
)
|
2023-03-27 19:59:45 -07:00
|
|
|
|
2024-06-09 09:22:48 -07:00
|
|
|
self.__configs[config.key] = config
|
2023-03-27 19:40:52 -07:00
|
|
|
|
2024-06-09 09:22:48 -07:00
|
|
|
@property
|
|
|
|
def config_files(self) -> [ConfigFile]:
|
|
|
|
return self.__configs.values()
|