xfstestsdb/xfstestsdb/xunit/delete.py

33 lines
1.3 KiB
Python

# Copyright 2023 (c) Anna Schumaker.
"""The `xfstestsdb xunit 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 xunit entry")
self.parser.add_argument("runid", metavar="runid", nargs=1, type=int,
help="runid of the xfstests xunit to delete")
self.parser.add_argument("name", metavar="name", nargs=1, type=str,
help="name of the xunit entry to delete")
def do_command(self, args: argparse.Namespace) -> None:
"""Delete a row from the xunits table."""
cur = self.sql("DELETE FROM xunits WHERE runid=? and name=?",
args.runid[0], args.name[0])
if cur.rowcount == 0:
print(f"error: either run #{args.runid[0]} or "
f"xunit '{args.name[0]}' do not exist", file=sys.stderr)
sys.exit(errno.ENOENT)
print(f"run #{args.runid[0]} xunit '{args.name[0]}' has been deleted")