From 30d6eebd0b720c6b31372fba4e6d87ac8487211e Mon Sep 17 00:00:00 2001 From: Raphael Ackermann Date: Fri, 14 Aug 2009 07:14:25 +0000 Subject: [PATCH] 0002542: Crash whilst generating web pages from command line Throwing Report Error if center person is not in database. Added catching of Report Error to CommandLineReport if using GUI it is not possible to cause this, as you have to select a person that is in the DB. However on the command line you can specify any PID and even no person with that pid exists an error was thrown. svn: r13004 --- src/ReportBase/_CommandLineReport.py | 49 +++++++++------- src/gen/proxy/private.py | 23 +++++--- src/plugins/drawreport/AncestorTree.py | 11 ++-- src/plugins/drawreport/Calendar.py | 15 +++-- src/plugins/drawreport/DescendTree.py | 7 ++- src/plugins/drawreport/FanChart.py | 5 +- src/plugins/graph/GVHourGlass.py | 11 ++-- src/plugins/textreport/AncestorReport.py | 13 +++-- src/plugins/textreport/BirthdayReport.py | 19 ++++--- src/plugins/textreport/DescendReport.py | 56 ++++++++++--------- src/plugins/textreport/DetAncestralReport.py | 27 +++++---- src/plugins/textreport/DetDescendantReport.py | 15 +++-- src/plugins/textreport/EndOfLineReport.py | 9 ++- src/plugins/textreport/IndivComplete.py | 3 +- src/plugins/textreport/KinshipReport.py | 5 +- .../textreport/NumberOfAncestorsReport.py | 7 ++- src/plugins/webreport/NarrativeWeb.py | 37 ++---------- 17 files changed, 169 insertions(+), 143 deletions(-) diff --git a/src/ReportBase/_CommandLineReport.py b/src/ReportBase/_CommandLineReport.py index 1aedaef23..2585c63e8 100644 --- a/src/ReportBase/_CommandLineReport.py +++ b/src/ReportBase/_CommandLineReport.py @@ -30,7 +30,6 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ -import sys import logging log = logging.getLogger(".") @@ -40,13 +39,18 @@ log = logging.getLogger(".") # Gramps modules # #------------------------------------------------------------------------- -import gen import Utils +from gen.plug import PluginManager from gen.plug.docgen import (StyleSheet, StyleSheetList, PaperStyle, PAPER_PORTRAIT, PAPER_LANDSCAPE) +from gen.plug.menu import (FamilyOption, PersonOption, NoteOption, + MediaOption, PersonListOption, NumberOption, + BooleanOption, DestinationOption, StringOption, + TextOption, EnumeratedListOption) from BasicUtils import name_displayer -from ReportBase import CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, \ - CATEGORY_GRAPHVIZ +from Errors import ReportError +from ReportBase import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, + CATEGORY_GRAPHVIZ) from _PaperMenu import paper_sizes import os import const @@ -72,7 +76,7 @@ def _validate_options(options, dbase): for name in menu.get_all_option_names(): option = menu.get_option_by_name(name) - if isinstance(option, gen.plug.menu.PersonOption): + if isinstance(option, PersonOption): pid = option.get_value() person = dbase.get_person_from_gramps_id(pid) if not person: @@ -85,7 +89,7 @@ def _validate_options(options, dbase): if person: option.set_value(person.get_gramps_id()) - elif isinstance(option, gen.plug.menu.FamilyOption): + elif isinstance(option, FamilyOption): fid = option.get_value() family = dbase.get_family_from_gramps_id(fid) if not family: @@ -118,7 +122,7 @@ class CommandLineReport(object): def __init__(self, database, name, category, option_class, options_str_dict, noopt=False): - pmgr = gen.plug.PluginManager.get_instance() + pmgr = PluginManager.get_instance() self.__textdoc_plugins = [] self.__drawdoc_plugins = [] self.__bookdoc_plugins = [] @@ -223,7 +227,7 @@ class CommandLineReport(object): self.options_dict[name] = option.get_value() self.options_help[name] = [ "", option.get_help() ] - if isinstance(option, gen.plug.menu.PersonOption): + if isinstance(option, PersonOption): id_list = [] for person_handle in self.database.get_person_handles(): person = self.database.get_person_from_handle(person_handle) @@ -231,7 +235,7 @@ class CommandLineReport(object): person.get_gramps_id(), name_displayer.display(person))) self.options_help[name].append(id_list) - elif isinstance(option, gen.plug.menu.FamilyOption): + elif isinstance(option, FamilyOption): id_list = [] for fhandle in self.database.iter_family_handles(): family = self.database.get_family_from_handle(fhandle) @@ -251,31 +255,31 @@ class CommandLineReport(object): (family.get_gramps_id(), fname, mname) id_list.append(text) self.options_help[name].append(id_list) - elif isinstance(option, gen.plug.menu.NoteOption): + elif isinstance(option, 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) - elif isinstance(option, gen.plug.menu.MediaOption): + elif isinstance(option, 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) - elif isinstance(option, gen.plug.menu.PersonListOption): + elif isinstance(option, PersonListOption): self.options_help[name].append("") - elif isinstance(option, gen.plug.menu.NumberOption): + elif isinstance(option, NumberOption): self.options_help[name].append("A number") - elif isinstance(option, gen.plug.menu.BooleanOption): + elif isinstance(option, BooleanOption): self.options_help[name].append(["0\tno", "1\tyes"]) - elif isinstance(option, gen.plug.menu.DestinationOption): + elif isinstance(option, DestinationOption): self.options_help[name].append("A file system path") - elif isinstance(option, gen.plug.menu.StringOption): + elif isinstance(option, StringOption): self.options_help[name].append("Any text") - elif isinstance(option, gen.plug.menu.TextOption): + elif isinstance(option, TextOption): self.options_help[name].append("Any text") - elif isinstance(option, gen.plug.menu.EnumeratedListOption): + elif isinstance(option, EnumeratedListOption): ilist = [] for (value, description) in option.get_items(): ilist.append("%s\t%s" % (value, description)) @@ -346,7 +350,7 @@ class CommandLineReport(object): # Read all style sheets available for this item style_file = self.option_class.handler.get_stylesheet_savefile() - self.style_list = StyleSheetList(style_file,default_style) + self.style_list = StyleSheetList(style_file, default_style) # Get the selected stylesheet style_name = self.option_class.handler.get_default_stylesheet_name() @@ -394,6 +398,7 @@ class CommandLineReport(object): def cl_report(database, name, category, report_class, options_class, options_str_dict): + err_msg = _("Failed to write report. ") clr = CommandLineReport(database, name, category, options_class, options_str_dict) @@ -415,5 +420,9 @@ def cl_report(database, name, category, report_class, options_class, MyReport.begin_report() MyReport.write_report() MyReport.end_report() + except ReportError, msg: + (m1, m2) = msg.messages() + print err_msg + print m1 except: - log.error("Failed to write report.", exc_info=True) + log.error(err_msg, exc_info=True) diff --git a/src/gen/proxy/private.py b/src/gen/proxy/private.py index 36a80dcdb..d61cdef70 100644 --- a/src/gen/proxy/private.py +++ b/src/gen/proxy/private.py @@ -24,6 +24,13 @@ Proxy class for the GRAMPS databases. Filter out all data marked private. """ +#------------------------------------------------------------------------- +# +# Python libraries +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + #------------------------------------------------------------------------- # # GRAMPS libraries @@ -132,7 +139,7 @@ class PrivateProxyDb(ProxyDbBase): If no such Person exists, None is returned. """ person = self.db.get_person_from_gramps_id(val) - if not person.get_privacy(): + if person and not person.get_privacy(): return sanitize_person(self.db, person) return None @@ -142,7 +149,7 @@ class PrivateProxyDb(ProxyDbBase): If no such Family exists, None is returned. """ family = self.db.get_family_from_gramps_id(val) - if not family.get_privacy(): + if family and not family.get_privacy(): return sanitize_family(self.db, family) return None @@ -152,7 +159,7 @@ class PrivateProxyDb(ProxyDbBase): If no such Event exists, None is returned. """ event = self.db.get_event_from_gramps_id(val) - if not event.get_privacy(): + if event and not event.get_privacy(): return sanitize_event(self.db, event) return None @@ -162,7 +169,7 @@ class PrivateProxyDb(ProxyDbBase): If no such Place exists, None is returned. """ place = self.db.get_place_from_gramps_id(val) - if not place.get_privacy(): + if place and not place.get_privacy(): return sanitize_place(self.db, place) return None @@ -182,7 +189,7 @@ class PrivateProxyDb(ProxyDbBase): If no such MediaObject exists, None is returned. """ obj = self.db.get_object_from_gramps_id(val) - if not obj.get_privacy(): + if obj and not obj.get_privacy(): return sanitize_media(self.db, obj) return None @@ -192,7 +199,7 @@ class PrivateProxyDb(ProxyDbBase): If no such Repository exists, None is returned. """ repository = self.db.get_repository_from_gramps_id(val) - if not repository.get_privacy(): + if repository and not repository.get_privacy(): return sanitize_repository(self.db, repository) return None @@ -202,7 +209,7 @@ class PrivateProxyDb(ProxyDbBase): If no such Note exists, None is returned. """ note = self.db.get_note_from_gramps_id(val) - if not note.get_privacy(): + if note and not note.get_privacy(): return note return None @@ -896,7 +903,7 @@ def sanitize_place(db, place): return new_place -def sanitize_event(db,event): +def sanitize_event(db, event): """ Create a new Event instance based off the passed Event instance. The returned instance has all private records diff --git a/src/plugins/drawreport/AncestorTree.py b/src/plugins/drawreport/AncestorTree.py index 7601f1578..389c29691 100644 --- a/src/plugins/drawreport/AncestorTree.py +++ b/src/plugins/drawreport/AncestorTree.py @@ -35,13 +35,14 @@ from TransUtils import sgettext as _ # GRAMPS modules # #------------------------------------------------------------------------ -from gen.plug.docgen import FontStyle, ParagraphStyle, GraphicsStyle,\ - FONT_SANS_SERIF, PARA_ALIGN_CENTER -from SubstKeywords import SubstKeywords +from BasicUtils import name_displayer +from Errors import ReportError from gen.plug import PluginManager +from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, + FONT_SANS_SERIF, PARA_ALIGN_CENTER) from gen.plug.menu import BooleanOption, NumberOption, TextOption, PersonOption from ReportBase import Report, ReportUtils, CATEGORY_DRAW, MenuReportOptions -from BasicUtils import name_displayer +from SubstKeywords import SubstKeywords pt2cm = ReportUtils.pt2cm @@ -190,6 +191,8 @@ class AncestorTree(Report): pid = menu.get_option_by_name('pid').get_value() center_person = database.get_person_from_gramps_id(pid) + if (center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) name = name_displayer.display_formal(center_person) self.title = _("Ancestor Graph for %s") % name diff --git a/src/plugins/drawreport/Calendar.py b/src/plugins/drawreport/Calendar.py index be479dee7..bb56b3f42 100644 --- a/src/plugins/drawreport/Calendar.py +++ b/src/plugins/drawreport/Calendar.py @@ -34,19 +34,20 @@ import time # GRAMPS modules # #------------------------------------------------------------------------ +from BasicUtils import name_displayer +from Errors import ReportError +from gen.plug import PluginManager from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, FONT_SERIF, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT, PARA_ALIGN_RIGHT) from gen.plug.docgen.fontscale import string_trim -from BasicUtils import name_displayer -from gen.plug import PluginManager +from gen.plug.menu import (BooleanOption, StringOption, NumberOption, + EnumeratedListOption, FilterOption, PersonOption) +from gui.utils import ProgressMeter from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_DRAW -from gen.plug.menu import BooleanOption, StringOption, NumberOption, \ - EnumeratedListOption, FilterOption, PersonOption +from Utils import probably_alive import GrampsLocale import gen.lib -from Utils import probably_alive -from gui.utils import ProgressMeter import libholiday from libholiday import g2iso @@ -87,6 +88,8 @@ class Calendar(Report): self.filter = self.filter_option.get_filter() pid = menu.get_option_by_name('pid').get_value() self.center_person = database.get_person_from_gramps_id(pid) + if (self.center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) def get_name(self, person, maiden_name = None): """ Return person's name, unless maiden_name given, diff --git a/src/plugins/drawreport/DescendTree.py b/src/plugins/drawreport/DescendTree.py index 298ee9e9d..8cc6289fb 100644 --- a/src/plugins/drawreport/DescendTree.py +++ b/src/plugins/drawreport/DescendTree.py @@ -30,13 +30,14 @@ # #------------------------------------------------------------------------ from BasicUtils import name_displayer +from Errors import ReportError from gen.plug import PluginManager +from gen.plug.docgen import (GraphicsStyle, FontStyle, ParagraphStyle, + FONT_SANS_SERIF, PARA_ALIGN_CENTER) from gen.plug.menu import TextOption, NumberOption, BooleanOption, PersonOption from ReportBase import Report, MenuReportOptions, ReportUtils, CATEGORY_DRAW from SubstKeywords import SubstKeywords from TransUtils import sgettext as _ -from gen.plug.docgen import GraphicsStyle, FontStyle, ParagraphStyle,\ - FONT_SANS_SERIF, PARA_ALIGN_CENTER #------------------------------------------------------------------------ # @@ -145,6 +146,8 @@ class DescendTree(Report): self.incblank = menu.get_option_by_name('incblank').get_value() pid = menu.get_option_by_name('pid').get_value() center_person = database.get_person_from_gramps_id(pid) + if (center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) self.showspouse = menu.get_option_by_name('shows').get_value() diff --git a/src/plugins/drawreport/FanChart.py b/src/plugins/drawreport/FanChart.py index 3ee4fd732..b95562ed1 100644 --- a/src/plugins/drawreport/FanChart.py +++ b/src/plugins/drawreport/FanChart.py @@ -33,9 +33,10 @@ from gettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ +from Errors import ReportError +from gen.plug import PluginManager from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, FONT_SANS_SERIF, PARA_ALIGN_CENTER) -from gen.plug import PluginManager from gen.plug.menu import EnumeratedListOption, NumberOption, PersonOption from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_DRAW from SubstKeywords import SubstKeywords @@ -90,6 +91,8 @@ class FanChart(Report): self.radial = menu.get_option_by_name('radial').get_value() pid = menu.get_option_by_name('pid').get_value() self.center_person = database.get_person_from_gramps_id(pid) + if (self.center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) self.background_style = [] self.text_style = [] diff --git a/src/plugins/graph/GVHourGlass.py b/src/plugins/graph/GVHourGlass.py index edccd4085..d009addbf 100644 --- a/src/plugins/graph/GVHourGlass.py +++ b/src/plugins/graph/GVHourGlass.py @@ -37,11 +37,12 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------ -from gen.plug import PluginManager -from gen.plug.menu import PersonOption, BooleanOption, NumberOption, \ - EnumeratedListOption -from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_GRAPHVIZ from BasicUtils import name_displayer +from Errors import ReportError +from gen.plug import PluginManager +from gen.plug.menu import (PersonOption, BooleanOption, NumberOption, + EnumeratedListOption) +from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_GRAPHVIZ import DateHandler #------------------------------------------------------------------------ @@ -94,6 +95,8 @@ class HourGlassReport(Report): self.max_ascend = menu.get_option_by_name('maxascend').get_value() pid = menu.get_option_by_name('pid').get_value() self.center_person = database.get_person_from_gramps_id(pid) + if (self.center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) self.colorize = menu.get_option_by_name('color').get_value() if self.colorize == 'colored': self.colors = colored diff --git a/src/plugins/textreport/AncestorReport.py b/src/plugins/textreport/AncestorReport.py index c484076c1..49b683d54 100644 --- a/src/plugins/textreport/AncestorReport.py +++ b/src/plugins/textreport/AncestorReport.py @@ -36,15 +36,16 @@ from gettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ +from BasicUtils import name_displayer +from Errors import ReportError +from gen.lib import ChildRefType from gen.plug import PluginManager from gen.plug.menu import BooleanOption, NumberOption, PersonOption -from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, - FONT_SANS_SERIF, - INDEX_TYPE_TOC, PARA_ALIGN_CENTER) -from BasicUtils import name_displayer + FONT_SANS_SERIF, INDEX_TYPE_TOC, + PARA_ALIGN_CENTER) +from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT -from gen.lib import ChildRefType #------------------------------------------------------------------------ # @@ -89,6 +90,8 @@ class AncestorReport(Report): self.opt_namebrk = menu.get_option_by_name('namebrk').get_value() pid = menu.get_option_by_name('pid').get_value() self.center_person = database.get_person_from_gramps_id(pid) + if (self.center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) def apply_filter(self, person_handle, index, generation=1): """ diff --git a/src/plugins/textreport/BirthdayReport.py b/src/plugins/textreport/BirthdayReport.py index e841863c3..1009a085d 100644 --- a/src/plugins/textreport/BirthdayReport.py +++ b/src/plugins/textreport/BirthdayReport.py @@ -35,18 +35,19 @@ import datetime, time # GRAMPS modules # #------------------------------------------------------------------------ +from BasicUtils import name_displayer as _nd +from Errors import ReportError +from gen.lib import NameType, EventType, Name, Date, Person +from gen.plug import PluginManager from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, FONT_SERIF, PARA_ALIGN_RIGHT, PARA_ALIGN_LEFT, PARA_ALIGN_CENTER) -from BasicUtils import name_displayer as _nd -from gen.plug import PluginManager -from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT -from gen.plug.menu import BooleanOption, StringOption, NumberOption, \ - EnumeratedListOption, FilterOption, PersonOption -import GrampsLocale -from gen.lib import NameType, EventType, Name, Date, Person -from Utils import probably_alive +from gen.plug.menu import (BooleanOption, StringOption, NumberOption, + EnumeratedListOption, FilterOption, PersonOption) from gui.utils import ProgressMeter +from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT +from Utils import probably_alive +import GrampsLocale import libholiday @@ -81,6 +82,8 @@ class CalendarReport(Report): self.filter = self.filter_option.get_filter() pid = mgobn('pid') self.center_person = database.get_person_from_gramps_id(pid) + if (self.center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) def get_name(self, person, maiden_name = None): """ diff --git a/src/plugins/textreport/DescendReport.py b/src/plugins/textreport/DescendReport.py index 694e440d8..37c0b834a 100644 --- a/src/plugins/textreport/DescendReport.py +++ b/src/plugins/textreport/DescendReport.py @@ -23,7 +23,7 @@ # $Id$ """ -Reports/Text Reports/Descendant Report +Reports/Text Reports/Descendant Report. """ #------------------------------------------------------------------------ @@ -39,14 +39,14 @@ from gettext import gettext as _ # #------------------------------------------------------------------------ from gen.plug import PluginManager -from gen.plug.menu import NumberOption, PersonOption -from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, - FONT_SANS_SERIF, - INDEX_TYPE_TOC, PARA_ALIGN_CENTER) -import Sort + FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) +from gen.plug.menu import NumberOption, PersonOption from BasicUtils import name_displayer +from Errors import ReportError +from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT import DateHandler +import Sort _BORN = _('b.') _DIED = _('d.') @@ -80,6 +80,8 @@ class DescendantReport(Report): self.max_generations = menu.get_option_by_name('gen').get_value() pid = menu.get_option_by_name('pid').get_value() self.center_person = database.get_person_from_gramps_id(pid) + if (self.center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) sort = Sort.Sort(self.database) self.by_birthdate = sort.by_birthdate @@ -128,16 +130,16 @@ class DescendantReport(Report): self.doc.start_paragraph("DR-Title") name = name_displayer.display(self.center_person) title = _("Descendants of %s") % name - mark = IndexMark(title,INDEX_TYPE_TOC,1) - self.doc.write_text(title,mark) + mark = IndexMark(title, INDEX_TYPE_TOC, 1) + self.doc.write_text(title, mark) self.doc.end_paragraph() - self.dump(1,self.center_person) + self.dump(1, self.center_person) - def dump(self,level,person): + def dump(self, level, person): - self.doc.start_paragraph("DR-Level%d" % min(level,32),"%d." % level) - mark = ReportUtils.get_person_mark(self.database,person) - self.doc.write_text(name_displayer.display(person),mark) + self.doc.start_paragraph("DR-Level%d" % min(level, 32), "%d." % level) + mark = ReportUtils.get_person_mark(self.database, person) + self.doc.write_text(name_displayer.display(person), mark) self.dump_dates(person) self.doc.end_paragraph() @@ -147,20 +149,20 @@ class DescendantReport(Report): for family_handle in person.get_family_handle_list(): family = self.database.get_family_from_handle(family_handle) - spouse_handle = ReportUtils.find_spouse(person,family) + spouse_handle = ReportUtils.find_spouse(person, family) if spouse_handle: spouse = self.database.get_person_from_handle(spouse_handle) - mark = ReportUtils.get_person_mark(self.database,person) - self.doc.start_paragraph("DR-Spouse%d" % min(level,32)) + mark = ReportUtils.get_person_mark(self.database, person) + self.doc.start_paragraph("DR-Spouse%d" % min(level, 32)) name = name_displayer.display(spouse) - self.doc.write_text(_("sp. %(spouse)s") % {'spouse':name},mark) + self.doc.write_text(_("sp. %(spouse)s") % {'spouse':name}, mark) self.dump_dates(spouse) self.doc.end_paragraph() childlist = family.get_child_ref_list()[:] for child_ref in childlist: child = self.database.get_person_from_handle(child_ref.ref) - self.dump(level+1,child) + self.dump(level+1, child) #------------------------------------------------------------------------ # @@ -183,11 +185,11 @@ class DescendantOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) - gen = NumberOption(_("Generations"),10,1,15) + gen = NumberOption(_("Generations"), 10, 1, 15) gen.set_help(_("The number of generations to include in the report")) - menu.add_option(category_name,"gen",gen) + menu.add_option(category_name, "gen", gen) - def make_default_style(self,default_style): + def make_default_style(self, default_style): """Make the default output style for the Descendant Report.""" f = FontStyle() f.set_size(12) @@ -201,29 +203,29 @@ class DescendantOptions(MenuReportOptions): p.set_font(f) p.set_alignment(PARA_ALIGN_CENTER) p.set_description(_("The style used for the title of the page.")) - default_style.add_paragraph_style("DR-Title",p) + default_style.add_paragraph_style("DR-Title", p) f = FontStyle() f.set_size(10) - for i in range(1,33): + for i in range(1, 33): p = ParagraphStyle() p.set_font(f) p.set_top_margin(ReportUtils.pt2cm(f.get_size()*0.125)) p.set_bottom_margin(ReportUtils.pt2cm(f.get_size()*0.125)) p.set_first_indent(-0.5) - p.set_left_margin(min(10.0,float(i-0.5))) + p.set_left_margin(min(10.0, float(i-0.5))) p.set_description(_("The style used for the " "level %d display.") % i) - default_style.add_paragraph_style("DR-Level%d" % min(i,32), p) + default_style.add_paragraph_style("DR-Level%d" % min(i, 32), p) p = ParagraphStyle() p.set_font(f) p.set_top_margin(ReportUtils.pt2cm(f.get_size()*0.125)) p.set_bottom_margin(ReportUtils.pt2cm(f.get_size()*0.125)) - p.set_left_margin(min(10.0,float(i-0.5))) + p.set_left_margin(min(10.0, float(i-0.5))) p.set_description(_("The style used for the " "spouse level %d display.") % i) - default_style.add_paragraph_style("DR-Spouse%d" % min(i,32), p) + default_style.add_paragraph_style("DR-Spouse%d" % min(i, 32), p) #------------------------------------------------------------------------ # diff --git a/src/plugins/textreport/DetAncestralReport.py b/src/plugins/textreport/DetAncestralReport.py index 44a7c23b4..afde04a02 100644 --- a/src/plugins/textreport/DetAncestralReport.py +++ b/src/plugins/textreport/DetAncestralReport.py @@ -38,16 +38,17 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------ -import gen.lib +from BasicUtils import name_displayer as _nd +from Errors import ReportError +from gen.lib import EventType, FamilyRelType, Person from gen.plug import PluginManager -from gen.plug.menu import BooleanOption, NumberOption, PersonOption -from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT -from ReportBase import Bibliography, Endnotes from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, FONT_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) +from gen.plug.menu import BooleanOption, NumberOption, PersonOption +from ReportBase import (Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT, + Bibliography, Endnotes) import DateHandler -from BasicUtils import name_displayer as _nd import Utils #------------------------------------------------------------------------ @@ -118,6 +119,8 @@ class DetAncestorReport(Report): self.inc_attrs = menu.get_option_by_name('incattrs').get_value() pid = menu.get_option_by_name('pid').get_value() self.center_person = database.get_person_from_gramps_id(pid) + if (self.center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) self.gen_handles = {} self.prev_gen_handles = {} @@ -184,7 +187,7 @@ class DetAncestorReport(Report): mother_handle = family.get_mother_handle() if (mother_handle is None or mother_handle not in self.map.itervalues() or - person.get_gender() == gen.lib.Person.FEMALE): + person.get_gender() == Person.FEMALE): # The second test above also covers the 1. person's # mate, which is not an ancestor and as such is not # included in the self.map dictionary @@ -578,7 +581,7 @@ class DetAncestorReport(Report): for family_handle in person.get_family_handle_list(): family = self.database.get_family_from_handle(family_handle) ind_handle = None - if person.get_gender() == gen.lib.Person.MALE: + if person.get_gender() == Person.MALE: ind_handle = family.get_mother_handle() else: ind_handle = family.get_father_handle() @@ -588,10 +591,10 @@ class DetAncestorReport(Report): event = self.database.get_event_from_handle(event_ref.ref) if event: etype = event.get_type() - if etype == gen.lib.EventType.BAPTISM or \ - etype == gen.lib.EventType.BURIAL or \ - etype == gen.lib.EventType.BIRTH or \ - etype == gen.lib.EventType.DEATH : + if etype == EventType.BAPTISM or \ + etype == EventType.BURIAL or \ + etype == EventType.BIRTH or \ + etype == EventType.DEATH : has_info = True break if not has_info: @@ -614,7 +617,7 @@ class DetAncestorReport(Report): name = _nd.display_formal(ind) mark = ReportUtils.get_person_mark(self.database, ind) - if family.get_relationship() == gen.lib.FamilyRelType.MARRIED: + if family.get_relationship() == FamilyRelType.MARRIED: self.doc.write_text(_("Spouse: %s") % name, mark) else: self.doc.write_text(_("Relationship with: %s") % name, mark) diff --git a/src/plugins/textreport/DetDescendantReport.py b/src/plugins/textreport/DetDescendantReport.py index 80ea98f18..2a64fceb1 100644 --- a/src/plugins/textreport/DetDescendantReport.py +++ b/src/plugins/textreport/DetDescendantReport.py @@ -39,16 +39,17 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------ -import gen.lib +from BasicUtils import name_displayer as _nd +from Errors import ReportError +from gen.lib import FamilyRelType, Person from gen.plug import PluginManager from gen.plug.menu import BooleanOption, NumberOption, PersonOption -from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT -from ReportBase import Bibliography, Endnotes from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, FONT_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) +from ReportBase import (Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT, + Bibliography, Endnotes) import DateHandler -from BasicUtils import name_displayer as _nd import Utils #------------------------------------------------------------------------ @@ -125,6 +126,8 @@ class DetDescendantReport(Report): self.inc_paths = menu.get_option_by_name('incpaths').get_value() pid = menu.get_option_by_name('pid').get_value() self.center_person = database.get_person_from_gramps_id(pid) + if (self.center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) self.gen_handles = {} self.prev_gen_handles = {} @@ -435,7 +438,7 @@ class DetDescendantReport(Report): """ Write information about the person's spouse/mate. """ - if person.get_gender() == gen.lib.Person.MALE: + if person.get_gender() == Person.MALE: mate_handle = family.get_mother_handle() else: mate_handle = family.get_father_handle() @@ -446,7 +449,7 @@ class DetDescendantReport(Report): self.doc.start_paragraph("DDR-MoreHeader") name = _nd.display_formal(mate) mark = ReportUtils.get_person_mark(self.database, mate) - if family.get_relationship() == gen.lib.FamilyRelType.MARRIED: + if family.get_relationship() == FamilyRelType.MARRIED: self.doc.write_text(_("Spouse: %s") % name, mark) else: self.doc.write_text(_("Relationship with: %s") % name, mark) diff --git a/src/plugins/textreport/EndOfLineReport.py b/src/plugins/textreport/EndOfLineReport.py index e8b43ba2b..a9c57c908 100644 --- a/src/plugins/textreport/EndOfLineReport.py +++ b/src/plugins/textreport/EndOfLineReport.py @@ -34,13 +34,14 @@ from gettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ +from BasicUtils import name_displayer +from Errors import ReportError from gen.plug import PluginManager -from gen.plug.menu import PersonOption -from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, TableStyle, TableCellStyle, FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) -from BasicUtils import name_displayer +from gen.plug.menu import PersonOption +from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT import DateHandler #------------------------------------------------------------------------ @@ -69,6 +70,8 @@ class EndOfLineReport(Report): menu = options_class.menu pid = menu.get_option_by_name('pid').get_value() self.center_person = database.get_person_from_gramps_id(pid) + if (self.center_person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) # eol_map is a map whose: # keys are the generations of the people diff --git a/src/plugins/textreport/IndivComplete.py b/src/plugins/textreport/IndivComplete.py index 3c17ffa5a..ae519a36e 100644 --- a/src/plugins/textreport/IndivComplete.py +++ b/src/plugins/textreport/IndivComplete.py @@ -61,7 +61,6 @@ class IndivCompleteReport(Report): The arguments are: database - the GRAMPS database instance - person - currently selected person options_class - instance of the Options class for this report This report needs the following parameters (class variables) @@ -70,7 +69,7 @@ class IndivCompleteReport(Report): filter - Filter to be applied to the people of the database. The option class carries its number, and the function returning the list of filters. - cites - Whether or not to include source informaiton. + cites - Whether or not to include source information. """ Report.__init__(self, database, options_class) diff --git a/src/plugins/textreport/KinshipReport.py b/src/plugins/textreport/KinshipReport.py index 79a6fc743..e3ce4df07 100644 --- a/src/plugins/textreport/KinshipReport.py +++ b/src/plugins/textreport/KinshipReport.py @@ -36,12 +36,13 @@ from gettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ +from BasicUtils import name_displayer +from Errors import ReportError from gen.plug import PluginManager from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) from gen.plug.menu import NumberOption, BooleanOption, PersonOption from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT -from BasicUtils import name_displayer import DateHandler #------------------------------------------------------------------------ @@ -80,6 +81,8 @@ class KinshipReport(Report): self.inc_aunts = menu.get_option_by_name('incaunts').get_value() pid = menu.get_option_by_name('pid').get_value() self.person = database.get_person_from_gramps_id(pid) + if (self.person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) self.__db = database self.rel_calc = PluginManager.get_instance().get_relationship_calculator() diff --git a/src/plugins/textreport/NumberOfAncestorsReport.py b/src/plugins/textreport/NumberOfAncestorsReport.py index 6b450fd32..470061110 100644 --- a/src/plugins/textreport/NumberOfAncestorsReport.py +++ b/src/plugins/textreport/NumberOfAncestorsReport.py @@ -40,13 +40,14 @@ import math # GRAMPS modules # #------------------------------------------------------------------------ +from BasicUtils import name_displayer +from Errors import ReportError from gen.plug import PluginManager from gen.plug.menu import PersonOption -from ReportBase import Report, MenuReportOptions, ReportUtils, CATEGORY_TEXT -from BasicUtils import name_displayer from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, PARA_ALIGN_CENTER, INDEX_TYPE_TOC) +from ReportBase import Report, MenuReportOptions, ReportUtils, CATEGORY_TEXT #------------------------------------------------------------------------ # @@ -71,6 +72,8 @@ class NumberOfAncestorsReport(Report): self.__db = database pid = options_class.menu.get_option_by_name('pid').get_value() self.__person = database.get_person_from_gramps_id(pid) + if (self.__person == None) : + raise ReportError(_("Person %s is not in the Database") % pid ) def write_report(self): """ diff --git a/src/plugins/webreport/NarrativeWeb.py b/src/plugins/webreport/NarrativeWeb.py index 38a038f28..6609d3848 100644 --- a/src/plugins/webreport/NarrativeWeb.py +++ b/src/plugins/webreport/NarrativeWeb.py @@ -144,36 +144,6 @@ LOCATIONS = _('Alternate Locations') TMPL = _('Temple') ST = _('Status') -# Repository Types from src/gen/lib/repotype.py -UNKNOWN = -1 -CUSTOM = 0 -LIBRARY = 1 -CEMETERY = 2 -CHURCH = 3 -ARCHIVE = 4 -ALBUM = 5 -WEBSITE = 6 -BOOKSTORE = 7 -COLLECTION = 8 -SAFE = 9 - -_CUSTOM = CUSTOM -_DEFAULT = LIBRARY - -_DATAMAP = [ - (UNKNOWN, _("Unknown"), "Unknown"), - (CUSTOM, _("Custom"), "Custom"), - (LIBRARY, _("Library"), "Library"), - (CEMETERY, _("Cemetery"), "Cemetery"), - (CHURCH, _("Church"), "Church"), - (ARCHIVE, _("Archive"), "Archive"), - (ALBUM, _("Album"), "Album"), - (WEBSITE, _("Web site"), "Web site"), - (BOOKSTORE, _("Bookstore"), "Bookstore"), - (COLLECTION, _("Collection"), "Collection"), - (SAFE, _("Safe"), "Safe"), - ] - # define clear blank line for proper styling fullclear = Html('div', class_='fullclear', inline=True) @@ -772,7 +742,7 @@ class BasePage(object): """ db = self.report.database - # Header contants + # Header constants xmllang = xml_lang() _META1 = 'name="generator" content="%s %s %s"' % ( const.PROGRAM_NAME, const.VERSION, const.URL_HOMEPAGE @@ -2067,7 +2037,10 @@ class MediaPage(BasePage): # TODO. Mixup url and path # path = convert_disk_path_to_url(path) url = self.report.build_url_fname(path, None, self.up) - hyper += Html('img', src=url, alt=html_escape(self.page_title)) + if hyper: + hyper += Html('img', src=url, alt=html_escape(self.page_title)) + else: + hyper = Html('img', src=url, alt=html_escape(self.page_title)) if target_exists: mediadisplay += hyper else: