0006483: Listing the Family Trees can corrupt them. Changed get_dbdir_summary to exit if the bsddb_version is not the current bsddb and to return both BSDDB and schema version. Changed family_tree_summary to output both versions. Changed argparser and arghandler to additionally support -t (table) option to list family tree in tab delimited format.
svn: r21827
This commit is contained in:
parent
ba12b62810
commit
9d8d1576b4
@ -166,6 +166,7 @@ class ArgHandler(object):
|
|||||||
self.actions = parser.actions
|
self.actions = parser.actions
|
||||||
self.list = parser.list
|
self.list = parser.list
|
||||||
self.list_more = parser.list_more
|
self.list_more = parser.list_more
|
||||||
|
self.list_table = parser.list_table
|
||||||
self.open_gui = parser.open_gui
|
self.open_gui = parser.open_gui
|
||||||
self.imp_db_path = None
|
self.imp_db_path = None
|
||||||
self.dbman = CLIDbManager(self.dbstate)
|
self.dbman = CLIDbManager(self.dbstate)
|
||||||
@ -425,6 +426,25 @@ class ArgHandler(object):
|
|||||||
print(" %s: %s" % (item, summary[item]))
|
print(" %s: %s" % (item, summary[item]))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
if self.list_table:
|
||||||
|
print(_('Gramps Family Trees:'))
|
||||||
|
summary_list = self.dbman.family_tree_summary()
|
||||||
|
print(_("Family Tree"), end="")
|
||||||
|
for key in sorted(summary_list[0]):
|
||||||
|
if key != "Family tree":
|
||||||
|
print("\t ", end="")
|
||||||
|
print(key, end="")
|
||||||
|
print()
|
||||||
|
for summary in sorted(summary_list,
|
||||||
|
key=lambda sum: sum[_("Family tree")].lower()):
|
||||||
|
print('"%s"' % summary["Family tree"], end="")
|
||||||
|
for item in sorted(summary):
|
||||||
|
if item != _("Family tree"):
|
||||||
|
print("\t ", end="")
|
||||||
|
print('"%s"' % summary[item], end="")
|
||||||
|
print()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
self.__open_action()
|
self.__open_action()
|
||||||
self.__import_action()
|
self.__import_action()
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ Application options
|
|||||||
-d, --debug=LOGGER_NAME Enable debug logs
|
-d, --debug=LOGGER_NAME Enable debug logs
|
||||||
-l List Family Trees
|
-l List Family Trees
|
||||||
-L List Family Trees in Detail
|
-L List Family Trees in Detail
|
||||||
|
-t List Family Trees in tabular (tab delimited) form
|
||||||
-u, --force-unlock Force unlock of family tree
|
-u, --force-unlock Force unlock of family tree
|
||||||
-s, --show Show config settings
|
-s, --show Show config settings
|
||||||
-c, --config=[config.setting[:value]] Set config setting(s) and start Gramps
|
-c, --config=[config.setting[:value]] Set config setting(s) and start Gramps
|
||||||
@ -176,6 +177,7 @@ class ArgParser(object):
|
|||||||
self.imp_db_path = None
|
self.imp_db_path = None
|
||||||
self.list = False
|
self.list = False
|
||||||
self.list_more = False
|
self.list_more = False
|
||||||
|
self.list_table = False
|
||||||
self.help = False
|
self.help = False
|
||||||
self.usage = False
|
self.usage = False
|
||||||
self.force_unlock = False
|
self.force_unlock = False
|
||||||
@ -293,6 +295,8 @@ class ArgParser(object):
|
|||||||
self.list = True
|
self.list = True
|
||||||
elif option in ('-L'):
|
elif option in ('-L'):
|
||||||
self.list_more = True
|
self.list_more = True
|
||||||
|
elif option in ('-t'):
|
||||||
|
self.list_table = True
|
||||||
elif option in ('-s','--show'):
|
elif option in ('-s','--show'):
|
||||||
print(_("Gramps config settings from %s:")
|
print(_("Gramps config settings from %s:")
|
||||||
% config.filename)
|
% config.filename)
|
||||||
@ -347,7 +351,8 @@ class ArgParser(object):
|
|||||||
del options[ind]
|
del options[ind]
|
||||||
|
|
||||||
if len(options) > 0 and self.open is None and self.imports == [] \
|
if len(options) > 0 and self.open is None and self.imports == [] \
|
||||||
and not (self.list or self.list_more or self.help or self.runqml):
|
and not (self.list or self.list_more or self.list_table or
|
||||||
|
self.help or self.runqml):
|
||||||
# Extract and convert to unicode the arguments in the list.
|
# Extract and convert to unicode the arguments in the list.
|
||||||
# The % operator replaces the list elements with repr() of
|
# The % operator replaces the list elements with repr() of
|
||||||
# the list elements, which is OK for latin characters
|
# the list elements, which is OK for latin characters
|
||||||
@ -374,7 +379,7 @@ class ArgParser(object):
|
|||||||
#errors in argument parsing ==> give cli error, no gui needed
|
#errors in argument parsing ==> give cli error, no gui needed
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.list or self.list_more or self.help:
|
if self.list or self.list_more or self.list_table or self.help:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.open_gui:
|
if self.open_gui:
|
||||||
|
@ -136,62 +136,85 @@ class CLIDbManager(object):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_dbdir_summary(self, file_name):
|
def get_dbdir_summary(self, dirpath, name):
|
||||||
"""
|
"""
|
||||||
Returns (people_count, version_number) of current DB.
|
Returns (people_count, bsddb_version, schema_version) of
|
||||||
Returns ("Unknown", "Unknown") if invalid DB or other error.
|
current DB.
|
||||||
|
Returns ("Unknown", "Unknown", "Unknown") if invalid DB or other error.
|
||||||
"""
|
"""
|
||||||
if config.get('preferences.use-bsddb3') or sys.version_info[0] >= 3:
|
if config.get('preferences.use-bsddb3') or sys.version_info[0] >= 3:
|
||||||
from bsddb3 import dbshelve, db
|
from bsddb3 import dbshelve, db
|
||||||
else:
|
else:
|
||||||
from bsddb import dbshelve, db
|
from bsddb import dbshelve, db
|
||||||
|
|
||||||
from gramps.gen.db import META, PERSON_TBL
|
from gramps.gen.db import META, PERSON_TBL
|
||||||
|
from gramps.gen.db.dbconst import BDBVERSFN
|
||||||
|
|
||||||
|
bdbversion_file = os.path.join(dirpath, BDBVERSFN)
|
||||||
|
if os.path.isfile(bdbversion_file):
|
||||||
|
vers_file = open(bdbversion_file)
|
||||||
|
bsddb_version = vers_file.readline().strip()
|
||||||
|
else:
|
||||||
|
return "Unknown", "Unknown", "Unknown"
|
||||||
|
|
||||||
|
current_bsddb_version = str(db.version())
|
||||||
|
if bsddb_version != current_bsddb_version:
|
||||||
|
return "Unknown", bsddb_version, "Unknown"
|
||||||
|
|
||||||
env = db.DBEnv()
|
env = db.DBEnv()
|
||||||
flags = db.DB_CREATE | db.DB_PRIVATE |\
|
flags = db.DB_CREATE | db.DB_PRIVATE |\
|
||||||
db.DB_INIT_MPOOL |\
|
db.DB_INIT_MPOOL |\
|
||||||
db.DB_INIT_LOG | db.DB_INIT_TXN
|
db.DB_INIT_LOG | db.DB_INIT_TXN
|
||||||
try:
|
try:
|
||||||
env.open(file_name, flags)
|
env.open(dirpath, flags)
|
||||||
except:
|
except Exception as msg:
|
||||||
return "Unknown", "Unknown"
|
LOG.warning("Error opening db environment for '%s': %s" %
|
||||||
|
(name, str(msg)))
|
||||||
|
try:
|
||||||
|
env.close()
|
||||||
|
except Exception as msg:
|
||||||
|
LOG.warning("Error closing db environment for '%s': %s" %
|
||||||
|
(name, str(msg)))
|
||||||
|
return "Unknown", bsddb_version, "Unknown"
|
||||||
dbmap1 = dbshelve.DBShelf(env)
|
dbmap1 = dbshelve.DBShelf(env)
|
||||||
fname = os.path.join(file_name, META + ".db")
|
fname = os.path.join(dirpath, META + ".db")
|
||||||
try:
|
try:
|
||||||
dbmap1.open(fname, META, db.DB_HASH, db.DB_RDONLY)
|
dbmap1.open(fname, META, db.DB_HASH, db.DB_RDONLY)
|
||||||
except:
|
except:
|
||||||
env.close()
|
env.close()
|
||||||
return "Unknown", "Unknown"
|
return "Unknown", bsddb_version, "Unknown"
|
||||||
version = dbmap1.get(b'version', default=None)
|
schema_version = dbmap1.get(b'version', default=None)
|
||||||
dbmap1.close()
|
dbmap1.close()
|
||||||
dbmap2 = dbshelve.DBShelf(env)
|
dbmap2 = dbshelve.DBShelf(env)
|
||||||
fname = os.path.join(file_name, PERSON_TBL + ".db")
|
fname = os.path.join(dirpath, PERSON_TBL + ".db")
|
||||||
try:
|
try:
|
||||||
dbmap2.open(fname, PERSON_TBL, db.DB_HASH, db.DB_RDONLY)
|
dbmap2.open(fname, PERSON_TBL, db.DB_HASH, db.DB_RDONLY)
|
||||||
except:
|
except:
|
||||||
env.close()
|
env.close()
|
||||||
return "Unknown", "Unknown"
|
return "Unknown", bsddb_version, schema_version
|
||||||
count = len(dbmap2)
|
count = len(dbmap2)
|
||||||
dbmap2.close()
|
dbmap2.close()
|
||||||
env.close()
|
env.close()
|
||||||
return (count, version)
|
return (count, bsddb_version, schema_version)
|
||||||
|
|
||||||
def family_tree_summary(self):
|
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.
|
||||||
"""
|
"""
|
||||||
# make the default directory if it does not exist
|
# make the default directory if it does not exist
|
||||||
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) = item
|
||||||
count, version = self.get_dbdir_summary(dirpath)
|
count, bsddb_version, schema_version = self.get_dbdir_summary(dirpath, name)
|
||||||
retval = {}
|
retval = {}
|
||||||
retval["Number of people"] = count
|
retval["Number of people"] = count
|
||||||
if enable:
|
if enable:
|
||||||
retval["Locked?"] = "yes"
|
retval["Locked?"] = "yes"
|
||||||
else:
|
else:
|
||||||
retval["Locked?"] = "no"
|
retval["Locked?"] = "no"
|
||||||
retval["DB version"] = version
|
retval["Bsddb version"] = bsddb_version
|
||||||
|
retval["Schema version"] = schema_version
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
retval["Family tree"] = name.encode(glocale.getfilesystemencoding())
|
retval["Family tree"] = name.encode(glocale.getfilesystemencoding())
|
||||||
else:
|
else:
|
||||||
@ -199,8 +222,8 @@ class CLIDbManager(object):
|
|||||||
retval["Path"] = dirpath
|
retval["Path"] = dirpath
|
||||||
retval["Last accessed"] = time.strftime('%x %X',
|
retval["Last accessed"] = time.strftime('%x %X',
|
||||||
time.localtime(tval))
|
time.localtime(tval))
|
||||||
list.append( retval )
|
summary_list.append( retval )
|
||||||
return list
|
return summary_list
|
||||||
|
|
||||||
def _populate_cli(self):
|
def _populate_cli(self):
|
||||||
""" Get the list of current names in the database dir
|
""" Get the list of current names in the database dir
|
||||||
|
@ -306,6 +306,6 @@ LONGOPTS = [
|
|||||||
"qml",
|
"qml",
|
||||||
]
|
]
|
||||||
|
|
||||||
SHORTOPTS = "O:C:i:e:f:a:p:d:c:lLhuv?s"
|
SHORTOPTS = "O:C:i:e:f:a:p:d:c:lLthuv?s"
|
||||||
|
|
||||||
GRAMPS_UUID = uuid.UUID('516cd010-5a41-470f-99f8-eb22f1098ad6')
|
GRAMPS_UUID = uuid.UUID('516cd010-5a41-470f-99f8-eb22f1098ad6')
|
||||||
|
Loading…
Reference in New Issue
Block a user