# -*- coding: utf-8 -*- r'''验证两个平台的发行版:标签、说明、附件。''' from __future__ import annotations import json import urllib.request from pathlib import Path GITEE_TOKEN = (Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote" r"\_build\.gitee_token").read_text(encoding="utf-8").strip()) EZHUB_TOKEN = (Path.home() / ".ykxmz" / "ezhub_token").read_text( encoding="utf-8").strip() TAG = "v1.8.0" EXPECT = ["ykxmz-setup-1.8.0.exe", "ykxmz-server-1.8.0.zip", "ykxmz-watch-1.8.0.apk"] def fetch(url: str, token: str, kind: str): headers = {"User-Agent": "ykxmz-verify"} if kind == "gitee": url += ("&" if "?" in url else "?") + "access_token=" + token else: headers["Authorization"] = "token " + token with urllib.request.urlopen( urllib.request.Request(url, headers=headers), timeout=60) as resp: return json.loads(resp.read().decode("utf-8", "replace")) def check(name: str, release: dict, web: str) -> None: print(" ═══ %s ═══" % name) print(" 标题: %s" % release.get("name")) print(" 标签: %s" % release.get("tag_name")) print(" 页面: %s" % (release.get("html_url") or web)) body = release.get("body") or "" print(" 说明: %d 字符 / %d 行" % (len(body), body.count("\n") + 1)) first = (body.strip().splitlines() or [""])[0] print(" 首行: %s" % first[:70]) # 对外口径:不许出现管理页字眼 bad = [w for w in ("zhongzhuanzhan", "/admin", "管理后台", "管理页") if w in body] print(" 管理页字眼: %s" % ("**有 " + str(bad) + "**" if bad else "无 ✓")) assets = (release.get("assets") or release.get("attach_files") or []) print(" 附件 %d 个:" % len(assets)) names = [] for a in assets: aname = a.get("name") or a.get("filename") or "?" size = a.get("size") or 0 names.append(aname) print(" %-32s %8.2f MB" % (aname, size / 1024 / 1024)) missing = [e for e in EXPECT if e not in names] print(" 三个产物齐全: %s" % ("**缺 " + str(missing) + "**" if missing else "✓")) print() def main() -> int: print(" 一、Gitee") try: r = fetch("https://gitee.com/api/v5/repos/xmz7891/ykxmz" "/releases/tags/" + TAG, GITEE_TOKEN, "gitee") check("Gitee", r, "https://gitee.com/xmz7891/ykxmz/releases/tag/" + TAG) except Exception as exc: # noqa: BLE001 print(" 查询失败: %s" % exc) print() print(" 二、EzHub") try: r = fetch("https://git.261826.xyz/api/v1/repos/xmz/ykxmz" "/releases/tags/" + TAG, EZHUB_TOKEN, "gitea") check("EzHub", r, "https://git.261826.xyz/xmz/ykxmz/releases/tag/" + TAG) except Exception as exc: # noqa: BLE001 print(" 查询失败: %s" % exc) print() print(" 三、两边的说明是否一致") try: g = fetch("https://gitee.com/api/v5/repos/xmz7891/ykxmz" "/releases/tags/" + TAG, GITEE_TOKEN, "gitee").get("body") e = fetch("https://git.261826.xyz/api/v1/repos/xmz/ykxmz" "/releases/tags/" + TAG, EZHUB_TOKEN, "gitea").get("body") same = (g or "").strip() == (e or "").strip() print(" %s" % ("✓ 完全一致" if same else "✗ 不一致")) if not same: print(" Gitee %d 字符 / EzHub %d 字符" % (len(g or ""), len(e or ""))) except Exception as exc: # noqa: BLE001 print(" 对比失败: %s" % exc) return 0 if __name__ == "__main__": raise SystemExit(main())