xfstestsdb/xfstestsdb/untag.py

34 lines
1.3 KiB
Python

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