File size: 1,469 Bytes
dab81f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
"""Add clipgt/map_data parquet files to NRE-exported USDZs.

Usage:
    python inject_map.py <src_usdz> <map_dir> <dst_usdz>

map_dir is the per-scene directory under
/mnt/data4/nurec_ood64/map/ood_closeloop_map/<uuid>/.
"""
from __future__ import annotations
import shutil
import sys
import zipfile
from pathlib import Path

MAP_FILES = [
    "cf_crosswalks.parquet",
    "cf_lane_topology_node.parquet",
    "cf_road_boundary.parquet",
    "dw_lane.parquet",
    "lane_chunk.parquet",
    "lane_rail.parquet",
]


def inject(src: Path, map_dir: Path, dst: Path) -> None:
    shutil.copy2(src, dst)
    with zipfile.ZipFile(dst, "a", compression=zipfile.ZIP_STORED) as zf:
        existing = set(zf.namelist())
        for name in MAP_FILES:
            arc = f"map_data/{name}"
            if arc in existing:
                print(f"  skip (already present): {arc}")
                continue
            src_file = map_dir / name
            if not src_file.exists():
                raise FileNotFoundError(src_file)
            zf.write(src_file, arcname=arc)
            print(f"  added: {arc} ({src_file.stat().st_size} bytes)")


def main() -> int:
    if len(sys.argv) != 4:
        print(__doc__)
        return 1
    src, map_dir, dst = map(Path, sys.argv[1:])
    print(f"inject {map_dir} -> {src} => {dst}")
    inject(src, map_dir, dst)
    print(f"wrote {dst} ({dst.stat().st_size} bytes)")
    return 0


if __name__ == "__main__":
    sys.exit(main())