Show recent db_events.
(ctx: click.Context, limit: int)
| 1194 | @click.option("-n", "limit", default=10, help="Number of events to show.") |
| 1195 | @click.pass_context |
| 1196 | def show_events(ctx: click.Context, limit: int) -> None: |
| 1197 | """Show recent db_events.""" |
| 1198 | import datetime |
| 1199 | |
| 1200 | import humanize |
| 1201 | |
| 1202 | db_path = _require_db(ctx, must_exist=True) |
| 1203 | s = store.Store(db_path, read_only=True) |
| 1204 | events = s.get_events(limit=limit) |
| 1205 | s.close() |
| 1206 | if not events: |
| 1207 | click.echo("No events recorded.") |
| 1208 | return |
| 1209 | events.reverse() |
| 1210 | for i, ev in enumerate(events): |
| 1211 | if i > 0: |
| 1212 | click.echo() |
| 1213 | dt = datetime.datetime.fromisoformat(ev["timestamp"]) |
| 1214 | short_ts = dt.strftime("%Y-%m-%d %H:%M") |
| 1215 | click.echo(f"{short_ts} ({humanize.naturaltime(dt)})") |
| 1216 | click.echo(f" event: {ev['event']}") |
| 1217 | if ev["event"] == "extraction": |
| 1218 | report = ExtractionReport(**ev["metadata"]) |
| 1219 | if report.config.mode: |
| 1220 | click.echo(f" mode: {report.config.mode}") |
| 1221 | if report.config.model: |
| 1222 | click.echo(f" model: {report.config.model}") |
| 1223 | sm = report.summary |
| 1224 | click.echo( |
| 1225 | f" result: ok={sm.succeeded} skip={sm.skipped} fail={sm.failed}" |
| 1226 | ) |
| 1227 | dm = report.db_after.manpages - report.db_before.manpages |
| 1228 | dmap = report.db_after.mappings - report.db_before.mappings |
| 1229 | click.echo( |
| 1230 | f" db: {report.db_after.manpages}({dm:+d})" |
| 1231 | f" mappings={report.db_after.mappings}({dmap:+d})" |
| 1232 | ) |
| 1233 | click.echo(f" reason: {report.reason or '(no reason provided)'}") |
| 1234 | else: |
| 1235 | meta = ev.get("metadata", {}) |
| 1236 | for k, v in meta.items(): |
| 1237 | if k in ("version", "command"): |
| 1238 | continue |
| 1239 | click.echo(f" {k}: {v}") |
| 1240 | |
| 1241 | |
| 1242 | # --------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected