File size: 2,221 Bytes
7a87926
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
Dataset / bundle layout helpers.

The spec (Appendix C) defines a canonical on-disk layout. This module provides
non-opinionated helpers for creating and validating directories without baking
policy into unrelated code.
"""

from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path
from typing import Iterable, List, Optional


@dataclass(frozen=True)
class CaptureBundleLayout:
    root: Path

    @property
    def manifest_path(self) -> Path:
        return self.root / "manifest.json"

    @property
    def devices_dir(self) -> Path:
        return self.root / "devices"

    @property
    def calibration_dir(self) -> Path:
        return self.root / "calibration"

    @property
    def annotations_dir(self) -> Path:
        return self.root / "annotations"

    @property
    def teacher_outputs_dir(self) -> Path:
        return self.root / "teacher_outputs"

    def device_dir(self, device_subdir: str) -> Path:
        return self.devices_dir / device_subdir


def discover_capture_bundles(root: Path) -> List[Path]:
    """
    Discover capture bundles under a directory.

    We define a capture bundle as any directory containing a `manifest.json`.
    """
    root = Path(root)
    if not root.exists():
        return []

    bundles: List[Path] = []
    for child in root.iterdir():
        if child.is_dir() and (child / "manifest.json").exists():
            bundles.append(child)
    return sorted(bundles)


def ensure_dir(path: Path) -> Path:
    path = Path(path)
    path.mkdir(parents=True, exist_ok=True)
    return path


def resolve_relative(root: Path, rel: Optional[str]) -> Optional[Path]:
    if rel is None:
        return None
    return (Path(root) / rel).resolve()


def validate_paths_exist(root: Path, rel_paths: Iterable[Optional[str]]) -> List[str]:
    """
    Validate that each non-null relative path exists (relative to root).

    Returns a list of human-readable errors; empty means OK.
    """
    errors: List[str] = []
    for rel in rel_paths:
        if not rel:
            continue
        p = Path(root) / rel
        if not p.exists():
            errors.append(f"Missing path: {rel} (resolved to {p})")
    return errors