refactor: 版本号从version.json读取 配置模板删version字段
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
framework:
|
framework:
|
||||||
debug: true
|
debug: true
|
||||||
name: SenSu
|
name: SenSu
|
||||||
version: v0.8.0
|
|
||||||
branch: dev
|
branch: dev
|
||||||
repo_url: https://git.yeij.top/AskaEth/SenSu
|
repo_url: https://git.yeij.top/AskaEth/SenSu
|
||||||
logging:
|
logging:
|
||||||
|
|||||||
+15
-16
@@ -149,11 +149,16 @@ class UpdateService:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _current_version(self) -> str:
|
def _current_version(self) -> str:
|
||||||
|
"""从 version.json 读取本地版本号"""
|
||||||
try:
|
try:
|
||||||
init = self.sm.get_service("init")
|
vf = _PROJECT_ROOT / "version.json"
|
||||||
return init.get_config("base").get("framework", {}).get("version", "0.0.0").lstrip("vV")
|
if vf.exists():
|
||||||
|
with open(vf) as f:
|
||||||
|
data = json.load(f)
|
||||||
|
return data.get("framework", {}).get("version", "0.0.0").lstrip("vV")
|
||||||
except Exception:
|
except Exception:
|
||||||
return "0.0.0"
|
pass
|
||||||
|
return "0.0.0"
|
||||||
|
|
||||||
# ── 执行更新 ──
|
# ── 执行更新 ──
|
||||||
|
|
||||||
@@ -250,21 +255,15 @@ class UpdateService:
|
|||||||
|
|
||||||
# 4.5 同步版本号到旧配置文件
|
# 4.5 同步版本号到旧配置文件
|
||||||
try:
|
try:
|
||||||
old_cfg_path = str(_PROJECT_ROOT / "config" / "framework" / "base_config.yaml")
|
# 同步版本号到 version.json
|
||||||
new_tpl_path = str(_PROJECT_ROOT / "config" / "framework" / "base_config.yaml.example")
|
vf = _PROJECT_ROOT / "version.json"
|
||||||
if os.path.exists(old_cfg_path) and os.path.exists(new_tpl_path):
|
if vf.exists():
|
||||||
import yaml as _yaml
|
with open(vf) as f:
|
||||||
with open(new_tpl_path) as f:
|
vdata = json.load(f)
|
||||||
new_tpl = _yaml.safe_load(f)
|
new_ver = vdata.get("framework", {}).get("version", "")
|
||||||
new_ver = new_tpl.get("framework", {}).get("version", "")
|
|
||||||
if new_ver:
|
if new_ver:
|
||||||
with open(old_cfg_path) as f:
|
|
||||||
old_cfg = _yaml.safe_load(f) or {}
|
|
||||||
old_cfg.setdefault("framework", {})["version"] = new_ver
|
|
||||||
with open(old_cfg_path, "w") as f:
|
|
||||||
_yaml.dump(old_cfg, f, default_flow_style=False, allow_unicode=True)
|
|
||||||
self._log(f"版本号已同步: {new_ver}")
|
self._log(f"版本号已同步: {new_ver}")
|
||||||
logger.info(f"📝 版本号已同步: {new_ver}")
|
logger.info(f"📝 版本号已同步: {new_ver}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"版本号同步失败: {e}")
|
logger.warning(f"版本号同步失败: {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user