35 lines
1.3 KiB
Python
35 lines
1.3 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")
|
|
|
|
args.need_vacuum = len(rows) > 0
|
|
|
|
def do_done(self, args: argparse.Namespace) -> None:
|
|
"""Vacuum the database after deleting."""
|
|
if args.need_vacuum and not args.dry_run:
|
|
self.sql.vacuum()
|