From bcbd556e7d37902371198f0d0dbe1902e06f48ee Mon Sep 17 00:00:00 2001 From: li-xiaochen <397721316@qq.com> Date: Sun, 15 Dec 2024 21:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=94=B9=E4=B8=BAjson=E7=B1=BB=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4yaml=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- launcher/config/__init__.py | 7 ++----- launcher/sys_config/__init__.py | 9 ++++----- launcher/sys_config/config_dist.json | 5 +++++ launcher/sys_config/config_dist.yaml | 3 --- launcher/sys_config/config_local.json | 5 +++++ launcher/sys_config/config_local.yaml | 3 --- 7 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 launcher/sys_config/config_dist.json delete mode 100644 launcher/sys_config/config_dist.yaml create mode 100644 launcher/sys_config/config_local.json delete mode 100644 launcher/sys_config/config_local.yaml diff --git a/README.md b/README.md index bfd89e0..1cd6865 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ 前端运行 `npm run build` 生成 `ui/dist`,之后安装 PyInstaller,运行 ```bash -pyinstaller -w --add-data "ui/dist:ui/dist" --add-data "launcher/sys_config/config_dist.yaml:launcher/sys_config" launcher.py +pyinstaller -w --add-data "ui/dist:ui/dist" --add-data "launcher/sys_config/config_dist.json:launcher/sys_config" launcher.py ``` 在dist文件夹生成launcher文件夹 diff --git a/launcher/config/__init__.py b/launcher/config/__init__.py index 972e9a5..01d7c22 100644 --- a/launcher/config/__init__.py +++ b/launcher/config/__init__.py @@ -2,9 +2,6 @@ import json import os from pathlib import Path -import yaml -from yamlcore import CoreLoader - from launcher.config.conf import Conf conf_path = Path(os.path.join(os.getcwd(), "conf.json")) @@ -22,8 +19,8 @@ def load_conf(): conf = Conf() save_conf() return - with conf_path.open("r", encoding="utf-8") as f: - data = yaml.load(f, Loader=CoreLoader) + with conf_path.open("r", encoding="utf-8") as file: + data = json.load(file) if data is None: data = {} conf = Conf(**data) diff --git a/launcher/sys_config/__init__.py b/launcher/sys_config/__init__.py index f0a93bf..78115eb 100644 --- a/launcher/sys_config/__init__.py +++ b/launcher/sys_config/__init__.py @@ -1,8 +1,7 @@ +import json import os import sys -import yaml - class SysConfig: """ @@ -26,13 +25,13 @@ class SysConfig: # 如果是打包后的可执行文件 base_path = sys._MEIPASS config_subdir = 'launcher/sys_config' # 添加子目录 - config_filename = 'config_dist.yaml' + config_filename = 'config_dist.json' else: # logger.error("本地配置") # 如果是本地开发环境 base_path = os.path.dirname(__file__) config_subdir = '' # 本地开发环境不需要子目录 - config_filename = 'config_local.yaml' + config_filename = 'config_local.json' config_path = os.path.join(base_path, config_subdir, config_filename) return config_path @@ -40,7 +39,7 @@ class SysConfig: def load_config(self): try: with open(self.config_path, 'r', encoding='utf-8') as file: - self.config = yaml.safe_load(file) + self.config = json.load(file) except FileNotFoundError: pass # logger.error(f"配置文件未找到: {self.config_path}") diff --git a/launcher/sys_config/config_dist.json b/launcher/sys_config/config_dist.json new file mode 100644 index 0000000..01d4337 --- /dev/null +++ b/launcher/sys_config/config_dist.json @@ -0,0 +1,5 @@ +{ + "version": "v0.4", + "url": "ui/dist/index.html", + "log_level": "ERROR" +} \ No newline at end of file diff --git a/launcher/sys_config/config_dist.yaml b/launcher/sys_config/config_dist.yaml deleted file mode 100644 index def4021..0000000 --- a/launcher/sys_config/config_dist.yaml +++ /dev/null @@ -1,3 +0,0 @@ -version: "v0.4" -url: "ui/dist/index.html" -log_level: "ERROR" \ No newline at end of file diff --git a/launcher/sys_config/config_local.json b/launcher/sys_config/config_local.json new file mode 100644 index 0000000..8b1423e --- /dev/null +++ b/launcher/sys_config/config_local.json @@ -0,0 +1,5 @@ +{ + "version": "dev", + "url": "http://localhost:5173/", + "log_level": "INFO" +} \ No newline at end of file diff --git a/launcher/sys_config/config_local.yaml b/launcher/sys_config/config_local.yaml deleted file mode 100644 index a556984..0000000 --- a/launcher/sys_config/config_local.yaml +++ /dev/null @@ -1,3 +0,0 @@ -version: "dev" -url: "http://localhost:5173/" -log_level: "INFO" \ No newline at end of file