Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -301,32 +301,58 @@ class DatabaseVersionManager:
|
||||
|
||||
def update_config_version(self, new_version: str):
|
||||
"""更新config.py中的APP_VERSION"""
|
||||
logger.info(f"正在更新config.py到版本: {new_version}")
|
||||
logger.info(f"配置文件路径: {self.config_file}")
|
||||
logger.info(f"配置文件绝对路径: {self.config_file.absolute()}")
|
||||
logger.info(f"配置文件是否存在: {self.config_file.exists()}")
|
||||
|
||||
if not self.config_file.exists():
|
||||
logger.warning(f"配置文件不存在: {self.config_file}")
|
||||
logger.error(f"❌ 配置文件不存在: {self.config_file}")
|
||||
return False
|
||||
|
||||
try:
|
||||
# 读取文件
|
||||
with open(self.config_file, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
logger.info(f"已读取config.py,文件大小: {len(content)} 字节")
|
||||
|
||||
# 查找当前版本
|
||||
import re
|
||||
pattern = r'APP_VERSION\s*=\s*["\'][\d.]+["\']'
|
||||
replacement = f'APP_VERSION = "{new_version}"'
|
||||
match = re.search(pattern, content)
|
||||
|
||||
if re.search(pattern, content):
|
||||
if match:
|
||||
old_version_line = match.group(0)
|
||||
logger.info(f"找到当前版本行: {old_version_line}")
|
||||
|
||||
replacement = f'APP_VERSION = "{new_version}"'
|
||||
new_content = re.sub(pattern, replacement, content)
|
||||
|
||||
logger.info(f"准备写入新版本: {replacement}")
|
||||
|
||||
# 写入文件
|
||||
with open(self.config_file, 'w', encoding='utf-8') as f:
|
||||
f.write(new_content)
|
||||
|
||||
# 验证写入
|
||||
with open(self.config_file, 'r', encoding='utf-8') as f:
|
||||
verify_content = f.read()
|
||||
verify_match = re.search(pattern, verify_content)
|
||||
if verify_match:
|
||||
logger.info(f"✅ 写入验证成功: {verify_match.group(0)}")
|
||||
|
||||
logger.info(f"✅ 已更新 config.py: APP_VERSION = \"{new_version}\"")
|
||||
return True
|
||||
else:
|
||||
logger.warning("未找到APP_VERSION配置项")
|
||||
logger.error(f"❌ 未找到APP_VERSION配置项,pattern: {pattern}")
|
||||
logger.info(f"文件内容预览(前200字符): {content[:200]}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"更新config.py失败: {e}")
|
||||
logger.error(f"❌ 更新config.py失败: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
return False
|
||||
|
||||
def create_version_record(self) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user