"""Add the epic QSIPrep scripts to the packed folder and to its index.json. Usage: python -I pack_epic_scripts.py OUT_DIR """ import hashlib import json import shutil import sys from pathlib import Path SRC = Path("/var/tmp/dwi-hmc/scripts/epic") NAMES = ("run-qsiprep.sh", "launch.sh", "pull-qsiprep.sh", "file_list.py") out = Path(sys.argv[1]) idx_path = out / "index.json" index = json.loads(idx_path.read_text()) for name in NAMES: src = SRC / name dst = out / "scripts/epic" / name dst.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(src, dst) index["files"][str(dst.relative_to(out))] = { "source": str(src), "source_sha256": hashlib.sha256(src.read_bytes()).hexdigest(), } idx_path.write_text(json.dumps(index, indent=1, sort_keys=True) + "\n")