Dorothydu's picture
Add files using upload-large-folder tool
8f79b61 verified
import yaml
from easydict import EasyDict
class YamlConfigManager:
def __init__(self, config_file_path, config_name):
super().__init__()
self.values = EasyDict()
if config_file_path:
self.config_file_path = config_file_path
self.config_name = config_name
self.reload()
def reload(self):
self.clear()
if self.config_file_path:
with open(self.config_file_path, 'r') as f:
self.values.update(yaml.safe_load(f)[self.config_name])
def clear(self):
self.values.clear()
def update(self, yml_dict):
for (k1, v1) in yml_dict.items():
if isinstance(v1, dict):
for (k2, v2) in v1.items():
if isinstance(v2, dict):
for (k3, v3) in v2.items():
self.values[k1][k2][k3] = v3
else:
self.values[k1][k2] = v2
else:
self.values[k1] = v1
def export(self, save_file_path):
if save_file_path:
with open(save_file_path, 'w') as f:
yaml.dump(dict(self.values), f)