0002019: Proposal to show person count and DB version --- this just adds a new command line flag, -L to show additional details
svn: r10603
This commit is contained in:
parent
bfdb86069b
commit
069fc653e3
@ -84,6 +84,7 @@ Application options
|
||||
-p, --options=OPTIONS_STRING Specify options
|
||||
-d, --debug=LOGGER_NAME Enable debug logs
|
||||
-l List Family Trees
|
||||
-L List Family Tree Details
|
||||
-u Force unlock of family tree
|
||||
"""
|
||||
|
||||
@ -131,6 +132,7 @@ class ArgHandler:
|
||||
self.imports = []
|
||||
self.imp_db_path = None
|
||||
self.list = False
|
||||
self.list_more = False
|
||||
self.help = False
|
||||
self.force_unlock = False
|
||||
self.dbman = CLIDbManager(self.state)
|
||||
@ -313,6 +315,8 @@ class ArgHandler:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
elif option in ('-l',):
|
||||
self.list = True
|
||||
elif option in ('-L',):
|
||||
self.list_more = True
|
||||
elif option in ('-h', '-?', '--help'):
|
||||
self.help = True
|
||||
elif option in ('-u', '--force-unlock'):
|
||||
@ -356,6 +360,15 @@ class ArgHandler:
|
||||
for name, dirname in self.dbman.family_tree_list():
|
||||
print dirname, ', with name ', name
|
||||
sys.exit(0)
|
||||
if self.list_more:
|
||||
print 'GRAMPS Family Trees:'
|
||||
list = self.dbman.family_tree_summary()
|
||||
for dict in list:
|
||||
print "Family Tree \"%s\":" % dict["Family tree"]
|
||||
for item in dict:
|
||||
if item != "Family tree":
|
||||
print " %s: %s" % (item, dict[item])
|
||||
sys.exit(0)
|
||||
if self.help:
|
||||
print _help
|
||||
sys.exit(0)
|
||||
|
@ -121,6 +121,62 @@ class CLIDbManager:
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_dbdir_summary(self, file_name):
|
||||
"""
|
||||
Returns (people_count, version_number) of current DB.
|
||||
Returns ("Unknown", "Unknown") if invalid DB or other error.
|
||||
"""
|
||||
from bsddb import dbshelve, db
|
||||
from gen.db import META, PERSON_TBL
|
||||
env = db.DBEnv()
|
||||
flags = db.DB_CREATE | db.DB_PRIVATE |\
|
||||
db.DB_INIT_MPOOL | db.DB_INIT_LOCK |\
|
||||
db.DB_INIT_LOG | db.DB_INIT_TXN | db.DB_THREAD
|
||||
try:
|
||||
env.open(file_name, flags)
|
||||
except:
|
||||
return "Unknown", "Unknown"
|
||||
dbmap1 = dbshelve.DBShelf(env)
|
||||
fname = os.path.join(file_name, META + ".db")
|
||||
dbmap1.open(fname, META, db.DB_HASH, db.DB_RDONLY)
|
||||
version = dbmap1.get('version', default=None)
|
||||
dbmap1.close()
|
||||
dbmap2 = dbshelve.DBShelf(env)
|
||||
fname = os.path.join(file_name, PERSON_TBL + ".db")
|
||||
try:
|
||||
dbmap2.open(fname, PERSON_TBL, db.DB_HASH, db.DB_RDONLY)
|
||||
except:
|
||||
env.close()
|
||||
return "Unknown", "Unknown"
|
||||
count = len(dbmap2)
|
||||
dbmap2.close()
|
||||
env.close()
|
||||
return (count, version)
|
||||
|
||||
def family_tree_summary(self):
|
||||
"""
|
||||
Return a list of dictionaries of the known family trees.
|
||||
"""
|
||||
# make the default directory if it does not exist
|
||||
list = []
|
||||
for item in self.current_names:
|
||||
(name, dirpath, path_name, last,
|
||||
tval, enable, stock_id) = item
|
||||
count, version = self.get_dbdir_summary(dirpath)
|
||||
retval = {}
|
||||
retval["Number of people"] = count
|
||||
if enable:
|
||||
retval["Locked?"] = "yes"
|
||||
else:
|
||||
retval["Locked?"] = "no"
|
||||
retval["DB version"] = version
|
||||
retval["Family tree"] = name
|
||||
retval["Path"] = dirpath
|
||||
retval["Last accessed"] = time.strftime('%x %X',
|
||||
time.localtime(tval))
|
||||
list.append( retval )
|
||||
return list
|
||||
|
||||
def _populate_cli(self):
|
||||
""" Get the list of current names in the database dir
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user