File size: 2,275 Bytes
5a5e5cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""Create a local ScenarioRunner overlay without modifying simlingo_f2d."""

from __future__ import annotations

import argparse
import shutil
from pathlib import Path


ROOT = Path(__file__).resolve().parent
FROZEN_SCENARIOS = {
    "ghost_driver_left_turn.py",
    "ghost_driver_right_turn.py",
    "lane_cut_in.py",
    "occluded_pedestrian.py",
    "reveal_obstacle.py",
    "signalized_junction_right_turn.py",
}


def _link_children(source: Path, destination: Path, excluded: set[str] | None = None) -> None:
    excluded = excluded or set()
    destination.mkdir(parents=True, exist_ok=True)
    for child in source.iterdir():
        if child.name in excluded:
            continue
        (destination / child.name).symlink_to(child)


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        "--base",
        default="/path/to/scenario_runner",
    )
    parser.add_argument(
        "--output",
        default=str(ROOT / "runtime_scenario_runner"),
    )
    args = parser.parse_args()
    base = Path(args.base).resolve()
    output = Path(args.output).resolve()
    if not (base / "srunner/scenarios").is_dir():
        raise FileNotFoundError(f"invalid ScenarioRunner root: {base}")

    if output.exists():
        shutil.rmtree(output)
    output.mkdir(parents=True)
    _link_children(base, output, {"srunner", ".gitignore", "__pycache__"})
    _link_children(base / "srunner", output / "srunner", {"scenarios"})
    _link_children(
        base / "srunner/scenarios",
        output / "srunner/scenarios",
        FROZEN_SCENARIOS | {"__pycache__"},
    )
    for name in sorted(FROZEN_SCENARIOS):
        source = ROOT / "source_snapshot" / name
        if not source.is_file():
            raise FileNotFoundError(f"missing frozen scenario: {source}")
        shutil.copy2(source, output / "srunner/scenarios" / name)
    (output / "srunner/scenarios/closed_coopeval_scenarios.py").symlink_to(
        ROOT / "scenarios/closed_coopeval_scenarios.py"
    )
    (output / "srunner/scenarios/closed_route_b_control.py").symlink_to(
        ROOT / "scenarios/closed_route_b_control.py"
    )
    print(output)
    return 0


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