From d092df28a5eeb639380545521d07694fda800ada Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Mon, 15 Sep 2008 02:20:25 +0000 Subject: [PATCH] 0002386: Command line reports do not work. svn: r11062 --- src/ReportBase/_CommandLineReport.py | 134 +++++++++++++-------------- 1 file changed, 66 insertions(+), 68 deletions(-) diff --git a/src/ReportBase/_CommandLineReport.py b/src/ReportBase/_CommandLineReport.py index 685935e4b..f048e86ac 100644 --- a/src/ReportBase/_CommandLineReport.py +++ b/src/ReportBase/_CommandLineReport.py @@ -141,73 +141,40 @@ class CommandLineReport: } self.options_help = { - 'of' : ["=filename", "Output file name. MANDATORY", "", ""], - 'off' : ["=format", "Output file format.", "", ""], - 'style' : ["=name", "Style name.", "", ""], - 'papers' : ["=name", "Paper size name.", "", ""], - 'papero' : ["=num", "Paper orientation number.", "", ""], - 'template' : ["=name", "Template name (HTML only).", "", ""], + 'of' : ["=filename", "Output file name. MANDATORY", ""], + 'off' : ["=format", "Output file format.", ""], + 'style' : ["=name", "Style name.", ""], + 'papers' : ["=name", "Paper size name.", ""], + 'papero' : ["=num", "Paper orientation number.", ""], + 'template' : ["=name", "Template name (HTML only).", ""], } if noopt: return - self.option_class.handler.output = self.options_dict['of'] - self.options_help['of'].append(os.path.join(const.USER_HOME, - "whatever_name")) + self.options_help['of'][2] = os.path.join(const.USER_HOME, + "whatever_name") if self.category == CATEGORY_TEXT: - print len(_textdoc_list), _textdoc_list - print len(self.options_dict), self.options_dict - for item in _textdoc_list: - print len(item), item - if item[6] == self.options_dict['off']: - self.format = item[1] - if self.format is None: - # Pick the first one as the default. - self.format = _textdoc_list[0][1] self.options_help['off'][2] = \ [ item[6] for item in _textdoc_list ] - self.options_help['off'][3] = False elif self.category == CATEGORY_DRAW: - for item in _drawdoc_list: - if item[6] == self.options_dict['off']: - self.format = item[1] - if self.format is None: - # Pick the first one as the default. - self.format = _drawdoc_list[0][1] self.options_help['off'][2] = \ [ item[6] for item in _drawdoc_list ] - self.options_help['off'][3] = False elif self.category == CATEGORY_BOOK: - for item in _bookdoc_list: - if item[6] == self.options_dict['off']: - self.format = item[1] - if self.format is None: - # Pick the first one as the default. - self.format = _bookdoc_list[0][1] self.options_help['off'][2] = \ [ item[6] for item in _bookdoc_list ] - self.options_help['off'][3] = False else: - self.format = None + self.options_help['off'][2] = "NA" - for paper in paper_sizes: - if paper.get_name() == self.options_dict['papers']: - self.paper = paper - self.option_class.handler.set_paper(self.paper) self.options_help['papers'][2] = \ [ paper.get_name() for paper in paper_sizes if paper.get_name() != _("Custom Size") ] - self.options_help['papers'][3] = False - self.orien = self.options_dict['papero'] self.options_help['papero'][2] = [ "%d\tPortrait" % BaseDoc.PAPER_PORTRAIT, "%d\tLandscape" % BaseDoc.PAPER_LANDSCAPE ] - self.options_help['papero'][3] = False - self.template_name = self.options_dict['template'] self.options_help['template'][2] = os.path.join(const.USER_HOME, "whatever_name") @@ -217,14 +184,9 @@ class CommandLineReport: # Read all style sheets available for this item style_file = self.option_class.handler.get_stylesheet_savefile() - self.style_list = BaseDoc.StyleSheetList(style_file,default_style) - - # Get the selected stylesheet - style_name = self.option_class.handler.get_default_stylesheet_name() - self.selected_style = self.style_list.get_style_sheet(style_name) + self.style_list = BaseDoc.StyleSheetList(style_file, default_style) self.options_help['style'][2] = self.style_list.get_style_names() - self.options_help['style'][3] = False def init_report_options(self): """ @@ -246,7 +208,6 @@ class CommandLineReport: person.get_gramps_id(), name_displayer.display(person))) self.options_help[name].append(id_list) - self.options_help[name].append(False) elif isinstance(option, PluginUtils.FamilyOption): id_list = [] for fhandle in self.database.get_family_handles(): @@ -267,45 +228,35 @@ class CommandLineReport: (family.get_gramps_id(), fname, mname) id_list.append(text) self.options_help[name].append(id_list) - self.options_help[name].append(False) elif isinstance(option, PluginUtils.NoteOption): id_list = [] for nhandle in self.database.get_note_handles(): note = self.database.get_note_from_handle(nhandle) id_list.append(note.get_gramps_id()) self.options_help[name].append(id_list) - self.options_help[name].append(False) elif isinstance(option, PluginUtils.MediaOption): id_list = [] for mhandle in self.database.get_media_object_handles(): mobject = self.database.get_object_from_handle(mhandle) id_list.append(mobject.get_gramps_id()) self.options_help[name].append(id_list) - self.options_help[name].append(False) elif isinstance(option, PluginUtils.PersonListOption): self.options_help[name].append("") - self.options_help[name].append(False) elif isinstance(option, PluginUtils.NumberOption): self.options_help[name].append("A number") - self.options_help[name].append(False) elif isinstance(option, PluginUtils.BooleanOption): self.options_help[name].append(["0\tno", "1\tyes"]) - self.options_help[name].append(False) elif isinstance(option, PluginUtils.DestinationOption): self.options_help[name].append("A file system path") - self.options_help[name].append(False) elif isinstance(option, PluginUtils.StringOption): self.options_help[name].append("Any text") - self.options_help[name].append(False) elif isinstance(option, PluginUtils.TextOption): self.options_help[name].append("Any text") - self.options_help[name].append(False) elif isinstance(option, PluginUtils.EnumeratedListOption): ilist = [] for (value, description) in option.get_items(): ilist.append("%s\t%s" % (value, description)) self.options_help[name].append(ilist) - self.options_help[name].append(False) else: print "Unknown option: ", option @@ -316,18 +267,69 @@ class CommandLineReport: if not hasattr(self.option_class, "menu"): return menu = self.option_class.menu + menu_opt_names = menu.get_all_option_names() for opt in self.options_str_dict.keys(): if opt in self.options_dict.keys(): converter = Utils.get_type_converter(self.options_dict[opt]) self.options_dict[opt] = converter(self.options_str_dict[opt]) self.option_class.handler.options_dict[opt] = \ self.options_dict[opt] - option = menu.get_option_by_name(opt) - option.set_value(self.options_dict[opt]) + + if opt in menu_opt_names: + option = menu.get_option_by_name(opt) + option.set_value(self.options_dict[opt]) else: print "Ignoring unknown option: %s" % opt - + + self.option_class.handler.output = self.options_dict['of'] + + pmgr = PluginUtils.PluginManager.get_instance() + + if self.category == CATEGORY_TEXT: + for item in pmgr.get_text_doc_list(): + if item[7] == self.options_dict['off']: + self.format = item[1] + if self.format is None: + # Pick the first one as the default. + self.format = pmgr.get_text_doc_list()[0][1] + elif self.category == CATEGORY_DRAW: + for item in pmgr.get_draw_doc_list(): + if item[6] == self.options_dict['off']: + self.format = item[1] + if self.format is None: + # Pick the first one as the default. + self.format = pmgr.get_draw_doc_list()[0][1] + elif self.category == CATEGORY_BOOK: + for item in pmgr.get_book_doc_list(): + if item[6] == self.options_dict['off']: + self.format = item[1] + if self.format is None: + # Pick the first one as the default. + self.format = pmgr.get_book_doc_list()[0][1] + else: + self.format = None + + for paper in paper_sizes: + if paper.get_name() == self.options_dict['papers']: + self.paper = paper + self.option_class.handler.set_paper(self.paper) + + self.orien = self.options_dict['papero'] + self.template_name = self.options_dict['template'] + + if self.category in (CATEGORY_TEXT, CATEGORY_DRAW): + default_style = BaseDoc.StyleSheet() + self.option_class.make_default_style(default_style) + + # Read all style sheets available for this item + style_file = self.option_class.handler.get_stylesheet_savefile() + self.style_list = BaseDoc.StyleSheetList(style_file,default_style) + + # Get the selected stylesheet + style_name = self.option_class.handler.get_default_stylesheet_name() + self.selected_style = self.style_list.get_style_sheet(style_name) + def show_options(self): """ Print available options on the CLI. @@ -357,12 +359,8 @@ class CommandLineReport: print " Available values are:" vals = self.options_help[self.show][2] if isinstance(vals, (list, tuple)): - if self.options_help[self.show][3]: - for num in range(len(vals)): - print " %d\t%s" % (num,vals[num]) - else: - for val in vals: - print " %s" % val + for val in vals: + print " %s" % val else: print " %s" % self.options_help[self.show][2]