77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""更新版本号脚本"""
|
||
|
|
import re
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
def get_version():
|
||
|
|
"""从 VERSION 文件读取版本号"""
|
||
|
|
version_file = Path(__file__).parent / "VERSION"
|
||
|
|
return version_file.read_text().strip()
|
||
|
|
|
||
|
|
|
||
|
|
def increment_version(version: str) -> str:
|
||
|
|
"""递增版本号的修订号"""
|
||
|
|
parts = version.split(".")
|
||
|
|
if len(parts) == 3:
|
||
|
|
parts[2] = str(int(parts[2]) + 1)
|
||
|
|
return ".".join(parts)
|
||
|
|
return version
|
||
|
|
|
||
|
|
|
||
|
|
def update_index_html(version: str):
|
||
|
|
"""更新 webui/index.html 中的标题版本号"""
|
||
|
|
index_file = Path(__file__).parent / "webui" / "index.html"
|
||
|
|
content = index_file.read_text(encoding="utf-8")
|
||
|
|
|
||
|
|
# 替换标题中的版本号
|
||
|
|
new_content = re.sub(
|
||
|
|
r"<title>EGM 输电线路绕击跳闸率计算( v[\d.]+)?</title>",
|
||
|
|
f"<title>EGM 输电线路绕击跳闸率计算 v{version}</title>",
|
||
|
|
content
|
||
|
|
)
|
||
|
|
|
||
|
|
index_file.write_text(new_content, encoding="utf-8")
|
||
|
|
print(f"Updated version in {index_file} to v{version}")
|
||
|
|
|
||
|
|
|
||
|
|
def update_version_file(version: str):
|
||
|
|
"""更新 VERSION 文件"""
|
||
|
|
version_file = Path(__file__).parent / "VERSION"
|
||
|
|
version_file.write_text(version + "\n")
|
||
|
|
|
||
|
|
|
||
|
|
def create_metadata(version: str):
|
||
|
|
"""创建 metadata.yml 文件"""
|
||
|
|
metadata_file = Path(__file__).parent / "metadata.yml"
|
||
|
|
content = f"""version: {version}
|
||
|
|
company_name: EGM
|
||
|
|
file_description: EGM Lightning Protection Calculator
|
||
|
|
product_name: Lightening
|
||
|
|
"""
|
||
|
|
metadata_file.write_text(content)
|
||
|
|
print(f"Created metadata.yml with version {version}")
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
# 检查是否只获取版本号
|
||
|
|
if len(sys.argv) > 1 and sys.argv[1] == "--get":
|
||
|
|
print(get_version())
|
||
|
|
return
|
||
|
|
|
||
|
|
# 获取当前版本并递增
|
||
|
|
current_version = get_version()
|
||
|
|
new_version = increment_version(current_version)
|
||
|
|
|
||
|
|
# 更新所有文件
|
||
|
|
update_version_file(new_version)
|
||
|
|
update_index_html(new_version)
|
||
|
|
create_metadata(new_version)
|
||
|
|
|
||
|
|
print(f"Version updated: {current_version} -> {new_version}")
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|