修复:Windows 离线启动误校验 Python 可再生缓存,提供原地修复工具

This commit is contained in:
2026-11-05 11:05:37 +08:00
parent 7357c309dd
commit c2410c4ce1
5 changed files with 276 additions and 1 deletions
+13 -1
View File
@@ -15,11 +15,22 @@ import subprocess
import tarfile
import tempfile
import zipfile
from repair_windows_cache import cache_source
ROOT = Path(__file__).resolve().parents[2]
TEMPLATES = Path(__file__).resolve().parent
def strip_runtime_bytecode(root):
# 目标机可能重建字节码,不能将它当作固定程序资源计算哈希。
for path in (root / 'runtimes/python').rglob('*.pyc'):
source = cache_source(path.relative_to(root).as_posix())
if source:
if not (root / source).is_file():
raise RuntimeError('Python 缓存缺少对应源码:' + str(path))
path.unlink()
def digest(path, algorithm='sha256'):
with path.open('rb') as stream:
return hashlib.file_digest(stream, algorithm).hexdigest()
@@ -237,7 +248,7 @@ def payload(root, work, osname, assets):
b'@echo off\r\nchcp 65001 >nul\r\npowershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0deploy\\bootstrap\\windows-start.ps1"\r\n'
b'if errorlevel 1 (echo Startup failed. See the message above.)\r\npause\r\n')
for name, action in (('停止服务.cmd', 'stop'), ('查看状态.cmd', 'status'), ('检查环境.cmd', 'verify')):
(root / name).write_bytes(('@echo off\r\nchcp 65001 >nul\r\nset PYTHONUTF8=1\r\nset PYTHONIOENCODING=utf-8\r\n'
(root / name).write_bytes(('@echo off\r\nchcp 65001 >nul\r\nset PYTHONUTF8=1\r\nset PYTHONIOENCODING=utf-8\r\nset PYTHONDONTWRITEBYTECODE=1\r\n'
'"%~dp0runtimes\\python\\python.exe" "%~dp0deploy\\offline\\control.py" ' + action + '\r\npause\r\n').encode())
else:
libs = root / 'runtimes/linux-libs'
@@ -274,6 +285,7 @@ def payload(root, work, osname, assets):
'默认网页端口 5280。更改 .runtime/deployment.json 中的 webPort 后重新运行入口。内网连接受现有防火墙规则限制,程序不会自动更改这些规则。\n'
'详细技术说明见 deploy/offline/README.md。\n\n'
'验证范围:前后端隔离构建及本机自动检查已完成;Windows/Linux 原生首次启动和跨电脑内网访问需要在目标机实测。\n', encoding='utf-8-sig')
strip_runtime_bytecode(root)
metadata = {'platform': osname, 'architecture': 'x86_64', 'builtAtUtc': datetime.now(timezone.utc).isoformat(),
'updateVersion': '2026.11.04.1', 'updateSequence': 1, 'installationScope': 'current-user', 'requiresAdministrator': False,
'databaseIncluded': False, 'credentialsIncluded': False, 'requiresDownloadAtInstall': False,