main
anastasia Premiere Pro Bridge 0.1.0: Rust bridge, UXP plugin, CEP helper, skills, macOS manifest 32fb583 10d ago
"""Entrypoint Adom Bridge spawns (spawn.kind=python).

Adom Bridge's unzip doesn't keep Unix file modes, so the Rust binary arrives without its
executable bit. Copy it to ~/.adom/premiere-bridge/bin/ (never write beside this file:
on macOS that can break an app-bundle seal), mark it executable, and exec it in place so
the PID Adom Bridge supervises — and the --port argument it appended — carry straight
through to the real server.
"""
import hashlib
import os
import shutil
import stat
import sys

HERE = os.path.dirname(os.path.abspath(__file__))
SRC = os.path.join(HERE, "premiere-bridge.exe" if os.name == "nt" else "premiere-bridge")


def main():
    with open(SRC, "rb") as f:
        digest = hashlib.sha256(f.read()).hexdigest()[:12]
    bindir = os.path.join(os.path.expanduser("~"), ".adom", "premiere-bridge", "bin")
    os.makedirs(bindir, exist_ok=True)
    dst = os.path.join(bindir, f"premiere-bridge-{digest}" + (".exe" if os.name == "nt" else ""))
    if not os.path.exists(dst):
        tmp = dst + ".tmp"
        shutil.copyfile(SRC, tmp)
        os.chmod(tmp, os.stat(tmp).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
        os.replace(tmp, dst)
        # Drop older copies.
        for name in os.listdir(bindir):
            if name.startswith("premiere-bridge-") and os.path.join(bindir, name) != dst:
                try:
                    os.remove(os.path.join(bindir, name))
                except OSError:
                    pass
    os.execv(dst, [dst] + sys.argv[1:])


if __name__ == "__main__":
    main()