diff --git a/src/gen/proxy/filter.py b/src/gen/proxy/filter.py index 0fa206911..85e742f7f 100644 --- a/src/gen/proxy/filter.py +++ b/src/gen/proxy/filter.py @@ -50,28 +50,36 @@ class FilterProxyDb(ProxyDbBase): self.person_filter = person_filter if person_filter: - self.plist = set(person_filter.apply( + #self.plist = set(person_filter.apply( + # self.db, self.db.iter_person_handles())) + self.plist = dict((h, 1) for h in person_filter.apply( self.db, self.db.iter_person_handles())) else: - self.plist = self.db.get_person_handles() + #self.plist = self.db.get_person_handles() + self.plist = dict((h, 1) for h in self.db.iter_person_handles()) if event_filter: - self.elist = set(event_filter.apply( + #self.elist = set(event_filter.apply( + # self.db, self.db.iter_event_handles())) + self.elist = dict((h, 1) for h in event_filter.apply( self.db, self.db.iter_event_handles())) else: - self.elist = self.db.get_event_handles() + #self.elist = self.db.get_event_handles() + self.elist = dict((h, 1) for h in self.db.iter_event_handles()) if note_filter: - self.nlist = set(note_filter.apply( + #self.nlist = set(note_filter.apply( + # self.db, self.db.iter_note_handles())) + self.nlist = dict((h, 1) for h in note_filter.apply( self.db, self.db.iter_note_handles())) else: - self.nlist = self.db.get_note_handles() + self.nlist = dict((h, 1) for h in self.db.iter_note_handles()) - self.flist = set() + self.flist = {} for handle in list(self.plist): person = self.db.get_person_from_handle(handle) - for family_handle in person.get_family_handle_list(): - self.flist.add(family_handle) + for handle in person.get_family_handle_list(): + self.flist[handle] = 1 def get_person_from_handle(self, handle): """ @@ -113,6 +121,18 @@ class FilterProxyDb(ProxyDbBase): else: return None + def include_person(self, handle): + return handle in self.plist + + def include_family(self, handle): + return handle in self.flist + + def include_event(self, handle): + return handle in self.elist + + def include_note(self, handle): + return handle in self.nlist + def get_source_from_handle(self, handle): """ Finds a Source in the database from the passed gramps' ID. @@ -289,6 +309,13 @@ class FilterProxyDb(ProxyDbBase): # FIXME: plist is not a sorted list of handles return self.plist + def iter_people(self): + """ + Return an iterator over handles and objects for Persons in the database + """ + for handle in self.plist: + yield handle, self.get_person_from_handle(handle) + def get_event_handles(self): """ Return a list of database handles, one handle for each Event in @@ -359,35 +386,11 @@ class FilterProxyDb(ProxyDbBase): """ return handle in self.elist - def has_source_handle(self, handle): - """ - returns True if the handle exists in the current Source database. - """ - return self.db.has_source_handle(handle) - - def has_place_handle(self, handle): - """ - returns True if the handle exists in the current Place database. - """ - return self.db.has_place_handle(handle) - def has_family_handle(self, handle): """ returns True if the handle exists in the current Family database. """ - return self.db.has_family_handle(handle) - - def has_object_handle(self, handle): - """ - returns True if the handle exists in the current MediaObjectdatabase. - """ - return self.db.has_object_handle(handle) - - def has_repository_handle(self, handle): - """ - returns True if the handle exists in the current Repository database. - """ - return self.db.has_repository_handle(handle) + return handle in self.flist def has_note_handle(self, handle): """ diff --git a/src/gen/proxy/living.py b/src/gen/proxy/living.py index 4f6a77f44..82978a304 100644 --- a/src/gen/proxy/living.py +++ b/src/gen/proxy/living.py @@ -97,34 +97,6 @@ class LivingProxyDb(ProxyDbBase): person = self.__restrict_person(person) return person - def get_source_from_handle(self, handle): - """ - Finds a Source in the database from the passed gramps ID. - If no such Source exists, None is returned. - """ - return self.db.get_source_from_handle(handle) - - def get_object_from_handle(self, handle): - """ - Finds an Object in the database from the passed gramps ID. - If no such Object exists, None is returned. - """ - return self.db.get_object_from_handle(handle) - - def get_place_from_handle(self, handle): - """ - Finds a Place in the database from the passed gramps ID. - If no such Place exists, None is returned. - """ - return self.db.get_place_from_handle(handle) - - def get_event_from_handle(self, handle): - """ - Finds a Event in the database from the passed gramps ID. - If no such Event exists, None is returned. - """ - return self.db.get_event_from_handle(handle) - def get_family_from_handle(self, handle): """ Finds a Family in the database from the passed handle. @@ -134,20 +106,6 @@ class LivingProxyDb(ProxyDbBase): family = self.__remove_living_from_family(family) return family - def get_repository_from_handle(self, handle): - """ - Finds a Repository in the database from the passed gramps' ID. - If no such Repository exists, None is returned. - """ - return self.db.get_repository_from_handle(handle) - - def get_note_from_handle(self, handle): - """ - Finds a Note in the database from the passed gramps' ID. - If no such Note exists, None is returned. - """ - return self.db.get_note_from_handle(handle) - def get_person_from_gramps_id(self, val): """ Finds a Person in the database from the passed GRAMPS ID. @@ -171,52 +129,10 @@ class LivingProxyDb(ProxyDbBase): family = self.__remove_living_from_family(family) return family - def get_event_from_gramps_id(self, val): - """ - Finds an Event in the database from the passed GRAMPS ID. - If no such Event exists, None is returned. - """ - return self.db.get_event_from_gramps_id(val) - - def get_place_from_gramps_id(self, val): - """ - Finds a Place in the database from the passed gramps' ID. - If no such Place exists, None is returned. - """ - return self.db.get_place_from_gramps_id(val) - - def get_source_from_gramps_id(self, val): - """ - Finds a Source in the database from the passed gramps' ID. - If no such Source exists, None is returned. - """ - return self.db.get_source_from_gramps_id(val) - - def get_object_from_gramps_id(self, val): - """ - Finds a MediaObject in the database from the passed gramps' ID. - If no such MediaObject exists, None is returned. - """ - return self.db.get_object_from_gramps_id(val) - - def get_repository_from_gramps_id(self, val): - """ - Finds a Repository in the database from the passed gramps' ID. - If no such Repository exists, None is returned. - """ - return self.db.get_repository_from_gramps_id(val) - - def get_note_from_gramps_id(self, val): - """ - Finds a Note in the database from the passed gramps' ID. - If no such Note exists, None is returned. - """ - return self.db.get_note_from_gramps_id(val) - - def person_predicate(self, handle): + def include_person(self, handle): if self.mode == self.MODE_EXCLUDE_ALL: - person = self.db.get_person_from_handle(handle) - if self.__is_living(person): + person = self.get_unfiltered_person(handle) + if person and self.__is_living(person): return False return True @@ -240,48 +156,6 @@ class LivingProxyDb(ProxyDbBase): return True return False - def has_event_handle(self, handle): - """ - returns True if the handle exists in the current Event database. - """ - return self.db.has_event_handle(handle) - - def has_source_handle(self, handle): - """ - returns True if the handle exists in the current Source database. - """ - return self.db.has_source_handle(handle) - - def has_place_handle(self, handle): - """ - returns True if the handle exists in the current Place database. - """ - return self.db.has_place_handle(handle) - - def has_family_handle(self, handle): - """ - returns True if the handle exists in the current Family database. - """ - return self.db.has_family_handle(handle) - - def has_object_handle(self, handle): - """ - returns True if the handle exists in the current MediaObjectdatabase. - """ - return self.db.has_object_handle(handle) - - def has_repository_handle(self, handle): - """ - returns True if the handle exists in the current Repository database. - """ - return self.db.has_repository_handle(handle) - - def has_note_handle(self, handle): - """ - returns True if the handle exists in the current Note database. - """ - return self.db.has_note_handle(handle) - def find_backlink_handles(self, handle, include_classes=None): """ Find all objects that hold a reference to the object handle. diff --git a/src/gen/proxy/private.py b/src/gen/proxy/private.py index d61cdef70..0d888082d 100644 --- a/src/gen/proxy/private.py +++ b/src/gen/proxy/private.py @@ -215,61 +215,61 @@ class PrivateProxyDb(ProxyDbBase): # Define predicate functions for use by default iterator methods - def person_predicate(self, handle): + def include_person(self, handle): """ Predicate returning True if object is to be included, else False """ - obj = self.db.get_person_from_handle(handle) - return not obj.get_privacy() + obj = self.get_unfiltered_person(handle) + return obj and not obj.get_privacy() - def family_predicate(self, handle): + def include_family(self, handle): """ Predicate returning True if object is to be included, else False """ - obj = self.db.get_family_from_handle(handle) - return not obj.get_privacy() + obj = self.get_unfiltered_family(handle) + return obj and not obj.get_privacy() - def event_predicate(self, handle): + def include_event(self, handle): """ Predicate returning True if object is to be included, else False """ - obj = self.db.get_event_from_handle(handle) - return not obj.get_privacy() + obj = self.get_unfiltered_event(handle) + return obj and not obj.get_privacy() - def source_predicate(self, handle): + def include_source(self, handle): """ Predicate returning True if object is to be included, else False """ - obj = self.db.get_source_from_handle(handle) - return not obj.get_privacy() + obj = self.get_unfiltered_source(handle) + return obj and not obj.get_privacy() - def place_predicate(self, handle): + def include_place(self, handle): """ Predicate returning True if object is to be included, else False """ - obj = self.db.get_place_from_handle(handle) - return not obj.get_privacy() + obj = self.get_unfiltered_place(handle) + return obj and not obj.get_privacy() - def object_predicate(self, handle): + def include_object(self, handle): + """ + Predicate returning True if object is to be included, else False + """ + obj = self.get_unfiltered_object(handle) + return obj and not obj.get_privacy() + + def include_repository(self, handle): """ Predicate returning True if object is to be included, else False """ - obj = self.db.get_object_from_handle(handle) - return not obj.get_privacy() + obj = self.get_unfiltered_repository(handle) + return obj and not obj.get_privacy() - def repository_predicate(self, handle): + def include_note(self, handle): """ Predicate returning True if object is to be included, else False """ - obj = self.db.get_repository_from_handle(handle) - return not obj.get_privacy() - - def note_predicate(self, handle): - """ - Predicate returning True if object is to be included, else False - """ - obj = self.db.get_note_from_handle(handle) - return not obj.get_privacy() + obj = self.get_unfiltered_note(handle) + return obj and not obj.get_privacy() def get_default_person(self): """returns the default Person of the database""" @@ -290,81 +290,73 @@ class PrivateProxyDb(ProxyDbBase): """ returns True if the handle exists in the current Person database. """ - has_person = False - person = self.db.get_person_from_handle() + person = self.db.get_person_from_handle(handle) if person and not person.get_privacy(): - has_person = True - return has_person + return True + return False def has_event_handle(self, handle): """ returns True if the handle exists in the current Event database. """ - has_event = False - event = self.db.get_event_from_handle() + event = self.db.get_event_from_handle(handle) if event and not event.get_privacy(): - has_event = True - return has_event + return True + return False def has_source_handle(self, handle): """ returns True if the handle exists in the current Source database. """ - has_source = False - source = self.db.get_source_from_handle() + source = self.db.get_source_from_handle(handle) if source and not source.get_privacy(): - has_source = True - return has_source + return True + return False def has_place_handle(self, handle): """ returns True if the handle exists in the current Place database. """ - has_place = False - place = self.db.get_place_from_handle() + place = self.db.get_place_from_handle(handle) if place and not place.get_privacy(): - has_place = True - return has_place + return True + return False def has_family_handle(self, handle): """ Return True if the handle exists in the current Family database. """ - has_family = False - family = self.db.get_family_from_handle() + family = self.db.get_family_from_handle(handle) if family and not family.get_privacy(): - has_family = True - return has_family + return True + return False def has_object_handle(self, handle): """ Return True if the handle exists in the current MediaObjectdatabase. """ - has_object = False - object = self.db.get_object_from_handle() + object = self.db.get_object_from_handle(handle) if object and not object.get_privacy(): - has_object = True - return has_object + return True + return False def has_repository_handle(self, handle): """ Return True if the handle exists in the current Repository database. """ - has_repository = False - repository = self.db.get_repository_from_handle() + repository = self.db.get_repository_from_handle(handle) if repository and not repository.get_privacy(): - has_repository = True - return has_repository + return True + return False def has_note_handle(self, handle): """ Return True if the handle exists in the current Note database. """ - has_note = False - note = self.db.get_note_from_handle() + note = self.db.get_note_from_handle(handle) if note and not note.get_privacy(): - has_note = True - return has_note + return True + return False def find_backlink_handles(self, handle, include_classes=None): """ @@ -413,7 +405,7 @@ class PrivateProxyDb(ProxyDbBase): else: raise NotImplementedError - if not obj.get_privacy(): + if obj and not obj.get_privacy(): yield (class_name, handle) return diff --git a/src/gen/proxy/proxybase.py b/src/gen/proxy/proxybase.py index 7d10a5cc0..5c648589f 100644 --- a/src/gen/proxy/proxybase.py +++ b/src/gen/proxy/proxybase.py @@ -36,9 +36,9 @@ from itertools import ifilter # GRAMPS libraries # #------------------------------------------------------------------------- -from dbbase import DbBase +from gen.db.base import GrampsDbBase -class ProxyDbBase(DbBase): +class ProxyDbBase(GrampsDbBase): """ ProxyDbBase is a base class for building a proxy to a Gramps database. This class attempts to implement functions that are likely to be common @@ -53,7 +53,9 @@ class ProxyDbBase(DbBase): """ Create a new PrivateProxyDb instance. """ - self.db = db + self.db = self.basedb = db + while isinstance(self.basedb, ProxyDbBase): + self.basedb = self.basedb.db self.name_formats = db.name_formats self.bookmarks = db.bookmarks self.family_bookmarks = db.family_bookmarks @@ -75,22 +77,25 @@ class ProxyDbBase(DbBase): the owner of the database""" return self.db.get_researcher() - def predicate(self, handle): + def include_something(self, handle, object=None): """ - Default predicate. Returns True + Model predicate. Returns True if object referred to by handle is to be + included, otherwise returns False. """ - return True + if object is None: + object = self.get_something_from_handle(handle) + return object.include() # Define default predicates for each object type - person_predicate = \ - family_predicate = \ - event_predicate = \ - source_predicate = \ - place_predicate = \ - object_predicate = \ - repository_predicate = \ - note_predicate = \ + include_person = \ + include_family = \ + include_event = \ + include_source = \ + include_place = \ + include_object = \ + include_repository = \ + include_note = \ None def get_person_handles(self, sort_handles=True): @@ -172,62 +177,230 @@ class ProxyDbBase(DbBase): return list(self.iter_note_handles()) else: return [] + + def get_default_person(self): + """returns the default Person of the database""" + return self.db.get_default_person() + + def get_default_handle(self): + """returns the default Person of the database""" + return self.db.get_default_handle() def iter_person_handles(self): """ Return an iterator over database handles, one handle for each Person in the database. """ - return ifilter(self.person_predicate, self.db.iter_person_handles()) + return ifilter(self.include_person, self.db.iter_person_handles()) + + def iter_people(self): + """ + Return an iterator over handles and objects for Persons in the database + """ + for handle, person in self.db.iter_people(): + if (self.include_person is None or + self.include_person(handle, person)): + yield handle, person def iter_family_handles(self): """ Return an iterator over database handles, one handle for each Family in the database. """ - return ifilter(self.family_predicate, self.db.iter_family_handles()) + return ifilter(self.include_family, self.db.iter_family_handles()) def iter_event_handles(self): """ Return an iterator over database handles, one handle for each Event in the database. """ - return ifilter(self.event_predicate, self.db.iter_event_handles()) + return ifilter(self.include_event, self.db.iter_event_handles()) def iter_source_handles(self): """ Return an iterator over database handles, one handle for each Source in the database. """ - return ifilter(self.source_predicate, self.db.iter_source_handles()) + return ifilter(self.include_source, self.db.iter_source_handles()) def iter_place_handles(self): """ Return an iterator over database handles, one handle for each Place in the database. """ - return ifilter(self.place_predicate, self.db.iter_place_handles()) + return ifilter(self.include_place, self.db.iter_place_handles()) def iter_media_object_handles(self): """ Return an iterator over database handles, one handle for each Media Object in the database. """ - return ifilter(self.object_predicate, self.db.iter_media_object_handles()) + return ifilter(self.include_object, self.db.iter_media_object_handles()) def iter_repository_handles(self): """ Return an iterator over database handles, one handle for each Repository in the database. """ - return ifilter(self.repository_predicate, self.db.iter_repository_handles()) + return ifilter(self.include_repository, self.db.iter_repository_handles()) def iter_note_handles(self): """ Return an iterator over database handles, one handle for each Note in the database. """ - return ifilter(self.note_predicate, self.db.iter_note_handles()) + return ifilter(self.include_note, self.db.iter_note_handles()) + + @staticmethod + def gfilter(predicate, obj): + """ + Returns obj if predicate is True or not callable, else returns None + """ + if predicate is not None: + return obj if predicate(obj) else None + return obj + + def __getattr__(self, name): + """ Handle unknown attribute lookups """ + sname = name.split('_') + if sname[:2] == ['get', 'unfiltered']: + """ + Handle get_unfiltered calls. Return the name of the access + method for the base database object. Call setattr before + returning so that the lookup happens at most once for a given + method call and a given object. + """ + attr = getattr(self.basedb, 'get_' + sname[2] + '_from_handle') + setattr(self, name, attr) + return attr + + def get_person_from_handle(self, handle): + """ + Finds a Person in the database from the passed gramps handle. + If no such Person exists, None is returned. + """ + return self.gfilter(self.include_person, + self.db.get_person_from_handle(handle)) + + def get_family_from_handle(self, handle): + """ + Finds a Family in the database from the passed gramps handle. + If no such Family exists, None is returned. + """ + return self.gfilter(self.include_family, + self.db.get_family_from_handle(handle)) + + def get_event_from_handle(self, handle): + """ + Finds a Event in the database from the passed gramps handle. + If no such Event exists, None is returned. + """ + return self.gfilter(self.include_event, + self.db.get_event_from_handle(handle)) + + def get_source_from_handle(self, handle): + """ + Finds a Source in the database from the passed gramps handle. + If no such Source exists, None is returned. + """ + return self.gfilter(self.include_source, + self.db.get_source_from_handle(handle)) + + def get_place_from_handle(self, handle): + """ + Finds a Place in the database from the passed gramps handle. + If no such Place exists, None is returned. + """ + return self.gfilter(self.include_place, + self.db.get_place_from_handle(handle)) + + def get_object_from_handle(self, handle): + """ + Finds an Object in the database from the passed gramps handle. + If no such Object exists, None is returned. + """ + return self.gfilter(self.include_object, + self.db.get_object_from_handle(handle)) + + def get_repository_from_handle(self, handle): + """ + Finds a Repository in the database from the passed gramps handle. + If no such Repository exists, None is returned. + """ + return self.gfilter(self.include_repository, + self.db.get_repository_from_handle(handle)) + + def get_note_from_handle(self, handle): + """ + Finds a Note in the database from the passed gramps handle. + If no such Note exists, None is returned. + """ + return self.gfilter(self.include_note, + self.db.get_note_from_handle(handle)) + + def get_person_from_gramps_id(self, val): + """ + Finds a Person in the database from the passed GRAMPS ID. + If no such Person exists, None is returned. + """ + return self.gfilter(self.include_person, + self.db.get_person_from_gramps_id(val)) + + def get_family_from_gramps_id(self, val): + """ + Finds a Family in the database from the passed GRAMPS ID. + If no such Family exists, None is returned. + """ + return self.gfilter(self.include_family, + self.db.get_family_from_gramps_id(val)) + + def get_event_from_gramps_id(self, val): + """ + Finds an Event in the database from the passed GRAMPS ID. + If no such Event exists, None is returned. + """ + return self.gfilter(self.include_event, + self.db.get_event_from_gramps_id(val)) + + def get_place_from_gramps_id(self, val): + """ + Finds a Place in the database from the passed gramps' ID. + If no such Place exists, None is returned. + """ + return self.gfilter(self.include_place, + self.db.get_place_from_gramps_id(val)) + + def get_source_from_gramps_id(self, val): + """ + Finds a Source in the database from the passed gramps' ID. + If no such Source exists, None is returned. + """ + return self.gfilter(self.include_source, + self.db.get_source_from_gramps_id(val)) + + def get_object_from_gramps_id(self, val): + """ + Finds a MediaObject in the database from the passed gramps' ID. + If no such MediaObject exists, None is returned. + """ + return self.gfilter(self.include_object, + self.db.get_object_from_gramps_id(val)) + + def get_repository_from_gramps_id(self, val): + """ + Finds a Repository in the database from the passed gramps' ID. + If no such Repository exists, None is returned. + """ + return self.gfilter(self.include_repository, + self.db.get_repository_from_gramps_id(val)) + + def get_note_from_gramps_id(self, val): + """ + Finds a Note in the database from the passed gramps' ID. + If no such Note exists, None is returned. + """ + return self.gfilter(self.include_note, + self.db.get_note_from_gramps_id(val)) def get_name_group_mapping(self, name): """ @@ -394,52 +567,60 @@ class ProxyDbBase(DbBase): def has_person_handle(self, handle): """ - returns True if the handle exists in the current Person database. + Returns True if the handle exists in the current Person database. """ - raise NotImplementedError + return self.gfilter(self.include_person, + self.db.get_person_from_gramps_id(val)) is not None + + def has_family_handle(self, handle): + """ + Returns True if the handle exists in the current Family database. + """ + return self.gfilter(self.include_family, + self.db.get_family_from_gramps_id(val)) is not None def has_event_handle(self, handle): """ returns True if the handle exists in the current Event database. """ - raise NotImplementedError + return self.gfilter(self.include_event, + self.db.get_event_from_gramps_id(val)) is not None def has_source_handle(self, handle): """ returns True if the handle exists in the current Source database. """ - raise NotImplementedError + return self.gfilter(self.include_source, + self.db.get_source_from_gramps_id(val)) is not None def has_place_handle(self, handle): """ returns True if the handle exists in the current Place database. """ - raise NotImplementedError - - def has_family_handle(self, handle): - """ - returns True if the handle exists in the current Family database. - """ - raise NotImplementedError + return self.gfilter(self.include_place, + self.db.get_place_from_gramps_id(val)) is not None def has_object_handle(self, handle): """ returns True if the handle exists in the current MediaObjectdatabase. """ - raise NotImplementedError + return self.gfilter(self.include_object, + self.db.get_object_from_gramps_id(val)) is not None def has_repository_handle(self, handle): """ returns True if the handle exists in the current Repository database. """ - raise NotImplementedError + return self.gfilter(self.include_repository, + self.db.get_repository_from_gramps_id(val)) is not None def has_note_handle(self, handle): """ returns True if the handle exists in the current Note database. """ - raise NotImplementedError - + return self.gfilter(self.include_note, + self.db.get_note_from_gramps_id(val)) is not None + def get_mediapath(self): """returns the default media path of the database""" return self.db.get_mediapath() diff --git a/src/gen/proxy/referenced.py b/src/gen/proxy/referenced.py index b1a1d0bd7..c383cbdc5 100644 --- a/src/gen/proxy/referenced.py +++ b/src/gen/proxy/referenced.py @@ -43,220 +43,52 @@ class ReferencedProxyDb(ProxyDbBase): Create a new ReferencedProxyDb instance. """ ProxyDbBase.__init__(self, dbase) - self.unreferenced_events = [] - self.unreferenced_places = [] - self.unreferenced_sources = [] - self.unreferenced_repositories = [] - self.unreferenced_media_objects = [] - self.unreferenced_notes = [] + self.unreferenced_events = {} + self.unreferenced_places = {} + self.unreferenced_sources = {} + self.unreferenced_repositories = {} + self.unreferenced_media_objects = {} + self.unreferenced_notes = {} # Build lists of unreferenced objects self.__find_unreferenced_objects() - def get_person_from_handle(self, handle): - """ - Finds a Person in the database from the passed gramps' ID. - If no such Person exists, None is returned. - """ - return self.db.get_person_from_handle(handle) - - def get_source_from_handle(self, handle): - """ - Finds a Source in the database from the passed gramps' ID. - If no such Source exists, None is returned. - """ - return self.db.get_source_from_handle(handle) - - def get_object_from_handle(self, handle): - """ - Finds an Object in the database from the passed gramps' ID. - If no such Object exists, None is returned. - """ - return self.db.get_object_from_handle(handle) - - def get_place_from_handle(self, handle): - """ - Finds a Place in the database from the passed gramps' ID. - If no such Place exists, None is returned. - """ - return self.db.get_place_from_handle(handle) - - def get_event_from_handle(self, handle): - """ - Finds a Event in the database from the passed gramps' ID. - If no such Event exists, None is returned. - """ - return self.db.get_event_from_handle(handle) - - def get_family_from_handle(self, handle): - """ - Finds a Family in the database from the passed gramps' ID. - If no such Family exists, None is returned. - """ - return self.db.get_family_from_handle(handle) - - def get_repository_from_handle(self, handle): - """ - Finds a Repository in the database from the passed gramps' ID. - If no such Repository exists, None is returned. - """ - return self.db.get_repository_from_handle(handle) - - def get_note_from_handle(self, handle): - """ - Finds a Note in the database from the passed gramps' ID. - If no such Note exists, None is returned. - """ - return self.db.get_note_from_handle(handle) - - def get_person_from_gramps_id(self, val): - """ - Finds a Person in the database from the passed GRAMPS ID. - If no such Person exists, None is returned. - """ - return self.db.get_person_from_gramps_id(val) - - def get_family_from_gramps_id(self, val): - """ - Finds a Family in the database from the passed GRAMPS ID. - If no such Family exists, None is returned. - """ - return self.db.get_family_from_gramps_id(val) - - def get_event_from_gramps_id(self, val): - """ - Finds an Event in the database from the passed GRAMPS ID. - If no such Event exists, None is returned. - """ - return self.db.get_event_from_gramps_id(val) - - def get_place_from_gramps_id(self, val): - """ - Finds a Place in the database from the passed gramps' ID. - If no such Place exists, None is returned. - """ - return self.db.get_place_from_gramps_id(val) - - def get_source_from_gramps_id(self, val): - """ - Finds a Source in the database from the passed gramps' ID. - If no such Source exists, None is returned. - """ - return self.db.get_source_from_gramps_id(val) - - def get_object_from_gramps_id(self, val): - """ - Finds a MediaObject in the database from the passed gramps' ID. - If no such MediaObject exists, None is returned. - """ - return self.db.get_object_from_gramps_id(val) - - def get_repository_from_gramps_id(self, val): - """ - Finds a Repository in the database from the passed gramps' ID. - If no such Repository exists, None is returned. - """ - return self.db.get_repository_from_gramps_id(val) - - def get_note_from_gramps_id(self, val): - """ - Finds a Note in the database from the passed gramps' ID. - If no such Note exists, None is returned. - """ - return self.db.get_note_from_gramps_id(val) - - def place_predicate(self, handle): + def include_place(self, handle): """ Filter for places """ return handle not in self.unreferenced_places - def object_predicate(self, handle): + def include_object(self, handle): """ Filter for media objects """ return handle not in self.unreferenced_media_objects - def event_predicate(self, handle): + def include_event(self, handle): """ Filter for events """ return handle not in self.unreferenced_events - def source_predicate(self, handle): + def include_source(self, handle): """ Filter for sources """ return handle not in self.unreferenced_sources - def repository_predicate(self, handle): + def include_repository(self, handle): """ Filter for repositories """ return handle not in self.unreferenced_repositories - def note_predicate(self, handle): + def include_note(self, handle): """ Filter for notes """ return handle not in self.unreferenced_notes - - def get_default_person(self): - """returns the default Person of the database""" - return self.db.get_default_person() - - def get_default_handle(self): - """returns the default Person of the database""" - return self.db.get_default_handle() - def has_person_handle(self, handle): - """ - returns True if the handle exists in the current Person database. - """ - return handle in self.iter_person_handles() - - def has_event_handle(self, handle): - """ - returns True if the handle exists in the current Event database. - """ - return handle in self.get_event_handles() - - def has_source_handle(self, handle): - """ - returns True if the handle exists in the current Source database. - """ - return handle in self.get_source_handles() - - def has_place_handle(self, handle): - """ - returns True if the handle exists in the current Place database. - """ - return handle in self.get_place_handles() - - def has_family_handle(self, handle): - """ - returns True if the handle exists in the current Family database. - """ - return handle in self.iter_family_handles() - - def has_object_handle(self, handle): - """ - returns True if the handle exists in the current MediaObjectdatabase. - """ - return handle in self.get_media_object_handles() - - def has_repository_handle(self, handle): - """ - returns True if the handle exists in the current Repository database. - """ - return handle in self.get_repository_handles() - - def has_note_handle(self, handle): - """ - returns True if the handle exists in the current Note database. - """ - return handle in self.get_note_handles() - def find_backlink_handles(self, handle, include_classes=None): """ Find all objects that hold a reference to the object handle. @@ -280,30 +112,12 @@ class ReferencedProxyDb(ProxyDbBase): """ handle_itr = self.db.find_backlink_handles(handle, include_classes) for (class_name, handle) in handle_itr: - if class_name == 'Person': + if class_name == 'Person': if not self.get_person_from_handle(handle): continue elif class_name == 'Family': if not self.get_family_from_handle(handle): continue - elif class_name == 'Event': - if handle in self.unreferenced_events: - continue - elif class_name == 'Place': - if handle in self.unreferenced_places: - continue - elif class_name == 'Source': - if handle in self.unreferenced_sources: - continue - elif class_name == 'Repository': - if handle in self.unreferenced_repositories: - continue - elif class_name == 'MediaObject': - if handle in self.unreferenced_media_objects: - continue - elif class_name == 'Note': - if handle in self.unreferenced_notes: - continue yield (class_name, handle) return @@ -339,8 +153,9 @@ class ReferencedProxyDb(ProxyDbBase): unref_list = object_dict['unref_list'] handle_list = object_dict['handle_list']() for handle in handle_list: - if not any(self.find_backlink_handles(handle)): - unref_list.append(handle) + if (handle not in unref_list and + not any(self.find_backlink_handles(handle)) ): + unref_list[handle] = True current_count += len(unref_list) if current_count == last_count: