From 0010db35c4ffa7a0c9f2d71604f1b3c30a97a26d Mon Sep 17 00:00:00 2001 From: Mika Date: Thu, 22 Jan 2026 11:58:39 +0000 Subject: [PATCH] Add sanity_check_tool/src/sanity_check_tool/cli.py --- .../src/sanity_check_tool/cli.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 sanity_check_tool/src/sanity_check_tool/cli.py diff --git a/sanity_check_tool/src/sanity_check_tool/cli.py b/sanity_check_tool/src/sanity_check_tool/cli.py new file mode 100644 index 0000000..2568851 --- /dev/null +++ b/sanity_check_tool/src/sanity_check_tool/cli.py @@ -0,0 +1,59 @@ +import argparse +import json +from pathlib import Path +from typing import Any, Dict +import sys + +from sanity_check_tool import core + + +def _load_run_summary(file_path: Path) -> Dict[str, Any]: + if not file_path.exists(): + raise FileNotFoundError(f'Eingabedatei nicht gefunden: {file_path}') + with file_path.open('r', encoding='utf-8') as f: + data = json.load(f) + if not isinstance(data, dict): + raise ValueError('Ungültiges Format: Run-Summary muss ein JSON-Objekt (dict) sein.') + return data + + +def _write_results(results: Dict[str, Any], output_path: Path) -> None: + output_path.parent.mkdir(parents=True, exist_ok=True) + with output_path.open('w', encoding='utf-8') as f: + json.dump(results, f, indent=2, ensure_ascii=False) + + +def main() -> None: + parser = argparse.ArgumentParser( + description='CLI für das N40 Sanity Check Tool – überprüft Run-Summaries auf Datenfehler.' + ) + parser.add_argument( + '--input', + required=True, + help='Pfad zur Run-Summary-JSON-Datei.' + ) + parser.add_argument( + '--output', + required=False, + default='output/sanity_results.json', + help='Pfad für die Ausgabe der Sanity-Ergebnisse (Standard: output/sanity_results.json).' + ) + + args = parser.parse_args() + + input_path = Path(args.input) + output_path = Path(args.output) + + try: + run_summary = _load_run_summary(input_path) + results = core.perform_sanity_check(run_summary) + assert isinstance(results, dict), 'Sanity Check Ergebnis muss ein Dictionary sein.' + _write_results(results, output_path) + print(f'Sanity Check abgeschlossen. Ergebnisse unter {output_path}') + except Exception as e: + print(f'Fehler während der Ausführung: {e}', file=sys.stderr) + sys.exit(1) + + +if __name__ == '__main__': + main()