xfstestsdb/xfstestsdb/delete.py

30 lines
1.1 KiB
Python

# Copyright 2023 (c) Anna Schumaker.
"""The `xfstestsdb delete` command."""
import argparse
import errno
import sys
from . import commands
from . import sqlite
class Command(commands.Command):
"""The `xfstestsdb delete` command."""
def __init__(self, subparser: argparse.Action,
sql: sqlite.Connection) -> None:
"""Set up the delete command."""
super().__init__(subparser, sql, "delete",
help="delete an xfstests run")
self.parser.add_argument("runid", metavar="runid", nargs=1, type=int,
help="runid of the xfstests run to delete")
def do_command(self, args: argparse.Namespace) -> None:
"""Delete a row from the xfstests_runs table."""
cur = self.sql("DELETE FROM xfstests_runs WHERE rowid=?",
args.runid[0])
if cur.rowcount == 0:
print(f"error: run #{args.runid[0]} does not exist",
file=sys.stderr)
sys.exit(errno.ENOENT)
print(f"run #{args.runid[0]} has been deleted")