DbManager: add database type column

This commit is contained in:
Doug Blank 2016-04-16 14:38:38 -04:00
parent 9c045c63c9
commit eafe35e4af
12 changed files with 109 additions and 44 deletions

View File

@ -33,6 +33,7 @@ creating, and deleting of databases.
import re import re
import os import os
import sys import sys
import ast
import time import time
from urllib.parse import urlparse from urllib.parse import urlparse
from urllib.request import urlopen, url2pathname from urllib.request import urlopen, url2pathname
@ -158,9 +159,9 @@ class CLIDbManager(object):
if not self.is_locked(dirpath): if not self.is_locked(dirpath):
try: try:
database = self.dbstate.make_database(dbid) database = self.dbstate.make_database(dbid)
database.load(dirpath, None, update=False) database.load(dirpath, None)
retval = database.get_summary() retval = database.get_summary()
database.close(update=False) database.close()
except Exception as msg: except Exception as msg:
retval = {_("Unavailable"): str(msg)[:74] + "..."} retval = {_("Unavailable"): str(msg)[:74] + "..."}
else: else:
@ -173,16 +174,14 @@ class CLIDbManager(object):
}) })
return retval return retval
def print_family_tree_summaries(self, database_names=None): def print_family_tree_summaries(self):
""" """
Prints a detailed list of the known family trees. Prints a detailed list of the known family trees.
""" """
print(_('Gramps Family Trees:')) print(_('Gramps Family Trees:'))
for item in self.current_names: for item in self.current_names:
(name, dirpath, path_name, last, (name, dirpath, path_name, last,
tval, enable, stock_id) = item tval, enable, stock_id, backend_type, version) = item
if (database_names is None or
any([re.match(dbname, name) for dbname in database_names])):
summary = self.get_dbdir_summary(dirpath, name) summary = self.get_dbdir_summary(dirpath, name)
print(_("Family Tree \"%s\":") % summary[_("Family Tree")]) print(_("Family Tree \"%s\":") % summary[_("Family Tree")])
for item in sorted(summary): for item in sorted(summary):
@ -192,7 +191,7 @@ class CLIDbManager(object):
'item' : item, 'item' : item,
'summary' : summary[item] } ) 'summary' : summary[item] } )
def family_tree_summary(self, database_names=None): def family_tree_summary(self):
""" """
Return a list of dictionaries of the known family trees. Return a list of dictionaries of the known family trees.
""" """
@ -200,9 +199,7 @@ class CLIDbManager(object):
summary_list = [] summary_list = []
for item in self.current_names: for item in self.current_names:
(name, dirpath, path_name, last, (name, dirpath, path_name, last,
tval, enable, stock_id) = item tval, enable, stock_id, backend_type) = item
if (database_names is None or
any([re.match(dbname, name) for dbname in database_names])):
retval = self.get_dbdir_summary(dirpath, name) retval = self.get_dbdir_summary(dirpath, name)
summary_list.append( retval ) summary_list.append( retval )
return summary_list return summary_list
@ -220,6 +217,15 @@ class CLIDbManager(object):
for dpath in os.listdir(dbdir): for dpath in os.listdir(dbdir):
dirpath = os.path.join(dbdir, dpath) dirpath = os.path.join(dbdir, dpath)
path_name = os.path.join(dirpath, NAME_FILE) path_name = os.path.join(dirpath, NAME_FILE)
try:
backend_type = open(os.path.join(dirpath, "database.txt")).read()
except:
backend_type = "bsddb"
try:
version = open(os.path.join(dirpath, "bdbversion.txt")).read()
except:
version = "(0, 0, 0)"
version = ast.literal_eval(version)
if os.path.isfile(path_name): if os.path.isfile(path_name):
file = open(path_name, 'r', encoding='utf8') file = open(path_name, 'r', encoding='utf8')
name = file.readline().strip() name = file.readline().strip()
@ -234,7 +240,7 @@ class CLIDbManager(object):
self.current_names.append( self.current_names.append(
(name, os.path.join(dbdir, dpath), path_name, (name, os.path.join(dbdir, dpath), path_name,
last, tval, enable, stock_id)) last, tval, enable, stock_id, backend_type, version))
self.current_names.sort() self.current_names.sort()
@ -294,7 +300,7 @@ class CLIDbManager(object):
(tval, last) = time_val(new_path) (tval, last) = time_val(new_path)
self.current_names.append((title, new_path, path_name, self.current_names.append((title, new_path, path_name,
last, tval, False, "")) last, tval, False, "", "Backend Type"))
return new_path, title return new_path, title
def _create_new_db(self, title=None, dbid=None): def _create_new_db(self, title=None, dbid=None):
@ -406,10 +412,10 @@ class CLIDbManager(object):
"No matching family tree found: '%s'" % dbname) "No matching family tree found: '%s'" % dbname)
# now delete them: # now delete them:
for (name, directory) in match_list: for (name, directory) in match_list:
if user is None or not user.prompt( if user is None or user.prompt(
_('Remove family tree warning'), _('Remove family tree warning'),
_('Are you sure you want to remove the family tree named\n"%s"?' % name), _('Are you sure you want to remove the family tree named\n"%s"?' % name),
_('no'), _('yes')): _('Yes'), _('No'), None):
try: try:
for (top, dirs, files) in os.walk(directory): for (top, dirs, files) in os.walk(directory):
for filename in files: for filename in files:

View File

@ -2001,6 +2001,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
_("Number of repositories"): self.get_number_of_repositories(), _("Number of repositories"): self.get_number_of_repositories(),
_("Number of notes"): self.get_number_of_notes(), _("Number of notes"): self.get_number_of_notes(),
_("Number of tags"): self.get_number_of_tags(), _("Number of tags"): self.get_number_of_tags(),
_("Schema version"): ".".join([str(v) for v in self.VERSION]),
} }
def get_dbname(self): def get_dbname(self):
@ -2102,3 +2103,20 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
""" """
self.__tables[table] = funcs self.__tables[table] = funcs
setattr(DbGeneric, table, property(lambda self: QuerySet(self, table))) setattr(DbGeneric, table, property(lambda self: QuerySet(self, table)))
def get_version(self):
"""
Return the version number of the schema.
"""
if self._directory:
filepath = os.path.join(self._directory, "bdbversion.txt")
try:
name_file = open(filepath, "r", encoding='utf-8')
version = name_file.readline().strip()
name_file.close()
except (OSError, IOError) as msg:
self.__log_error()
version = "(0, 0, 0)"
return ast.literal_eval(version)
else:
return (0, 0, 0)

View File

@ -106,6 +106,7 @@ DATE_COL = 3
DSORT_COL = 4 DSORT_COL = 4
OPEN_COL = 5 OPEN_COL = 5
ICON_COL = 6 ICON_COL = 6
BACKEND_COL = 7
RCS_BUTTON = { True : _('_Extract'), False : _('_Archive') } RCS_BUTTON = { True : _('_Extract'), False : _('_Archive') }
@ -299,7 +300,7 @@ class DbManager(CLIDbManager):
""" """
Builds the columns for the TreeView. The columns are: Builds the columns for the TreeView. The columns are:
Icon, Database Name, Last Modified Icon, Database Name, Last Modified, Backend Type
The Icon column gets its data from column 6 of the database model. The Icon column gets its data from column 6 of the database model.
It is expecting either None, or a GTK stock icon name It is expecting either None, or a GTK stock icon name
@ -310,8 +311,9 @@ class DbManager(CLIDbManager):
The last accessed column simply displays the last time famtree was The last accessed column simply displays the last time famtree was
opened. opened.
"""
The Backend Type column is a string based on database backend.
"""
# build the database name column # build the database name column
render = Gtk.CellRendererText() render = Gtk.CellRendererText()
render.set_property('ellipsize', Pango.EllipsizeMode.END) render.set_property('ellipsize', Pango.EllipsizeMode.END)
@ -341,6 +343,12 @@ class DbManager(CLIDbManager):
column.set_sort_column_id(DSORT_COL) column.set_sort_column_id(DSORT_COL)
self.dblist.append_column(column) self.dblist.append_column(column)
# build the backend column
render = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(_('Database Type'), render, text=BACKEND_COL)
column.set_sort_column_id(BACKEND_COL)
self.dblist.append_column(column)
def __populate(self): def __populate(self):
""" """
Builds the data and the display model. Builds the data and the display model.
@ -352,14 +360,17 @@ class DbManager(CLIDbManager):
""" """
Builds the display model. Builds the display model.
""" """
self.model = Gtk.TreeStore(str, str, str, str, int, bool, str) self.model = Gtk.TreeStore(str, str, str, str, int, bool, str, str)
#use current names to set up the model #use current names to set up the model
for items in self.current_names: for items in self.current_names:
data = list(items[:7]) data = list(items[:8])
node = self.model.append(None, data) backend_type = self.get_backend_name_from_dbid(data[7])
version = str(".".join([str(v) for v in items[8]]))
node = self.model.append(None, data[:-1] + [backend_type + ", " + version])
for rdata in find_revisions(os.path.join(items[1], ARCHIVE_V)): for rdata in find_revisions(os.path.join(items[1], ARCHIVE_V)):
data = [ rdata[2], rdata[0], items[1], rdata[1], 0, False, "" ] data = [rdata[2], rdata[0], items[1], rdata[1], 0, False, "",
backend_type + ", " + version]
self.model.append(node, data) self.model.append(node, data)
self.model.set_sort_column_id(NAME_COL, Gtk.SortType.ASCENDING) self.model.set_sort_column_id(NAME_COL, Gtk.SortType.ASCENDING)
self.dblist.set_model(self.model) self.dblist.set_model(self.model)
@ -808,6 +819,13 @@ class DbManager(CLIDbManager):
str(msg)) str(msg))
self.new.set_sensitive(True) self.new.set_sensitive(True)
def get_backend_name_from_dbid(self, dbid):
pmgr = GuiPluginManager.get_instance()
for plugin in pmgr.get_reg_databases():
if plugin.id == dbid:
return plugin._name
return _("Unknown Database Type")
def _create_new_db(self, title=None, create_db=True, dbid=None): def _create_new_db(self, title=None, create_db=True, dbid=None):
""" """
Create a new database, append to model Create a new database, append to model
@ -815,8 +833,9 @@ class DbManager(CLIDbManager):
new_path, title = self.create_new_db_cli(title, create_db, dbid) new_path, title = self.create_new_db_cli(title, create_db, dbid)
path_name = os.path.join(new_path, NAME_FILE) path_name = os.path.join(new_path, NAME_FILE)
(tval, last) = time_val(new_path) (tval, last) = time_val(new_path)
backend_type = self.get_backend_name_from_dbid(dbid)
node = self.model.append(None, [title, new_path, path_name, node = self.model.append(None, [title, new_path, path_name,
last, tval, False, '']) last, tval, False, '', backend_type])
self.selection.select_iter(node) self.selection.select_iter(node)
path = self.model.get_path(node) path = self.model.get_path(node)
self.name_renderer.set_property('editable', True) self.name_renderer.set_property('editable', True)

View File

@ -106,7 +106,7 @@
<property name="border_width">6</property> <property name="border_width">6</property>
<property name="title" translatable="yes">Family Trees - Gramps</property> <property name="title" translatable="yes">Family Trees - Gramps</property>
<property name="window_position">center-on-parent</property> <property name="window_position">center-on-parent</property>
<property name="default_width">710</property> <property name="default_width">800</property>
<property name="default_height">300</property> <property name="default_height">300</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<child internal-child="vbox"> <child internal-child="vbox">

View File

@ -20,8 +20,8 @@
plg = newplugin() plg = newplugin()
plg.id = 'bsddb' plg.id = 'bsddb'
plg.name = _("BSDDB Database Backend") plg.name = _("BSDDB Database")
plg.name_accell = _("_BSDDB Database Backend") plg.name_accell = _("_BSDDB Database")
plg.description = _("Berkeley Software Distribution Database Backend") plg.description = _("Berkeley Software Distribution Database Backend")
plg.version = '1.0' plg.version = '1.0'
plg.gramps_target_version = "5.0" plg.gramps_target_version = "5.0"

View File

@ -35,6 +35,7 @@ import random
import os import os
from sys import maxsize from sys import maxsize
from operator import itemgetter from operator import itemgetter
import ast
try: try:
from bsddb3 import db from bsddb3 import db
@ -2047,6 +2048,17 @@ class DbBsddbRead(DbReadBase, Callback):
name = None name = None
return name return name
def get_version(self):
filepath = os.path.join(self.path, "bdbversion.txt")
try:
name_file = open(filepath, "r", encoding='utf-8')
version = name_file.readline().strip()
name_file.close()
except (OSError, IOError) as msg:
self.__log_error()
version = "(0, 0, 0)"
return ast.literal_eval(version)
def get_summary(self): def get_summary(self):
""" """
Returns dictionary of summary item. Returns dictionary of summary item.

View File

@ -20,9 +20,9 @@
register(DATABASE, register(DATABASE,
id = 'dbapi', id = 'dbapi',
name = _("DB-API 2.0 Database Backend"), name = _("DB-API Database"),
name_accell = _("DB-_API 2.0 Database Backend"), name_accell = _("DB-_API Database"),
description = _("DB-API 2.0 Database Backend"), description = _("DB-API Database"),
version = '1.0.32', version = '1.0.32',
gramps_target_version = "5.0", gramps_target_version = "5.0",
status = STABLE, status = STABLE,

View File

@ -40,6 +40,7 @@ class DBAPI(DbGeneric):
""" """
Database backends class for DB-API 2.0 databases Database backends class for DB-API 2.0 databases
""" """
VERSION = (18, 0, 0)
def restore(self): def restore(self):
""" """
@ -53,6 +54,9 @@ class DBAPI(DbGeneric):
LOG.debug("Write database backend file to 'dbapi'") LOG.debug("Write database backend file to 'dbapi'")
with open(versionpath, "w") as version_file: with open(versionpath, "w") as version_file:
version_file.write("dbapi") version_file.write("dbapi")
versionpath = os.path.join(directory, "bdbversion.txt")
with open(versionpath, "w") as version_file:
version_file.write(str(self.VERSION))
# Write default_settings, sqlite.db # Write default_settings, sqlite.db
defaults = os.path.join(os.path.dirname(os.path.abspath(__file__)), defaults = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"dbapi_support", "defaults") "dbapi_support", "defaults")

View File

@ -20,9 +20,9 @@
plg = newplugin() plg = newplugin()
plg.id = 'dictionarydb' plg.id = 'dictionarydb'
plg.name = _("Dictionary Database Backend") plg.name = _("Dictionary Database")
plg.name_accell = _("Di_ctionary Database Backend") plg.name_accell = _("Di_ctionary Database")
plg.description = _("Dictionary (in-memory) Database Backend") plg.description = _("Dictionary Database")
plg.version = '1.0' plg.version = '1.0'
plg.gramps_target_version = "5.0" plg.gramps_target_version = "5.0"
plg.status = STABLE plg.status = STABLE

View File

@ -103,6 +103,9 @@ class DictionaryDb(DbGeneric):
LOG.debug("Write database backend file to 'dictionarydb'") LOG.debug("Write database backend file to 'dictionarydb'")
with open(versionpath, "w") as version_file: with open(versionpath, "w") as version_file:
version_file.write("dictionarydb") version_file.write("dictionarydb")
versionpath = os.path.join(directory, "bdbversion.txt")
with open(versionpath, "w") as version_file:
version_file.write(str(self.VERSION))
def initialize_backend(self, directory): def initialize_backend(self, directory):
pass pass

View File

@ -20,9 +20,9 @@
register(DATABASE, register(DATABASE,
id = 'inmemorydb', id = 'inmemorydb',
name = _("In-Memory Database Backend"), name = _("In-Memory Database"),
name_accell = _("In-_Memory Database Backend"), name_accell = _("In-_Memory Database"),
description = _("In-Memory Database Backend"), description = _("In-Memory Database"),
version = '1.0.0', version = '1.0.0',
gramps_target_version = "5.0", gramps_target_version = "5.0",
status = STABLE, status = STABLE,

View File

@ -42,6 +42,9 @@ class InMemoryDB(DBAPI):
LOG.debug("Write database backend file to 'inmemorydb'") LOG.debug("Write database backend file to 'inmemorydb'")
with open(versionpath, "w") as version_file: with open(versionpath, "w") as version_file:
version_file.write("inmemorydb") version_file.write("inmemorydb")
versionpath = os.path.join(directory, "bdbversion.txt")
with open(versionpath, "w") as version_file:
version_file.write(str(self.VERSION))
def load(self, directory, callback=None, mode=None, def load(self, directory, callback=None, mode=None,
force_schema_upgrade=False, force_schema_upgrade=False,