#!/usr/bin/env python3 """Publish the existing local Python/WASM runtime without running it.""" import argparse import hashlib import json from pathlib import Path import shutil ROOT = Path(__file__).resolve().parents[2] def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--source', type=Path, default=Path('/home/mes123456/workingRobotDKToWeb/public/wasm/pyodide')) args = parser.parse_args() origin = json.loads((args.source / 'runtime-manifest.json').read_text()) package = json.loads((args.source / 'package.json').read_text()) lock = json.loads((args.source / 'pyodide-lock.json').read_text()) destination = ROOT / 'web/app/public/vendor/pyodide' files = [] for item in origin['files']: name = item['path'] if Path(name).name != name: raise ValueError('Runtime manifest must contain only file names') source = args.source / name digest = hashlib.sha256(source.read_bytes()).hexdigest() if digest != item['sha256'] or source.stat().st_size != item['bytes']: raise ValueError('Local artifact does not match its manifest: ' + name) files.append((source, dict(item))) destination.mkdir(parents=True, exist_ok=True) for source, item in files: target = destination / item['path'] if not target.exists() or hashlib.sha256(target.read_bytes()).hexdigest() != item['sha256']: shutil.copy2(source, target) manifest = dict(schemaVersion=1, status='COPIED_UNVERIFIED', validation='NOT_RUN', source=str(args.source), package=package['version'], python=lock['info']['python'], abi=lock['info']['abi_version'], files=[item for _, item in files]) (destination / 'runtime-manifest.json').write_text(json.dumps(manifest, indent=2) + '\n') print(json.dumps(manifest)) if __name__ == '__main__': main()