-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.py
More file actions
53 lines (38 loc) · 1.37 KB
/
verify.py
File metadata and controls
53 lines (38 loc) · 1.37 KB
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
"""
Verify that every plan dir under ``snapshot/<n>/`` contains a ``meta.json``.
Walks each numbered snapshot directory and reports any plan dirs missing the
``meta.json`` sidecar. Exits non-zero if anything is missing.
Usage::
python3 verify.py
"""
from __future__ import annotations
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent
SNAPSHOT_ROOT = REPO_ROOT / "snapshot"
def main() -> int:
if not SNAPSHOT_ROOT.is_dir():
print(f"Missing snapshot dir: {SNAPSHOT_ROOT}", file=sys.stderr)
return 1
snapshots = sorted(p for p in SNAPSHOT_ROOT.iterdir() if p.is_dir())
if not snapshots:
print(f"No snapshot dirs found under {SNAPSHOT_ROOT}", file=sys.stderr)
return 1
missing: list[Path] = []
checked = 0
for snapshot in snapshots:
plan_dirs = sorted(p for p in snapshot.iterdir() if p.is_dir())
for plan_dir in plan_dirs:
checked += 1
if not (plan_dir / "meta.json").is_file():
missing.append(plan_dir.relative_to(REPO_ROOT))
if missing:
print(f"Missing meta.json in {len(missing)} of {checked} plan dirs:")
for path in missing:
print(f" {path}")
return 1
print(f"OK: all {checked} plan dirs have meta.json")
return 0
if __name__ == "__main__":
sys.exit(main())