File size: 1,673 Bytes
1fa45cf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | """Compare locally obtained public inputs with the recorded release fingerprints."""
import argparse
import csv
import hashlib
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("names", nargs="+", help="Local names from the provenance CSVs")
parser.add_argument("--inputs", type=Path, default=Path("inputs"))
args = parser.parse_args()
manifests = Path(__file__).resolve().parents[1] / "provenance"
records = {}
for filename in ("source_manifest.csv", "single_cell_and_rnai.csv"):
with (manifests / filename).open(encoding="utf-8", newline="") as handle:
records.update({row["local_name"]: row for row in csv.DictReader(handle)})
failures = []
for name in args.names:
if name not in records:
parser.error(f"Unknown source name: {name}")
row = records[name]
local = args.inputs / name
if not local.is_file():
failures.append(f"{name}: local file missing")
elif local.stat().st_size != int(row["bytes"]):
failures.append(f"{name}: unexpected byte count")
elif row["sha256"]:
with local.open("rb") as handle:
actual = hashlib.file_digest(handle, "sha256").hexdigest()
if actual == row["sha256"].lower():
print(f"{name}: size and SHA-256 match")
else:
failures.append(f"{name}: SHA-256 mismatch")
else:
print(f"{name}: size matches; source SHA-256 was unavailable")
if failures:
raise SystemExit("\n".join(failures))
if __name__ == "__main__":
main()
|