Rename load_config_from_file to more descriptive parse_config_from_file

This commit is contained in:
Debanjum Singh Solanky
2022-08-10 22:28:51 +03:00
parent 328cc00439
commit 62eb66b8ca
2 changed files with 20 additions and 5 deletions

View File

@@ -5,11 +5,26 @@ import yaml
from src.utils.helpers import get_absolute_path
from src.utils.rawconfig import FullConfig
def save_config_to_file(yaml_config, yaml_config_file):
"Write config to YML file"
with open(get_absolute_path(yaml_config_file), 'w', encoding='utf-8') as config_file:
yaml.dump(yaml_config, config_file, allow_unicode=True)
def load_config_from_file(yaml_config_file):
# Read Config from YML file
"Read config from YML file"
config_from_file = None
with open(get_absolute_path(yaml_config_file), 'r', encoding='utf-8') as config_file:
config_from_file = yaml.safe_load(config_file)
return config_from_file
# Parse, Validate Config in YML file
return FullConfig.parse_obj(config_from_file)
def parse_config_from_string(yaml_config):
"Parse and validate config in YML string"
return FullConfig.parse_obj(yaml_config)
def parse_config_from_file(yaml_config_file):
"Parse and validate config in YML file"
return parse_config_from_string(load_config_from_file(yaml_config_file))