From b601f4bdf21159c7feec62eb534ada4edf361543 Mon Sep 17 00:00:00 2001 From: Gerald Britton Date: Wed, 8 Jul 2009 16:11:20 +0000 Subject: [PATCH] Replace get_family_handles with iter_family_handles svn: r12776 --- src/FilterEditor/_FilterEditor.py | 2 +- src/Merge/_MergePlace.py | 2 +- src/Merge/_MergeSource.py | 2 +- src/PluginUtils/_GuiOptions.py | 6 ++---- src/ReportBase/_CommandLineReport.py | 5 +++-- src/gen/proxy/living.py | 11 +++++++++-- src/gen/proxy/private.py | 12 +++++++++++- src/gen/proxy/referenced.py | 11 +++++++++-- src/plugins/BookReport.py | 3 ++- src/plugins/Records.py | 2 +- src/plugins/export/ExportCd.py | 2 +- src/plugins/export/ExportCsv.py | 2 +- src/plugins/export/ExportGedcom.py | 2 +- src/plugins/export/ExportPkg.py | 2 +- src/plugins/export/ExportXml.py | 2 +- src/plugins/gramplet/StatsGramplet.py | 4 ++-- src/plugins/quickview/FilterByName.py | 2 +- src/plugins/textreport/MarkerReport.py | 2 +- src/plugins/textreport/Summary.py | 4 ++-- src/plugins/tool/EventNames.py | 2 +- src/plugins/tool/Verify.py | 2 +- 21 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/FilterEditor/_FilterEditor.py b/src/FilterEditor/_FilterEditor.py index 0cb55c1fb..ceb8e74e7 100644 --- a/src/FilterEditor/_FilterEditor.py +++ b/src/FilterEditor/_FilterEditor.py @@ -238,7 +238,7 @@ class FilterEditor(ManagedWindow.ManagedWindow): if self.namespace == 'Person': return self.db.iter_person_handles() elif self.namespace == 'Family': - return self.db.get_family_handles() + return self.db.iter_family_handles() elif self.namespace == 'Event': return self.db.get_event_handles() elif self.namespace == 'Source': diff --git a/src/Merge/_MergePlace.py b/src/Merge/_MergePlace.py index 73f3009f6..78b778965 100644 --- a/src/Merge/_MergePlace.py +++ b/src/Merge/_MergePlace.py @@ -168,7 +168,7 @@ class MergePlaces(ManagedWindow.ManagedWindow): self.old_handle,self.new_handle) self.db.commit_person(person,trans) # families - for handle in self.db.get_family_handles(): + for handle in self.db.iter_family_handles(): family = self.db.get_family_from_handle(handle) if family.has_handle_reference('Place',self.old_handle): family.replace_handle_reference('Place', diff --git a/src/Merge/_MergeSource.py b/src/Merge/_MergeSource.py index b979b80b3..662f72198 100644 --- a/src/Merge/_MergeSource.py +++ b/src/Merge/_MergeSource.py @@ -173,7 +173,7 @@ class MergeSources(ManagedWindow.ManagedWindow): self.db.commit_person(person,trans) # family - for handle in self.db.get_family_handles(): + for handle in self.db.iter_family_handles(): family = self.db.get_family_from_handle(handle) if family.has_source_reference(self.old_handle): family.replace_source_references(self.old_handle, diff --git a/src/PluginUtils/_GuiOptions.py b/src/PluginUtils/_GuiOptions.py index 0bef29989..3467fa537 100644 --- a/src/PluginUtils/_GuiOptions.py +++ b/src/PluginUtils/_GuiOptions.py @@ -551,10 +551,8 @@ class GuiFamilyOption(gtk.HBox): if not family_list: # Finally, take any family you can find. - family_list = self.__db.get_family_handles() - - if family_list: - family = self.__db.get_family_from_handle(family_list[0]) + for family in self.__db.iter_family_handles(): + break self.__update_family(family) def __get_family_clicked(self, obj): # IGNORE:W0613 - obj is unused diff --git a/src/ReportBase/_CommandLineReport.py b/src/ReportBase/_CommandLineReport.py index 9bc42e98c..5ab0a8251 100644 --- a/src/ReportBase/_CommandLineReport.py +++ b/src/ReportBase/_CommandLineReport.py @@ -93,7 +93,8 @@ def _validate_options(options, dbase): if family_list: family_handle = family_list[0] else: - family_handle = dbase.get_family_handles()[0] + for family_handle in dbase.iter_family_handles(): + break family = dbase.get_family_from_handle(family_handle) option.set_value(family.get_gramps_id()) @@ -224,7 +225,7 @@ class CommandLineReport(object): self.options_help[name].append(id_list) elif isinstance(option, gen.plug.menu.FamilyOption): id_list = [] - for fhandle in self.database.get_family_handles(): + for fhandle in self.database.iter_family_handles(): family = self.database.get_family_from_handle(fhandle) mname = "" fname = "" diff --git a/src/gen/proxy/living.py b/src/gen/proxy/living.py index c3d5cd568..f7eaf9fd7 100644 --- a/src/gen/proxy/living.py +++ b/src/gen/proxy/living.py @@ -230,7 +230,7 @@ class LivingProxyDb(ProxyDbBase): def iter_person_handles(self): """ Return an iterator over database handles, one handle for each Person in - the database. If sort_handles is True, the list is sorted by surnames + the database. """ if self.mode == self.MODE_EXCLUDE_ALL: for handle in self.db.iter_person_handles(): @@ -238,7 +238,7 @@ class LivingProxyDb(ProxyDbBase): if not self.__is_living(person): yield handle else: - handles = self.db.iter_person_handles() + return self.db.iter_person_handles() def get_place_handles(self, sort_handles=True): """ @@ -277,6 +277,13 @@ class LivingProxyDb(ProxyDbBase): """ return self.db.get_family_handles() + def iter_family_handles(self): + """ + Return an iterator over database handles, one handle for each Family in + the database.. + """ + return self.db.iter_family_handles() + def get_repository_handles(self): """ Return a list of database handles, one handle for each Repository in diff --git a/src/gen/proxy/private.py b/src/gen/proxy/private.py index 504c0f3dd..90e52d580 100644 --- a/src/gen/proxy/private.py +++ b/src/gen/proxy/private.py @@ -284,12 +284,22 @@ class PrivateProxyDb(ProxyDbBase): the database. """ handles = [] - for handle in self.db.get_family_handles(): + for handle in self.db.iter_family_handles(): family = self.db.get_family_from_handle(handle) if not family.get_privacy(): handles.append(handle) return handles + def iter_family_handles(self): + """ + Return an iterator over database handles, one handle for each Family in + the database. + """ + for handle in self.db.iter_family_handles(): + family = self.db.get_family_from_handle(handle) + if not family.get_privacy(): + yield handle + def get_repository_handles(self): """ Return a list of database handles, one handle for each Repository in diff --git a/src/gen/proxy/referenced.py b/src/gen/proxy/referenced.py index bb2c8c4d2..505afe81a 100644 --- a/src/gen/proxy/referenced.py +++ b/src/gen/proxy/referenced.py @@ -221,6 +221,13 @@ class ReferencedProxyDb(ProxyDbBase): """ return self.db.get_family_handles() + def iter_family_handles(self): + """ + Return an iterator over database handles, one handle for each Family in + the database.. + """ + return self.db.iter_family_handles() + def get_repository_handles(self): """ Return a list of database handles, one handle for each Repository still @@ -254,7 +261,7 @@ class ReferencedProxyDb(ProxyDbBase): """ returns True if the handle exists in the current Person database. """ - return handle in self.get_person_handles() + return handle in self.iter_person_handles() def has_event_handle(self, handle): """ @@ -278,7 +285,7 @@ class ReferencedProxyDb(ProxyDbBase): """ returns True if the handle exists in the current Family database. """ - return handle in self.get_family_handles() + return handle in self.iter_family_handles() def has_object_handle(self, handle): """ diff --git a/src/plugins/BookReport.py b/src/plugins/BookReport.py index 62da4145a..c67a7ff2b 100644 --- a/src/plugins/BookReport.py +++ b/src/plugins/BookReport.py @@ -123,7 +123,8 @@ def _initialize_options(options, dbstate): if family_list: family_handle = family_list[0] else: - family_handle = dbase.get_family_handles()[0] + for family_handle in dbase.iter_family_handles(): + break family = dbase.get_family_from_handle(family_handle) option.set_value(family.get_gramps_id()) diff --git a/src/plugins/Records.py b/src/plugins/Records.py index 703eb829f..aef84cd2b 100644 --- a/src/plugins/Records.py +++ b/src/plugins/Records.py @@ -196,7 +196,7 @@ def _find_records(db, filter, callname): family_shortest = [] family_longest = [] - for family_handle in db.get_family_handles(): + for family_handle in db.iter_family_handles(): family = db.get_family_from_handle(family_handle) father_handle = family.get_father_handle() diff --git a/src/plugins/export/ExportCd.py b/src/plugins/export/ExportCd.py index 668d9b0ad..0ea50b4e1 100644 --- a/src/plugins/export/ExportCd.py +++ b/src/plugins/export/ExportCd.py @@ -176,7 +176,7 @@ class PackageWriter(object): #-------------------------------------------------------- def remove_clicked(): # File is lost => remove all references and the object itself - for p_id in self.db.get_family_handles(): + for p_id in self.db.iter_family_handles(): p = self.db.get_family_from_handle(p_id) nl = p.get_media_list() for o in nl: diff --git a/src/plugins/export/ExportCsv.py b/src/plugins/export/ExportCsv.py index e84bd8778..9f11ac7f6 100644 --- a/src/plugins/export/ExportCsv.py +++ b/src/plugins/export/ExportCsv.py @@ -263,7 +263,7 @@ class CSVWriter(object): for family_handle in p.get_family_handle_list(): self.flist[family_handle] = 1 # now add the families for which these people are a child: - family_handles = self.db.get_family_handles() + family_handles = self.db.iter_family_handles() for family_handle in family_handles: family = self.db.get_family_from_handle(family_handle) for child_ref in family.get_child_ref_list(): diff --git a/src/plugins/export/ExportGedcom.py b/src/plugins/export/ExportGedcom.py index 1fccf181f..1a0b1e3ff 100644 --- a/src/plugins/export/ExportGedcom.py +++ b/src/plugins/export/ExportGedcom.py @@ -918,7 +918,7 @@ class GedcomWriter(BasicUtils.UpdateCallback): # generate a list of (GRAMPS_ID, HANDLE) pairs. This list # can then be sorted by the sort routine, which will use the # first value of the tuple as the sort key. - sorted_list = sort_handles_by_id(self.dbase.get_family_handles(), + sorted_list = sort_handles_by_id(self.dbase.iter_family_handles(), self.dbase.get_family_from_handle) # loop through the sorted list, pulling of the handle. This list diff --git a/src/plugins/export/ExportPkg.py b/src/plugins/export/ExportPkg.py index 29b1469d8..3df2c41bb 100644 --- a/src/plugins/export/ExportPkg.py +++ b/src/plugins/export/ExportPkg.py @@ -114,7 +114,7 @@ class PackageWriter(object): #-------------------------------------------------------------- def remove_clicked(): # File is lost => remove all references and the object itself - for p_id in self.db.get_family_handles(): + for p_id in self.db.iter_family_handles(): p = self.db.get_family_from_handle(p_id) nl = p.get_media_list() for o in nl: diff --git a/src/plugins/export/ExportXml.py b/src/plugins/export/ExportXml.py index f4ab88bb9..1ed61b91e 100644 --- a/src/plugins/export/ExportXml.py +++ b/src/plugins/export/ExportXml.py @@ -251,7 +251,7 @@ class GrampsDbXmlWriter(UpdateCallback): if family_len > 0: self.g.write(" \n") - for handle in self.db.get_family_handles(): + for handle in self.db.iter_family_handles(): family = self.db.get_family_from_handle(handle) self.write_family(family,2) self.update() diff --git a/src/plugins/gramplet/StatsGramplet.py b/src/plugins/gramplet/StatsGramplet.py index 4ed94a36e..60de1b4b5 100644 --- a/src/plugins/gramplet/StatsGramplet.py +++ b/src/plugins/gramplet/StatsGramplet.py @@ -67,7 +67,7 @@ class StatsGramplet(Gramplet): self.set_text(_("Processing...")) database = self.dbstate.db personList = database.iter_person_handles() - familyList = database.get_family_handles() + familyList = database.iter_family_handles() with_photos = 0 total_photos = 0 @@ -160,7 +160,7 @@ class StatsGramplet(Gramplet): self.append_text("----------------------------\n") self.link("%s:" % _("Number of families"), 'Filter', 'all families') - self.append_text(" %s" % len(familyList)) + self.append_text(" %s" % database.get_number_of_families()) self.append_text("\n") self.link("%s:" % _("Unique surnames"), 'Filter', 'unique surnames') diff --git a/src/plugins/quickview/FilterByName.py b/src/plugins/quickview/FilterByName.py index 41dedff10..f7f55f44d 100644 --- a/src/plugins/quickview/FilterByName.py +++ b/src/plugins/quickview/FilterByName.py @@ -130,7 +130,7 @@ def run(database, document, filter_name, *args, **kwargs): str(person.get_primary_name().get_type())) matches += 1 elif (filter_name == 'all families'): - familyList = database.get_family_handles() + familyList = database.iter_family_handles() stab.columns(_("Family")) for family_handle in familyList: family = database.get_family_from_handle(family_handle) diff --git a/src/plugins/textreport/MarkerReport.py b/src/plugins/textreport/MarkerReport.py index e9aba646a..e1419800d 100644 --- a/src/plugins/textreport/MarkerReport.py +++ b/src/plugins/textreport/MarkerReport.py @@ -178,7 +178,7 @@ class MarkerReport(Report): self.doc.end_table() def write_families(self): - flist = self.database.get_family_handles() + flist = self.database.iter_family_handles() FilterClass = GenericFilterFactory('Family') filter = FilterClass() filter.add_rule(Rules.Family.HasMarkerOf([self.marker])) diff --git a/src/plugins/textreport/Summary.py b/src/plugins/textreport/Summary.py index 9ad847521..ee020a695 100644 --- a/src/plugins/textreport/Summary.py +++ b/src/plugins/textreport/Summary.py @@ -189,9 +189,9 @@ class SummaryReport(Report): self.doc.write_text(_("Family Information")) self.doc.end_paragraph() - family_list = self.__db.get_family_handles() + family_list = self.__db.iter_family_handles() self.doc.start_paragraph("SR-Normal") - self.doc.write_text(_("Number of families: %d") % len(family_list)) + self.doc.write_text(_("Number of families: %d") % self.__db.get_number_of_families()) self.doc.end_paragraph() def summarize_media(self): diff --git a/src/plugins/tool/EventNames.py b/src/plugins/tool/EventNames.py index 2c39b7f90..234c8e66b 100644 --- a/src/plugins/tool/EventNames.py +++ b/src/plugins/tool/EventNames.py @@ -95,7 +95,7 @@ class EventNames(Tool.BatchTool, ManagedWindow.ManagedWindow): self.change = True counter += 1 - for handle in self.db.get_family_handles(): + for handle in self.db.iter_family_handles(): family = self.db.get_family_from_handle(handle) for event_ref in family.get_event_ref_list(): if event_ref.get_role() == gen.lib.EventRoleType.FAMILY: diff --git a/src/plugins/tool/Verify.py b/src/plugins/tool/Verify.py index 18cc6a885..f2e9fd83a 100644 --- a/src/plugins/tool/Verify.py +++ b/src/plugins/tool/Verify.py @@ -357,7 +357,7 @@ class Verify(Tool.Tool, ManagedWindow, UpdateCallback): self.update() # Family-based rules - for family_handle in self.db.get_family_handles(): + for family_handle in self.db.iter_family_handles(): family = find_family(self.db,family_handle) rule_list = [