From dd55b367cef28a68ab009d742a3798d2c043c61d Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 14 Apr 2016 20:42:40 -0400 Subject: [PATCH] Add optional list of trees to command-line args: -t -l -L --- gramps/cli/arghandler.py | 11 ++++++----- gramps/cli/argparser.py | 15 ++++++++++++--- gramps/cli/clidbman.py | 26 ++++++++++++++------------ 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/gramps/cli/arghandler.py b/gramps/cli/arghandler.py index 6c6bc55b3..668a538b2 100644 --- a/gramps/cli/arghandler.py +++ b/gramps/cli/arghandler.py @@ -170,6 +170,7 @@ class ArgHandler(object): self.list = parser.list self.list_more = parser.list_more self.list_table = parser.list_table + self.database_names = parser.database_names self.open_gui = parser.open_gui self.imp_db_path = None self.dbman = CLIDbManager(self.dbstate) @@ -396,9 +397,9 @@ class ArgHandler(object): for name, dirname in sorted(self.dbman.family_tree_list(), key=lambda pair: pair[0].lower()): - - print(_("%(full_DB_path)s with name \"%(f_t_name)s\"") - % {'full_DB_path' : dirname, 'f_t_name' : name}) + if self.database_names is None or name in self.database_names: + print(_("%(full_DB_path)s with name \"%(f_t_name)s\"") + % {'full_DB_path' : dirname, 'f_t_name' : name}) return # Handle the "--remove" Family Tree @@ -409,13 +410,13 @@ class ArgHandler(object): # Handle the "-L" List Family Trees in detail option. if self.list_more: - self.dbman.print_family_tree_summaries() + self.dbman.print_family_tree_summaries(self.database_names) return # Handle the "-t" List Family Trees, tab delimited option. if self.list_table: 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: return # We have to construct the line elements together, to avoid diff --git a/gramps/cli/argparser.py b/gramps/cli/argparser.py index a50171a0d..9dbced54e 100644 --- a/gramps/cli/argparser.py +++ b/gramps/cli/argparser.py @@ -67,9 +67,9 @@ Application options -a, --action=ACTION Specify action -p, --options=OPTIONS_STRING Specify options -d, --debug=LOGGER_NAME Enable debug logs - -l List Family Trees - -L List Family Trees in Detail - -t List Family Trees, tab delimited + -l [FAMILY_TREE...] List Family Trees + -L [FAMILY_TREE...] List Family Trees in Detail + -t [FAMILY_TREE...] List Family Trees, tab delimited -u, --force-unlock Force unlock of Family Tree -s, --show Show config settings -c, --config=[config.setting[:value]] Set config setting(s) and start Gramps @@ -201,6 +201,7 @@ class ArgParser(object): self.list = False self.list_more = False self.list_table = False + self.database_names = None self.help = False self.usage = False self.force_unlock = False @@ -241,6 +242,14 @@ class ArgParser(object): "read the manual pages.") % cliargs)] 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 there were an argument without option, # use it as a file to open and return diff --git a/gramps/cli/clidbman.py b/gramps/cli/clidbman.py index 4e3181499..1d966e685 100644 --- a/gramps/cli/clidbman.py +++ b/gramps/cli/clidbman.py @@ -173,7 +173,7 @@ class CLIDbManager(object): }) 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. """ @@ -181,16 +181,17 @@ class CLIDbManager(object): for item in self.current_names: (name, dirpath, path_name, last, tval, enable, stock_id) = 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] } ) + if database_names is None or name 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] } ) - def family_tree_summary(self): + def family_tree_summary(self, database_names=None): """ Return a list of dictionaries of the known family trees. """ @@ -199,8 +200,9 @@ class CLIDbManager(object): for item in self.current_names: (name, dirpath, path_name, last, tval, enable, stock_id) = item - retval = self.get_dbdir_summary(dirpath, name) - summary_list.append( retval ) + if database_names is None or name in database_names: + retval = self.get_dbdir_summary(dirpath, name) + summary_list.append( retval ) return summary_list def _populate_cli(self):