Files
xiaozhi-esp32-server/config/settings.py
T

30 lines
900 B
Python
Raw Permalink Normal View History

2025-02-14 00:54:59 +08:00
import os
2025-02-02 23:01:14 +08:00
import argparse
from ruamel.yaml import YAML
2025-02-14 00:54:59 +08:00
from core.utils.util import read_config, get_project_dir
2025-02-02 23:01:14 +08:00
def get_config_file():
default_config_file = "config.yaml"
# 判断是否存在私有的配置文件
2025-02-16 16:58:07 +08:00
if os.path.exists(get_project_dir() + "data/." + default_config_file):
default_config_file = "data/." + default_config_file
return default_config_file
2025-02-02 23:01:14 +08:00
def load_config():
"""加载配置文件"""
parser = argparse.ArgumentParser(description="Server configuration")
default_config_file = get_config_file()
2025-02-14 00:54:59 +08:00
parser.add_argument("--config_path", type=str, default=default_config_file)
2025-02-02 23:01:14 +08:00
args = parser.parse_args()
return read_config(args.config_path)
def update_config(config):
yaml = YAML()
yaml.preserve_quotes = True
"""将配置保存到YAML文件"""
with open(get_config_file(), 'w') as f:
yaml.dump(config, f)