feat(compare): offer a drift check after the full tenant export
After menu item 23 finishes it offers to compare with the newest earlier export of the same tenant (assignments included) and writes the report to <root>/_drift/<old>-to-<new>/. Compare-Tenants.py now also accepts a folder that holds a single export folder (e.g. a dated folder containing Exports/).
This commit is contained in:
@@ -79,6 +79,20 @@ def clean_name(raw: str, strip: str) -> str:
|
||||
return re.sub(strip, "", raw, count=1, flags=re.IGNORECASE).strip() if strip else raw
|
||||
|
||||
|
||||
def resolve_root(root: Path) -> Path:
|
||||
"""Accept either the export root or its parent (e.g. a dated folder holding a single 'Export' folder)."""
|
||||
def has_categories(p: Path) -> bool:
|
||||
return any(d.is_dir() and any(d.rglob("*.json")) for d in p.iterdir())
|
||||
if not root.is_dir() or any(f.suffix == ".json" for f in root.glob("MigrationTable.json")) or \
|
||||
any(d.name in LOOKUP_CATEGORIES or d.name == "SettingsCatalog" for d in root.iterdir() if d.is_dir()):
|
||||
return root
|
||||
inner = [d for d in root.iterdir() if d.is_dir() and has_categories(d)]
|
||||
if len(inner) == 1:
|
||||
print(f"Using {inner[0]} as export root")
|
||||
return inner[0]
|
||||
return root
|
||||
|
||||
|
||||
def load_json(path: Path) -> Any:
|
||||
try:
|
||||
return json.loads(path.read_text(encoding="utf-8-sig"))
|
||||
@@ -251,6 +265,7 @@ def main() -> None:
|
||||
for r in (args.root_a, args.root_b):
|
||||
if not r.is_dir():
|
||||
raise SystemExit(f"Not a folder: {r}")
|
||||
args.root_a, args.root_b = resolve_root(args.root_a), resolve_root(args.root_b)
|
||||
ta = Tenant(args.root_a, args.strip_a, args.label_a)
|
||||
tb = Tenant(args.root_b, args.strip_b, args.label_b)
|
||||
cats = sorted(ta.categories() & tb.categories())
|
||||
|
||||
Reference in New Issue
Block a user