"""Install only the same pinned DWG decoder used on the verified local host. Build-time only. No drawings, credentials or model generation are involved. """ import hashlib from pathlib import Path import platform import shutil import tarfile import tempfile import urllib.request URL = ('https://conda.anaconda.org/conda-forge/linux-64/' 'libredwg-0.11.3876-py38pl5321hf1fe3a4_2.tar.bz2') SHA256 = '23e82c10d5e09b1444ca099c3710893f363d67a98417b0b69afd7155b9759f21' def install(destination=Path('/opt/libredwg')): if platform.machine() not in ('x86_64', 'AMD64'): raise RuntimeError('This pinned converter requires a linux/amd64 Docker host') members = {'bin/dwg2dxf': 'bin/dwg2dxf', 'lib/libredwg.so.0.0.11': 'lib/libredwg.so.0.0.11', 'info/licenses/COPYING': 'licenses/COPYING', 'info/recipe/meta.yaml': 'licenses/package-source.yaml'} with tempfile.TemporaryDirectory(prefix='dwg-runtime-') as tmp: archive = Path(tmp) / 'runtime.tar.bz2' with urllib.request.urlopen(URL, timeout=120) as response, archive.open('wb') as out: shutil.copyfileobj(response, out) with archive.open('rb') as stream: if hashlib.file_digest(stream, 'sha256').hexdigest() != SHA256: raise ValueError('DWG runtime checksum mismatch') with tarfile.open(archive) as bundle: for source, relative in members.items(): member = bundle.getmember(source) if not member.isfile(): raise ValueError('Expected regular DWG runtime file') target = destination / relative target.parent.mkdir(parents=True, exist_ok=True) with bundle.extractfile(member) as inp, target.open('xb') as out: shutil.copyfileobj(inp, out) target.chmod(0o755 if relative.startswith(('bin/', 'lib/')) else 0o644) (destination / 'lib/libredwg.so.0').symlink_to('libredwg.so.0.0.11') if __name__ == '__main__': install()