From d25248ccb85aa94c3098f97ed3d4c5743c99d25f Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Thu, 30 Jun 2011 02:47:48 +0000 Subject: [PATCH] 0004705: Book Report does not work from CLI (Patch from Paul Franklin). svn: r17870 --- src/cli/plug/__init__.py | 23 ++++++++++++++++------- src/plugins/BookReport.py | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/cli/plug/__init__.py b/src/cli/plug/__init__.py index 955891d53..39b6eed56 100644 --- a/src/cli/plug/__init__.py +++ b/src/cli/plug/__init__.py @@ -146,7 +146,6 @@ def _validate_options(options, dbase): dbase: the database the options will be applied to """ if not hasattr(options, "menu"): - print 'no menu' return menu = options.menu @@ -322,6 +321,15 @@ class CommandLineReport(object): """ Initialize the options that are defined by each report. """ + + if self.category == CATEGORY_BOOK: # a Book Report has no "menu" + for key in self.option_class.options_dict: + self.options_dict[key] = self.option_class.options_dict[key] + self.options_help[key] = \ + self.option_class.options_help[key][:3] + # a Book Report can't have HTML output so "css" is meaningless + self.options_dict.pop('css') + if not hasattr(self.option_class, "menu"): return menu = self.option_class.menu @@ -400,9 +408,10 @@ class CommandLineReport(object): Load the options that the user has entered. """ if not hasattr(self.option_class, "menu"): - return - menu = self.option_class.menu - menu_opt_names = menu.get_all_option_names() + menu = None + else: + menu = self.option_class.menu + menu_opt_names = menu.get_all_option_names() for opt in self.options_str_dict: if opt in self.options_dict: self.options_dict[opt] = \ @@ -412,7 +421,7 @@ class CommandLineReport(object): self.option_class.handler.options_dict[opt] = \ self.options_dict[opt] - if opt in menu_opt_names: + if menu and opt in menu_opt_names: option = menu.get_option_by_name(opt) option.set_value(self.options_dict[opt]) @@ -503,12 +512,12 @@ class CommandLineReport(object): elif self.show in self.options_help: opt = self.options_help[self.show] 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[1], opt[0]) print " Available values are:" vals = opt[2] if isinstance(vals, (list, tuple)): for val in vals: - optmsg = " %s" % val + optmsg = " %s" % val print optmsg.encode(sys.getfilesystemencoding()) else: optmsg = " %s" % opt[2] diff --git a/src/plugins/BookReport.py b/src/plugins/BookReport.py index 5cd111bab..88da98df6 100644 --- a/src/plugins/BookReport.py +++ b/src/plugins/BookReport.py @@ -72,7 +72,7 @@ import Utils import ListModel import Errors from gui.pluginmanager import GuiPluginManager -from gen.plug.docgen import StyleSheet, StyleSheetList +from gen.plug.docgen import StyleSheet, StyleSheetList, PaperStyle from QuestionDialog import WarningDialog, ErrorDialog from gen.plug.menu import PersonOption, FilterOption, FamilyOption import ManagedWindow @@ -700,7 +700,7 @@ class BookOptions(ReportOptions): 'bookname' : '', } self.options_help = { - 'bookname' : ("=name","Name of the book. MANDATORY", + 'bookname' : ("=name",_("Name of the book. MANDATORY"), BookList('books.xml',dbase).get_book_names(), False), } @@ -1301,6 +1301,9 @@ def cl_report(database, name, category, options_str_dict): book_list = BookList('books.xml', database) book_name = clr.options_dict['bookname'] if book_name: + if book_name not in book_list.get_book_names(): + print _("No such book '%s'") % book_name + return book = book_list.get_book(book_name) else: print _("Please specify a book name") @@ -1326,8 +1329,34 @@ def cl_report(database, name, category, options_str_dict): this_style_name, style_sheet.get_paragraph_style(this_style_name)) + for this_style_name in style_sheet.get_draw_style_names(): + selected_style.add_draw_style( + this_style_name, + style_sheet.get_draw_style(this_style_name)) + + for this_style_name in style_sheet.get_table_style_names(): + selected_style.add_table_style( + this_style_name, + style_sheet.get_table_style(this_style_name)) + + for this_style_name in style_sheet.get_cell_style_names(): + selected_style.add_cell_style( + this_style_name, + style_sheet.get_cell_style(this_style_name)) + + # The option values were loaded magically by the book parser. + # But they still need to be applied to the menu options. + opt_dict = item.option_class.options_dict + menu = item.option_class.menu + for optname in opt_dict: + menu_option = menu.get_option_by_name(optname) + if menu_option: + menu_option.set_value(opt_dict[optname]) + # write report - doc = clr.format(selected_style, clr.paper, clr.template_name, clr.orien) + doc = clr.format(selected_style, + PaperStyle(clr.paper, clr.orien, clr.marginl, + clr.marginr, clr.margint, clr.marginb)) rptlist = [] for item in book.get_item_list(): item.option_class.set_document(doc)