diff --git a/po/POTFILES.in b/po/POTFILES.in index aa7aa9d42..8f35ad6d0 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -324,7 +324,6 @@ src/gen/simple/_simpletable.py src/gen/utils/alive.py src/gen/utils/keyword.py src/gen/utils/lds.py -src/gen/utils/name.py src/gen/utils/place.py src/gen/utils/string.py src/gen/utils/trans.py diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 29245c3b8..68062cd38 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -218,8 +218,6 @@ src/gen/utils/debug.py src/gen/utils/file.py src/gen/utils/id.py src/gen/utils/image.py -src/gen/utils/referent.py -src/gen/utils/tree.py # gen.utils.docgen src/gen/utils/docgen/__init__.py diff --git a/src/gen/filters/rules/person/_hascommonancestorwith.py b/src/gen/filters/rules/person/_hascommonancestorwith.py index 2f07c1680..b92bc201a 100644 --- a/src/gen/filters/rules/person/_hascommonancestorwith.py +++ b/src/gen/filters/rules/person/_hascommonancestorwith.py @@ -32,7 +32,7 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from gen.utils.tree import for_each_ancestor +from gen.utils.db import for_each_ancestor from gen.filters.rules import Rule #------------------------------------------------------------------------- diff --git a/src/gen/filters/rules/person/_hascommonancestorwithfiltermatch.py b/src/gen/filters/rules/person/_hascommonancestorwithfiltermatch.py index c20cb89dd..93ea47bcb 100644 --- a/src/gen/filters/rules/person/_hascommonancestorwithfiltermatch.py +++ b/src/gen/filters/rules/person/_hascommonancestorwithfiltermatch.py @@ -32,7 +32,7 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from gen.utils.tree import for_each_ancestor +from gen.utils.db import for_each_ancestor from _hascommonancestorwith import HasCommonAncestorWith from _matchesfilter import MatchesFilter diff --git a/src/gen/filters/rules/person/_hastextmatchingsubstringof.py b/src/gen/filters/rules/person/_hastextmatchingsubstringof.py index d02483511..b2ef735e6 100644 --- a/src/gen/filters/rules/person/_hastextmatchingsubstringof.py +++ b/src/gen/filters/rules/person/_hastextmatchingsubstringof.py @@ -35,7 +35,7 @@ LOG = logging.getLogger(".citationfilter") # GRAMPS modules # #------------------------------------------------------------------------- -from gen.utils.referent import get_source_and_citation_referents +from gen.utils.db import get_source_and_citation_referents from gen.filters.rules import Rule #------------------------------------------------------------------------- diff --git a/src/gen/utils/Makefile.am b/src/gen/utils/Makefile.am index 12c698aab..7abe27c3c 100644 --- a/src/gen/utils/Makefile.am +++ b/src/gen/utils/Makefile.am @@ -23,13 +23,10 @@ pkgpython_PYTHON = \ image.py \ keyword.py \ lds.py \ - name.py \ mactrans.py \ place.py \ - referent.py \ string.py \ trans.py \ - tree.py \ unknown.py pkgpyexecdir = @pkgpyexecdir@/gen/utils diff --git a/src/gen/utils/db.py b/src/gen/utils/db.py index ce77da626..7bdbd71cc 100644 --- a/src/gen/utils/db.py +++ b/src/gen/utils/db.py @@ -23,13 +23,21 @@ """ Utilities for getting information from the database. """ +#------------------------------------------------------------------------- +# +# Standard python modules +# +#------------------------------------------------------------------------- +import logging +LOG = logging.getLogger(".gui.utils.db") + #------------------------------------------------------------------------- # # Gramps modules # #------------------------------------------------------------------------- +import gen.lib from gen.display.name import displayer as name_displayer -from gen.utils.name import family_name from gen.ggettext import sgettext as _ #------------------------------------------------------------------------- @@ -291,3 +299,282 @@ def navigation_label(db, nav_type, handle): label = '[%s] %s' % (obj.get_gramps_id(), label) return (label, obj) + +#------------------------------------------------------------------------- +# +# Function to return children's list of a person +# +#------------------------------------------------------------------------- +def find_children(db,p): + """ + Return the list of all children's IDs for a person. + """ + childlist = [] + for family_handle in p.get_family_handle_list(): + family = db.get_family_from_handle(family_handle) + for child_ref in family.get_child_ref_list(): + childlist.append(child_ref.ref) + return childlist + +#------------------------------------------------------------------------- +# +# Function to return parent's list of a person +# +#------------------------------------------------------------------------- +def find_parents(db,p): + """ + Return the unique list of all parents' IDs for a person. + """ + parentlist = [] + for f in p.get_parent_family_handle_list(): + family = db.get_family_from_handle(f) + father_handle = family.get_father_handle() + mother_handle = family.get_mother_handle() + if father_handle not in parentlist: + parentlist.append(father_handle) + if mother_handle not in parentlist: + parentlist.append(mother_handle) + return parentlist + +#------------------------------------------------------------------------- +# +# Function to return persons, that share the same event. +# This for example links witnesses to the tree +# +#------------------------------------------------------------------------- +def find_witnessed_people(db,p): + people = [] + for event_ref in p.get_event_ref_list(): + for l in db.find_backlink_handles( event_ref.ref): + if l[0] == 'Person' and l[1] != p.get_handle() and l[1] not in people: + people.append(l[1]) + if l[0] == 'Family': + fam = db.get_family_from_handle(l[1]) + if fam: + father_handle = fam.get_father_handle() + if father_handle and father_handle != p.get_handle() and father_handle not in people: + people.append(father_handle) + mother_handle = fam.get_mother_handle() + if mother_handle and mother_handle != p.get_handle() and mother_handle not in people: + people.append(mother_handle) + for f in p.get_family_handle_list(): + family = db.get_family_from_handle(f) + for event_ref in family.get_event_ref_list(): + for l in db.find_backlink_handles( event_ref.ref): + if l[0] == 'Person' and l[1] != p.get_handle() and l[1] not in people: + people.append(l[1]) + for pref in p.get_person_ref_list(): + if pref.ref != p.get_handle and pref.ref not in people: + people.append(pref.ref) + return people + +#------------------------------------------------------------------------- +# +# Iterate over ancestors. +# +#------------------------------------------------------------------------- +def for_each_ancestor(db, start, func, data): + """ + Recursively iterate (breadth-first) over ancestors of + people listed in start. + Call func(data, pid) for the Id of each person encountered. + Exit and return 1, as soon as func returns true. + Return 0 otherwise. + """ + todo = start + done_ids = set() + while len(todo): + p_handle = todo.pop() + p = db.get_person_from_handle(p_handle) + # Don't process the same handle twice. This can happen + # if there is a cycle in the database, or if the + # initial list contains X and some of X's ancestors. + if p_handle in done_ids: + continue + done_ids.add(p_handle) + if func(data, p_handle): + return 1 + for fam_handle in p.get_parent_family_handle_list(): + fam = db.get_family_from_handle(fam_handle) + if fam: + f_handle = fam.get_father_handle() + m_handle = fam.get_mother_handle() + if f_handle: todo.append(f_handle) + if m_handle: todo.append(m_handle) + return 0 + +#------------------------------------------------------------------------- +# +# Preset a name with a name of family member +# +#------------------------------------------------------------------------- +def preset_name(basepers, name, sibling=False): + """Fill up name with all family common names of basepers. + If sibling=True, pa/matronymics are retained. + """ + surnlist = [] + primname = basepers.get_primary_name() + prim = False + for surn in primname.get_surname_list(): + if (not sibling) and (surn.get_origintype().value in + [gen.lib.NameOriginType.PATRONYMIC, + gen.lib.NameOriginType.MATRONYMIC]): + continue + surnlist.append(gen.lib.Surname(source=surn)) + if surn.primary: + prim=True + if not surnlist: + surnlist = [gen.lib.Surname()] + name.set_surname_list(surnlist) + if not prim: + name.set_primary_surname(0) + name.set_family_nick_name(primname.get_family_nick_name()) + name.set_group_as(primname.get_group_as()) + name.set_sort_as(primname.get_sort_as()) + +#------------------------------------------------------------------------- +# +# Short hand function to return either the person's name, or an empty +# string if the person is None +# +#------------------------------------------------------------------------- +def family_name(family, db, noname=_("unknown")): + """Builds a name for the family from the parents names""" + + father_handle = family.get_father_handle() + mother_handle = family.get_mother_handle() + father = db.get_person_from_handle(father_handle) + mother = db.get_person_from_handle(mother_handle) + if father and mother: + fname = name_displayer.display(father) + mname = name_displayer.display(mother) + name = _("%(father)s and %(mother)s") % { + "father" : fname, + "mother" : mname} + elif father: + name = name_displayer.display(father) + elif mother: + name = name_displayer.display(mother) + else: + name = noname + return name + +#------------------------------------------------------------------------- +# +# Referents functions +# +#------------------------------------------------------------------------- +def get_referents(handle, db, primary_objects): + """ Find objects that refer to an object. + + This function is the base for other get__referents functions. + + """ + # Use one pass through the reference map to grab all the references + object_list = list(db.find_backlink_handles(handle)) + + # Then form the object-specific lists + the_lists = () + + for primary in primary_objects: + primary_list = [item[1] for item in object_list if item[0] == primary] + the_lists = the_lists + (primary_list, ) + + return the_lists + +def get_source_referents(source_handle, db): + """ Find objects that refer the source. + + This function finds all primary objects that refer (directly or through + secondary child-objects) to a given source handle in a given database. + + Only Citations can refer to sources, so that is all we need to check + """ + _primaries = ('Citation',) + + return (get_referents(source_handle, db, _primaries)) + +def get_citation_referents(citation_handle, db): + """ Find objects that refer the citation. + + This function finds all primary objects that refer (directly or through + secondary child-objects) to a given citation handle in a given database. + + """ + _primaries = ('Person', 'Family', 'Event', 'Place', + 'Source', 'MediaObject', 'Repository') + + return (get_referents(citation_handle, db, _primaries)) + +def get_source_and_citation_referents(source_handle, db): + """ + Find all citations that refer to the sources, and recursively, all objects + that refer to the sources. + + This function finds all primary objects that refer (directly or through + secondary child-objects) to a given source handle in a given database. + + Objects -> Citations -> Source + e.g. + Media object M1 -> Citation C1 -> Source S1 + Media object M2 -> Citation C1 -> Source S1 + Person object P1 -> Citation C2 -> Source S1 + + The returned structure is rather ugly, but provides all the information in + a way that is consistent with the other Util functions. + ( + tuple of objects that refer to the source - only first element is present + ([C1, C2],), + list of citations with objects that refer to them + [ + (C1, + tuple of reference lists + P, F, E, Pl, S, M, R + ([], [], [], [], [], [M1, M2]. []) + ) + (C2, + tuple of reference lists + P, F, E, Pl, S, M, R + ([P1], [], [], [], [], []. []) + ) + ] + ) + """ + the_lists = get_source_referents(source_handle, db) + LOG.debug('source referents %s' % [the_lists]) + # now, for each citation, get the objects that refer to that citation + citation_referents_list = [] + for citation in the_lists[0]: + LOG.debug('citation %s' % citation) + refs = get_citation_referents(citation, db) + citation_referents_list += [(citation, refs)] + LOG.debug('citation_referents_list %s' % [citation_referents_list]) + + (citation_list) = the_lists + the_lists = (citation_list, citation_referents_list) + + LOG.debug('the_lists %s' % [the_lists]) + return the_lists + +def get_media_referents(media_handle, db): + """ Find objects that refer the media object. + + This function finds all primary objects that refer + to a given media handle in a given database. + + """ + _primaries = ('Person', 'Family', 'Event', 'Place', 'Source', 'Citation') + + return (get_referents(media_handle, db, _primaries)) + +def get_note_referents(note_handle, db): + """ Find objects that refer a note object. + + This function finds all primary objects that refer + to a given note handle in a given database. + + """ + _primaries = ('Person', 'Family', 'Event', 'Place', + 'Source', 'Citation', 'MediaObject', 'Repository') + + return (get_referents(note_handle, db, _primaries)) diff --git a/src/gen/utils/name.py b/src/gen/utils/name.py deleted file mode 100644 index fa7e2e591..000000000 --- a/src/gen/utils/name.py +++ /dev/null @@ -1,112 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2009 Gary Burton -# Copyright (C) 2011 Tim G L Lyons -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -# $Id$ - -""" -Name related utility functions -""" -#------------------------------------------------------------------------- -# -# Gramps modules -# -#------------------------------------------------------------------------- -import gen.lib -from gen.display.name import displayer as name_displayer -from gen.ggettext import sgettext as _ - -#------------------------------------------------------------------------- -# -# Preset a name with a name of family member -# -#------------------------------------------------------------------------- - -def preset_name(basepers, name, sibling=False): - """Fill up name with all family common names of basepers. - If sibling=True, pa/matronymics are retained. - """ - surnlist = [] - primname = basepers.get_primary_name() - prim = False - for surn in primname.get_surname_list(): - if (not sibling) and (surn.get_origintype().value in - [gen.lib.NameOriginType.PATRONYMIC, - gen.lib.NameOriginType.MATRONYMIC]): - continue - surnlist.append(gen.lib.Surname(source=surn)) - if surn.primary: - prim=True - if not surnlist: - surnlist = [gen.lib.Surname()] - name.set_surname_list(surnlist) - if not prim: - name.set_primary_surname(0) - name.set_family_nick_name(primname.get_family_nick_name()) - name.set_group_as(primname.get_group_as()) - name.set_sort_as(primname.get_sort_as()) - -#------------------------------------------------------------------------- -# -# Short hand function to return either the person's name, or an empty -# string if the person is None -# -#------------------------------------------------------------------------- - -def family_name(family, db, noname=_("unknown")): - """Builds a name for the family from the parents names""" - - father_handle = family.get_father_handle() - mother_handle = family.get_mother_handle() - father = db.get_person_from_handle(father_handle) - mother = db.get_person_from_handle(mother_handle) - if father and mother: - fname = name_displayer.display(father) - mname = name_displayer.display(mother) - name = _("%(father)s and %(mother)s") % { - "father" : fname, - "mother" : mname} - elif father: - name = name_displayer.display(father) - elif mother: - name = name_displayer.display(mother) - else: - name = noname - return name - -def family_upper_name(family, db): - """Builds a name for the family from the parents names""" - father_handle = family.get_father_handle() - mother_handle = family.get_mother_handle() - father = db.get_person_from_handle(father_handle) - mother = db.get_person_from_handle(mother_handle) - if father and mother: - fname = father.get_primary_name().get_upper_name() - mname = mother.get_primary_name().get_upper_name() - name = _("%(father)s and %(mother)s") % { - 'father' : fname, - 'mother' : mname - } - elif father: - name = father.get_primary_name().get_upper_name() - else: - name = mother.get_primary_name().get_upper_name() - return name diff --git a/src/gen/utils/referent.py b/src/gen/utils/referent.py deleted file mode 100644 index 59ba1a60c..000000000 --- a/src/gen/utils/referent.py +++ /dev/null @@ -1,161 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2009 Gary Burton -# Copyright (C) 2011 Tim G L Lyons -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -# $Id$ - -""" -Functions to return referents of primary objects. -""" - -#------------------------------------------------------------------------- -# -# Standard python modules -# -#------------------------------------------------------------------------- -import logging -LOG = logging.getLogger(".gui.utils.referents") - -#------------------------------------------------------------------------- -# -# Referents functions -# -#------------------------------------------------------------------------- - -def get_referents(handle, db, primary_objects): - """ Find objects that refer to an object. - - This function is the base for other get__referents functions. - - """ - # Use one pass through the reference map to grab all the references - object_list = list(db.find_backlink_handles(handle)) - - # Then form the object-specific lists - the_lists = () - - for primary in primary_objects: - primary_list = [item[1] for item in object_list if item[0] == primary] - the_lists = the_lists + (primary_list, ) - - return the_lists - -def get_source_referents(source_handle, db): - """ Find objects that refer the source. - - This function finds all primary objects that refer (directly or through - secondary child-objects) to a given source handle in a given database. - - Only Citations can refer to sources, so that is all we need to check - """ - _primaries = ('Citation',) - - return (get_referents(source_handle, db, _primaries)) - -def get_citation_referents(citation_handle, db): - """ Find objects that refer the citation. - - This function finds all primary objects that refer (directly or through - secondary child-objects) to a given citation handle in a given database. - - """ - _primaries = ('Person', 'Family', 'Event', 'Place', - 'Source', 'MediaObject', 'Repository') - - return (get_referents(citation_handle, db, _primaries)) - -def get_source_and_citation_referents(source_handle, db): - """ - Find all citations that refer to the sources, and recursively, all objects - that refer to the sources. - - This function finds all primary objects that refer (directly or through - secondary child-objects) to a given source handle in a given database. - - Objects -> Citations -> Source - e.g. - Media object M1 -> Citation C1 -> Source S1 - Media object M2 -> Citation C1 -> Source S1 - Person object P1 -> Citation C2 -> Source S1 - - The returned structure is rather ugly, but provides all the information in - a way that is consistent with the other Util functions. - ( - tuple of objects that refer to the source - only first element is present - ([C1, C2],), - list of citations with objects that refer to them - [ - (C1, - tuple of reference lists - P, F, E, Pl, S, M, R - ([], [], [], [], [], [M1, M2]. []) - ) - (C2, - tuple of reference lists - P, F, E, Pl, S, M, R - ([P1], [], [], [], [], []. []) - ) - ] - ) -#47738: DEBUG: citationtreeview.py: line 428: source referents [(['bfe59e90dbb555d0d87'],)] -#47743: DEBUG: citationtreeview.py: line 432: citation bfe59e90dbb555d0d87 -#47825: DEBUG: citationtreeview.py: line 435: citation_referents_list [[('bfe59e90dbb555d0d87', ([], [], ['ba77932bf0b2d59eccb'], [], [], [], []))]] -#47827: DEBUG: citationtreeview.py: line 440: the_lists [((['bfe59e90dbb555d0d87'],), [('bfe59e90dbb555d0d87', ([], [], ['ba77932bf0b2d59eccb'], [], [], [], []))])] - - """ - the_lists = get_source_referents(source_handle, db) - LOG.debug('source referents %s' % [the_lists]) - # now, for each citation, get the objects that refer to that citation - citation_referents_list = [] - for citation in the_lists[0]: - LOG.debug('citation %s' % citation) - refs = get_citation_referents(citation, db) - citation_referents_list += [(citation, refs)] - LOG.debug('citation_referents_list %s' % [citation_referents_list]) - - (citation_list) = the_lists - the_lists = (citation_list, citation_referents_list) - - LOG.debug('the_lists %s' % [the_lists]) - return the_lists - -def get_media_referents(media_handle, db): - """ Find objects that refer the media object. - - This function finds all primary objects that refer - to a given media handle in a given database. - - """ - _primaries = ('Person', 'Family', 'Event', 'Place', 'Source', 'Citation') - - return (get_referents(media_handle, db, _primaries)) - -def get_note_referents(note_handle, db): - """ Find objects that refer a note object. - - This function finds all primary objects that refer - to a given note handle in a given database. - - """ - _primaries = ('Person', 'Family', 'Event', 'Place', - 'Source', 'Citation', 'MediaObject', 'Repository') - - return (get_referents(note_handle, db, _primaries)) diff --git a/src/gen/utils/tree.py b/src/gen/utils/tree.py deleted file mode 100644 index d674d530a..000000000 --- a/src/gen/utils/tree.py +++ /dev/null @@ -1,130 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2009 Gary Burton -# Copyright (C) 2011 Tim G L Lyons -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -# $Id$ - -""" -Tree related utility functions -""" - -#------------------------------------------------------------------------- -# -# Function to return children's list of a person -# -#------------------------------------------------------------------------- -def find_children(db,p): - """ - Return the list of all children's IDs for a person. - """ - childlist = [] - for family_handle in p.get_family_handle_list(): - family = db.get_family_from_handle(family_handle) - for child_ref in family.get_child_ref_list(): - childlist.append(child_ref.ref) - return childlist - -#------------------------------------------------------------------------- -# -# Function to return parent's list of a person -# -#------------------------------------------------------------------------- -def find_parents(db,p): - """ - Return the unique list of all parents' IDs for a person. - """ - parentlist = [] - for f in p.get_parent_family_handle_list(): - family = db.get_family_from_handle(f) - father_handle = family.get_father_handle() - mother_handle = family.get_mother_handle() - if father_handle not in parentlist: - parentlist.append(father_handle) - if mother_handle not in parentlist: - parentlist.append(mother_handle) - return parentlist - -#------------------------------------------------------------------------- -# -# Function to return persons, that share the same event. -# This for example links witnesses to the tree -# -#------------------------------------------------------------------------- -def find_witnessed_people(db,p): - people = [] - for event_ref in p.get_event_ref_list(): - for l in db.find_backlink_handles( event_ref.ref): - if l[0] == 'Person' and l[1] != p.get_handle() and l[1] not in people: - people.append(l[1]) - if l[0] == 'Family': - fam = db.get_family_from_handle(l[1]) - if fam: - father_handle = fam.get_father_handle() - if father_handle and father_handle != p.get_handle() and father_handle not in people: - people.append(father_handle) - mother_handle = fam.get_mother_handle() - if mother_handle and mother_handle != p.get_handle() and mother_handle not in people: - people.append(mother_handle) - for f in p.get_family_handle_list(): - family = db.get_family_from_handle(f) - for event_ref in family.get_event_ref_list(): - for l in db.find_backlink_handles( event_ref.ref): - if l[0] == 'Person' and l[1] != p.get_handle() and l[1] not in people: - people.append(l[1]) - for pref in p.get_person_ref_list(): - if pref.ref != p.get_handle and pref.ref not in people: - people.append(pref.ref) - return people - -#------------------------------------------------------------------------- -# -# Iterate over ancestors. -# -#------------------------------------------------------------------------- -def for_each_ancestor(db, start, func, data): - """ - Recursively iterate (breadth-first) over ancestors of - people listed in start. - Call func(data, pid) for the Id of each person encountered. - Exit and return 1, as soon as func returns true. - Return 0 otherwise. - """ - todo = start - done_ids = set() - while len(todo): - p_handle = todo.pop() - p = db.get_person_from_handle(p_handle) - # Don't process the same handle twice. This can happen - # if there is a cycle in the database, or if the - # initial list contains X and some of X's ancestors. - if p_handle in done_ids: - continue - done_ids.add(p_handle) - if func(data, p_handle): - return 1 - for fam_handle in p.get_parent_family_handle_list(): - fam = db.get_family_from_handle(fam_handle) - if fam: - f_handle = fam.get_father_handle() - m_handle = fam.get_mother_handle() - if f_handle: todo.append(f_handle) - if m_handle: todo.append(m_handle) - return 0 diff --git a/src/gui/editors/displaytabs/backrefmodel.py b/src/gui/editors/displaytabs/backrefmodel.py index 7d2451807..553b94521 100644 --- a/src/gui/editors/displaytabs/backrefmodel.py +++ b/src/gui/editors/displaytabs/backrefmodel.py @@ -37,8 +37,7 @@ from gen.ggettext import gettext as _ # #------------------------------------------------------------------------- from gen.display.name import displayer as name_displayer -from gen.utils.name import family_name -from gen.utils.db import get_participant_from_event +from gen.utils.db import family_name, get_participant_from_event #------------------------------------------------------------------------- # diff --git a/src/gui/editors/editfamily.py b/src/gui/editors/editfamily.py index e9799ab66..aba8d4e92 100644 --- a/src/gui/editors/editfamily.py +++ b/src/gui/editors/editfamily.py @@ -62,7 +62,6 @@ import gobject #------------------------------------------------------------------------- from gen.config import config from gen.display.name import displayer as name_displayer -from gen.utils.db import get_marriage_or_fallback import gen.lib from gen.db import DbTxn from gen.errors import WindowActiveError @@ -80,10 +79,10 @@ from gui.widgets import (PrivacyButton, MonitoredEntry, MonitoredDataType, from gen.plug import CATEGORY_QR_FAMILY from gui.dialog import (ErrorDialog, RunDatabaseRepair, WarningDialog, MessageHideDialog) -from gen.utils.db import get_birth_or_fallback, get_death_or_fallback +from gen.utils.db import (get_birth_or_fallback, get_death_or_fallback, + get_marriage_or_fallback, preset_name, family_name) from gui.selectors import SelectorFactory from gen.utils.id import create_id -from gen.utils.name import preset_name, family_name SelectPerson = SelectorFactory('Person') diff --git a/src/gui/editors/filtereditor.py b/src/gui/editors/filtereditor.py index 52a1c083e..29ab0f1ab 100644 --- a/src/gui/editors/filtereditor.py +++ b/src/gui/editors/filtereditor.py @@ -68,7 +68,7 @@ from gen.filters import rules from gui.autocomp import StandardCustomSelector, fill_entry from gui.selectors import SelectorFactory from gen.display.name import displayer as _nd -from gen.utils.name import family_name +from gen.utils.db import family_name from gen.utils.string import confidence #------------------------------------------------------------------------- diff --git a/src/gui/views/treemodels/citationtreemodel.py b/src/gui/views/treemodels/citationtreemodel.py index c8c28a4ba..c89da4c2e 100644 --- a/src/gui/views/treemodels/citationtreemodel.py +++ b/src/gui/views/treemodels/citationtreemodel.py @@ -52,7 +52,7 @@ import gtk # GRAMPS modules # #------------------------------------------------------------------------- -from gen.utils.referent import get_source_referents +from gen.utils.db import get_source_referents from gui.views.treemodels.treebasemodel import TreeBaseModel from gui.views.treemodels.citationbasemodel import CitationBaseModel diff --git a/src/gui/views/treemodels/familymodel.py b/src/gui/views/treemodels/familymodel.py index 0b239746e..496e0cfc1 100644 --- a/src/gui/views/treemodels/familymodel.py +++ b/src/gui/views/treemodels/familymodel.py @@ -43,9 +43,9 @@ import gtk #------------------------------------------------------------------------- import gen.datehandler from gen.display.name import displayer as name_displayer -import gen.lib -from gen.lib import EventRoleType +from gen.lib import EventRoleType, FamilyRelType from gui.views.treemodels.flatbasemodel import FlatBaseModel +from gen.utils.db import get_marriage_or_fallback from gen.config import config invalid_date_format = config.get('preferences.invalid-date-format') @@ -140,10 +140,9 @@ class FamilyModel(FlatBaseModel): return u"" def column_type(self, data): - return unicode(gen.lib.FamilyRelType(data[5])) + return unicode(FamilyRelType(data[5])) def column_marriage(self, data): - from gen.utils.db import get_marriage_or_fallback family = self.db.get_family_from_handle(data[0]) event = get_marriage_or_fallback(self.db, family, "%s") if event: @@ -157,7 +156,6 @@ class FamilyModel(FlatBaseModel): return u'' def sort_marriage(self, data): - from gen.utils.db import get_marriage_or_fallback family = self.db.get_family_from_handle(data[0]) event = get_marriage_or_fallback(self.db, family) if event: diff --git a/src/plugins/export/exportvcalendar.py b/src/plugins/export/exportvcalendar.py index 5cc5a4c3f..ed4fcc8c6 100644 --- a/src/plugins/export/exportvcalendar.py +++ b/src/plugins/export/exportvcalendar.py @@ -48,7 +48,7 @@ log = logging.getLogger(".ExportVCal") # #------------------------------------------------------------------------- from gui.plug.export import WriterOptionBox -from gen.utils.name import family_name +from gen.utils.db import family_name from gen.lib import Date, EventType from gui.glade import Glade diff --git a/src/plugins/gramplet/fanchartgramplet.py b/src/plugins/gramplet/fanchartgramplet.py index 7eb2cf23b..fd1d878b0 100644 --- a/src/plugins/gramplet/fanchartgramplet.py +++ b/src/plugins/gramplet/fanchartgramplet.py @@ -55,7 +55,7 @@ if gtk.pygtk_version < (2,3,93): from gen.display.name import displayer as name_displayer from gen.ggettext import gettext as _ from gen.plug import Gramplet -from gen.utils.tree import (find_children, find_parents, find_witnessed_people) +from gen.utils.db import (find_children, find_parents, find_witnessed_people) from libformatting import FormattingHelper import gen.lib from gen.errors import WindowActiveError diff --git a/src/plugins/gramplet/sessionloggramplet.py b/src/plugins/gramplet/sessionloggramplet.py index 3903b1d65..8834905ec 100644 --- a/src/plugins/gramplet/sessionloggramplet.py +++ b/src/plugins/gramplet/sessionloggramplet.py @@ -30,7 +30,7 @@ from gen.db import PERSON_KEY, FAMILY_KEY, TXNDEL from gen.plug import Gramplet from gen.ggettext import sgettext as _ from gen.display.name import displayer as name_displayer -from gen.utils.name import family_name +from gen.utils.db import family_name #------------------------------------------------------------------------ # diff --git a/src/plugins/import/importxml.py b/src/plugins/import/importxml.py index 6ac6625af..59d659f92 100644 --- a/src/plugins/import/importxml.py +++ b/src/plugins/import/importxml.py @@ -49,7 +49,7 @@ from gen.db import DbTxn from gen.db.write import CLASS_TO_KEY_MAP from gen.errors import GrampsImportError from gen.utils.id import create_id -from gen.utils.name import family_name +from gen.utils.db import family_name from gen.utils.unknown import make_unknown, create_explanation_note import gen.datehandler from gen.display.name import displayer as name_displayer diff --git a/src/plugins/tool/check.py b/src/plugins/tool/check.py index 1861f2f74..39d76c6f2 100644 --- a/src/plugins/tool/check.py +++ b/src/plugins/tool/check.py @@ -66,7 +66,7 @@ import gen.lib from gen.db import DbTxn from gen.config import config from gen.utils.id import create_id -from gen.utils.name import family_name +from gen.utils.db import family_name from gen.utils.unknown import make_unknown from gen.utils.file import (media_path_full, find_file, fix_encoding, get_unicode_path_from_file_chooser) diff --git a/src/plugins/tool/eventnames.py b/src/plugins/tool/eventnames.py index 8302b2784..a2b37f90c 100644 --- a/src/plugins/tool/eventnames.py +++ b/src/plugins/tool/eventnames.py @@ -46,7 +46,7 @@ from gen.ggettext import ngettext from gui.managedwindow import ManagedWindow import gen.lib from gen.db import DbTxn -from gen.utils.name import family_name +from gen.utils.db import family_name from gui.plug import tool from gen.display.name import displayer as name_displayer diff --git a/src/plugins/tool/verify.py b/src/plugins/tool/verify.py index d8168a1e4..13ea76b81 100644 --- a/src/plugins/tool/verify.py +++ b/src/plugins/tool/verify.py @@ -57,7 +57,7 @@ import gobject import const import gen.lib from gui.editors import EditPerson, EditFamily -from gen.utils.name import family_name +from gen.utils.db import family_name from gui.display import display_help from gui.managedwindow import ManagedWindow from gen.updatecallback import UpdateCallback diff --git a/src/plugins/view/citationlistview.py b/src/plugins/view/citationlistview.py index 82bca1e06..e091e5f74 100644 --- a/src/plugins/view/citationlistview.py +++ b/src/plugins/view/citationlistview.py @@ -49,7 +49,7 @@ from gui.views.treemodels.citationlistmodel import CitationListModel from gen.plug import CATEGORY_QR_CITATION import gen.lib from gui.views.listview import ListView -from gen.utils.referent import get_citation_referents +from gen.utils.db import get_citation_referents from gui.views.bookmarks import CitationBookmarks from gen.errors import WindowActiveError from gui.ddtargets import DdTargets diff --git a/src/plugins/view/citationtreeview.py b/src/plugins/view/citationtreeview.py index 971157894..54c9f0545 100644 --- a/src/plugins/view/citationtreeview.py +++ b/src/plugins/view/citationtreeview.py @@ -50,7 +50,7 @@ from gui.views.treemodels.citationtreemodel import CitationTreeModel from gen.plug import CATEGORY_QR_SOURCE_OR_CITATION import gen.lib from gui.views.listview import ListView -from gen.utils.referent import (get_source_and_citation_referents, +from gen.utils.db import (get_source_and_citation_referents, get_citation_referents) from gui.views.bookmarks import CitationBookmarks from gen.errors import WindowActiveError diff --git a/src/plugins/view/fanchartview.py b/src/plugins/view/fanchartview.py index c9e41ad21..ae797c013 100644 --- a/src/plugins/view/fanchartview.py +++ b/src/plugins/view/fanchartview.py @@ -54,7 +54,7 @@ if gtk.pygtk_version < (2,3,93): # #------------------------------------------------------------------------- from gen.display.name import displayer as name_displayer -from gen.utils.tree import (find_children, find_parents, find_witnessed_people) +from gen.utils.db import (find_children, find_parents, find_witnessed_people) from libformatting import FormattingHelper import gen.lib from gui.views.navigationview import NavigationView diff --git a/src/plugins/view/mediaview.py b/src/plugins/view/mediaview.py index 58b68b484..21950c296 100644 --- a/src/plugins/view/mediaview.py +++ b/src/plugins/view/mediaview.py @@ -57,7 +57,7 @@ from gen.constfunc import win from gen.config import config from gen.utils.file import (media_path, relative_path, media_path_full, fix_encoding) -from gen.utils.referent import get_media_referents +from gen.utils.db import get_media_referents from gui.views.bookmarks import MediaBookmarks import gen.mime import gen.lib diff --git a/src/plugins/view/noteview.py b/src/plugins/view/noteview.py index 6085a5723..ef5a80526 100644 --- a/src/plugins/view/noteview.py +++ b/src/plugins/view/noteview.py @@ -47,7 +47,7 @@ import gtk #------------------------------------------------------------------------- from gui.views.listview import ListView from gui.views.treemodels import NoteModel -from gen.utils.referent import get_note_referents +from gen.utils.db import get_note_referents from gen.errors import WindowActiveError from gui.views.bookmarks import NoteBookmarks from gen.config import config diff --git a/src/plugins/view/pedigreeview.py b/src/plugins/view/pedigreeview.py index a86a481b1..d69b344fc 100644 --- a/src/plugins/view/pedigreeview.py +++ b/src/plugins/view/pedigreeview.py @@ -53,7 +53,7 @@ from gui.editors import FilterEditor from gen.display.name import displayer as name_displayer from gen.utils.alive import probably_alive from gen.utils.file import media_path_full -from gen.utils.tree import find_children, find_parents, find_witnessed_people +from gen.utils.db import find_children, find_parents, find_witnessed_people from libformatting import FormattingHelper from gui.thumbnails import get_thumbnail_path from gen.errors import WindowActiveError diff --git a/src/plugins/view/persontreeview.py b/src/plugins/view/persontreeview.py index abec50e24..cf8299909 100644 --- a/src/plugins/view/persontreeview.py +++ b/src/plugins/view/persontreeview.py @@ -37,7 +37,7 @@ from gui.views.treemodels.peoplemodel import PersonTreeModel import gen.lib from gen.errors import WindowActiveError from gui.editors import EditPerson -from gen.utils.name import preset_name +from gen.utils.db import preset_name #------------------------------------------------------------------------- # diff --git a/src/plugins/view/relview.py b/src/plugins/view/relview.py index 334b0eaca..5313fb248 100644 --- a/src/plugins/view/relview.py +++ b/src/plugins/view/relview.py @@ -63,8 +63,8 @@ from gui.selectors import SelectorFactory from gen.errors import WindowActiveError from gui.views.bookmarks import PersonBookmarks import const -from gen.utils.name import preset_name -from gen.utils.db import get_birth_or_fallback, get_death_or_fallback +from gen.utils.db import (get_birth_or_fallback, get_death_or_fallback, + preset_name) from gui.listmodel import ListModel from gui.managedwindow import ManagedWindow from gui.glade import Glade diff --git a/src/plugins/view/sourceview.py b/src/plugins/view/sourceview.py index 4889fc8c5..f57827367 100644 --- a/src/plugins/view/sourceview.py +++ b/src/plugins/view/sourceview.py @@ -43,7 +43,7 @@ import gen.lib from gen.config import config from gui.views.listview import ListView from gui.views.treemodels import SourceModel -from gen.utils.referent import get_source_and_citation_referents +from gen.utils.db import get_source_and_citation_referents from gui.views.bookmarks import SourceBookmarks from gen.errors import WindowActiveError from gui.ddtargets import DdTargets diff --git a/src/plugins/webreport/narrativeweb.py b/src/plugins/webreport/narrativeweb.py index d505fffea..ca8aab759 100644 --- a/src/plugins/webreport/narrativeweb.py +++ b/src/plugins/webreport/narrativeweb.py @@ -91,7 +91,7 @@ from gen.plug.report import MenuReportOptions from gen.utils.config import get_researcher from gen.utils.string import confidence from gen.utils.file import media_path_full -from gen.utils.referent import get_source_and_citation_referents +from gen.utils.db import get_source_and_citation_referents from gen.constfunc import win from gui.thumbnails import get_thumbnail_path, run_thumbnailer from gen.utils.image import image_size, resize_to_jpeg_buffer