32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from __future__ import annotations
|
|
import os
|
|
from pathlib import Path
|
|
from typing import List, Tuple
|
|
|
|
|
|
def discover_playbooks(root: Path, data_subdir: str = "data") -> List[Tuple[str, Path, int]]:
|
|
"""
|
|
Liefert Liste aus (Display-Text, voller Pfad, Level).
|
|
Ignoriert das data-Verzeichnis auf oberster Ebene.
|
|
"""
|
|
playbooks: List[Tuple[str, Path, int]] = []
|
|
if not root.exists():
|
|
return playbooks
|
|
|
|
for dirpath, dirnames, filenames in os.walk(root):
|
|
path = Path(dirpath)
|
|
# ignore top-level data dir
|
|
if path.parent == root and path.name == data_subdir:
|
|
dirnames[:] = []
|
|
continue
|
|
|
|
rel = path.relative_to(root)
|
|
level = 0 if rel == Path(".") else len(rel.parts)
|
|
for fn in filenames:
|
|
if fn.endswith(".yml") or fn.endswith(".yaml"):
|
|
full = path / fn
|
|
indent = " " * level
|
|
display = f"{indent}{fn}"
|
|
playbooks.append((display, full, level))
|
|
return playbooks
|