45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
# SPDX-License-Identifier: WTFPL
|
|
|
|
import os
|
|
import gi
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import Gtk
|
|
|
|
from yms import gtkutils, combobox, treeview
|
|
|
|
class StatusView:
|
|
|
|
def __init__(self, context):
|
|
self.context = context
|
|
self.title = _("Status")
|
|
builder = Gtk.Builder()
|
|
builder.set_translation_domain(context.textdomain)
|
|
builder.add_from_file(os.path.join(context.ui_path, "status.ui"))
|
|
builder.connect_signals(self)
|
|
self.topwidget = builder.get_object("topobject")
|
|
gtkutils.init_named_controls(self, builder)
|
|
|
|
# Load table status info
|
|
self.lst_tables = Gtk.ListStore(str, int)
|
|
for row in self.get_table_counts():
|
|
self.lst_tables.append(row)
|
|
treeview.add_column(self.tree['tables'], 'Table', 0)
|
|
treeview.add_column(self.tree['tables'], '# Records', 1)
|
|
self.tree['tables'].set_model(self.lst_tables)
|
|
|
|
def get_table_counts(self):
|
|
# Detect all tables in database
|
|
sql= ("SELECT table_name "
|
|
"FROM information_schema.tables "
|
|
"WHERE table_schema='yms' AND table_type='BASE TABLE' "
|
|
"ORDER BY table_name")
|
|
self.context.db.cur.execute(sql)
|
|
tables = [row[0] for row in self.context.db.cur.fetchall()]
|
|
# Loop over tables and get current record count
|
|
records = []
|
|
for table in tables:
|
|
sql = f"SELECT COUNT(*) FROM {table}"
|
|
self.context.db.cur.execute(sql)
|
|
records.append((table, self.context.db.cur.fetchone()[0]))
|
|
return records
|