xfstestsdb/xfstestsdb/new.py

35 lines
1.4 KiB
Python

# Copyright 2023 (c) Anna Schumaker.
"""The `xfstestsdb new` command."""
import argparse
from . import commands
from . import sqlite
class Command(commands.Command):
"""The `xfstestsdb new` command."""
def __init__(self, subparser: argparse.Action,
sql: sqlite.Connection) -> None:
"""Set up the New command."""
super().__init__(subparser, sql, "new",
help="create a new xfstests run")
self.parser.add_argument("device", metavar="device", nargs=1,
help="the test device used for"
"this xfstests run")
self.parser.add_argument("--terse", action="store_true",
help="output only the new runid")
def do_command(self, args: argparse.Namespace) -> None:
"""Create a new row in the xfstestsdb_runs table."""
cur = self.sql("""INSERT INTO xfstests_runs (device)
VALUES (?) RETURNING rowid, device,
datetime(timestamp, 'localtime') as timestamp""",
args.device[0])
row = cur.fetchone()
if args.terse:
print(row['runid'])
else:
print(f"created run #{row['runid']}", end=" ")
print(f"with test device '{row['device']}'", end=" ")
print(f"[{row['timestamp']}]")