Ver Fonte

代码优化-新增版本管理

derrickx há 1 ano atrás
pai
commit
1a08706357
1 ficheiros alterados com 19 adições e 6 exclusões
  1. 19 6
      build_exe.py

+ 19 - 6
build_exe.py

@@ -1,11 +1,24 @@
 import PyInstaller.__main__
-import json
+import yaml
+
+
+def read_config(config_path):
+    """读取配置文件"""
+    try:
+        with open(config_path, "r") as f:
+            config = yaml.safe_load(f)
+            return config
+    except FileNotFoundError:
+        print(f"配置文件 {config_path} 不存在!")
+        exit(1)
+    except yaml.YAMLError as e:
+        print(f"读取配置文件 {config_path} 失败:{e}")
+        exit(1)
+
 
 # 从配置文件读取版本号
-with open("tools/config.yaml", "r") as f:
-    config = json.load(f)
-    print(f"config content: {config}")
-    version = config.get("version", "1.0.0")  # 获取版本号,如果没有则默认使用 "1.0.0"
+config = read_config("tools/config.yaml")
+version = config.get("version", "1.0.0")
 
 PyInstaller.__main__.run([
     'main.py',  # 你的主脚本文件名
@@ -20,4 +33,4 @@ PyInstaller.__main__.run([
     '--add-data=icon.ico:.',  # 添加图标文件
     '--add-data=tools/config.yaml;tools',  # 添加资源文件到tools文件夹
     '--add-data=Redis-x64-5.0.14.1.msi;.',  # 添加资源文件
-])
+])