mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 21:14:15 +02:00
[config] new general config file
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
|
||||
import yaml
|
||||
|
||||
@@ -7,13 +8,10 @@ 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:
|
||||
def read_config(file_path: str, template: dict, update_file: bool = False, update_async: 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))
|
||||
|
||||
save_config(template, file_path)
|
||||
else:
|
||||
with open(file_path) as f:
|
||||
local_config = yaml.safe_load(f.read())
|
||||
@@ -22,7 +20,14 @@ def read_config(file_path: str, template: dict, update_file: bool = False) -> di
|
||||
util.deep_update(template, local_config)
|
||||
|
||||
if update_file:
|
||||
with open(file_path, 'w+') as f:
|
||||
f.write(yaml.dump(template))
|
||||
if update_async:
|
||||
Thread(target=save_config, args=(template, file_path), daemon=True).start()
|
||||
else:
|
||||
save_config(template, file_path)
|
||||
|
||||
return template
|
||||
|
||||
|
||||
def save_config(config: dict, file_path: str):
|
||||
with open(file_path, 'w+') as f:
|
||||
f.write(yaml.dump(config))
|
||||
|
||||
Reference in New Issue
Block a user