Use new iter_objects methods

svn: r13203
This commit is contained in:
Gerald Britton 2009-09-14 20:50:25 +00:00
parent 5001b771b5
commit 966d2bcd42
20 changed files with 98 additions and 171 deletions

View File

@ -67,10 +67,9 @@ class IsAncestorOfFilterMatch(IsAncestorOf,MatchesFilter):
filt = MatchesFilter(self.list[0:1])
filt.prepare(db)
for person_handle in db.iter_person_handles():
person = db.get_person_from_handle( person_handle)
if filt.apply (db, person):
self.init_ancestor_list (db,person,first)
for person in db.iter_people():
if filt.apply(db, person):
self.init_ancestor_list(db, person, first)
filt.reset()
def reset(self):

View File

@ -53,10 +53,9 @@ class IsChildOfFilterMatch(MatchesFilter):
self.map = {}
filt = MatchesFilter(self.list)
filt.prepare(db)
for person_handle in db.iter_person_handles():
person = db.get_person_from_handle( person_handle)
if filt.apply (db, person):
self.init_list (person)
for person in db.iter_people():
if filt.apply(db, person):
self.init_list(person)
filt.reset()
def reset(self):

View File

@ -67,10 +67,9 @@ class IsDescendantOfFilterMatch(IsDescendantOf,MatchesFilter):
filt = MatchesFilter(self.list[0:1])
filt.prepare(db)
for person_handle in db.iter_person_handles():
person = db.get_person_from_handle( person_handle)
if filt.apply (db, person):
self.init_list (person,first)
for person in db.iter_people():
if filt.apply(db, person):
self.init_list(person, first)
filt.reset()
def reset(self):

View File

@ -53,10 +53,9 @@ class IsParentOfFilterMatch(MatchesFilter):
self.map = {}
filt = MatchesFilter(self.list)
filt.prepare(db)
for person_handle in db.iter_person_handles():
person = db.get_person_from_handle(person_handle)
if filt.apply (db, person):
self.init_list (person)
for person in db.iter_people():
if filt.apply(db, person):
self.init_list(person)
filt.reset()
def reset(self):
@ -68,6 +67,6 @@ class IsParentOfFilterMatch(MatchesFilter):
def init_list(self,person):
for fam_id in person.get_parent_family_handle_list():
fam = self.db.get_family_from_handle(fam_id)
for parent_id in [fam.get_father_handle (), fam.get_mother_handle ()]:
for parent_id in [fam.get_father_handle(), fam.get_mother_handle()]:
if parent_id:
self.map[parent_id] = 1

View File

@ -161,22 +161,21 @@ class MergePlaces(ManagedWindow.ManagedWindow):
# replace references in other objetcs
# people
for handle in self.db.iter_person_handles():
person = self.db.get_person_from_handle(handle)
for person in self.db.iter_people():
if person.has_handle_reference('Place',self.old_handle):
person.replace_handle_reference('Place',
self.old_handle,self.new_handle)
self.db.commit_person(person,trans)
# families
for handle in self.db.iter_family_handles():
family = self.db.get_family_from_handle(handle)
for family in self.db.iter_families():
if family.has_handle_reference('Place',self.old_handle):
family.replace_handle_reference('Place',
self.old_handle,self.new_handle)
self.db.commit_family(family,trans)
# events
for handle in self.db.get_event_handles():
event = self.db.get_event_from_handle(handle)
for event in self.db.iter_events():
if event.has_handle_reference('Place',self.old_handle):
event.replace_handle_reference('Place',
self.old_handle,self.new_handle)

View File

@ -165,48 +165,42 @@ class MergeSources(ManagedWindow.ManagedWindow):
# replace handles
# people
for handle in self.db.iter_person_handles():
person = self.db.get_person_from_handle(handle)
for person in self.db.iter_people():
if person.has_source_reference(self.old_handle):
person.replace_source_references(self.old_handle,
self.new_handle)
self.db.commit_person(person,trans)
# family
for handle in self.db.iter_family_handles():
family = self.db.get_family_from_handle(handle)
for family in self.db.iter_families():
if family.has_source_reference(self.old_handle):
family.replace_source_references(self.old_handle,
self.new_handle)
self.db.commit_family(family,trans)
# events
for handle in self.db.get_event_handles():
event = self.db.get_event_from_handle(handle)
for event in self.db.iter_events():
if event.has_source_reference(self.old_handle):
event.replace_source_references(self.old_handle,
self.new_handle)
self.db.commit_event(event,trans)
# sources
for handle in self.db.get_source_handles():
source = self.db.get_source_from_handle(handle)
for source in self.db.iter_sources():
if source.has_source_reference(self.old_handle):
source.replace_source_references(self.old_handle,
self.new_handle)
self.db.commit_source(source,trans)
# places
for handle in self.iter.get_place_handles():
place = self.db.get_place_from_handle(handle)
for place in self.db.iter_places():
if place.has_source_reference(self.old_handle):
place.replace_source_references(self.old_handle,
self.new_handle)
self.db.commit_place(place,trans)
# media
for handle in self.db.get_media_object_handles():
obj = self.db.get_object_from_handle(handle)
for obj in self.db.iter_media_objects():
if obj.has_source_reference(self.old_handle):
obj.replace_source_references(self.old_handle,
self.new_handle)

View File

@ -111,9 +111,8 @@ class LastNameDialog(ManagedWindow.ManagedWindow):
progress = ProgressMeter(_('Finding Surnames'))
progress.set_pass(_('Finding surnames'),
database.get_number_of_people())
for person_handle in database.iter_person_handles():
for person in database.iter_people():
progress.step()
person = database.get_person_from_handle(person_handle)
key = person.get_primary_name().get_surname()
count = 0
if key in surnames:

View File

@ -82,7 +82,7 @@ def _validate_options(options, dbase):
if not person:
person = dbase.get_default_person()
if not person:
phandle = dbase.get_person_handles()[0]
phandle = dbase.iter_person_handles().next()
person = dbase.get_person_from_handle(phandle)
if not person:
print "ERROR: Please specify a person"
@ -101,8 +101,7 @@ def _validate_options(options, dbase):
if family_list:
family_handle = family_list[0]
else:
for family_handle in dbase.iter_family_handles():
break
family_handle = dbase.iter_family_handles().next()
if family_handle:
family = dbase.get_family_from_handle(family_handle)
option.set_value(family.get_gramps_id())
@ -237,8 +236,7 @@ class CommandLineReport(object):
self.options_help[name].append(id_list)
elif isinstance(option, FamilyOption):
id_list = []
for fhandle in self.database.iter_family_handles():
family = self.database.get_family_from_handle(fhandle)
for family in self.database.iter_families():
mname = ""
fname = ""
mhandle = family.get_mother_handle()

View File

@ -165,29 +165,25 @@ class BSDDBTxn(object):
"""
Returns the data object associated with key
"""
if txn == None: txn = self.txn
return self.db.get(key, default, txn, **kwargs)
return self.db.get(key, default, txn or self.txn, **kwargs)
def pget(self, key, default=None, txn=None, **kwargs):
"""
Returns the primary key, given the secondary one, and associated data
"""
if txn == None: txn = self.txn
return self.db.pget(key, default, txn, **kwargs)
return self.db.pget(key, default, txn or self.txn, **kwargs)
def put(self, key, data, txn=None, **kwargs):
"""
Stores the key/data pair in the database
"""
if txn == None: txn = self.txn
return self.db.put(key, data, txn, **kwargs)
return self.db.put(key, data, txn or self.txn, **kwargs)
def delete(self, key, txn=None, **kwargs):
"""
Removes a key/data pair from the database
"""
if txn == None: txn = self.txn
self.db.delete(key, txn, **kwargs)
self.db.delete(key, txn or self.txn, **kwargs)
# test code
if __name__ == "__main__":

View File

@ -126,8 +126,7 @@ def _initialize_options(options, dbstate):
if family_list:
family_handle = family_list[0]
else:
for family_handle in dbase.iter_family_handles():
break
family_handle = dbase.iter_family_handles().next()
family = dbase.get_family_from_handle(family_handle)
option.set_value(family.get_gramps_id())

View File

@ -84,10 +84,9 @@ class AgeStatsGramplet(Gramplet):
mother_handles = [[] for age in range(self.max_mother_diff)]
father_handles = [[] for age in range(self.max_father_diff)]
text = ""
handles = self.dbstate.db.iter_person_handles()
for h in handles:
for p in self.dbstate.db.iter_people():
yield True
p = self.dbstate.db.get_person_from_handle(h)
# if birth_date and death_date, compute age
birth_ref = p.get_birth_ref()
birth_date = None
@ -103,7 +102,7 @@ class AgeStatsGramplet(Gramplet):
age = death_date.get_year() - birth_date.get_year()
if age >= 0 and age < self.max_age:
age_dict[age] = age_dict.get(age, 0) + 1
age_handles[age].append(h)
age_handles[age].append(p.handle)
#else:
# print "Age out of range: %d for %s" % (age,
# p.get_primary_name().get_first_name()

View File

@ -283,8 +283,7 @@ class DataEntryGramplet(Gramplet):
def get_or_create_place(self, place_name):
if place_name == "": return (-1, None)
for place_handle in self.dbstate.db.iter_place_handles():
place = self.dbstate.db.get_place_from_handle(place_handle)
for place in self.dbstate.db.iter_places():
if place.get_title().strip() == place_name:
return (0, place) # (old, object)
place = gen.lib.Place()

View File

@ -78,22 +78,19 @@ class SurnameCloudGramplet(Gramplet):
def main(self):
self.set_text(_("Processing...") + "\n")
yield True
people = self.dbstate.db.iter_person_handles()
surnames = {}
representative_handle = {}
cnt = 0
for person_handle in people:
person = self.dbstate.db.get_person_from_handle(person_handle)
if person:
allnames = [person.get_primary_name()] + person.get_alternate_names()
allnames = set([name.get_group_name().strip() for name in allnames])
for surname in allnames:
surnames[surname] = surnames.get(surname, 0) + 1
representative_handle[surname] = person_handle
for person in self.dbstate.db.iter_people():
allnames = [person.get_primary_name()] + person.get_alternate_names()
allnames = set([name.get_group_name().strip() for name in allnames])
for surname in allnames:
surnames[surname] = surnames.get(surname, 0) + 1
representative_handle[surname] = person.handle
cnt += 1
if not cnt % _YIELD_INTERVAL:
yield True
cnt += 1
total_people = cnt
surname_sort = []
@ -101,9 +98,9 @@ class SurnameCloudGramplet(Gramplet):
for surname in surnames:
surname_sort.append( (surnames[surname], surname) )
total += surnames[surname]
cnt += 1
if not cnt % _YIELD_INTERVAL:
yield True
cnt += 1
total_surnames = cnt
surname_sort.sort(reverse=True)
@ -114,8 +111,7 @@ class SurnameCloudGramplet(Gramplet):
cloud_values.append( count )
cloud_names.sort(key=lambda k:k[1])
counts = list(set(cloud_values))
counts.sort(reverse=True)
counts = reversed(set(cloud_values))
line = 0
### All done!
# Now, find out how many we can display without going over top_size:

View File

@ -62,20 +62,17 @@ class TopSurnamesGramplet(Gramplet):
def main(self):
self.set_text(_("Processing...") + "\n")
people = self.dbstate.db.iter_person_handles()
surnames = {}
representative_handle = {}
cnt = 0
for person_handle in people:
person = self.dbstate.db.get_person_from_handle(person_handle)
if person:
cnt += 1
allnames = [person.get_primary_name()] + person.get_alternate_names()
allnames = set([name.get_group_name().strip() for name in allnames])
for surname in allnames:
surnames[surname] = surnames.get(surname, 0) + 1
representative_handle[surname] = person_handle
for person in self.dbstate.db.iter_people():
allnames = [person.get_primary_name()] + person.get_alternate_names()
allnames = set([name.get_group_name().strip() for name in allnames])
for surname in allnames:
surnames[surname] = surnames.get(surname, 0) + 1
representative_handle[surname] = person.handle
cnt += 1
if not cnt % _YIELD_INTERVAL:
yield True
@ -83,9 +80,11 @@ class TopSurnamesGramplet(Gramplet):
surname_sort = []
total = 0
for cnt, surname in enumerate(surnames):
cnt = 0
for surname in surnames:
surname_sort.append( (surnames[surname], surname) )
total += surnames[surname]
cnt += 1
if not cnt % _YIELD_INTERVAL:
yield True

View File

@ -53,10 +53,8 @@ def run(database, document, *args, **kwargs):
sdoc.paragraph("")
matches = 0
stab.columns(_("Name"), _("Primary Name"), _("Name Type"))
people = database.iter_person_handles()
names = [] # name, person
for person_handle in people:
person = database.get_person_from_handle(person_handle)
for person in database.iter_people():
primary_name = person.get_primary_name()
if primary_name:
names += [(nd.display_name(primary_name),

View File

@ -60,16 +60,13 @@ def run(database, document, filter_name, *args, **kwargs):
matches = 0
if (filter_name == 'all people'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
people = database.iter_person_handles()
for person_handle in people:
person = database.get_person_from_handle(person_handle)
for person in database.iter_people():
stab.row(person, sdb.birth_date_obj(person),
str(person.get_primary_name().get_type()))
matches += 1
elif (filter_name == 'males'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
people = database.iter_person_handles()
for person_handle in people:
for person in database.iter_people():
person = database.get_person_from_handle(person_handle)
if person.gender == Person.MALE:
stab.row(person, sdb.birth_date_obj(person),
@ -77,27 +74,21 @@ def run(database, document, filter_name, *args, **kwargs):
matches += 1
elif (filter_name == 'females'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
people = database.iter_person_handles()
for person_handle in people:
person = database.get_person_from_handle(person_handle)
for person in database.iter_people():
if person.gender == Person.FEMALE:
stab.row(person, sdb.birth_date_obj(person),
str(person.get_primary_name().get_type()))
matches += 1
elif (filter_name == 'people with unknown gender'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
people = database.iter_person_handles()
for person_handle in people:
person = database.get_person_from_handle(person_handle)
for person in database.iter_people():
if person.gender not in [Person.FEMALE, Person.MALE]:
stab.row(person, sdb.birth_date_obj(person),
str(person.get_primary_name().get_type()))
matches += 1
elif (filter_name == 'people with incomplete names'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
people = database.iter_person_handles()
for person_handle in people:
person = database.get_person_from_handle(person_handle)
for person in database.iter_people():
for name in [person.get_primary_name()] + person.get_alternate_names():
if name.get_group_name() == "" or name.get_first_name() == "":
stab.row(person, sdb.birth_date_obj(person),
@ -105,48 +96,36 @@ def run(database, document, filter_name, *args, **kwargs):
matches += 1
elif (filter_name == 'people with missing birth dates'):
stab.columns(_("Person"), _("Type"))
people = database.iter_person_handles()
for person_handle in people:
person = database.get_person_from_handle(person_handle)
if person:
birth_ref = person.get_birth_ref()
if birth_ref:
birth = database.get_event_from_handle(birth_ref.ref)
if not DateHandler.get_date(birth):
stab.row(person, _("birth event but no date"))
matches += 1
else:
stab.row(person, _("missing birth event"))
for person in database.iter_people():
birth_ref = person.get_birth_ref()
if birth_ref:
birth = database.get_event_from_handle(birth_ref.ref)
if not DateHandler.get_date(birth):
stab.row(person, _("birth event but no date"))
matches += 1
else:
stab.row(person, _("missing birth event"))
matches += 1
elif (filter_name == 'disconnected people'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
people = database.iter_person_handles()
for person_handle in people:
person = database.get_person_from_handle(person_handle)
if person:
if ((not person.get_main_parents_family_handle()) and
(not len(person.get_family_handle_list()))):
stab.row(person, sdb.birth_date_obj(person),
str(person.get_primary_name().get_type()))
matches += 1
elif (filter_name == 'all families'):
familyList = database.iter_family_handles()
stab.columns(_("Family"))
for family_handle in familyList:
family = database.get_family_from_handle(family_handle)
if family:
stab.row(family)
for person in database.iter_people():
if ((not person.get_main_parents_family_handle()) and
(not len(person.get_family_handle_list()))):
stab.row(person, sdb.birth_date_obj(person),
str(person.get_primary_name().get_type()))
matches += 1
elif (filter_name == 'all families'):
stab.columns(_("Family"))
for family in database.iter_families():
stab.row(family)
matches += 1
elif (filter_name == 'unique surnames'):
namelist = {}
people = database.iter_person_handles()
for person_handle in people:
person = database.get_person_from_handle(person_handle)
if person:
names = [person.get_primary_name()] + person.get_alternate_names()
surnames = list(set([name.get_group_name() for name in names]))
for surname in surnames:
namelist[surname] = namelist.get(surname, 0) + 1
for person in database.iter_people():
names = [person.get_primary_name()] + person.get_alternate_names()
surnames = list(set([name.get_group_name() for name in names]))
for surname in surnames:
namelist[surname] = namelist.get(surname, 0) + 1
stab.columns(_("Surname"), _("Count"))
for name in sorted(namelist):
stab.row(name, namelist[name])
@ -158,39 +137,27 @@ def run(database, document, filter_name, *args, **kwargs):
name))
elif (filter_name == 'people with media'):
stab.columns(_("Person"), _("Media count"))
people = database.iter_person_handles()
for person_handle in people:
person = database.get_person_from_handle(person_handle)
if not person:
continue
for person in database.iter_people():
length = len(person.get_media_list())
if length > 0:
stab.row(person, length)
matches += 1
elif (filter_name == 'media references'):
stab.columns(_("Person"), _("Reference"))
people = database.iter_person_handles()
for person_handle in people:
person = database.get_person_from_handle(person_handle)
if not person:
continue
for person in database.iter_people():
medialist = person.get_media_list()
for item in medialist:
stab.row(person, _("media"))
matches += 1
elif (filter_name == 'unique media'):
stab.columns(_("Unique Media"))
pobjects = database.get_media_object_handles()
for photo_id in database.get_media_object_handles():
photo = database.get_object_from_handle(photo_id)
for photo in database.iter_media_objects():
fullname = media_path_full(database, photo.get_path())
stab.row(fullname)
matches += 1
elif (filter_name == 'missing media'):
stab.columns(_("Missing Media"))
pobjects = database.get_media_object_handles()
for photo_id in database.get_media_object_handles():
photo = database.get_object_from_handle(photo_id)
for photo in database.iter_media_objects():
fullname = media_path_full(database, photo.get_path())
try:
posixpath.getsize(fullname)
@ -199,9 +166,7 @@ def run(database, document, filter_name, *args, **kwargs):
matches += 1
elif (filter_name == 'media by size'):
stab.columns(_("Media"), _("Size in bytes"))
pobjects = database.get_media_object_handles()
for photo_id in database.get_media_object_handles():
photo = database.get_object_from_handle(photo_id)
for photo in database.iter_media_objects():
fullname = media_path_full(database, photo.get_path())
try:
bytes = posixpath.getsize(fullname)
@ -212,8 +177,7 @@ def run(database, document, filter_name, *args, **kwargs):
elif (filter_name == 'list of people'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
people = kwargs["handles"]
for person_handle in people:
person = database.get_person_from_handle(person_handle)
for person in database.iter_people():
stab.row(person, sdb.birth_date_obj(person),
str(person.get_primary_name().get_type()))
matches += 1

View File

@ -100,12 +100,8 @@ class SummaryReport(Report):
self.doc.write_text(_("Individuals"))
self.doc.end_paragraph()
person_list = self.__db.iter_person_handles()
num_people = 0
for person_handle in person_list:
person = self.__db.get_person_from_handle(person_handle)
if not person:
continue
for person in self.__db.iter_people():
num_people += 1
# Count people with media.
@ -191,7 +187,6 @@ class SummaryReport(Report):
self.doc.write_text(_("Family Information"))
self.doc.end_paragraph()
family_list = self.__db.iter_family_handles()
self.doc.start_paragraph("SR-Normal")
self.doc.write_text(_("Number of families: %d") % self.__db.get_number_of_families())
self.doc.end_paragraph()

View File

@ -83,8 +83,7 @@ class EventNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
self.change = False
counter = 0
for handle in self.db.iter_person_handles():
person = self.db.get_person_from_handle(handle)
for person in self.db.iter_people():
for event_ref in person.get_event_ref_list():
if event_ref.get_role() == gen.lib.EventRoleType.PRIMARY:
event_handle = event_ref.ref
@ -95,8 +94,7 @@ class EventNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
self.change = True
counter += 1
for handle in self.db.iter_family_handles():
family = self.db.get_family_from_handle(handle)
for family in self.db.iter_families():
for event_ref in family.get_event_ref_list():
if event_ref.get_role() == gen.lib.EventRoleType.FAMILY:
event_handle = event_ref.ref

View File

@ -122,9 +122,8 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
self.progress.set_pass(_('Analyzing names'),
self.db.get_number_of_people())
for key in self.db.iter_person_handles():
person = self.db.get_person_from_handle(key)
for person in self.db.iter_people():
key = person.handle
name = person.get_primary_name()
first = name.get_first_name()
sname = name.get_surname()

View File

@ -76,8 +76,7 @@ class SoundGen(Tool.Tool, ManagedWindow.ManagedWindow):
names = []
person = None
for person_handle in self.db.iter_person_handles():
person = self.db.get_person_from_handle(person_handle)
for person in self.db.iter_people():
lastname = person.get_primary_name().get_surname()
if lastname not in names:
names.append(lastname)