32 lines
1.6 KiB
Python
32 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Fetch the hash-pinned non-V8 PDFium dependency for Linux or Windows x64."""
|
|
from pathlib import Path
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import platform
|
|
import tarfile
|
|
import tempfile
|
|
import urllib.request
|
|
|
|
root = Path(__file__).resolve().parent.parent
|
|
lock = json.loads((root / 'cmake/pdfium.lock.json').read_text())
|
|
host = {'Linux': 'linux-x64', 'Windows': 'windows-x64'}.get(platform.system())
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--platform', choices=['linux-x64', 'windows-x64'], default=host)
|
|
parser.add_argument('--destination', type=Path)
|
|
args = parser.parse_args()
|
|
if args.platform is None or (args.platform == host and platform.machine() not in ('x86_64', 'AMD64')):
|
|
raise SystemExit('A supported x64 platform is required; specify --platform for a cross-platform download.')
|
|
prefix = 'windowsX64' if args.platform == 'windows-x64' else 'linuxX64'
|
|
destination = args.destination or root / '.deps' / ('pdfium' if args.platform == host else 'pdfium-' + args.platform.split('-')[0])
|
|
with tempfile.TemporaryDirectory(prefix='docview-pdfium-') as temporary:
|
|
archive = Path(temporary) / 'pdfium.tgz'
|
|
urllib.request.urlretrieve(lock[prefix + 'Archive'], archive)
|
|
if hashlib.sha256(archive.read_bytes()).hexdigest() != lock[prefix + 'Sha256']:
|
|
raise SystemExit('PDFium archive hash mismatch; dependency not installed.')
|
|
destination.mkdir(parents=True, exist_ok=True)
|
|
with tarfile.open(archive) as bundle:
|
|
bundle.extractall(destination, filter='data')
|
|
print(f'Installed pinned PDFium {lock["version"]} in {destination}')
|