Cleanup of CLI output (sorts lists, gives additional help, straight columns) and don't crash on non-gui Options

svn: r16312
This commit is contained in:
Doug Blank 2010-12-25 16:52:12 +00:00
parent f8b99a00b2
commit 320cbb0308
2 changed files with 17 additions and 11 deletions

View File

@ -302,16 +302,16 @@ class ArgHandler(object):
if self.list: if self.list:
print 'List of known family trees in your database path\n' print 'List of known family trees in your database path\n'
for name, dirname in self.dbman.family_tree_list(): for name, dirname in sorted(self.dbman.family_tree_list(), key=lambda pair: pair[0].lower()):
print dirname, ', with name ', name.encode(sys.getfilesystemencoding()) print "%s with name \"%s\"" % (dirname, name.encode(sys.getfilesystemencoding()))
sys.exit(0) sys.exit(0)
if self.list_more: if self.list_more:
print 'Gramps Family Trees:' print 'Gramps Family Trees:'
summary_list = self.dbman.family_tree_summary() summary_list = self.dbman.family_tree_summary()
for summary in summary_list: for summary in sorted(summary_list, key=lambda summary: summary["Family tree"].lower()):
print "Family Tree \"%s\":" % summary["Family tree"] print "Family Tree \"%s\":" % summary["Family tree"]
for item in summary: for item in sorted(summary):
if item != "Family tree": if item != "Family tree":
print " %s: %s" % (item, summary[item]) print " %s: %s" % (item, summary[item])
sys.exit(0) sys.exit(0)
@ -497,7 +497,7 @@ class ArgHandler(object):
msg = "Report name not given. Please use one of [-p|--options] name=reportname." msg = "Report name not given. Please use one of [-p|--options] name=reportname."
print >> sys.stderr, "%s\n Available names are:" % msg print >> sys.stderr, "%s\n Available names are:" % msg
for pdata in _cl_list: for pdata in sorted(_cl_list, key= lambda pdata: pdata.id.lower()):
# Print cli report name ([item[0]) and GUI report name (item[4]) # Print cli report name ([item[0]) and GUI report name (item[4])
if len(pdata.id) <= 25: if len(pdata.id) <= 25:
print >> sys.stderr, \ print >> sys.stderr, \
@ -536,7 +536,7 @@ class ArgHandler(object):
msg = "Tool name not given. Please use one of [-p|--options] name=toolname." msg = "Tool name not given. Please use one of [-p|--options] name=toolname."
print >> sys.stderr, "%s\n Available names are:" % msg print >> sys.stderr, "%s\n Available names are:" % msg
for pdata in _cli_tool_list: for pdata in sorted(_cli_tool_list, key=lambda pdata: pdata.id.lower()):
# Print cli report name ([item[0]) and GUI report name (item[4]) # Print cli report name ([item[0]) and GUI report name (item[4])
if len(pdata.id) <= 25: if len(pdata.id) <= 25:
print >> sys.stderr, \ print >> sys.stderr, \

View File

@ -52,7 +52,7 @@ from gen.plug.docgen import (StyleSheet, StyleSheetList, PaperStyle,
from gen.plug.menu import (FamilyOption, PersonOption, NoteOption, from gen.plug.menu import (FamilyOption, PersonOption, NoteOption,
MediaOption, PersonListOption, NumberOption, MediaOption, PersonListOption, NumberOption,
BooleanOption, DestinationOption, StringOption, BooleanOption, DestinationOption, StringOption,
TextOption, EnumeratedListOption) TextOption, EnumeratedListOption, Option)
from gen.display.name import displayer as name_displayer from gen.display.name import displayer as name_displayer
from Errors import ReportError from Errors import ReportError
from gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, from gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK,
@ -289,8 +289,12 @@ class CommandLineReport(object):
for (value, description) in option.get_items(): for (value, description) in option.get_items():
ilist.append("%s\t%s" % (value, description)) ilist.append("%s\t%s" % (value, description))
self.options_help[name].append(ilist) self.options_help[name].append(ilist)
elif isinstance(option, Option):
self.options_help[name].append(option.get_help())
else: else:
print "Unknown option: ", option print "Unknown option: ", option
print " Valid options are:", ", ".join(self.options_dict.keys())
print " Use 'show=option' to see description and acceptable values"
def parse_options(self): def parse_options(self):
""" """
@ -313,6 +317,8 @@ class CommandLineReport(object):
else: else:
print "Ignoring unknown option: %s" % opt print "Ignoring unknown option: %s" % opt
print " Valid options are:", ", ".join(self.options_dict.keys())
print " Use 'show=option' to see description and acceptable values"
self.option_class.handler.output = self.options_dict['of'] self.option_class.handler.output = self.options_dict['of']
@ -369,11 +375,11 @@ class CommandLineReport(object):
return return
elif self.show == 'all': elif self.show == 'all':
print " Available options:" print " Available options:"
for key in self.options_dict: for key in sorted(self.options_dict.keys()):
if key in self.options_help: if key in self.options_help:
opt = self.options_help[key] opt = self.options_help[key]
# Make the output nicer to read, assume that tab has 8 spaces # Make the output nicer to read, assume that tab has 8 spaces
tabs = '\t' if len(key) < 10 else '\t'*2 tabs = '\t\t' if len(key) < 10 else '\t'
optmsg = " %s%s%s (%s)" % (key, tabs, opt[1], opt[0]) optmsg = " %s%s%s (%s)" % (key, tabs, opt[1], opt[0])
print optmsg.encode(sys.getfilesystemencoding()) print optmsg.encode(sys.getfilesystemencoding())
else: else:
@ -382,13 +388,13 @@ class CommandLineReport(object):
print " Use 'show=option' to see description and acceptable values" print " Use 'show=option' to see description and acceptable values"
elif self.show in self.options_help: elif self.show in self.options_help:
opt = self.options_help[self.show] opt = self.options_help[self.show]
tabs = '\t' if len(self.show) < 10 else '\t'*2 tabs = '\t\t' if len(self.show) < 10 else '\t'
print ' %s%s%s%s' % (self.show, tabs, opt[0], opt[1]) print ' %s%s%s%s' % (self.show, tabs, opt[0], opt[1])
print " Available values are:" print " Available values are:"
vals = opt[2] vals = opt[2]
if isinstance(vals, (list, tuple)): if isinstance(vals, (list, tuple)):
for val in vals: for val in vals:
optmsg = " %s" % key optmsg = " %s" % val
print optmsg.encode(sys.getfilesystemencoding()) print optmsg.encode(sys.getfilesystemencoding())
else: else:
optmsg = " %s" % opt[2] optmsg = " %s" % opt[2]