Pylint cleanup for the relationship calculator.

svn: r13421
This commit is contained in:
Brian Matherly 2009-10-26 02:10:14 +00:00
parent 7290694c43
commit 22693cfbad

View File

@ -342,13 +342,14 @@ _nephews_nieces_level = [ "",
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# # RelationshipCalculator
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class RelationshipCalculator(object): class RelationshipCalculator(object):
"""
The relationship calculator helps to determine the relationship between
two people.
"""
REL_MOTHER = 'm' # going up to mother REL_MOTHER = 'm' # going up to mother
REL_FATHER = 'f' # going up to father REL_FATHER = 'f' # going up to father
REL_MOTHER_NOTBIRTH = 'M' # going up to mother, not birth relation REL_MOTHER_NOTBIRTH = 'M' # going up to mother, not birth relation
@ -369,10 +370,10 @@ class RelationshipCalculator(object):
UNKNOWN_SIB = 4 # insufficient data to draw conclusion UNKNOWN_SIB = 4 # insufficient data to draw conclusion
#sibling strings #sibling strings
STEP= 'step' STEP = 'step'
HALF = 'half-' HALF = 'half-'
INLAW='-in-law' INLAW = '-in-law'
#partner types #partner types
PARTNER_MARRIED = 1 PARTNER_MARRIED = 1
@ -413,13 +414,12 @@ class RelationshipCalculator(object):
""" """
return self.depth return self.depth
DIST_FATHER = "distant %(step)sancestor%(inlaw)s (%(level)d generations)" DIST_FATHER = "distant %(step)sancestor%(inlaw)s (%(level)d generations)"
def _get_father(self, level, step='', inlaw=''): def _get_father(self, level, step='', inlaw=''):
"""Internal english method to create relation string """Internal english method to create relation string
""" """
if level>len(_father_level)-1: if level > len(_father_level) - 1:
return self.DIST_FATHER % {'step': step, 'inlaw': inlaw, return self.DIST_FATHER % {'step': step, 'inlaw': inlaw,
'level': level} 'level': level}
else: else:
@ -430,7 +430,7 @@ class RelationshipCalculator(object):
def _get_son(self, level, step='', inlaw=''): def _get_son(self, level, step='', inlaw=''):
"""Internal english method to create relation string """Internal english method to create relation string
""" """
if level>len(_son_level)-1: if level > len(_son_level) - 1:
return self.DIST_SON % {'step': step, 'inlaw': inlaw, return self.DIST_SON % {'step': step, 'inlaw': inlaw,
'level': level} 'level': level}
else: else:
@ -441,7 +441,7 @@ class RelationshipCalculator(object):
def _get_mother(self, level, step='', inlaw=''): def _get_mother(self, level, step='', inlaw=''):
"""Internal english method to create relation string """Internal english method to create relation string
""" """
if level>len(_mother_level)-1: if level > len(_mother_level) - 1:
return self.DIST_MOTHER % {'step': step, 'inlaw': inlaw, return self.DIST_MOTHER % {'step': step, 'inlaw': inlaw,
'level': level} 'level': level}
else: else:
@ -452,7 +452,7 @@ class RelationshipCalculator(object):
def _get_daughter(self, level, step='', inlaw=''): def _get_daughter(self, level, step='', inlaw=''):
"""Internal english method to create relation string """Internal english method to create relation string
""" """
if level>len(_daughter_level)-1: if level > len(_daughter_level) - 1:
return self.DIST_DAUGHTER % {'step': step, 'inlaw': inlaw, return self.DIST_DAUGHTER % {'step': step, 'inlaw': inlaw,
'level': level} 'level': level}
else: else:
@ -483,7 +483,7 @@ class RelationshipCalculator(object):
def _get_aunt(self, level, step='', inlaw=''): def _get_aunt(self, level, step='', inlaw=''):
"""Internal english method to create relation string """Internal english method to create relation string
""" """
if level>len(_sister_level)-1: if level > len(_sister_level) - 1:
return self.DIST_AUNT % {'step': step, 'inlaw': inlaw} return self.DIST_AUNT % {'step': step, 'inlaw': inlaw}
else: else:
return _sister_level[level] % {'step': step, 'inlaw': inlaw} return _sister_level[level] % {'step': step, 'inlaw': inlaw}
@ -493,7 +493,7 @@ class RelationshipCalculator(object):
def _get_uncle(self, level, step='', inlaw=''): def _get_uncle(self, level, step='', inlaw=''):
"""Internal english method to create relation string """Internal english method to create relation string
""" """
if level>len(_brother_level)-1: if level > len(_brother_level) - 1:
return self.DIST_UNCLE % {'step': step, 'inlaw': inlaw} return self.DIST_UNCLE % {'step': step, 'inlaw': inlaw}
else: else:
return _brother_level[level] % {'step': step, 'inlaw': inlaw} return _brother_level[level] % {'step': step, 'inlaw': inlaw}
@ -503,7 +503,7 @@ class RelationshipCalculator(object):
def _get_nephew(self, level, step='', inlaw=''): def _get_nephew(self, level, step='', inlaw=''):
"""Internal english method to create relation string """Internal english method to create relation string
""" """
if level>len(_nephew_level)-1: if level > len(_nephew_level) - 1:
return self.DIST_NEPHEW % {'step': step, 'inlaw': inlaw} return self.DIST_NEPHEW % {'step': step, 'inlaw': inlaw}
else: else:
return _nephew_level[level] % {'step': step, 'inlaw': inlaw} return _nephew_level[level] % {'step': step, 'inlaw': inlaw}
@ -513,12 +513,12 @@ class RelationshipCalculator(object):
def _get_niece(self, level, step='', inlaw=''): def _get_niece(self, level, step='', inlaw=''):
"""Internal english method to create relation string """Internal english method to create relation string
""" """
if level>len(_niece_level)-1: if level > len(_niece_level) - 1:
return self.DIST_NIECE % {'step': step, 'inlaw': inlaw} return self.DIST_NIECE % {'step': step, 'inlaw': inlaw}
else: else:
return _niece_level[level] % {'step': step, 'inlaw': inlaw} return _niece_level[level] % {'step': step, 'inlaw': inlaw}
def _get_cousin(self, level, removed, dir = '', step='', inlaw=''): def _get_cousin(self, level, removed, dir='', step='', inlaw=''):
"""Internal english method to create relation string """Internal english method to create relation string
""" """
if removed == 0 and level < len(_level_name): if removed == 0 and level < len(_level_name):
@ -635,7 +635,7 @@ class RelationshipCalculator(object):
#make every person appear only once: #make every person appear only once:
return list(set(nb_parents)) return list(set(nb_parents))
def get_spouse_type(self, db, orig, other, all_rel = False): def _get_spouse_type(self, db, orig, other, all_rel = False):
""" Translation free determination if orig and other are partners. """ Translation free determination if orig and other are partners.
The procedure returns partner types, these can be passed to The procedure returns partner types, these can be passed to
get_partner_relationship_string. get_partner_relationship_string.
@ -643,8 +643,8 @@ class RelationshipCalculator(object):
If all_rel=True, returns a list, empty if no partner If all_rel=True, returns a list, empty if no partner
""" """
val = [] val = []
for f in orig.get_family_handle_list(): for family_handle in orig.get_family_handle_list():
family = db.get_family_from_handle(f) family = db.get_family_from_handle(family_handle)
# return first found spouse type # return first found spouse type
if family and other.get_handle() in [family.get_father_handle(), if family and other.get_handle() in [family.get_father_handle(),
family.get_mother_handle()]: family.get_mother_handle()]:
@ -690,9 +690,9 @@ class RelationshipCalculator(object):
def is_spouse(self, db, orig, other, all_rel=False): def is_spouse(self, db, orig, other, all_rel=False):
""" determine the spouse relation """ determine the spouse relation
""" """
type = self.get_spouse_type(db, orig, other, all_rel) spouse_type = self._get_spouse_type(db, orig, other, all_rel)
if type: if spouse_type:
return self.get_partner_relationship_string(type, return self.get_partner_relationship_string(spouse_type,
orig.get_gender(), other.get_gender()) orig.get_gender(), other.get_gender())
else: else:
return None return None
@ -764,15 +764,11 @@ class RelationshipCalculator(object):
firstRel = -1 firstRel = -1
secondRel = -1 secondRel = -1
common_str = []
common_fam = []
self.__msg = [] self.__msg = []
common = [] common = []
firstMap = {} firstMap = {}
firstList = []
secondMap = {} secondMap = {}
secondList = []
rank = 9999999 rank = 9999999
try: try:
@ -1090,15 +1086,17 @@ class RelationshipCalculator(object):
# first time we see this family path # first time we see this family path
if (posfam is not None and relstrfirst is not None and if (posfam is not None and relstrfirst is not None and
relstrsec is not None): relstrsec is not None):
#we already have a common ancestor of this family, just add the # We already have a common ancestor of this family, just
#other, setting correct family relation # add the other, setting correct family relation.
tmp = commonnew[posfam] tmp = commonnew[posfam]
frstcomstr = rela2[-1] frstcomstr = rela2[-1]
scndcomstr = tmp[2][-1] scndcomstr = tmp[2][-1]
newcomstra = self.famrel_from_persrel(frstcomstr, scndcomstr) newcomstra = self._famrel_from_persrel(frstcomstr,
scndcomstr)
frstcomstr = rela4[-1] frstcomstr = rela4[-1]
scndcomstr = tmp[4][-1] scndcomstr = tmp[4][-1]
newcomstrb = self.famrel_from_persrel(frstcomstr, scndcomstr) newcomstrb = self._famrel_from_persrel(frstcomstr,
scndcomstr)
commonnew[posfam] = (tmp[0], tmp[1]+commonhandle, commonnew[posfam] = (tmp[0], tmp[1]+commonhandle,
rela2[:-1]+newcomstra, rela2[:-1]+newcomstra,
@ -1142,7 +1140,7 @@ class RelationshipCalculator(object):
return collapsed return collapsed
def famrel_from_persrel(self, persrela, persrelb): def _famrel_from_persrel(self, persrela, persrelb):
""" Conversion from eg 'f' and 'm' to 'a', so relation to the two """ Conversion from eg 'f' and 'm' to 'a', so relation to the two
persons of a common family is converted to a family relation persons of a common family is converted to a family relation
""" """
@ -1230,7 +1228,7 @@ class RelationshipCalculator(object):
databest.append(rel) databest.append(rel)
rel = databest[0] rel = databest[0]
dist_orig = len(rel[2]) dist_orig = len(rel[2])
dist_other= len(rel[4]) dist_other = len(rel[4])
if len(databest) == 1: if len(databest) == 1:
birth = self.only_birth(rel[2]) and self.only_birth(rel[4]) birth = self.only_birth(rel[2]) and self.only_birth(rel[4])
if dist_orig == dist_other == 1: if dist_orig == dist_other == 1:
@ -1256,7 +1254,7 @@ class RelationshipCalculator(object):
orderbest = order.index(self.REL_MOTHER) orderbest = order.index(self.REL_MOTHER)
for relother in databest: for relother in databest:
relbirth = self.only_birth(rel[2]) and self.only_birth(rel[4]) relbirth = self.only_birth(rel[2]) and self.only_birth(rel[4])
if relother[2] == '' or relother[4]== '': if relother[2] == '' or relother[4] == '':
#direct relation, take that #direct relation, take that
rel = relother rel = relother
break break
@ -1285,7 +1283,7 @@ class RelationshipCalculator(object):
rel = relother rel = relother
continue continue
dist_orig = len(rel[2]) dist_orig = len(rel[2])
dist_other= len(rel[4]) dist_other = len(rel[4])
birth = self.only_birth(rel[2]) and self.only_birth(rel[4]) birth = self.only_birth(rel[2]) and self.only_birth(rel[4])
if dist_orig == dist_other == 1: if dist_orig == dist_other == 1:
rel_str = self.get_sibling_relationship_string( rel_str = self.get_sibling_relationship_string(
@ -1335,7 +1333,7 @@ class RelationshipCalculator(object):
rel4 = rel[4] rel4 = rel[4]
rel1 = rel[1] rel1 = rel[1]
dist_orig = len(rel[2]) dist_orig = len(rel[2])
dist_other= len(rel[4]) dist_other = len(rel[4])
if rel[2] and rel[2][-1] == self.REL_SIBLING: if rel[2] and rel[2][-1] == self.REL_SIBLING:
rel2 = rel2[:-1] + self.REL_FAM_BIRTH rel2 = rel2[:-1] + self.REL_FAM_BIRTH
dist_other += 1 dist_other += 1
@ -1767,7 +1765,7 @@ def get_relationship_calculator(reinit=False):
for plugin in PluginRegister.get_instance().relcalc_plugins(): for plugin in PluginRegister.get_instance().relcalc_plugins():
if os.environ["LANG"] in plugin.lang_list: if os.environ["LANG"] in plugin.lang_list:
pmgr = BasePluginManager.get_instance() pmgr = BasePluginManager.get_instance()
#the loaded module is put in variable mod # the loaded module is put in variable mod
mod = pmgr.load_plugin(plugin) mod = pmgr.load_plugin(plugin)
if mod: if mod:
__RELCALC_CLASS = eval('mod.' + plugin.relcalcclass) __RELCALC_CLASS = eval('mod.' + plugin.relcalcclass)