improve pylint score of Descendant report from 7.91 to 9.71

This commit is contained in:
Paul Franklin
2016-06-03 12:23:25 -07:00
parent 283ac0f8bb
commit 99fbd648a0

View File

@@ -51,7 +51,6 @@ from gramps.gen.plug.report import Report
from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import utils as ReportUtils
from gramps.gen.plug.report import MenuReportOptions from gramps.gen.plug.report import MenuReportOptions
from gramps.gen.plug.report import stdoptions from gramps.gen.plug.report import stdoptions
from gramps.gen.sort import Sort
from gramps.gen.utils.db import (get_birth_or_fallback, get_death_or_fallback, from gramps.gen.utils.db import (get_birth_or_fallback, get_death_or_fallback,
get_marriage_or_fallback, get_marriage_or_fallback,
get_divorce_or_fallback) get_divorce_or_fallback)
@@ -64,11 +63,14 @@ from gramps.gen.proxy import CacheProxyDb
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class PrintSimple: class PrintSimple:
""" Simple numbering system """
def __init__(self, showdups): def __init__(self, showdups):
self.showdups = showdups self.showdups = showdups
self.num = {0:1} self.num = {0:1}
def number(self, level): def number(self, level):
""" the number of the person """
if self.showdups: if self.showdups:
# Just show original simple numbering # Just show original simple numbering
to_return = "%d." % level to_return = "%d." % level
@@ -91,11 +93,14 @@ class PrintSimple:
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class PrintVilliers: class PrintVilliers:
""" de_Villiers_Pama numbering system """
def __init__(self): def __init__(self):
self.pama = 'abcdefghijklmnopqrstuvwxyz' self.pama = 'abcdefghijklmnopqrstuvwxyz'
self.num = {0:1} self.num = {0:1}
def number(self, level): def number(self, level):
""" the number of the person """
to_return = self.pama[level-1] to_return = self.pama[level-1]
if level > 1: if level > 1:
to_return += str(self.num[level-1]) to_return += str(self.num[level-1])
@@ -114,10 +119,13 @@ class PrintVilliers:
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class PrintMeurgey: class PrintMeurgey:
""" Meurgey_de_Tupigny numbering system """
def __init__(self): def __init__(self):
self.childnum = [""] self.childnum = [""]
def number(self, level): def number(self, level):
""" the number of the person """
if level == 1: if level == 1:
dash = "" dash = ""
else: else:
@@ -157,7 +165,8 @@ class Printinfo:
self._ = rlocale.translation.sgettext # needed for English self._ = rlocale.translation.sgettext # needed for English
self._get_date = rlocale.get_date self._get_date = rlocale.get_date
def __date_place(self,event): def __date_place(self, event):
""" return the date and/or place an event happened """
if event: if event:
date = self._get_date(event.get_date_object()) date = self._get_date(event.get_date_object())
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
@@ -177,11 +186,12 @@ class Printinfo:
return "" return ""
def dump_string(self, person, family=None): def dump_string(self, person, family=None):
""" generate a descriptive string for a person """
string = self.__date_place( string = self.__date_place(
get_birth_or_fallback(self.database, person) get_birth_or_fallback(self.database, person))
)
tmp = self.__date_place(get_death_or_fallback(self.database, person)) tmp = self.__date_place(
get_death_or_fallback(self.database, person))
if string and tmp: if string and tmp:
string += ", " string += ", "
string += tmp string += tmp
@@ -190,20 +200,21 @@ class Printinfo:
string = " (" + string + ")" string = " (" + string + ")"
if family and self.showmarriage: if family and self.showmarriage:
tmp = self.__date_place(get_marriage_or_fallback(self.database, tmp = self.__date_place(
family)) get_marriage_or_fallback(self.database, family))
if tmp: if tmp:
string += ", " + tmp string += ", " + tmp
if family and self.showdivorce: if family and self.showdivorce:
tmp = self.__date_place(get_divorce_or_fallback(self.database, tmp = self.__date_place(
family)) get_divorce_or_fallback(self.database, family))
if tmp: if tmp:
string += ", " + tmp string += ", " + tmp
self.doc.write_text(string) self.doc.write_text(string)
def print_person(self, level, person): def print_person(self, level, person):
""" print the person """
display_num = self.numbering.number(level) display_num = self.numbering.number(level)
self.doc.start_paragraph("DR-Level%d" % min(level, 32), display_num) self.doc.start_paragraph("DR-Level%d" % min(level, 32), display_num)
mark = ReportUtils.get_person_mark(self.database, person) mark = ReportUtils.get_person_mark(self.database, person)
@@ -213,6 +224,7 @@ class Printinfo:
return display_num return display_num
def print_spouse(self, level, spouse_handle, family_handle): def print_spouse(self, level, spouse_handle, family_handle):
""" print the spouse """
#Currently print_spouses is the same for all numbering systems. #Currently print_spouses is the same for all numbering systems.
if spouse_handle: if spouse_handle:
spouse = self.database.get_person_from_handle(spouse_handle) spouse = self.database.get_person_from_handle(spouse_handle)
@@ -230,15 +242,17 @@ class Printinfo:
self.doc.end_paragraph() self.doc.end_paragraph()
def print_reference(self, level, person, display_num): def print_reference(self, level, person, display_num):
""" print the reference """
#Person and their family have already been printed so #Person and their family have already been printed so
#print reference here #print reference here
if person: if person:
mark = ReportUtils.get_person_mark(self.database, person) mark = ReportUtils.get_person_mark(self.database, person)
self.doc.start_paragraph("DR-Spouse%d" % min(level, 32)) self.doc.start_paragraph("DR-Spouse%d" % min(level, 32))
name = self._name_display.display(person) name = self._name_display.display(person)
self.doc.write_text( self.doc.write_text(self._("sp. see %(reference)s: %(spouse)s"
self._("sp. see %(reference)s : %(spouse)s") % % {'reference' : display_num,
{'reference':display_num, 'spouse':name}, mark) 'spouse' : name}),
mark)
self.doc.end_paragraph() self.doc.end_paragraph()
@@ -255,21 +269,23 @@ class RecurseDown:
max_generations: The max number of generations max_generations: The max number of generations
database: The database object database: The database object
objPrint: A Printinfo derived class that prints person obj_print: A Printinfo derived class that prints person
information on the report information on the report
""" """
def __init__(self, max_generations, database, objPrint, showdups, rlocale): def __init__(self, max_generations, database,
obj_print, showdups, rlocale):
self.max_generations = max_generations self.max_generations = max_generations
self.database = database self.database = database
self.objPrint = objPrint self.obj_print = obj_print
self.showdups = showdups self.showdups = showdups
self.person_printed = {} self.person_printed = {}
self._ = rlocale.translation.sgettext # needed for English self._ = rlocale.translation.sgettext # needed for English
def recurse(self, level, person, curdepth): def recurse(self, level, person, curdepth):
""" recurse """
person_handle = person.get_handle() person_handle = person.get_handle()
display_num = self.objPrint.print_person(level, person) display_num = self.obj_print.print_person(level, person)
if curdepth is None: if curdepth is None:
ref_str = display_num ref_str = display_num
@@ -287,10 +303,10 @@ class RecurseDown:
if not self.showdups and spouse_handle in self.person_printed: if not self.showdups and spouse_handle in self.person_printed:
# Just print a reference # Just print a reference
spouse = self.database.get_person_from_handle(spouse_handle) spouse = self.database.get_person_from_handle(spouse_handle)
self.objPrint.print_reference(level, spouse, self.obj_print.print_reference(
self.person_printed[spouse_handle]) level, spouse, self.person_printed[spouse_handle])
else: else:
self.objPrint.print_spouse(level, spouse_handle, family) self.obj_print.print_spouse(level, spouse_handle, family)
if spouse_handle: if spouse_handle:
spouse_num = self._("%s sp." % (ref_str)) spouse_num = self._("%s sp." % (ref_str))
@@ -311,6 +327,7 @@ class RecurseDown:
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class DescendantReport(Report): class DescendantReport(Report):
""" Descendant report """
def __init__(self, database, options, user): def __init__(self, database, options, user):
""" """
@@ -347,10 +364,8 @@ class DescendantReport(Report):
self.max_generations = menu.get_option_by_name('gen').get_value() self.max_generations = menu.get_option_by_name('gen').get_value()
pid = menu.get_option_by_name('pid').get_value() pid = menu.get_option_by_name('pid').get_value()
self.center_person = self.database.get_person_from_gramps_id(pid) self.center_person = self.database.get_person_from_gramps_id(pid)
if (self.center_person == None) : if self.center_person is None:
raise ReportError(_("Person %s is not in the Database") % pid ) raise ReportError(_("Person %s is not in the Database") % pid)
sort = Sort(self.database)
#Initialize the Printinfo class #Initialize the Printinfo class
self._showdups = menu.get_option_by_name('dups').get_value() self._showdups = menu.get_option_by_name('dups').get_value()
@@ -362,14 +377,14 @@ class DescendantReport(Report):
elif numbering == "Meurgey de Tupigny": elif numbering == "Meurgey de Tupigny":
obj = PrintMeurgey() obj = PrintMeurgey()
else: else:
raise AttributeError("no such numbering: '%s'" % self.numbering) raise AttributeError("no such numbering: '%s'" % numbering)
marrs = menu.get_option_by_name('marrs').get_value() marrs = menu.get_option_by_name('marrs').get_value()
divs = menu.get_option_by_name('divs').get_value() divs = menu.get_option_by_name('divs').get_value()
stdoptions.run_name_format_option(self, menu) stdoptions.run_name_format_option(self, menu)
self.objPrint = Printinfo(self.doc, self.database, obj, marrs, divs, self.obj_print = Printinfo(self.doc, self.database, obj, marrs, divs,
self._name_display, self._locale) self._name_display, self._locale)
def write_report(self): def write_report(self):
@@ -382,7 +397,7 @@ class DescendantReport(Report):
self.doc.end_paragraph() self.doc.end_paragraph()
recurse = RecurseDown(self.max_generations, self.database, recurse = RecurseDown(self.max_generations, self.database,
self.objPrint, self._showdups, self._locale) self.obj_print, self._showdups, self._locale)
recurse.recurse(1, self.center_person, None) recurse.recurse(1, self.center_person, None)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -425,7 +440,8 @@ class DescendantOptions(MenuReportOptions):
menu.add_option(category_name, "gen", gen) menu.add_option(category_name, "gen", gen)
marrs = BooleanOption(_('Show marriage info'), False) marrs = BooleanOption(_('Show marriage info'), False)
marrs.set_help(_("Whether to show marriage information in the report.")) marrs.set_help(
_("Whether to show marriage information in the report."))
menu.add_option(category_name, "marrs", marrs) menu.add_option(category_name, "marrs", marrs)
divs = BooleanOption(_('Show divorce info'), False) divs = BooleanOption(_('Show divorce info'), False)
@@ -441,38 +457,42 @@ class DescendantOptions(MenuReportOptions):
def make_default_style(self, default_style): def make_default_style(self, default_style):
"""Make the default output style for the Descendant Report.""" """Make the default output style for the Descendant Report."""
f = FontStyle() fstyle = FontStyle()
f.set_size(12) fstyle.set_size(12)
f.set_type_face(FONT_SANS_SERIF) fstyle.set_type_face(FONT_SANS_SERIF)
f.set_bold(1) fstyle.set_bold(1)
p = ParagraphStyle() pstyle = ParagraphStyle()
p.set_header_level(1) pstyle.set_header_level(1)
p.set_bottom_border(1) pstyle.set_bottom_border(1)
p.set_top_margin(ReportUtils.pt2cm(3)) pstyle.set_top_margin(ReportUtils.pt2cm(3))
p.set_bottom_margin(ReportUtils.pt2cm(3)) pstyle.set_bottom_margin(ReportUtils.pt2cm(3))
p.set_font(f) pstyle.set_font(fstyle)
p.set_alignment(PARA_ALIGN_CENTER) pstyle.set_alignment(PARA_ALIGN_CENTER)
p.set_description(_("The style used for the title of the page.")) pstyle.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", pstyle)
f = FontStyle() fstyle = FontStyle()
f.set_size(10) fstyle.set_size(10)
for i in range(1, 33): for i in range(1, 33):
p = ParagraphStyle() pstyle = ParagraphStyle()
p.set_font(f) pstyle.set_font(fstyle)
p.set_top_margin(ReportUtils.pt2cm(f.get_size()*0.125)) pstyle.set_top_margin(ReportUtils.pt2cm(fstyle.get_size()*0.125))
p.set_bottom_margin(ReportUtils.pt2cm(f.get_size()*0.125)) pstyle.set_bottom_margin(
p.set_first_indent(-0.5) ReportUtils.pt2cm(fstyle.get_size()*0.125))
p.set_left_margin(min(10.0, float(i-0.5))) pstyle.set_first_indent(-0.5)
p.set_description(_("The style used for the " pstyle.set_left_margin(min(10.0, float(i-0.5)))
"level %d display.") % i) pstyle.set_description(
default_style.add_paragraph_style("DR-Level%d" % min(i, 32), p) _("The style used for the level %d display.") % i)
default_style.add_paragraph_style("DR-Level%d" % min(i, 32),
pstyle)
p = ParagraphStyle() pstyle = ParagraphStyle()
p.set_font(f) pstyle.set_font(fstyle)
p.set_top_margin(ReportUtils.pt2cm(f.get_size()*0.125)) pstyle.set_top_margin(ReportUtils.pt2cm(fstyle.get_size()*0.125))
p.set_bottom_margin(ReportUtils.pt2cm(f.get_size()*0.125)) pstyle.set_bottom_margin(
p.set_left_margin(min(10.0, float(i-0.5))) ReportUtils.pt2cm(fstyle.get_size()*0.125))
p.set_description(_("The style used for the " pstyle.set_left_margin(min(10.0, float(i-0.5)))
"spouse level %d display.") % i) pstyle.set_description(
default_style.add_paragraph_style("DR-Spouse%d" % min(i, 32), p) _("The style used for the spouse level %d display.") % i)
default_style.add_paragraph_style("DR-Spouse%d" % min(i, 32),
pstyle)