[config] adding config loading function
This commit is contained in:
parent
b22ef04317
commit
e16211b988
@ -102,15 +102,20 @@ class Config:
|
|||||||
metadata: Metadata
|
metadata: Metadata
|
||||||
pyrelacs: PyRelacs
|
pyrelacs: PyRelacs
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def load_config(cls):
|
def load_config():
|
||||||
pyrelacs_config_path = pathlib.Path(__file__).parent / "config.yaml"
|
pyrelacs_config_path = pathlib.Path(__file__).parent.parent / "config.yaml"
|
||||||
log.debug(pyrelacs_config_path)
|
log.debug(pyrelacs_config_path)
|
||||||
if not pyrelacs_config_path.is_file():
|
if not pyrelacs_config_path.is_file():
|
||||||
log.error("Config File was not found")
|
log.error("Config File was not found")
|
||||||
with open(pyrelacs_config_path, "r") as config_file:
|
with open(pyrelacs_config_path, "r") as config_file:
|
||||||
try:
|
try:
|
||||||
return yaml.full_load(config_file)
|
data = yaml.full_load(config_file)
|
||||||
|
try:
|
||||||
|
config = from_dict(data_class=Config, data=data)
|
||||||
|
return config
|
||||||
|
except dacite.DaciteError as e:
|
||||||
|
log.error(f"Invalid Config, {e}")
|
||||||
except yaml.YAMLError as e:
|
except yaml.YAMLError as e:
|
||||||
raise yaml.YAMLError(f"Error parsing YAML file: {e}")
|
raise yaml.YAMLError(f"Error parsing YAML file: {e}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user