93 lines
3.1 KiB
Python
93 lines
3.1 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""The `xfstestsdb gtk` command."""
|
|
import argparse
|
|
import errno
|
|
import sys
|
|
from . import gsetup
|
|
from gi.repository import GObject
|
|
from gi.repository import Gio
|
|
from gi.repository import Adw
|
|
from . import model
|
|
from . import view
|
|
from . import window
|
|
from .. import commands
|
|
from .. import sqlite
|
|
|
|
|
|
class Application(Adw.Application):
|
|
"""Our Adw.Application for displaying xfstests results."""
|
|
|
|
runid = GObject.Property(type=int)
|
|
model = GObject.Property(type=model.TestCaseList)
|
|
win = GObject.Property(type=window.Window)
|
|
view = GObject.Property(type=view.XfstestsView)
|
|
sql = GObject.Property(type=GObject.TYPE_PYOBJECT)
|
|
|
|
def __init__(self, sql: sqlite.Connection):
|
|
"""Initialize the application."""
|
|
super().__init__(application_id=gsetup.APPLICATION_ID,
|
|
resource_base_path=gsetup.RESOURCE_PATH,
|
|
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
|
|
sql=sql)
|
|
|
|
def do_command_line(self, cmd_line: Gio.ApplicationCommandLine) -> int:
|
|
"""Handle the Adw.Application::command-line signal."""
|
|
Adw.Application.do_command_line(self, cmd_line)
|
|
|
|
for arg in cmd_line.get_arguments():
|
|
split = arg.split("=")
|
|
match split[0]:
|
|
case "runid":
|
|
self.runid = int(split[1])
|
|
self.model = model.TestCaseList(self.sql, self.runid)
|
|
|
|
self.activate()
|
|
return 0
|
|
|
|
def do_startup(self) -> None:
|
|
"""Handle the Adw.Application::startup signal."""
|
|
Adw.Application.do_startup(self)
|
|
gsetup.add_style()
|
|
|
|
self.view = view.XfstestsView()
|
|
self.win = window.Window(child=self.view)
|
|
self.win.headerbar.pack_end(self.view.filterbuttons)
|
|
|
|
self.bind_property("runid", self.win, "runid")
|
|
self.bind_property("model", self.view, "model")
|
|
self.add_window(self.win)
|
|
|
|
def do_activate(self) -> None:
|
|
"""Handle the Adw.Application::activate signal."""
|
|
Adw.Application.do_activate(self)
|
|
self.win.present()
|
|
|
|
def do_shutdown(self) -> None:
|
|
"""Handle the Adw.Application::shutdown signal."""
|
|
Adw.Application.do_shutdown(self)
|
|
|
|
|
|
class Command(commands.Command):
|
|
"""The `xfstestsdb gtk` command."""
|
|
|
|
def __init__(self, subparser: argparse.Action,
|
|
sql: sqlite.Connection) -> None:
|
|
"""Set up the gtk command."""
|
|
super().__init__(subparser, sql, "gtk", help="show a gtk-based ui")
|
|
self.parser.add_argument("runid", metavar="runid", nargs=1, type=int,
|
|
help="show a specific xfstests run")
|
|
|
|
def do_command(self, args: argparse.Namespace) -> None:
|
|
"""Run the Gtk UI."""
|
|
app_args = []
|
|
|
|
if self.sql("SELECT 1 FROM xfstests_runs WHERE runid=?",
|
|
args.runid[0]).fetchone():
|
|
app_args.append(f"runid={args.runid[0]}")
|
|
else:
|
|
print(f"error: run #{args.runid[0]} does not exist",
|
|
file=sys.stderr)
|
|
sys.exit(errno.ENOENT)
|
|
|
|
Application(self.sql).run(app_args)
|