72 lines
2.9 KiB
Python
72 lines
2.9 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""The `xfstestsdb xunit properties` command."""
|
|
import argparse
|
|
from .. import colors
|
|
from .. import commands
|
|
from .. import sqlite
|
|
from .. import table
|
|
|
|
|
|
class Command(commands.Command):
|
|
"""The `xfstestsdb xunit properties` command."""
|
|
|
|
def __init__(self, subparser: argparse.Action,
|
|
sql: sqlite.Connection) -> None:
|
|
"""Set up the xunit properties command."""
|
|
super().__init__(subparser, sql, "properties",
|
|
help="list the xfstest xunit properties")
|
|
self.parser.add_argument("--color", metavar="color", nargs="?",
|
|
choices=["light", "dark", "none"],
|
|
const=colors.get_default_colors(),
|
|
default=colors.get_default_colors(),
|
|
help="show properties with color output "
|
|
f"[default={colors.get_default_colors()}]")
|
|
self.parser.add_argument("--property", metavar="property", nargs=1,
|
|
help="show properties matching "
|
|
"the given pattern")
|
|
self.parser.add_argument("--runid", metavar="runid", nargs=1, type=int,
|
|
help="show properties belonging "
|
|
"to the given run")
|
|
self.parser.add_argument("--value", metavar="value", nargs=1,
|
|
help="show properties with a value "
|
|
"matching the given pattern")
|
|
self.parser.add_argument("--xunit", metavar="xunit", nargs=1,
|
|
help="show properties with an xunit "
|
|
"matching the given pattern")
|
|
|
|
def do_command(self, args: argparse.Namespace) -> None:
|
|
"""Print out the xfstestsdb xunits table."""
|
|
tbl = table.Table(["run", "xunit", "property", "value"],
|
|
["r", "l", "l", "l"], args.color)
|
|
sql_where = ""
|
|
sql_args = []
|
|
filter = []
|
|
|
|
if args.property:
|
|
filter.append("key GLOB ?")
|
|
sql_args.append(args.property[0])
|
|
|
|
if args.runid:
|
|
filter.append("runid=?")
|
|
sql_args.append(args.runid[0])
|
|
|
|
if args.value:
|
|
filter.append("value GLOB ?")
|
|
sql_args.append(args.value[0])
|
|
|
|
if args.xunit:
|
|
filter.append("xunit GLOB ?")
|
|
sql_args.append(args.xunit[0])
|
|
|
|
if len(filter) > 0:
|
|
sql_where = " WHERE " + " AND ".join(filter) + " "
|
|
|
|
cur = self.sql("""SELECT runid, xunit, key, value
|
|
FROM xunit_properties_view""" + sql_where + """
|
|
ORDER BY runid, xunit, key""", *sql_args)
|
|
for row in cur.fetchall():
|
|
tbl.add_row(row["runid"], row["xunit"], row["key"], row["value"])
|
|
#
|
|
if len(tbl.rows) > 0:
|
|
print(tbl)
|