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 os
import sys
import ast
import time
from urllib.parse import urlparse
from urllib.request import urlopen, url2pathname
@ -158,9 +159,9 @@ class CLIDbManager(object):
if not self.is_locked(dirpath):
try:
database = self.dbstate.make_database(dbid)
database.load(dirpath, None, update=False)
database.load(dirpath, None)
retval = database.get_summary()
database.close(update=False)
database.close()
except Exception as msg:
retval = {_("Unavailable"): str(msg)[:74] + "..."}
else:
@ -173,26 +174,24 @@ class CLIDbManager(object):
})
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.
"""
print(_('Gramps Family Trees:'))
for item in self.current_names:
(name, dirpath, path_name, last,
tval, enable, stock_id) = item
if (database_names is None or
any([re.match(dbname, name) for dbname in database_names])):
summary = self.get_dbdir_summary(dirpath, name)
print(_("Family Tree \"%s\":") % summary[_("Family Tree")])
for item in sorted(summary):
if item != "Family Tree":
# translators: needed for French, ignore otherwise
print(_(" %(item)s: %(summary)s") % {
'item' : item,
'summary' : summary[item] } )
tval, enable, stock_id, backend_type, version) = item
summary = self.get_dbdir_summary(dirpath, name)
print(_("Family Tree \"%s\":") % summary[_("Family Tree")])
for item in sorted(summary):
if item != "Family Tree":
# translators: needed for French, ignore otherwise
print(_(" %(item)s: %(summary)s") % {
'item' : 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.
"""
@ -200,11 +199,9 @@ class CLIDbManager(object):
summary_list = []
for item in self.current_names:
(name, dirpath, path_name, last,
tval, enable, stock_id) = item
if (database_names is None or
any([re.match(dbname, name) for dbname in database_names])):
retval = self.get_dbdir_summary(dirpath, name)
summary_list.append( retval )
tval, enable, stock_id, backend_type) = item
retval = self.get_dbdir_summary(dirpath, name)
summary_list.append( retval )
return summary_list
def _populate_cli(self):
@ -220,6 +217,15 @@ class CLIDbManager(object):
for dpath in os.listdir(dbdir):
dirpath = os.path.join(dbdir, dpath)
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):
file = open(path_name, 'r', encoding='utf8')
name = file.readline().strip()
@ -231,10 +237,10 @@ class CLIDbManager(object):
if (stock_id == 'gramps-lock'):
last = find_locker_name(dirpath)
self.current_names.append(
(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()
@ -294,7 +300,7 @@ class CLIDbManager(object):
(tval, last) = time_val(new_path)
self.current_names.append((title, new_path, path_name,
last, tval, False, ""))
last, tval, False, "", "Backend Type"))
return new_path, title
def _create_new_db(self, title=None, dbid=None):
@ -406,10 +412,10 @@ class CLIDbManager(object):
"No matching family tree found: '%s'" % dbname)
# now delete them:
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'),
_('Are you sure you want to remove the family tree named\n"%s"?' % name),
_('no'), _('yes')):
_('Yes'), _('No'), None):
try:
for (top, dirs, files) in os.walk(directory):
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 notes"): self.get_number_of_notes(),
_("Number of tags"): self.get_number_of_tags(),
_("Schema version"): ".".join([str(v) for v in self.VERSION]),
}
def get_dbname(self):
@ -2102,3 +2103,20 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
"""
self.__tables[table] = funcs
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
OPEN_COL = 5
ICON_COL = 6
BACKEND_COL = 7
RCS_BUTTON = { True : _('_Extract'), False : _('_Archive') }
@ -299,7 +300,7 @@ class DbManager(CLIDbManager):
"""
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.
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
opened.
"""
The Backend Type column is a string based on database backend.
"""
# build the database name column
render = Gtk.CellRendererText()
render.set_property('ellipsize', Pango.EllipsizeMode.END)
@ -341,6 +343,12 @@ class DbManager(CLIDbManager):
column.set_sort_column_id(DSORT_COL)
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):
"""
Builds the data and the display model.
@ -352,14 +360,17 @@ class DbManager(CLIDbManager):
"""
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
for items in self.current_names:
data = list(items[:7])
node = self.model.append(None, data)
data = list(items[:8])
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)):
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.set_sort_column_id(NAME_COL, Gtk.SortType.ASCENDING)
self.dblist.set_model(self.model)
@ -808,6 +819,13 @@ class DbManager(CLIDbManager):
str(msg))
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):
"""
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)
path_name = os.path.join(new_path, NAME_FILE)
(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,
last, tval, False, ''])
last, tval, False, '', backend_type])
self.selection.select_iter(node)
path = self.model.get_path(node)
self.name_renderer.set_property('editable', True)

View File

@ -106,7 +106,7 @@
<property name="border_width">6</property>
<property name="title" translatable="yes">Family Trees - Gramps</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="type_hint">dialog</property>
<child internal-child="vbox">

View File

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

View File

@ -35,6 +35,7 @@ import random
import os
from sys import maxsize
from operator import itemgetter
import ast
try:
from bsddb3 import db
@ -2047,6 +2048,17 @@ class DbBsddbRead(DbReadBase, Callback):
name = None
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):
"""
Returns dictionary of summary item.

View File

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

View File

@ -40,6 +40,7 @@ class DBAPI(DbGeneric):
"""
Database backends class for DB-API 2.0 databases
"""
VERSION = (18, 0, 0)
def restore(self):
"""
@ -53,6 +54,9 @@ class DBAPI(DbGeneric):
LOG.debug("Write database backend file to 'dbapi'")
with open(versionpath, "w") as version_file:
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
defaults = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"dbapi_support", "defaults")

View File

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

View File

@ -103,6 +103,9 @@ class DictionaryDb(DbGeneric):
LOG.debug("Write database backend file to 'dictionarydb'")
with open(versionpath, "w") as version_file:
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):
pass

View File

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

View File

@ -42,6 +42,9 @@ class InMemoryDB(DBAPI):
LOG.debug("Write database backend file to 'inmemorydb'")
with open(versionpath, "w") as version_file:
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,
force_schema_upgrade=False,