Branchwell

PulseCanvas / app · pulsecanvas.ai / scripts / prepare-sparkle.py

Raw 1.1 KB on 0e4fe45e403a1b6b5a57aa68addd681995d37722
1#!/usr/bin/env python3
2"""Download the official pinned Sparkle distribution; never export signing keys."""
3import hashlib, json, tarfile, urllib.request
4from pathlib import Path
5root = Path(__file__).resolve().parents[1]
6config = json.loads((root / 'macOS/DirectRelease.json').read_text())
7folder = root / '.build/sparkle'
8folder.mkdir(parents=True, exist_ok=True)
9version = config['sparkleVersion']
10archive = folder / f'Sparkle-{version}.tar.xz'
11if not archive.exists():
12 urllib.request.urlretrieve(f'https://github.com/sparkle-project/Sparkle/releases/download/{version}/{archive.name}', archive)
13assert hashlib.sha256(archive.read_bytes()).hexdigest() == config['sparkleArchiveSHA256'], 'Sparkle SHA-256 mismatch'
14with tarfile.open(archive) as package:
15 for entry in package.getmembers():
16 assert not Path(entry.name).is_absolute() and '..' not in Path(entry.name).parts
17 if entry.issym() or entry.islnk():
18 assert not Path(entry.linkname).is_absolute() and '..' not in Path(entry.linkname).parts
19 package.extractall(folder)
20print(f'Verified official Sparkle {version}')