系统配置文件改为json类型,移除yaml的使用
This commit is contained in:
parent
987f1b6929
commit
bcbd556e7d
7 changed files with 17 additions and 17 deletions
|
@ -9,7 +9,7 @@
|
||||||
前端运行 `npm run build` 生成 `ui/dist`,之后安装 PyInstaller,运行
|
前端运行 `npm run build` 生成 `ui/dist`,之后安装 PyInstaller,运行
|
||||||
|
|
||||||
```bash
|
```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文件夹
|
在dist文件夹生成launcher文件夹
|
||||||
|
|
|
@ -2,9 +2,6 @@ import json
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import yaml
|
|
||||||
from yamlcore import CoreLoader
|
|
||||||
|
|
||||||
from launcher.config.conf import Conf
|
from launcher.config.conf import Conf
|
||||||
|
|
||||||
conf_path = Path(os.path.join(os.getcwd(), "conf.json"))
|
conf_path = Path(os.path.join(os.getcwd(), "conf.json"))
|
||||||
|
@ -22,8 +19,8 @@ def load_conf():
|
||||||
conf = Conf()
|
conf = Conf()
|
||||||
save_conf()
|
save_conf()
|
||||||
return
|
return
|
||||||
with conf_path.open("r", encoding="utf-8") as f:
|
with conf_path.open("r", encoding="utf-8") as file:
|
||||||
data = yaml.load(f, Loader=CoreLoader)
|
data = json.load(file)
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
conf = Conf(**data)
|
conf = Conf(**data)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
|
|
||||||
class SysConfig:
|
class SysConfig:
|
||||||
"""
|
"""
|
||||||
|
@ -26,13 +25,13 @@ class SysConfig:
|
||||||
# 如果是打包后的可执行文件
|
# 如果是打包后的可执行文件
|
||||||
base_path = sys._MEIPASS
|
base_path = sys._MEIPASS
|
||||||
config_subdir = 'launcher/sys_config' # 添加子目录
|
config_subdir = 'launcher/sys_config' # 添加子目录
|
||||||
config_filename = 'config_dist.yaml'
|
config_filename = 'config_dist.json'
|
||||||
else:
|
else:
|
||||||
# logger.error("本地配置")
|
# logger.error("本地配置")
|
||||||
# 如果是本地开发环境
|
# 如果是本地开发环境
|
||||||
base_path = os.path.dirname(__file__)
|
base_path = os.path.dirname(__file__)
|
||||||
config_subdir = '' # 本地开发环境不需要子目录
|
config_subdir = '' # 本地开发环境不需要子目录
|
||||||
config_filename = 'config_local.yaml'
|
config_filename = 'config_local.json'
|
||||||
|
|
||||||
config_path = os.path.join(base_path, config_subdir, config_filename)
|
config_path = os.path.join(base_path, config_subdir, config_filename)
|
||||||
return config_path
|
return config_path
|
||||||
|
@ -40,7 +39,7 @@ class SysConfig:
|
||||||
def load_config(self):
|
def load_config(self):
|
||||||
try:
|
try:
|
||||||
with open(self.config_path, 'r', encoding='utf-8') as file:
|
with open(self.config_path, 'r', encoding='utf-8') as file:
|
||||||
self.config = yaml.safe_load(file)
|
self.config = json.load(file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
# logger.error(f"配置文件未找到: {self.config_path}")
|
# logger.error(f"配置文件未找到: {self.config_path}")
|
||||||
|
|
5
launcher/sys_config/config_dist.json
Normal file
5
launcher/sys_config/config_dist.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"version": "v0.4",
|
||||||
|
"url": "ui/dist/index.html",
|
||||||
|
"log_level": "ERROR"
|
||||||
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
version: "v0.4"
|
|
||||||
url: "ui/dist/index.html"
|
|
||||||
log_level: "ERROR"
|
|
5
launcher/sys_config/config_local.json
Normal file
5
launcher/sys_config/config_local.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"version": "dev",
|
||||||
|
"url": "http://localhost:5173/",
|
||||||
|
"log_level": "INFO"
|
||||||
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
version: "dev"
|
|
||||||
url: "http://localhost:5173/"
|
|
||||||
log_level: "INFO"
|
|
Loading…
Reference in a new issue