116 行
6.9 KiB
Python
116 行
6.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Package the verified formal Dayu Color installation through the PKG Forge skill."""
|
|
import argparse
|
|
import datetime
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import plistlib
|
|
import shutil
|
|
import subprocess
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
APP = Path("/Library/Plug-Ins/FxPlug/大鱼调色.app")
|
|
CACHE = Path.home() / "Library/Caches/CodexBuilds/com.dayu.color"
|
|
LOCK = Path.home() / ".codex/app-delivery-locks/com.dayu.color.lock"
|
|
|
|
|
|
def run(*args, cwd=None):
|
|
return subprocess.check_output(args, cwd=cwd, text=True, stderr=subprocess.STDOUT).strip()
|
|
|
|
|
|
def history(profile, keychain):
|
|
return json.loads(run("xcrun", "notarytool", "history", "--keychain-profile", profile,
|
|
"--keychain", keychain, "--output-format", "json"))["history"]
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--pkg-forge-repo", type=Path,
|
|
default=Path.home() / "Documents/dayu-git/repositories/pkg-forge")
|
|
parser.add_argument("--output-dir", type=Path, default=ROOT.parent / "发行包")
|
|
parser.add_argument("--prepare-only", action="store_true")
|
|
args = parser.parse_args()
|
|
args.output_dir = args.output_dir.expanduser().resolve()
|
|
forge = args.pkg_forge_repo.expanduser().resolve()
|
|
skill = forge / "skills/pkg-forge/scripts"
|
|
assert (skill / "package_fxplug.py").is_file(), "请指定含 pkg-forge 技能的 PKG 工坊 checkout"
|
|
delivery = json.loads((ROOT / "verification/Delivery.json").read_text())
|
|
info = plistlib.loads((APP / "Contents/Info.plist").read_bytes())
|
|
assert delivery["status"] == "verified" and delivery["path"] == str(APP)
|
|
assert info["CFBundleIdentifier"] == "com.dayu.color"
|
|
assert (info["CFBundleShortVersionString"], info["CFBundleVersion"]) == (delivery["version"], delivery["build"])
|
|
args.output_dir.mkdir(parents=True, exist_ok=True)
|
|
CACHE.mkdir(parents=True, exist_ok=True)
|
|
LOCK.parent.mkdir(parents=True, exist_ok=True)
|
|
LOCK.mkdir()
|
|
(LOCK / "owner.json").write_text(json.dumps(dict(PID=os.getpid(), cwd=str(ROOT),
|
|
product="大鱼调色", phase="PKG packaging", started=datetime.datetime.now(datetime.timezone.utc).isoformat())))
|
|
try:
|
|
source = APP / "Contents/Resources/FCP Templates"
|
|
staged = CACHE / "pkg-inputs/大鱼调色/大鱼调色"
|
|
staged.mkdir(parents=True, exist_ok=True)
|
|
hashes = {}
|
|
for name in ["大鱼调色.moef", "large.png", "small.png"]:
|
|
data = (source / name).read_bytes()
|
|
assert data == (ROOT / "template" / name).read_bytes(), name
|
|
target = staged / name
|
|
if target.exists():
|
|
os.chflags(target, 0)
|
|
target.write_bytes(data)
|
|
target.chmod(0o644)
|
|
if name.endswith(".png"):
|
|
os.chflags(target, 2)
|
|
hashes[name] = hashlib.sha256(data).hexdigest()
|
|
for folder in [staged, staged.parent]:
|
|
folder.chmod(0o755)
|
|
keychain = str(Path.home() / "Library/Keychains/login.keychain-db")
|
|
profile = "codex-dayu-notary-B3W25FX5H5"
|
|
version = info["CFBundleShortVersionString"]
|
|
manifest = dict(name="大鱼调色", output=str(args.output_dir / "大鱼调色.pkg"),
|
|
identifierPrefix="com.dayu.color.installer", resources=[dict(source=str(APP)),
|
|
dict(source=str(staged.parent), destination="~/Movies/Motion Templates.localized/Effects.localized")],
|
|
signing=dict(identity="Developer ID Installer: zhong luo (B3W25FX5H5)", profile=profile,
|
|
keychain=keychain, notaryKeychain=keychain),
|
|
appearance=dict(title="大鱼调色", subtitle="适用于 Final Cut Pro 与 Motion 的原生调色效果",
|
|
badgeImage=str(ROOT / "design/dayu-color-app-icon-v1.png"), authorContact="https://dayu.media"),
|
|
pages=dict(welcome="安装大鱼调色 " + version + ",包含原生 FxPlug 调色插件和 Final Cut Pro 效果入口。",
|
|
readme="系统要求:macOS 14.6 或更高版本。本发行构建适用于 Apple Silicon Mac。\n\n安装内容:\n/Library/Plug-Ins/FxPlug/大鱼调色.app\n登录用户“影片/Motion Templates/Effects/大鱼调色”中的效果模板与预览图。\n\n重新打开 Final Cut Pro 后,在“效果 → 大鱼调色”中应用;Motion 中可选择原生滤镜。\n本安装包不包含用户自选 LUT、预设或媒体文件。",
|
|
license="", conclusion="大鱼调色已安装。主 APP 自动注册插件,成功后显示3秒倒计时退出。可点击“打开 FCP 检查”保留窗口,并在宿主中实际检查效果。"))
|
|
manifest_path = CACHE / "dayu-color-package-manifest.json"
|
|
manifest_path.write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n")
|
|
command = ["/usr/bin/python3", str(skill / "package_fxplug.py"), "--repo", str(forge), "--manifest", str(manifest_path)]
|
|
subprocess.run(command + ["--check"], check=True)
|
|
if args.prepare_only:
|
|
print("清单:" + str(manifest_path))
|
|
return
|
|
before = {x["id"] for x in history(profile, keychain)}
|
|
log_path = CACHE / "pkg-release-build.log"
|
|
with log_path.open("w") as log:
|
|
subprocess.run(command, stdout=log, stderr=subprocess.STDOUT, check=True)
|
|
package = args.output_dir / ("大鱼调色-" + version + ".pkg")
|
|
report_path = ROOT / "verification/Package.json"
|
|
subprocess.run(["/usr/bin/python3", str(skill / "verify_fxplug_package.py"), "--manifest", str(manifest_path),
|
|
"--package", str(package), "--report", str(report_path)], check=True)
|
|
jobs = [x for x in history(profile, keychain) if x["id"] not in before and x["name"] == package.name]
|
|
assert len(jobs) == 1, "安装包已生成,请核对公证 ID;不要重复提交同一包"
|
|
job = json.loads(run("xcrun", "notarytool", "info", jobs[0]["id"], "--keychain-profile", profile,
|
|
"--keychain", keychain, "--output-format", "json"))
|
|
assert job["status"] == "Accepted"
|
|
report = json.loads(report_path.read_text())
|
|
report.update(notarization=job, appCompiledSource=delivery["sourceCommit"], appBuild=info["CFBundleVersion"],
|
|
packageBuilderRemote="https://dayu.media/git/dayu/pkg-forge.git",
|
|
packageBuilderCommit=run("git", "rev-parse", "HEAD", cwd=forge), templateSHA256=hashes,
|
|
installedAppHostAcceptance=delivery.get("hostVerification", "verification/HostLUTLoading.json"),
|
|
installScope="本轮仅生成并验包,未再次执行系统安装;正式 APP 已有独立宿主验收。")
|
|
report_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n")
|
|
print("正式安装包:" + str(package))
|
|
finally:
|
|
(LOCK / "owner.json").unlink()
|
|
LOCK.rmdir()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|