Database API, -L: database reports summary, if possible
This commit is contained in:
parent
3c52f7016b
commit
ea996cf6dd
@ -133,12 +133,42 @@ class CLIDbManager(object):
|
|||||||
|
|
||||||
def get_dbdir_summary(self, dirpath, name):
|
def get_dbdir_summary(self, dirpath, name):
|
||||||
"""
|
"""
|
||||||
Returns (people_count, bsddb_version, schema_version) of
|
dirpath: full path to database
|
||||||
current DB.
|
name: proper name of family tree
|
||||||
Returns ("Unknown", "Unknown", "Unknown") if invalid DB or other error.
|
|
||||||
|
Returns dictionary of summary item.
|
||||||
|
Should include at least, if possible:
|
||||||
|
|
||||||
|
_("Path")
|
||||||
|
_("Family Tree")
|
||||||
|
_("Last accessed")
|
||||||
|
_("Database backend")
|
||||||
|
_("Locked?")
|
||||||
|
|
||||||
|
and these details:
|
||||||
|
|
||||||
|
_("Number of people")
|
||||||
|
_("Version")
|
||||||
|
_("Schema version")
|
||||||
"""
|
"""
|
||||||
## Maybe return the txt file contents, for now
|
dbid = "bsddb"
|
||||||
return ("Unknown", "Unknown", "Unknown")
|
dbid_path = os.path.join(dirpath, "database.txt")
|
||||||
|
if os.path.isfile(dbid_path):
|
||||||
|
dbid = open(dbid_path).read().strip()
|
||||||
|
try:
|
||||||
|
database = self.dbstate.make_database(dbid)
|
||||||
|
database.load(dirpath, None)
|
||||||
|
retval = database.get_summary()
|
||||||
|
except Exception as msg:
|
||||||
|
retval = {"Unavailable": str(msg)[:74] + "..."}
|
||||||
|
retval.update({
|
||||||
|
_("Family Tree"): name,
|
||||||
|
_("Path"): dirpath,
|
||||||
|
_("Database backend"): dbid,
|
||||||
|
_("Last accessed"): time_val(dirpath)[1],
|
||||||
|
_("Locked?"): self.is_locked(dirpath),
|
||||||
|
})
|
||||||
|
return retval
|
||||||
|
|
||||||
def family_tree_summary(self):
|
def family_tree_summary(self):
|
||||||
"""
|
"""
|
||||||
@ -149,19 +179,7 @@ class CLIDbManager(object):
|
|||||||
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) = item
|
||||||
count, bsddb_version, schema_version = self.get_dbdir_summary(dirpath, name)
|
retval = self.get_dbdir_summary(dirpath, name)
|
||||||
retval = {}
|
|
||||||
retval[_("Number of people")] = count
|
|
||||||
if enable:
|
|
||||||
retval[_("Locked?")] = _("yes")
|
|
||||||
else:
|
|
||||||
retval[_("Locked?")] = _("no")
|
|
||||||
retval[_("Bsddb version")] = bsddb_version
|
|
||||||
retval[_("Schema version")] = schema_version
|
|
||||||
retval[_("Family Tree")] = name
|
|
||||||
retval[_("Path")] = dirpath
|
|
||||||
retval[_("Last accessed")] = time.strftime('%x %X',
|
|
||||||
time.localtime(tval))
|
|
||||||
summary_list.append( retval )
|
summary_list.append( retval )
|
||||||
return summary_list
|
return summary_list
|
||||||
|
|
||||||
|
@ -1976,3 +1976,16 @@ class DbBsddbRead(DbReadBase, Callback):
|
|||||||
self.__log_error()
|
self.__log_error()
|
||||||
name = None
|
name = None
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
def get_summary(self):
|
||||||
|
"""
|
||||||
|
Returns dictionary of summary item.
|
||||||
|
Should include, if possible:
|
||||||
|
|
||||||
|
_("Number of people")
|
||||||
|
_("Version")
|
||||||
|
_("Schema version")
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
_("Number of people"): self.get_number_of_people(),
|
||||||
|
}
|
||||||
|
@ -36,6 +36,8 @@ import logging
|
|||||||
# Gramps Modules
|
# Gramps Modules
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
|
_ = glocale.translation.gettext
|
||||||
from gramps.gen.db import DbReadBase, DbWriteBase, DbTxn, KEY_TO_NAME_MAP
|
from gramps.gen.db import DbReadBase, DbWriteBase, DbTxn, KEY_TO_NAME_MAP
|
||||||
from gramps.gen.db.undoredo import DbUndo
|
from gramps.gen.db.undoredo import DbUndo
|
||||||
from gramps.gen.db.dbconst import *
|
from gramps.gen.db.dbconst import *
|
||||||
@ -1711,3 +1713,30 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
"""
|
"""
|
||||||
return self._bm_changes > 0
|
return self._bm_changes > 0
|
||||||
|
|
||||||
|
def get_summary(self):
|
||||||
|
"""
|
||||||
|
Returns dictionary of summary item.
|
||||||
|
Should include, if possible:
|
||||||
|
|
||||||
|
_("Number of people")
|
||||||
|
_("Version")
|
||||||
|
_("Schema version")
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
_("Number of people"): self.get_number_of_people(),
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_dbname(self):
|
||||||
|
"""
|
||||||
|
In DictionaryDb, the database is in a text file at the path
|
||||||
|
"""
|
||||||
|
filepath = os.path.join(self._directory, "name.txt")
|
||||||
|
try:
|
||||||
|
name_file = open(filepath, "r")
|
||||||
|
name = name_file.readline().strip()
|
||||||
|
name_file.close()
|
||||||
|
except (OSError, IOError) as msg:
|
||||||
|
_LOG.error(str(msg))
|
||||||
|
name = None
|
||||||
|
return name
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ from django.db import transaction
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
import gramps
|
import gramps
|
||||||
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
|
_ = glocale.translation.gettext
|
||||||
from gramps.gen.lib import (Person, Family, Event, Place, Repository,
|
from gramps.gen.lib import (Person, Family, Event, Place, Repository,
|
||||||
Citation, Source, Note, MediaObject, Tag,
|
Citation, Source, Note, MediaObject, Tag,
|
||||||
Researcher)
|
Researcher)
|
||||||
@ -2028,9 +2030,6 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
## FIXME
|
## FIXME
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_dbname(self):
|
|
||||||
return "Django Database"
|
|
||||||
|
|
||||||
## missing
|
## missing
|
||||||
|
|
||||||
def find_place_child_handles(self, handle):
|
def find_place_child_handles(self, handle):
|
||||||
@ -2111,3 +2110,30 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
"""
|
"""
|
||||||
return self._bm_changes > 0
|
return self._bm_changes > 0
|
||||||
|
|
||||||
|
def get_summary(self):
|
||||||
|
"""
|
||||||
|
Returns dictionary of summary item.
|
||||||
|
Should include, if possible:
|
||||||
|
|
||||||
|
_("Number of people")
|
||||||
|
_("Version")
|
||||||
|
_("Schema version")
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
_("Number of people"): self.get_number_of_people(),
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_dbname(self):
|
||||||
|
"""
|
||||||
|
In Django, the database is in a text file at the path
|
||||||
|
"""
|
||||||
|
filepath = os.path.join(self._directory, "name.txt")
|
||||||
|
try:
|
||||||
|
name_file = open(filepath, "r")
|
||||||
|
name = name_file.readline().strip()
|
||||||
|
name_file.close()
|
||||||
|
except (OSError, IOError) as msg:
|
||||||
|
_LOG.error(str(msg))
|
||||||
|
name = None
|
||||||
|
return name
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user