xfstestsdb/xfstestsdb/new.py
Anna Schumaker 6a6fe5dda8 xfstestsdb: Create the xfstestsdb new command
This command inserts a new row into the xfstests_runs table and prints
out the result.

Note that sqlite stores timestamps as UTC, so I use the datetime()
function to convert to localtime when returning the new row.

Implements: #1 (`xfstestsdb new`)
Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
2023-02-15 15:56:42 -05:00

30 lines
1.2 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")
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()
print(f"created run #{row['runid']}", end=" ")
print(f"with test device '{row['device']}'", end=" ")
print(f"[{row['timestamp']}]")