mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
confi.get
This commit is contained in:
7
main.py
7
main.py
@ -8,13 +8,8 @@ from src.configuration import EnvConf, LogConf, singleton
|
|||||||
class Main():
|
class Main():
|
||||||
env_conf: EnvConf
|
env_conf: EnvConf
|
||||||
@inject
|
@inject
|
||||||
def __init__(self, log_config: LogConf, env_conf: EnvConf, log_handler: LogHandler) -> None:
|
def __init__(self, log_config: LogConf, env_conf: EnvConf) -> None:
|
||||||
self.env_conf=env_conf
|
self.env_conf=env_conf
|
||||||
logging.basicConfig(
|
|
||||||
handlers=[log_handler],
|
|
||||||
level=log_config.level,
|
|
||||||
datefmt=log_config.time_format,
|
|
||||||
format='%(asctime)s %(message)s')
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|||||||
@ -27,17 +27,17 @@ class Configuration():
|
|||||||
bbb:
|
bbb:
|
||||||
ccc: "hello world"
|
ccc: "hello world"
|
||||||
"""
|
"""
|
||||||
def get(self, path: str | list[str], cfg: dict = None, default = None):
|
def get(self, path: str | list[str], cfg: dict = None, default=None):
|
||||||
if isinstance(path, str):
|
if isinstance(path, str):
|
||||||
if cfg is None:
|
if cfg is None:
|
||||||
cfg = self.cfg
|
cfg = self.cfg
|
||||||
return self.get(path.split("."), cfg)
|
return self.get(path.split("."), cfg)
|
||||||
length = len(path)
|
length = len(path)
|
||||||
if length == 0 or not isinstance(cfg, dict):
|
if length == 0 or not isinstance(cfg, dict):
|
||||||
return None
|
return default
|
||||||
if length == 1:
|
if length == 1:
|
||||||
return cfg.get(path[0])
|
return cfg.get(path[0])
|
||||||
return self.get(path[1:], cfg.get(path[0]), default=default)
|
return self.get(path[1:], cfg.get(path[0]))
|
||||||
|
|
||||||
class TesouConf():
|
class TesouConf():
|
||||||
url: str
|
url: str
|
||||||
|
|||||||
Reference in New Issue
Block a user