Add optional list of trees to command-line args: -t -l -L

This commit is contained in:
Doug Blank 2016-04-14 20:42:40 -04:00
parent dbd00b2a32
commit dd55b367ce
3 changed files with 32 additions and 20 deletions

View File

@ -170,6 +170,7 @@ class ArgHandler(object):
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.list_table = parser.list_table
self.database_names = parser.database_names
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)
@ -396,9 +397,9 @@ class ArgHandler(object):
for name, dirname in sorted(self.dbman.family_tree_list(), for name, dirname in sorted(self.dbman.family_tree_list(),
key=lambda pair: pair[0].lower()): key=lambda pair: pair[0].lower()):
if self.database_names is None or name in self.database_names:
print(_("%(full_DB_path)s with name \"%(f_t_name)s\"") print(_("%(full_DB_path)s with name \"%(f_t_name)s\"")
% {'full_DB_path' : dirname, 'f_t_name' : name}) % {'full_DB_path' : dirname, 'f_t_name' : name})
return return
# Handle the "--remove" Family Tree # Handle the "--remove" Family Tree
@ -409,13 +410,13 @@ class ArgHandler(object):
# Handle the "-L" List Family Trees in detail option. # Handle the "-L" List Family Trees in detail option.
if self.list_more: if self.list_more:
self.dbman.print_family_tree_summaries() self.dbman.print_family_tree_summaries(self.database_names)
return return
# Handle the "-t" List Family Trees, tab delimited option. # Handle the "-t" List Family Trees, tab delimited option.
if self.list_table: if self.list_table:
print(_('Gramps Family Trees:')) print(_('Gramps Family Trees:'))
summary_list = self.dbman.family_tree_summary() summary_list = self.dbman.family_tree_summary(self.database_names)
if not summary_list: if not summary_list:
return return
# We have to construct the line elements together, to avoid # We have to construct the line elements together, to avoid

View File

@ -67,9 +67,9 @@ Application options
-a, --action=ACTION Specify action -a, --action=ACTION Specify action
-p, --options=OPTIONS_STRING Specify options -p, --options=OPTIONS_STRING Specify options
-d, --debug=LOGGER_NAME Enable debug logs -d, --debug=LOGGER_NAME Enable debug logs
-l List Family Trees -l [FAMILY_TREE...] List Family Trees
-L List Family Trees in Detail -L [FAMILY_TREE...] List Family Trees in Detail
-t List Family Trees, tab delimited -t [FAMILY_TREE...] List Family Trees, tab delimited
-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
@ -201,6 +201,7 @@ class ArgParser(object):
self.list = False self.list = False
self.list_more = False self.list_more = False
self.list_table = False self.list_table = False
self.database_names = None
self.help = False self.help = False
self.usage = False self.usage = False
self.force_unlock = False self.force_unlock = False
@ -241,6 +242,14 @@ class ArgParser(object):
"read the manual pages.") % cliargs)] "read the manual pages.") % cliargs)]
return return
# Some args can work on a list of databases:
if leftargs:
for opt_ix in range(len(options)):
option, value = options[opt_ix]
if option in ['-L', '-l', '-t']:
self.database_names = leftargs
leftargs = []
if leftargs: if leftargs:
# if there were an argument without option, # if there were an argument without option,
# use it as a file to open and return # use it as a file to open and return

View File

@ -173,7 +173,7 @@ class CLIDbManager(object):
}) })
return retval return retval
def print_family_tree_summaries(self): def print_family_tree_summaries(self, database_names=None):
""" """
Prints a detailed list of the known family trees. Prints a detailed list of the known family trees.
""" """
@ -181,16 +181,17 @@ 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
summary = self.get_dbdir_summary(dirpath, name) if database_names is None or name in database_names:
print(_("Family Tree \"%s\":") % summary[_("Family Tree")]) summary = self.get_dbdir_summary(dirpath, name)
for item in sorted(summary): print(_("Family Tree \"%s\":") % summary[_("Family Tree")])
if item != "Family Tree": for item in sorted(summary):
# translators: needed for French, ignore otherwise if item != "Family Tree":
print(_(" %(item)s: %(summary)s") % { # translators: needed for French, ignore otherwise
'item' : item, print(_(" %(item)s: %(summary)s") % {
'summary' : summary[item] } ) 'item' : item,
'summary' : summary[item] } )
def family_tree_summary(self): def family_tree_summary(self, database_names=None):
""" """
Return a list of dictionaries of the known family trees. Return a list of dictionaries of the known family trees.
""" """
@ -199,8 +200,9 @@ 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
retval = self.get_dbdir_summary(dirpath, name) if database_names is None or name in database_names:
summary_list.append( retval ) retval = self.get_dbdir_summary(dirpath, name)
summary_list.append( retval )
return summary_list return summary_list
def _populate_cli(self): def _populate_cli(self):