mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 19:44:15 +02:00
29 lines
703 B
Python
29 lines
703 B
Python
import os
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
from bauh.api.constants import CONFIG_PATH
|
|
from bauh.commons import util
|
|
|
|
|
|
def read_config(file_path: str, template: dict, update_file: bool = False) -> dict:
|
|
if not os.path.exists(file_path):
|
|
Path(CONFIG_PATH).mkdir(parents=True, exist_ok=True)
|
|
|
|
with open(file_path, 'w+') as f:
|
|
f.write(yaml.dump(template))
|
|
|
|
else:
|
|
with open(file_path) as f:
|
|
local_config = yaml.safe_load(f.read())
|
|
|
|
if local_config:
|
|
util.deep_update(template, local_config)
|
|
|
|
if update_file:
|
|
with open(file_path, 'w+') as f:
|
|
f.write(yaml.dump(template))
|
|
|
|
return template
|