28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""The `xfstestsdb gc` command."""
|
|
import argparse
|
|
from . import commands
|
|
from . import sqlite
|
|
|
|
|
|
class Command(commands.Command):
|
|
"""The `xfstestsdb gc` command."""
|
|
|
|
def __init__(self, subparser: argparse.Action,
|
|
sql: sqlite.Connection) -> None:
|
|
"""Set up the gc command."""
|
|
super().__init__(subparser, sql, "gc",
|
|
help="garbage collect xfstestsdb entries")
|
|
self.parser.add_argument("--dry-run", action="store_true",
|
|
help="do not remove the xunit entries")
|
|
|
|
def do_command(self, args: argparse.Namespace) -> None:
|
|
"""Clean up the xunit table."""
|
|
how = "would be" if args.dry_run else "has been"
|
|
rows = self.sql("SELECT runid FROM xfstests_gc_runs").fetchall()
|
|
|
|
for runid in sorted([row['runid'] for row in rows]):
|
|
if not args.dry_run:
|
|
self.sql("DELETE FROM xfstests_runs WHERE runid=?", runid)
|
|
print(f"run #{runid} {how} deleted")
|