Implement performance-enhanced proxy databases

svn: r13140
This commit is contained in:
Gerald Britton 2009-08-31 18:43:05 +00:00
parent 1587cb8ad1
commit 03ee012325
5 changed files with 327 additions and 462 deletions

View File

@ -50,28 +50,36 @@ class FilterProxyDb(ProxyDbBase):
self.person_filter = person_filter self.person_filter = person_filter
if 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())) self.db, self.db.iter_person_handles()))
else: 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: 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())) self.db, self.db.iter_event_handles()))
else: 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: 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())) self.db, self.db.iter_note_handles()))
else: 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): for handle in list(self.plist):
person = self.db.get_person_from_handle(handle) person = self.db.get_person_from_handle(handle)
for family_handle in person.get_family_handle_list(): for handle in person.get_family_handle_list():
self.flist.add(family_handle) self.flist[handle] = 1
def get_person_from_handle(self, handle): def get_person_from_handle(self, handle):
""" """
@ -113,6 +121,18 @@ class FilterProxyDb(ProxyDbBase):
else: else:
return None 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): def get_source_from_handle(self, handle):
""" """
Finds a Source in the database from the passed gramps' ID. 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 # FIXME: plist is not a sorted list of handles
return self.plist 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): def get_event_handles(self):
""" """
Return a list of database handles, one handle for each Event in Return a list of database handles, one handle for each Event in
@ -359,35 +386,11 @@ class FilterProxyDb(ProxyDbBase):
""" """
return handle in self.elist 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): def has_family_handle(self, handle):
""" """
returns True if the handle exists in the current Family database. returns True if the handle exists in the current Family database.
""" """
return self.db.has_family_handle(handle) return handle in self.flist
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): def has_note_handle(self, handle):
""" """

View File

@ -97,34 +97,6 @@ class LivingProxyDb(ProxyDbBase):
person = self.__restrict_person(person) person = self.__restrict_person(person)
return 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): def get_family_from_handle(self, handle):
""" """
Finds a Family in the database from the passed 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) family = self.__remove_living_from_family(family)
return 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): def get_person_from_gramps_id(self, val):
""" """
Finds a Person in the database from the passed GRAMPS ID. 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) family = self.__remove_living_from_family(family)
return family return family
def get_event_from_gramps_id(self, val): def include_person(self, handle):
"""
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):
if self.mode == self.MODE_EXCLUDE_ALL: if self.mode == self.MODE_EXCLUDE_ALL:
person = self.db.get_person_from_handle(handle) person = self.get_unfiltered_person(handle)
if self.__is_living(person): if person and self.__is_living(person):
return False return False
return True return True
@ -240,48 +156,6 @@ class LivingProxyDb(ProxyDbBase):
return True return True
return False 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): def find_backlink_handles(self, handle, include_classes=None):
""" """
Find all objects that hold a reference to the object handle. Find all objects that hold a reference to the object handle.

View File

@ -215,61 +215,61 @@ class PrivateProxyDb(ProxyDbBase):
# Define predicate functions for use by default iterator methods # 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 Predicate returning True if object is to be included, else False
""" """
obj = self.db.get_person_from_handle(handle) obj = self.get_unfiltered_person(handle)
return not obj.get_privacy() 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 Predicate returning True if object is to be included, else False
""" """
obj = self.db.get_family_from_handle(handle) obj = self.get_unfiltered_family(handle)
return not obj.get_privacy() 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 Predicate returning True if object is to be included, else False
""" """
obj = self.db.get_event_from_handle(handle) obj = self.get_unfiltered_event(handle)
return not obj.get_privacy() 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 Predicate returning True if object is to be included, else False
""" """
obj = self.db.get_source_from_handle(handle) obj = self.get_unfiltered_source(handle)
return not obj.get_privacy() 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 Predicate returning True if object is to be included, else False
""" """
obj = self.db.get_place_from_handle(handle) obj = self.get_unfiltered_place(handle)
return not obj.get_privacy() 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 Predicate returning True if object is to be included, else False
""" """
obj = self.db.get_object_from_handle(handle) obj = self.get_unfiltered_repository(handle)
return not obj.get_privacy() 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 Predicate returning True if object is to be included, else False
""" """
obj = self.db.get_repository_from_handle(handle) obj = self.get_unfiltered_note(handle)
return not obj.get_privacy() return obj and 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()
def get_default_person(self): def get_default_person(self):
"""returns the default Person of the database""" """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. returns True if the handle exists in the current Person database.
""" """
has_person = False person = self.db.get_person_from_handle(handle)
person = self.db.get_person_from_handle()
if person and not person.get_privacy(): if person and not person.get_privacy():
has_person = True return True
return has_person return False
def has_event_handle(self, handle): def has_event_handle(self, handle):
""" """
returns True if the handle exists in the current Event database. returns True if the handle exists in the current Event database.
""" """
has_event = False event = self.db.get_event_from_handle(handle)
event = self.db.get_event_from_handle()
if event and not event.get_privacy(): if event and not event.get_privacy():
has_event = True return True
return has_event return False
def has_source_handle(self, handle): def has_source_handle(self, handle):
""" """
returns True if the handle exists in the current Source database. returns True if the handle exists in the current Source database.
""" """
has_source = False source = self.db.get_source_from_handle(handle)
source = self.db.get_source_from_handle()
if source and not source.get_privacy(): if source and not source.get_privacy():
has_source = True return True
return has_source return False
def has_place_handle(self, handle): def has_place_handle(self, handle):
""" """
returns True if the handle exists in the current Place database. returns True if the handle exists in the current Place database.
""" """
has_place = False place = self.db.get_place_from_handle(handle)
place = self.db.get_place_from_handle()
if place and not place.get_privacy(): if place and not place.get_privacy():
has_place = True return True
return has_place return False
def has_family_handle(self, handle): def has_family_handle(self, handle):
""" """
Return True if the handle exists in the current Family database. Return True if the handle exists in the current Family database.
""" """
has_family = False family = self.db.get_family_from_handle(handle)
family = self.db.get_family_from_handle()
if family and not family.get_privacy(): if family and not family.get_privacy():
has_family = True return True
return has_family return False
def has_object_handle(self, handle): def has_object_handle(self, handle):
""" """
Return True if the handle exists in the current MediaObjectdatabase. Return True if the handle exists in the current MediaObjectdatabase.
""" """
has_object = False object = self.db.get_object_from_handle(handle)
object = self.db.get_object_from_handle()
if object and not object.get_privacy(): if object and not object.get_privacy():
has_object = True return True
return has_object return False
def has_repository_handle(self, handle): def has_repository_handle(self, handle):
""" """
Return True if the handle exists in the current Repository database. Return True if the handle exists in the current Repository database.
""" """
has_repository = False repository = self.db.get_repository_from_handle(handle)
repository = self.db.get_repository_from_handle()
if repository and not repository.get_privacy(): if repository and not repository.get_privacy():
has_repository = True return True
return has_repository return False
def has_note_handle(self, handle): def has_note_handle(self, handle):
""" """
Return True if the handle exists in the current Note database. Return True if the handle exists in the current Note database.
""" """
has_note = False note = self.db.get_note_from_handle(handle)
note = self.db.get_note_from_handle()
if note and not note.get_privacy(): if note and not note.get_privacy():
has_note = True return True
return has_note return False
def find_backlink_handles(self, handle, include_classes=None): def find_backlink_handles(self, handle, include_classes=None):
""" """
@ -413,7 +405,7 @@ class PrivateProxyDb(ProxyDbBase):
else: else:
raise NotImplementedError raise NotImplementedError
if not obj.get_privacy(): if obj and not obj.get_privacy():
yield (class_name, handle) yield (class_name, handle)
return return

View File

@ -36,9 +36,9 @@ from itertools import ifilter
# GRAMPS libraries # 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. 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 This class attempts to implement functions that are likely to be common
@ -53,7 +53,9 @@ class ProxyDbBase(DbBase):
""" """
Create a new PrivateProxyDb instance. 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.name_formats = db.name_formats
self.bookmarks = db.bookmarks self.bookmarks = db.bookmarks
self.family_bookmarks = db.family_bookmarks self.family_bookmarks = db.family_bookmarks
@ -75,22 +77,25 @@ class ProxyDbBase(DbBase):
the owner of the database""" the owner of the database"""
return self.db.get_researcher() 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 # Define default predicates for each object type
person_predicate = \ include_person = \
family_predicate = \ include_family = \
event_predicate = \ include_event = \
source_predicate = \ include_source = \
place_predicate = \ include_place = \
object_predicate = \ include_object = \
repository_predicate = \ include_repository = \
note_predicate = \ include_note = \
None None
def get_person_handles(self, sort_handles=True): def get_person_handles(self, sort_handles=True):
@ -172,62 +177,230 @@ class ProxyDbBase(DbBase):
return list(self.iter_note_handles()) return list(self.iter_note_handles())
else: else:
return [] 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): def iter_person_handles(self):
""" """
Return an iterator over database handles, one handle for each Person in Return an iterator over database handles, one handle for each Person in
the database. 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): def iter_family_handles(self):
""" """
Return an iterator over database handles, one handle for each Family in Return an iterator over database handles, one handle for each Family in
the database. 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): def iter_event_handles(self):
""" """
Return an iterator over database handles, one handle for each Event in Return an iterator over database handles, one handle for each Event in
the database. 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): def iter_source_handles(self):
""" """
Return an iterator over database handles, one handle for each Source in Return an iterator over database handles, one handle for each Source in
the database. 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): def iter_place_handles(self):
""" """
Return an iterator over database handles, one handle for each Place in Return an iterator over database handles, one handle for each Place in
the database. 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): def iter_media_object_handles(self):
""" """
Return an iterator over database handles, one handle for each Media Return an iterator over database handles, one handle for each Media
Object in the database. 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): def iter_repository_handles(self):
""" """
Return an iterator over database handles, one handle for each Return an iterator over database handles, one handle for each
Repository in the database. 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): def iter_note_handles(self):
""" """
Return an iterator over database handles, one handle for each Note in Return an iterator over database handles, one handle for each Note in
the database. 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): def get_name_group_mapping(self, name):
""" """
@ -394,52 +567,60 @@ class ProxyDbBase(DbBase):
def has_person_handle(self, handle): 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): def has_event_handle(self, handle):
""" """
returns True if the handle exists in the current Event database. 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): def has_source_handle(self, handle):
""" """
returns True if the handle exists in the current Source database. 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): def has_place_handle(self, handle):
""" """
returns True if the handle exists in the current Place database. returns True if the handle exists in the current Place database.
""" """
raise NotImplementedError return self.gfilter(self.include_place,
self.db.get_place_from_gramps_id(val)) is not None
def has_family_handle(self, handle):
"""
returns True if the handle exists in the current Family database.
"""
raise NotImplementedError
def has_object_handle(self, handle): def has_object_handle(self, handle):
""" """
returns True if the handle exists in the current MediaObjectdatabase. 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): def has_repository_handle(self, handle):
""" """
returns True if the handle exists in the current Repository database. 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): def has_note_handle(self, handle):
""" """
returns True if the handle exists in the current Note database. 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): def get_mediapath(self):
"""returns the default media path of the database""" """returns the default media path of the database"""
return self.db.get_mediapath() return self.db.get_mediapath()

View File

@ -43,220 +43,52 @@ class ReferencedProxyDb(ProxyDbBase):
Create a new ReferencedProxyDb instance. Create a new ReferencedProxyDb instance.
""" """
ProxyDbBase.__init__(self, dbase) ProxyDbBase.__init__(self, dbase)
self.unreferenced_events = [] self.unreferenced_events = {}
self.unreferenced_places = [] self.unreferenced_places = {}
self.unreferenced_sources = [] self.unreferenced_sources = {}
self.unreferenced_repositories = [] self.unreferenced_repositories = {}
self.unreferenced_media_objects = [] self.unreferenced_media_objects = {}
self.unreferenced_notes = [] self.unreferenced_notes = {}
# Build lists of unreferenced objects # Build lists of unreferenced objects
self.__find_unreferenced_objects() self.__find_unreferenced_objects()
def get_person_from_handle(self, handle): def include_place(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):
""" """
Filter for places Filter for places
""" """
return handle not in self.unreferenced_places return handle not in self.unreferenced_places
def object_predicate(self, handle): def include_object(self, handle):
""" """
Filter for media objects Filter for media objects
""" """
return handle not in self.unreferenced_media_objects return handle not in self.unreferenced_media_objects
def event_predicate(self, handle): def include_event(self, handle):
""" """
Filter for events Filter for events
""" """
return handle not in self.unreferenced_events return handle not in self.unreferenced_events
def source_predicate(self, handle): def include_source(self, handle):
""" """
Filter for sources Filter for sources
""" """
return handle not in self.unreferenced_sources return handle not in self.unreferenced_sources
def repository_predicate(self, handle): def include_repository(self, handle):
""" """
Filter for repositories Filter for repositories
""" """
return handle not in self.unreferenced_repositories return handle not in self.unreferenced_repositories
def note_predicate(self, handle): def include_note(self, handle):
""" """
Filter for notes Filter for notes
""" """
return handle not in self.unreferenced_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): def find_backlink_handles(self, handle, include_classes=None):
""" """
Find all objects that hold a reference to the object handle. 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) handle_itr = self.db.find_backlink_handles(handle, include_classes)
for (class_name, handle) in handle_itr: for (class_name, handle) in handle_itr:
if class_name == 'Person': if class_name == 'Person':
if not self.get_person_from_handle(handle): if not self.get_person_from_handle(handle):
continue continue
elif class_name == 'Family': elif class_name == 'Family':
if not self.get_family_from_handle(handle): if not self.get_family_from_handle(handle):
continue 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) yield (class_name, handle)
return return
@ -339,8 +153,9 @@ class ReferencedProxyDb(ProxyDbBase):
unref_list = object_dict['unref_list'] unref_list = object_dict['unref_list']
handle_list = object_dict['handle_list']() handle_list = object_dict['handle_list']()
for handle in handle_list: for handle in handle_list:
if not any(self.find_backlink_handles(handle)): if (handle not in unref_list and
unref_list.append(handle) not any(self.find_backlink_handles(handle)) ):
unref_list[handle] = True
current_count += len(unref_list) current_count += len(unref_list)
if current_count == last_count: if current_count == last_count: