File size: 1,869 Bytes
360b3dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
"""Fetch versioned upstream fixtures used by second-batch native smoke tests."""

from __future__ import annotations

import argparse
import hashlib
import json
import urllib.request
from pathlib import Path


USHER_FIXTURES = {
    "global_phylo.nh": {
        "url": "https://raw.githubusercontent.com/yatisht/usher/master/test/global_phylo.nh",
        "sha256": "84797b29b897135ca01aab4297ada5cfa44f66d78eafcce4d707a7ecd20691fd",
    },
    "global_samples.vcf": {
        "url": "https://raw.githubusercontent.com/yatisht/usher/master/test/global_samples.vcf",
        "sha256": "b83581907f313e2f08323c3c72835969a8f99a4ecf1307da55872409616991bb",
    },
    "new_samples.vcf": {
        "url": "https://raw.githubusercontent.com/yatisht/usher/master/test/new_samples.vcf",
        "sha256": "0137f1695f3e42d8338be4bea25c1e7fd71428abd840c195b2902a995d763855",
    },
}


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--out", type=Path, default=Path("data/fixtures/usher"))
    args = parser.parse_args()
    args.out.mkdir(parents=True, exist_ok=True)
    provenance = []
    for name, source in USHER_FIXTURES.items():
        target = args.out / name
        data = urllib.request.urlopen(source["url"], timeout=60).read()
        digest = hashlib.sha256(data).hexdigest()
        if digest != source["sha256"]:
            raise RuntimeError(f"checksum mismatch for {name}: {digest}")
        target.write_bytes(data)
        provenance.append({"name": name, **source, "size": len(data)})
        print(f"verified {name} ({len(data)} bytes)")
    (args.out / "provenance.json").write_text(
        json.dumps({"source": "official UShER repository test data", "files": provenance}, indent=2) + "\n",
        encoding="utf-8",
    )
    return 0


if __name__ == "__main__":
    raise SystemExit(main())