40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""The `xfstestsdb rename` command."""
|
|
import argparse
|
|
import errno
|
|
import sys
|
|
from . import commands
|
|
from . import sqlite
|
|
|
|
|
|
class Command(commands.Command):
|
|
"""The `xfstestsdb rename` command."""
|
|
|
|
def __init__(self, subparser: argparse.Action,
|
|
sql: sqlite.Connection) -> None:
|
|
"""Set up the rename command."""
|
|
super().__init__(subparser, sql, "rename",
|
|
help="change the device name for an xfstests run")
|
|
self.parser.add_argument("runid", metavar="runid", nargs=1, type=int,
|
|
help="runid of the xfstests run to change")
|
|
self.parser.add_argument("name", metavar="name", nargs=1,
|
|
help="new device name for the xfstests run")
|
|
|
|
def do_command(self, args: argparse.Namespace) -> None:
|
|
"""Rename a device in the xfstests_runs table."""
|
|
row = self.sql("SELECT device FROM xfstests_runs WHERE rowid=?",
|
|
args.runid[0]).fetchone()
|
|
if row is None:
|
|
print(f"error: run #{args.runid[0]} does not exist",
|
|
file=sys.stderr)
|
|
sys.exit(errno.ENOENT)
|
|
|
|
old_name = row["device"]
|
|
if args.name[0] == old_name:
|
|
return
|
|
|
|
self.sql("UPDATE xfstests_runs SET device=? WHERE rowid=?",
|
|
args.name[0], args.runid[0])
|
|
print(f"renamed run #{args.runid[0]} device '{old_name}'", end=" ")
|
|
print(f"to '{args.name[0]}'")
|