工具:完善串流对照测试并同步开发进度

This commit is contained in:
songyiming committed 2026-11-03 17:50:31 +08:00
1 parent 853bcb7574
commit b2de05c6a6
6 files changed
+75 -8

No files matched your search

+7 -2
View File
@@ -4,14 +4,19 @@ import base64
from pathlib import Path
import runpy
import sys
import re
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("action", choices=["Query", "List", "Apply", "Restore"])
parser.add_argument("--hz", type=int, default=60)
parser.add_argument("--backup-tag", default="", help="Separate backup for this verification run")
args = parser.parse_args()
if not 24 <= args.hz <= 240:
parser.error("--hz must be in 24..240")
if args.backup_tag and not re.fullmatch(r"[A-Za-z0-9_-]{1,64}", args.backup_tag):
parser.error("--backup-tag must contain 1..64 letters, digits, underscores or hyphens")
backup_name = "display-before" + ("-" + args.backup_tag if args.backup_tag else "") + ".json"
root = Path(__file__).resolve().parent
term = runpy.run_path(str(root / "pve_term_exec.py"))
vm = runpy.run_path(str(root / "pve_vm.py"))
@@ -33,7 +38,7 @@ $rule=New-Object Security.AccessControl.FileSystemAccessRule($user,'Modify','Con
$acl.SetAccessRule($rule)
Set-Acl -LiteralPath $folder -AclObject $acl
[IO.File]::WriteAllBytes("$folder\mode.ps1",[Convert]::FromBase64String('__VDI_PAYLOAD__'))
$run="try { & '$folder\mode.ps1' -Action __VDI_ACTION__ -RefreshRate __VDI_HZ__ | Out-File -Encoding utf8 -Width 300 '$folder\mode-result.txt' } catch { `$_ | Out-String | Out-File -Encoding utf8 -Width 300 '$folder\mode-result.txt'; exit 1 }"
$run="try { & '$folder\mode.ps1' -Action __VDI_ACTION__ -RefreshRate __VDI_HZ__ -BackupPath '$folder\__VDI_BACKUP__' | Out-File -Encoding utf8 -Width 300 '$folder\mode-result.txt' } catch { `$_ | Out-String | Out-File -Encoding utf8 -Width 300 '$folder\mode-result.txt'; exit 1 }"
$encoded=[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($run))
$action=New-ScheduledTaskAction -Execute powershell.exe -Argument "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand $encoded"
$principal=New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited
@@ -53,7 +58,7 @@ try {
Stop-ScheduledTask -TaskName $task -ErrorAction SilentlyContinue
Unregister-ScheduledTask -TaskName $task -Confirm:$false
}
""".replace("__VDI_ACTION__", args.action).replace("__VDI_HZ__", str(args.hz)).replace("__VDI_PAYLOAD__", payload)
""".replace("__VDI_ACTION__", args.action).replace("__VDI_HZ__", str(args.hz)).replace("__VDI_BACKUP__", backup_name).replace("__VDI_PAYLOAD__", payload)
out, error = vm["agent"](ticket, csrf, ["powershell.exe", "-NoProfile", "-Command", command])
print(out)
if error or "task_result=0" not in out: