Add sanity_check_tool/src/sanity_check_tool/cli.py
This commit is contained in:
parent
a43cdd9519
commit
0010db35c4
1 changed files with 59 additions and 0 deletions
59
sanity_check_tool/src/sanity_check_tool/cli.py
Normal file
59
sanity_check_tool/src/sanity_check_tool/cli.py
Normal file
|
|
@ -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()
|
||||
Loading…
Reference in a new issue