Use itertools ifilter and imap to simplify some operations
svn: r15480
This commit is contained in:
parent
5e632304dc
commit
2604ee39fa
@ -25,6 +25,14 @@
|
|||||||
"""
|
"""
|
||||||
Proxy class for the GRAMPS databases. Apply filter
|
Proxy class for the GRAMPS databases. Apply filter
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Python libraries
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
from itertools import imap
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# GRAMPS libraries
|
# GRAMPS libraries
|
||||||
@ -313,8 +321,7 @@ class FilterProxyDb(ProxyDbBase):
|
|||||||
"""
|
"""
|
||||||
Return an iterator over objects for Persons in the database
|
Return an iterator over objects for Persons in the database
|
||||||
"""
|
"""
|
||||||
for handle in self.plist:
|
return imap(self.get_person_from_handle, self.plist)
|
||||||
yield self.get_person_from_handle(handle)
|
|
||||||
|
|
||||||
def get_event_handles(self):
|
def get_event_handles(self):
|
||||||
"""
|
"""
|
||||||
@ -325,11 +332,17 @@ class FilterProxyDb(ProxyDbBase):
|
|||||||
|
|
||||||
def iter_event_handles(self):
|
def iter_event_handles(self):
|
||||||
"""
|
"""
|
||||||
Return an iterator over database handles, one handle for each Person in
|
Return an iterator over database handles, one handle for each Event in
|
||||||
the database.
|
the database.
|
||||||
"""
|
"""
|
||||||
return self.elist
|
return self.elist
|
||||||
|
|
||||||
|
def iter_events(self):
|
||||||
|
"""
|
||||||
|
Return an iterator over objects for Events in the database
|
||||||
|
"""
|
||||||
|
return imap(self.get_event_from_handle, self.elist)
|
||||||
|
|
||||||
def get_family_handles(self):
|
def get_family_handles(self):
|
||||||
"""
|
"""
|
||||||
Return a list of database handles, one handle for each Family in
|
Return a list of database handles, one handle for each Family in
|
||||||
@ -339,11 +352,17 @@ class FilterProxyDb(ProxyDbBase):
|
|||||||
|
|
||||||
def iter_family_handles(self):
|
def iter_family_handles(self):
|
||||||
"""
|
"""
|
||||||
Return an iterator over database handles, one handle for each Person in
|
Return an iterator over database handles, one handle for each Family in
|
||||||
the database.
|
the database.
|
||||||
"""
|
"""
|
||||||
return self.flist
|
return self.flist
|
||||||
|
|
||||||
|
def iter_families(self):
|
||||||
|
"""
|
||||||
|
Return an iterator over objects for Families in the database
|
||||||
|
"""
|
||||||
|
return imap(self.get_family_from_handle, self.flist)
|
||||||
|
|
||||||
def get_note_handles(self):
|
def get_note_handles(self):
|
||||||
"""
|
"""
|
||||||
Return a list of database handles, one handle for each Note in
|
Return a list of database handles, one handle for each Note in
|
||||||
@ -353,11 +372,17 @@ class FilterProxyDb(ProxyDbBase):
|
|||||||
|
|
||||||
def iter_note_handles(self):
|
def iter_note_handles(self):
|
||||||
"""
|
"""
|
||||||
Return an iterator over database handles, one handle for each Person in
|
Return an iterator over database handles, one handle for each Note in
|
||||||
the database.
|
the database.
|
||||||
"""
|
"""
|
||||||
return self.nlist
|
return self.nlist
|
||||||
|
|
||||||
|
def iter_notes(self):
|
||||||
|
"""
|
||||||
|
Return an iterator over objects for Notes in the database
|
||||||
|
"""
|
||||||
|
return imap(self.get_note_from_handle, self.nlist)
|
||||||
|
|
||||||
def get_default_person(self):
|
def get_default_person(self):
|
||||||
"""returns the default Person of the database"""
|
"""returns the default Person of the database"""
|
||||||
person = self.db.get_default_person()
|
person = self.db.get_default_person()
|
||||||
|
@ -29,6 +29,7 @@ Proxy class for the GRAMPS databases. Filter out all living people.
|
|||||||
# Python libraries
|
# Python libraries
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
from itertools import ifilter
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -110,13 +111,12 @@ class LivingProxyDb(ProxyDbBase):
|
|||||||
"""
|
"""
|
||||||
Protected version of iter_people
|
Protected version of iter_people
|
||||||
"""
|
"""
|
||||||
for person in self.db.iter_people():
|
for person in ifilter(None, self.db.iter_people()):
|
||||||
if person and self.__is_living(person):
|
if not(self.__is_living(person) and
|
||||||
if self.mode == self.MODE_EXCLUDE_ALL:
|
self.mode == self.MODE_EXCLUDE_ALL):
|
||||||
person = None
|
|
||||||
|
yield self.__restrict_person(person)
|
||||||
else:
|
else:
|
||||||
person = self.__restrict_person(person)
|
|
||||||
if person:
|
|
||||||
yield person
|
yield person
|
||||||
|
|
||||||
def get_person_from_gramps_id(self, val):
|
def get_person_from_gramps_id(self, val):
|
||||||
|
Loading…
Reference in New Issue
Block a user