xfstestsdb/xfstestsdb/delete.py
Anna Schumaker 6987a13f54 xfstestsdb: Create the xfstestsdb delete command
This command deletes a row from the xfstests_runs table and prints
either a success or failure message depending on if the row exists.

I use an sqlite trigger to automatically remove tags for the matching run.

Implements: #2 (`xfstestsdb delete`)
Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
2023-02-15 15:57:18 -05:00

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")