Files
vibemake-pcb-studio/backend/tools/fetch_router.py
T

25 lines
1.1 KiB
Python

"""Fetch the pinned upstream binary; it is a cache, never a tracked credential."""
import hashlib
import os
from pathlib import Path
import urllib.request
SHA = '9084a4888937a7f31f857ecc12aa7a37407f51160e4d2892dff9c9bb47ae3102'
URL = 'https://github.com/freerouting/freerouting/releases/download/v1.9.0/freerouting-1.9.0.jar'
def main():
path = Path(os.getenv('AI_PCB_FREEROUTING_JAR', str(Path(__file__).resolve().parents[1] / '.cache/freerouting/freerouting-1.9.0.jar'))).expanduser()
if not path.is_file() or hashlib.sha256(path.read_bytes()).hexdigest() != SHA:
path.parent.mkdir(parents=True, exist_ok=True)
with urllib.request.urlopen(URL, timeout=60) as response:
data = response.read(20 * 1024 * 1024)
if hashlib.sha256(data).hexdigest() != SHA:
raise SystemExit('Freerouting checksum mismatch; no binary installed')
temporary = path.with_name(path.name + '.' + str(os.getpid()) + '.tmp')
temporary.write_bytes(data)
temporary.replace(path)
print(path)
if __name__ == '__main__':
main()