taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

report.py (3029B)


      1 # This file is part of GNU Taler
      2 # (C) 2026 Taler Systems S.A.
      3 #
      4 # GNU Taler is free software; you can redistribute it and/or modify it under the
      5 # terms of the GNU General Public License as published by the Free Software
      6 # Foundation; either version 3, or (at your option) any later version.
      7 #
      8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
      9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     10 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     11 #
     12 # You should have received a copy of the GNU General Public License along with
     13 # GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     14 """Summarise episode directories.
     15 
     16     python3 report.py                      # everything, newest last
     17     python3 report.py 'suite-w*-1792268945-*'
     18     python3 report.py --notes 'suite-*'    # with the scenario notes
     19     python3 report.py --findings           # only the findings, deduplicated
     20 """
     21 
     22 from __future__ import annotations
     23 
     24 import glob
     25 import json
     26 import os
     27 import sys
     28 from pathlib import Path
     29 
     30 OUT = Path("/opt/taler-sim/run/out")
     31 
     32 
     33 def load(pattern: str) -> list[dict]:
     34     rows = []
     35     for d in sorted(glob.glob(str(OUT / pattern)), key=os.path.getmtime):
     36         path = Path(d) / "summary.json"
     37         if path.is_file():
     38             try:
     39                 rows.append(json.loads(path.read_text()) | {"dir": d})
     40             except json.JSONDecodeError:
     41                 continue
     42     return rows
     43 
     44 
     45 def main() -> int:
     46     args = [a for a in sys.argv[1:] if not a.startswith("--")]
     47     pattern = args[0] if args else "*"
     48     rows = load(pattern)
     49     show_notes = "--notes" in sys.argv
     50     only_findings = "--findings" in sys.argv
     51 
     52     findings: dict[str, dict] = {}
     53     broken = 0
     54     for r in rows:
     55         for f in r.get("findings", []):
     56             findings.setdefault(f.get("fingerprint", f["detail"][:40]), f)
     57         if r.get("status") not in (None, "ok"):
     58             broken += 1
     59         if only_findings:
     60             continue
     61         name = r.get("scenario") or r.get("name", "?")
     62         status = r.get("status", "-")
     63         print(f"{name:28} {status:13} serious={r.get('serious', 0)} "
     64               f"findings={len(r.get('findings', []))} steps={r.get('steps', 0)} "
     65               f"{r.get('seconds', '?')}s")
     66         if r.get("error"):
     67             print(f"    error: {r['error'][:200]}")
     68         if show_notes:
     69             for note in r.get("notes", []):
     70                 print(f"    note: {note[:200]}")
     71 
     72     serious = [f for f in findings.values() if f["kind"] != "error-screen"]
     73     print(f"\n{len(rows)} episodes, {broken} driver errors, "
     74           f"{len(findings)} distinct findings ({len(serious)} serious)")
     75     for f in findings.values():
     76         mark = "***" if f["kind"] != "error-screen" else "   "
     77         print(f" {mark} [{f['kind']:22}] {f.get('fingerprint', '')} "
     78               f"{f['detail'][:150].replace(chr(10), ' ')}")
     79     return 0
     80 
     81 
     82 if __name__ == "__main__":
     83     raise SystemExit(main())