def cl_report(database, name, category, report_class, options_class, options_str_dict): """ function to actually run the selected report """ err_msg = _("Failed to write report. ") clr = CommandLineReport(database, name, category, options_class, options_str_dict) # Exit here if show option was given if clr.show: return # write report try: if category in [CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK]: if clr.doc_options: clr.option_class.handler.doc = clr.format( clr.selected_style, PaperStyle(clr.paper, clr.orien, clr.marginl, clr.marginr, clr.margint, clr.marginb), clr.doc_options) else: clr.option_class.handler.doc = clr.format( clr.selected_style, PaperStyle(clr.paper, clr.orien, clr.marginl, clr.marginr, clr.margint, clr.marginb)) elif category == CATEGORY_GRAPHVIZ: clr.option_class.handler.doc = clr.format( clr.option_class, PaperStyle(clr.paper, clr.orien, clr.marginl, clr.marginr, clr.margint, clr.marginb)) if (clr.css_filename is not None and hasattr(clr.option_class.handler.doc, 'set_css_filename')): clr.option_class.handler.doc.set_css_filename(clr.css_filename) my_report = report_class(database, clr.option_class, User()) my_report.doc.init() my_report.begin_report() my_report.write_report() my_report.end_report() return clr except ReportError as msg: (msg1, msg2) = msg.messages() print(err_msg, file=sys.stderr) print(msg1, file=sys.stderr) if msg2: print(msg2, file=sys.stderr) except: if len(LOG.handlers) > 0: LOG.error(err_msg, exc_info=True) else: print(err_msg, file=sys.stderr) ## Something seems to eat the exception above. ## Hack to re-get the exception: try: raise except: traceback.print_exc()
def get_paper_style(self): paper_size, paper_name = self.get_paper_size() paper_orientation = self.orientation_menu.get_value() paper_margins = self.get_paper_margins() pstyle = PaperStyle(paper_size, paper_orientation, *paper_margins) return pstyle
def cl_book(database, name, book, options_str_dict): """ function to actually run the selected book, which in turn runs whatever reports the book has in it """ clr = CommandLineReport(database, name, CATEGORY_BOOK, ReportOptions, options_str_dict) # Exit here if show option was given if clr.show: return # write report doc = clr.format( None, PaperStyle(clr.paper, clr.orien, clr.marginl, clr.marginr, clr.margint, clr.marginb)) user = User() rptlist = [] selected_style = StyleSheet() for item in book.get_item_list(): # 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]) item.option_class.set_document(doc) report_class = item.get_write_item() obj = (write_book_item(database, report_class, item.option_class, user), item.get_translated_name()) if obj: append_styles(selected_style, item) rptlist.append(obj) doc.set_style_sheet(selected_style) doc.open(clr.option_class.get_output()) doc.init() newpage = 0 err_msg = _("Failed to make '%s' report.") try: for (rpt, name) in rptlist: if newpage: doc.page_break() newpage = 1 rpt.begin_report() rpt.write_report() doc.close() except ReportError as msg: (msg1, msg2) = msg.messages() print(err_msg % name, file=sys.stderr) # which report has the error? print(msg1, file=sys.stderr) if msg2: print(msg2, file=sys.stderr)
def cl_book(database, name, book, options_str_dict): clr = CommandLineReport(database, name, CATEGORY_BOOK, ReportOptions, options_str_dict) # Exit here if show option was given if clr.show: return # write report doc = clr.format( None, PaperStyle(clr.paper, clr.orien, clr.marginl, clr.marginr, clr.margint, clr.marginb)) user = User() rptlist = [] selected_style = StyleSheet() for item in book.get_item_list(): # 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]) item.option_class.set_document(doc) report_class = item.get_write_item() obj = write_book_item(database, report_class, item.option_class, user) if obj: append_styles(selected_style, item) rptlist.append(obj) doc.set_style_sheet(selected_style) doc.open(clr.option_class.get_output()) doc.init() newpage = 0 for rpt in rptlist: if newpage: doc.page_break() newpage = 1 rpt.begin_report() rpt.write_report() doc.close()
def test_write_report(self): """ Creates a report from test data. """ options = FamilyChroniclesOptions("Familiy Chronicles", self.db) options.load_previous_values() options.menu.get_option_by_name('pid').set_value(TEST_PERSON_ID) docgen_plugin = Familychroniclestest.__get_docgen_plugin('latexdoc') doc_class = docgen_plugin.get_basedoc() styles = StyleSheet() options.make_default_style(styles) paper_layout = PaperStyle(PaperSize("a4", None, None), PAPER_LANDSCAPE) doc = doc_class(styles, paper_layout, []) options.set_document(doc) options.set_output(TEST_OUTPUT) # Initialization sequence inspired by _reportdialog.py, report() my_report = FamilyChronicles(self.db, options, User()) my_report.doc.init() my_report.begin_report() my_report.write_report() my_report.end_report()