Files
ykxmz/_build/fix_release_notes.py

121 lines
4.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
r"""收尾两件事:
1. 发行版说明去掉重复标题
CHANGELOG.md 每条以 "## 1.7.0" 开头,而 gitee_release 又包了一层
"## 更新内容",结果页面上是两个标题叠着,很蠢。
改成:body 直接用 changelog 正文(去掉那条 "## 版本号")。
2. 设备下载区也换成安装包
sync_device_161.py 还在传 ykxmz-agent-*.zip,
但用户要求对外发的电脑端是**安装包**。
"""
from __future__ import annotations
import ast
import re
import sys
from pathlib import Path
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
GITEE = ROOT / "_build" / "gitee_release.py"
SYNC = ROOT / "_build" / "sync_device_161.py"
# ---------- 1. 说明不再套一层标题 ----------
G_OLD = ''' # 发行版说明**只放更新内容**(用户要求)。
# 不放下载表格、不放用法说明 —— 那些在 README 里,
# 这里堆一堆反而看不清这版改了什么。
body = f"""## 更新内容
{changelog}
"""'''
G_NEW = ''' # 发行版说明**只放更新内容**(用户要求)。
# 不再套一层 "## 更新内容" —— CHANGELOG 每段自带 "## 版本号",
# 套一层会变成两个标题叠在一起。
body = changelog.strip()
if not body:
body = f"版本 {version}"
# 保险:Gitee 上 markdown 首行若被吃掉,这里补个空行
if not body.endswith("\\n"):
body += "\\n"'''
# 顺带:读 changelog 时把 "## 1.7.0" 那行去掉(版本号已经在标题里了)
C_OLD = ''' for b in blocks:
if b.startswith(version) or b.startswith("v" + version):
changelog = b
break
if not changelog and blocks:
changelog = blocks[0]'''
C_NEW = ''' for b in blocks:
if b.startswith(version) or b.startswith("v" + version):
changelog = b
break
if not changelog and blocks:
changelog = blocks[0]
# 去掉第一行的 "## 版本号" —— 发行版标题已经有了,
# 正文里再来一条就重复了
if changelog:
lines = changelog.splitlines()
if lines and lines[0].strip().startswith("#"):
changelog = "\\n".join(lines[1:]).strip()'''
# ---------- 2. 设备下载区换成安装包 ----------
S_OLD = '''UPLOADS = [
(f"dist/ykxmz-agent-{VER}.zip", f"{REMOTE_DIR}/ykxmz-agent-{VER}.zip"),
(f"dist/ykxmz-server-{VER}.zip", f"{REMOTE_DIR}/ykxmz-server-{VER}.zip"),
(f"dist/ykxmz-watch-{VER}.apk", f"{REMOTE_DIR}/ykxmz-watch-{VER}.apk"),
]'''
S_NEW = '''# 电脑端对外发的是**安装包**,不是 zip(和 Gitee 发行版保持一致)
UPLOADS = [
(f"dist/ykxmz-setup-{VER}.exe", f"{REMOTE_DIR}/ykxmz-setup-{VER}.exe"),
(f"dist/ykxmz-server-{VER}.zip", f"{REMOTE_DIR}/ykxmz-server-{VER}.zip"),
(f"dist/ykxmz-watch-{VER}.apk", f"{REMOTE_DIR}/ykxmz-watch-{VER}.apk"),
]'''
def patch(path: Path, pairs) -> bool:
text = path.read_text(encoding="utf-8")
changed = False
for old, new in pairs:
if new in text:
continue
if old not in text:
print(f" [提示] {path.name}: 一处锚点没找到")
continue
text = text.replace(old, new, 1)
changed = True
if changed:
path.write_text(text, encoding="utf-8", newline="\n")
print(f" {path.name}: 已更新")
else:
print(f" {path.name}: 无需改动")
try:
ast.parse(path.read_text(encoding="utf-8"))
return True
except SyntaxError as exc:
print(f" [失败] {path.name} 语法错误: 行 {exc.lineno}: {exc.msg}")
return False
def main() -> int:
ok = patch(GITEE, [(G_OLD, G_NEW), (C_OLD, C_NEW)])
ok = patch(SYNC, [(S_OLD, S_NEW)]) and ok
print()
print(" 复核:")
g = GITEE.read_text(encoding="utf-8")
s = SYNC.read_text(encoding="utf-8")
print(f" 说明不再套标题: {'✓' if 'body = changelog.strip()' in g else '✗'}")
print(f" 去掉重复的 ## 版本号: {'✓' if 'lines[0].strip().startswith' in g else '✗'}")
print(f" 下载区用安装包: {'✓' if 'ykxmz-setup-{VER}.exe' in s else '✗'}")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())