配置文件改回yml

This commit is contained in:
Elaina 2024-10-21 19:28:22 +08:00
parent 2e31ba8b52
commit 0a6826687e
2 changed files with 15 additions and 4 deletions

View file

@ -5,7 +5,9 @@ from threading import Event
from typing import TYPE_CHECKING, Any, Optional
import requests
import yaml
from pydantic import BaseModel
from yamlcore import CoreDumper, CoreLoader
from mower.utils.config.conf import Conf
from mower.utils.config.plan import PlanModel
@ -15,13 +17,22 @@ if TYPE_CHECKING:
from mower.utils.device.device import Device
from mower.utils.recognize import Recognizer
conf_path = get_path("@app/conf.json")
# conf_path = get_path("@app/conf.json")
conf_path = get_path("@app/conf.yml")
plan_path = get_path("@app/plan.json")
def save_conf():
with conf_path.open("w", encoding="utf8") as f:
json.dump(conf.model_dump(), f, ensure_ascii=False, indent=4) # Use json.dump
# json.dump(conf.model_dump(), f, ensure_ascii=False, indent=4) # Use json.dump
yaml.dump(
conf.model_dump(),
f,
Dumper=CoreDumper,
encoding="utf-8",
default_flow_style=False,
allow_unicode=True,
)
def load_conf():
@ -32,7 +43,8 @@ def load_conf():
save_conf()
return
with conf_path.open("r", encoding="utf-8") as f:
conf = Conf(**json.load(f))
# conf = Conf(**json.load(f))
conf = Conf(**yaml.load(f, Loader=CoreLoader))
conf: Conf