diff --git a/src/PluginUtils/_GuiOptions.py b/src/PluginUtils/_GuiOptions.py index fbe32c5b7..0bef29989 100644 --- a/src/PluginUtils/_GuiOptions.py +++ b/src/PluginUtils/_GuiOptions.py @@ -111,7 +111,7 @@ class LastNameDialog(ManagedWindow.ManagedWindow): progress = ProgressMeter(_('Finding Surnames')) progress.set_pass(_('Finding surnames'), database.get_number_of_people()) - for person_handle in database.get_person_handles(False): + for person_handle in database.iter_person_handles(): progress.step() person = database.get_person_from_handle(person_handle) key = person.get_primary_name().get_surname() diff --git a/src/gen/proxy/dbbase.py b/src/gen/proxy/dbbase.py index ae10f8dbe..147577f2c 100644 --- a/src/gen/proxy/dbbase.py +++ b/src/gen/proxy/dbbase.py @@ -608,6 +608,13 @@ class DbBase(object): """ raise NotImplementedError + 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 + """ + raise NotImplementedError + def get_place_handles(self, sort_handles=True): """ Return a list of database handles, one handle for each Place in @@ -1267,7 +1274,7 @@ class DbBase(object): Note that this is a generator function, it returns a iterator for use in loops. If you want a list of the results use: - > result_list = [i for i in find_backlink_handles(handle)] + > result_list = list(find_backlink_handles(handle)) """ raise NotImplementedError diff --git a/src/gen/proxy/filter.py b/src/gen/proxy/filter.py index 42669f13a..7710c927f 100644 --- a/src/gen/proxy/filter.py +++ b/src/gen/proxy/filter.py @@ -281,6 +281,14 @@ class FilterProxyDb(ProxyDbBase): # FIXME: plist is not a sorted list of handles return list(self.plist) + 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 + """ + # FIXME: plist is not a sorted list of handles + return (h for h in self.plist) + def get_place_handles(self, sort_handles=True): """ Return a list of database handles, one handle for each Place in @@ -420,7 +428,7 @@ class FilterProxyDb(ProxyDbBase): Note that this is a generator function, it returns a iterator for use in loops. If you want a list of the results use: - > result_list = [i for i in find_backlink_handles(handle)] + > result_list = list(find_backlink_handles(handle)) """ #FIXME: add a filter for returned handles (see private.py as an example) return self.db.find_backlink_handles(handle, include_classes) diff --git a/src/gen/proxy/living.py b/src/gen/proxy/living.py index a7f4621da..c3d5cd568 100644 --- a/src/gen/proxy/living.py +++ b/src/gen/proxy/living.py @@ -227,6 +227,19 @@ class LivingProxyDb(ProxyDbBase): handles = self.db.get_person_handles(sort_handles) return handles + 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 + """ + if self.mode == self.MODE_EXCLUDE_ALL: + for handle in self.db.iter_person_handles(): + person = self.db.get_person_from_handle(handle) + if not self.__is_living(person): + yield handle + else: + handles = self.db.iter_person_handles() + def get_place_handles(self, sort_handles=True): """ Return a list of database handles, one handle for each Place in @@ -364,7 +377,7 @@ class LivingProxyDb(ProxyDbBase): Note that this is a generator function, it returns a iterator for use in loops. If you want a list of the results use: - > result_list = [i for i in find_backlink_handles(handle)] + > result_list = list(find_backlink_handles(handle)) """ handle_itr = self.db.find_backlink_handles(handle, include_classes) for (class_name, handle) in handle_itr: diff --git a/src/gen/proxy/private.py b/src/gen/proxy/private.py index a044f79b0..504c0f3dd 100644 --- a/src/gen/proxy/private.py +++ b/src/gen/proxy/private.py @@ -218,6 +218,16 @@ class PrivateProxyDb(ProxyDbBase): handles.append(handle) return handles + 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 + """ + for handle in self.db.iter_person_handles(): + person = self.db.get_person_from_handle(handle) + if not person.get_privacy(): + yield handle + def get_place_handles(self, sort_handles=True): """ Return a list of database handles, one handle for each Place in diff --git a/src/gen/proxy/proxybase.py b/src/gen/proxy/proxybase.py index 9b534d177..64a90fde0 100644 --- a/src/gen/proxy/proxybase.py +++ b/src/gen/proxy/proxybase.py @@ -445,7 +445,7 @@ class ProxyDbBase(DbBase): Note that this is a generator function, it returns a iterator for use in loops. If you want a list of the results use: - > result_list = [i for i in find_backlink_handles(handle)] + > result_list = list(find_backlink_handles(handle)) """ raise NotImplementedError diff --git a/src/gen/proxy/referenced.py b/src/gen/proxy/referenced.py index aeb47c6f7..bb2c8c4d2 100644 --- a/src/gen/proxy/referenced.py +++ b/src/gen/proxy/referenced.py @@ -172,6 +172,13 @@ class ReferencedProxyDb(ProxyDbBase): """ return self.db.get_person_handles(sort_handles) + 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 + """ + return self.db.iter_person_handles() + def get_place_handles(self, sort_handles=True): """ Return a list of database handles, one handle for each Place still @@ -310,7 +317,7 @@ class ReferencedProxyDb(ProxyDbBase): Note that this is a generator function, it returns a iterator for use in loops. If you want a list of the results use: - > result_list = [i for i in find_backlink_handles(handle)] + > result_list = list(find_backlink_handles(handle)) """ handle_itr = self.db.find_backlink_handles(handle, include_classes) for (class_name, handle) in handle_itr: @@ -366,22 +373,17 @@ class ReferencedProxyDb(ProxyDbBase): 'handle_list': self.get_note_handles} } - has_unreferenced_handles = True - last_count = 0 - while has_unreferenced_handles: + while True: current_count = 0 for object_type, object_dict in object_types.iteritems(): unref_list = object_dict['unref_list'] handle_list = object_dict['handle_list']() for handle in handle_list: - ref_handles = [i for i in \ - self.find_backlink_handles(handle)] - if len(ref_handles) == 0: + if not any(self.find_backlink_handles(handle)): unref_list.append(handle) current_count += len(unref_list) if current_count == last_count: - has_unreferenced_handles = False - else: - last_count = current_count + break + last_count = current_count diff --git a/src/plugins/Records.py b/src/plugins/Records.py index 7cad0df03..703eb829f 100644 --- a/src/plugins/Records.py +++ b/src/plugins/Records.py @@ -100,7 +100,7 @@ def _find_records(db, filter, callname): person_oldestfather = [] person_oldestmother = [] - person_handle_list = db.get_person_handles(sort_handles=False) + person_handle_list = db.iter_person_handles() if filter: person_handle_list = filter.apply(db, person_handle_list) diff --git a/src/plugins/drawreport/Calendar.py b/src/plugins/drawreport/Calendar.py index dec996e40..be479dee7 100644 --- a/src/plugins/drawreport/Calendar.py +++ b/src/plugins/drawreport/Calendar.py @@ -245,8 +245,8 @@ class Calendar(Report): This method runs through the data, and collects the relevant dates and text. """ - people = self.database.get_person_handles(sort_handles=False) - self.progress.set_pass(_('Applying Filter...'), len(people)) + people = self.database.iter_person_handles() + self.progress.set_pass(_('Applying Filter...'), self.database.get_number_of_people()) people = self.filter.apply(self.database, people, self.progress) pmgr = PluginManager.get_instance() rel_calc = pmgr.get_relationship_calculator() diff --git a/src/plugins/drawreport/StatisticsChart.py b/src/plugins/drawreport/StatisticsChart.py index 06c808b18..55738fa4f 100644 --- a/src/plugins/drawreport/StatisticsChart.py +++ b/src/plugins/drawreport/StatisticsChart.py @@ -417,7 +417,7 @@ class Extract(object): data.append((ext[name][1], {}, ext[name][2], ext[name][3])) # go through the people and collect data - for person_handle in filter_func.apply(db, db.get_person_handles(sort_handles=False)): + for person_handle in filter_func.apply(db, db.iter_person_handles()): person = db.get_person_from_handle(person_handle) # check whether person has suitable gender diff --git a/src/plugins/drawreport/TimeLine.py b/src/plugins/drawreport/TimeLine.py index b5dc3e60c..336ee7c10 100644 --- a/src/plugins/drawreport/TimeLine.py +++ b/src/plugins/drawreport/TimeLine.py @@ -239,7 +239,7 @@ class TimeLine(Report): high = -999999 self.plist = self.filter.apply(self.database, - self.database.get_person_handles(sort_handles=False)) + self.database.iter_person_handles()) for p_id in self.plist: p = self.database.get_person_from_handle(p_id) @@ -280,7 +280,7 @@ class TimeLine(Report): def name_size(self): self.plist = self.filter.apply(self.database, - self.database.get_person_handles(sort_handles=False)) + self.database.iter_person_handles()) style_sheet = self.doc.get_style_sheet() gstyle = style_sheet.get_draw_style('TLG-text') diff --git a/src/plugins/export/ExportCd.py b/src/plugins/export/ExportCd.py index 4aaa4e1f3..668d9b0ad 100644 --- a/src/plugins/export/ExportCd.py +++ b/src/plugins/export/ExportCd.py @@ -185,7 +185,7 @@ class PackageWriter(object): p.set_media_list(nl) self.db.commit_family(p, None) - for key in self.db.get_person_handles(sort_handles=False): + for key in self.db.iter_person_handles(): p = self.db.get_person_from_handle(key) nl = p.get_media_list() for o in nl: diff --git a/src/plugins/export/ExportCsv.py b/src/plugins/export/ExportCsv.py index 8c2a195d9..e84bd8778 100644 --- a/src/plugins/export/ExportCsv.py +++ b/src/plugins/export/ExportCsv.py @@ -254,7 +254,7 @@ class CSVWriter(object): if not option_box.cfilter.is_empty(): self.db = gen.proxy.FilterProxyDb(self.db, option_box.cfilter) - for p in self.db.get_person_handles(sort_handles=False): + for p in self.db.iter_person_handles(): self.plist[p] = 1 # get the families for which these people are spouses: self.flist = {} diff --git a/src/plugins/export/ExportFtree.py b/src/plugins/export/ExportFtree.py index 4ffbb616b..16178b265 100644 --- a/src/plugins/export/ExportFtree.py +++ b/src/plugins/export/ExportFtree.py @@ -144,14 +144,15 @@ class FtreeWriter(object): self.restrict = self.option_box.restrict if self.option_box.cfilter is None: - for p in self.db.get_person_handles(sort_handles=False): - self.plist[p] = 1 + self.plist.update((p,1) + for p in self.db.iter_person_handles()) + else: try: - for p in self.option_box.cfilter.apply( - self.db, self.db.get_person_handles(sort_handles=False) - ): - self.plist[p] = 1 + self.plist.update((p,1) + for p in self.option_box.cfilter.apply( + self.db, self.db.iter_person_handles())) + except Errors.FilterError, msg: (m1, m2) = msg.messages() ErrorDialog(m1, m2) @@ -169,8 +170,8 @@ class FtreeWriter(object): def cl_setup(self): self.restrict = True - for p in self.db.get_person_handles(sort_handles=False): - self.plist[p] = 1 + self.plist.update((p,1) + for p in self.db.iter_person_handles()) def export_data(self): name_map = {} diff --git a/src/plugins/export/ExportGedcom.py b/src/plugins/export/ExportGedcom.py index 7cabb847e..1fccf181f 100644 --- a/src/plugins/export/ExportGedcom.py +++ b/src/plugins/export/ExportGedcom.py @@ -413,7 +413,6 @@ class GedcomWriter(BasicUtils.UpdateCallback): self.dirname = os.path.dirname (filename) self.gedcom_file = open(filename, "w") - self.__header(filename) self.__submitter() self.__individuals() @@ -574,8 +573,8 @@ class GedcomWriter(BasicUtils.UpdateCallback): self.reset(_("Writing individuals")) self.progress_cnt += 1 self.update(self.progress_cnt) - phandles = self.dbase.get_person_handles() - + phandles = self.dbase.iter_person_handles() + sorted_list = [] for handle in phandles: person = self.dbase.get_person_from_handle(handle) diff --git a/src/plugins/export/ExportGeneWeb.py b/src/plugins/export/ExportGeneWeb.py index 595fbbed8..b73d4decd 100644 --- a/src/plugins/export/ExportGeneWeb.py +++ b/src/plugins/export/ExportGeneWeb.py @@ -174,7 +174,7 @@ class GeneWebWriter(object): if not option_box.cfilter.is_empty(): self.db = gen.proxy.FilterProxyDb(self.db, option_box.cfilter) - for p in self.db.get_person_handles(sort_handles=False): + for p in self.db.iter_person_handles(): self.plist[p] = 1 self.flist = {} diff --git a/src/plugins/export/ExportPkg.py b/src/plugins/export/ExportPkg.py index 79bf05dbf..29b1469d8 100644 --- a/src/plugins/export/ExportPkg.py +++ b/src/plugins/export/ExportPkg.py @@ -122,7 +122,7 @@ class PackageWriter(object): nl.remove(o) p.set_media_list(nl) self.db.commit_family(p,None) - for key in self.db.get_person_handles(sort_handles=False): + for key in self.db.iter_person_handles(): p = self.db.get_person_from_handle(key) nl = p.get_media_list() for o in nl: diff --git a/src/plugins/export/ExportVCalendar.py b/src/plugins/export/ExportVCalendar.py index 04ffbf5b2..f2326be21 100644 --- a/src/plugins/export/ExportVCalendar.py +++ b/src/plugins/export/ExportVCalendar.py @@ -145,12 +145,12 @@ class CalendarWriter(object): self.option_box.parse_options() if self.option_box.cfilter is None: - for p in self.db.get_person_handles(sort_handles=False): + for p in self.db.iter_person_handles(): self.plist[p] = 1 else: try: for p in self.option_box.cfilter.apply(self.db, - self.db.get_person_handles(sort_handles=False)): + self.db.iter_person_handles()): self.plist[p] = 1 except Errors.FilterError, msg: (m1, m2) = msg.messages() @@ -174,7 +174,7 @@ class CalendarWriter(object): self.oldval = newval def cl_setup(self): - for p in self.db.get_person_handles(sort_handles=False): + for p in self.db.iter_person_handles(): self.plist[p] = 1 self.flist = {} diff --git a/src/plugins/export/ExportVCard.py b/src/plugins/export/ExportVCard.py index 9ebcc70f5..fde81c6bc 100644 --- a/src/plugins/export/ExportVCard.py +++ b/src/plugins/export/ExportVCard.py @@ -136,12 +136,12 @@ class CardWriter(object): self.option_box.parse_options() if self.option_box.cfilter is None: - for p in self.db.get_person_handles(sort_handles=False): + for p in self.db.iter_person_handles(): self.plist[p] = 1 else: try: for p in self.option_box.cfilter.apply(self.db, - self.db.get_person_handles(sort_handles=False)): + self.db.iter_person_handles()): self.plist[p] = 1 except Errors.FilterError, msg: (m1, m2) = msg.messages() @@ -159,7 +159,7 @@ class CardWriter(object): self.oldval = newval def cl_setup(self): - for p in self.db.get_person_handles(sort_handles=False): + for p in self.db.iter_person_handles(): self.plist[p] = 1 def writeln(self, text): diff --git a/src/plugins/gramplet/AgeStats.py b/src/plugins/gramplet/AgeStats.py index 203ffe4fa..37c2d5a8f 100644 --- a/src/plugins/gramplet/AgeStats.py +++ b/src/plugins/gramplet/AgeStats.py @@ -83,7 +83,7 @@ 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.get_person_handles(sort_handles=False) + handles = self.dbstate.db.iter_person_handles() for h in handles: yield True p = self.dbstate.db.get_person_from_handle(h) @@ -203,7 +203,7 @@ class AgeStatsGramplet(Gramplet): print "compute_stats", hash hashkeys = sorted(hash) count = sum(hash.itervalues()) - sumval = sum([k * hash[k] for k in hash]) + sumval = sum(k * hash[k] for k in hash) minval = min(hashkeys) maxval = max(hashkeys) median = 0 diff --git a/src/plugins/gramplet/GivenNameGramplet.py b/src/plugins/gramplet/GivenNameGramplet.py index 76ee1eda8..94ba4b747 100644 --- a/src/plugins/gramplet/GivenNameGramplet.py +++ b/src/plugins/gramplet/GivenNameGramplet.py @@ -25,6 +25,8 @@ from gettext import gettext as _ from DataViews import Gramplet, register import Config +_YIELD_INTERVAL = 350 + def make_tag_size(n, counts, mins=8, maxs=20): # return font sizes mins to maxs diff = maxs - mins @@ -56,11 +58,11 @@ class GivenNameCloudGramplet(Gramplet): def main(self): self.set_text(_("Processing...") + "\n") yield True - people = self.dbstate.db.get_person_handles(sort_handles=False) + people = self.dbstate.db.iter_person_handles() givensubnames = {} representative_handle = {} - cnt = 0 - for person_handle in people: + + for cnt, person_handle in enumerate(people): person = self.dbstate.db.get_person_from_handle(person_handle) if person: allnames = [person.get_primary_name()] + person.get_alternate_names() @@ -69,32 +71,31 @@ class GivenNameCloudGramplet(Gramplet): for givensubname in givenname.split(): givensubnames[givensubname] = givensubnames.get(givensubname, 0) + 1 representative_handle[givensubname] = person_handle - if cnt % 350 == 0: + if not cnt % _YIELD_INTERVAL: yield True - cnt += 1 + total_people = cnt givensubname_sort = [] total = 0 - cnt = 0 - for givensubname in givensubnames: + + for cnt, givensubname in enumerate(givensubnames): givensubname_sort.append( (givensubnames[givensubname], givensubname) ) total += givensubnames[givensubname] - if cnt % 100 == 0: + if not cnt % _YIELD_INTERVAL: yield True - cnt += 1 + total_givensubnames = cnt - givensubname_sort.sort(lambda a,b: -cmp(a,b)) + givensubname_sort.sort(reverse=True) cloud_names = [] cloud_values = [] - cnt = 0 - for (count, givensubname) in givensubname_sort: + + for cnt, (count, givensubname) in enumerate(givensubname_sort): cloud_names.append( (count, givensubname) ) cloud_values.append( count ) - cnt += 1 - cloud_names.sort(lambda a,b: cmp(a[1], b[1])) + + cloud_names.sort(key=lambda k: k[1]) counts = list(set(cloud_values)) - counts.sort() - counts.reverse() + counts.sort(reverse=True) line = 0 ### All done! # Now, find out how many we can display without going over top_size: @@ -111,9 +112,9 @@ class GivenNameCloudGramplet(Gramplet): include_greater_than = s break # Ok, now we can show those counts > include_greater_than: - showing = 0 + self.set_text("") - for (count, givensubname) in cloud_names: # givensubname_sort: + for showing, (count, givensubname) in enumerate(cloud_names): # givensubname_sort: if count > include_greater_than: if len(givensubname) == 0: text = Config.get(Config.NO_SURNAME_TEXT) @@ -126,7 +127,7 @@ class GivenNameCloudGramplet(Gramplet): (float(count)/total_people) * 100, count)) self.append_text(" ") - showing += 1 + self.append_text(("\n\n" + _("Total unique given names") + ": %d\n") % total_givensubnames) self.append_text((_("Total given names showing") + ": %d\n") % showing) diff --git a/src/plugins/gramplet/StatsGramplet.py b/src/plugins/gramplet/StatsGramplet.py index 4a3f05dcb..4ed94a36e 100644 --- a/src/plugins/gramplet/StatsGramplet.py +++ b/src/plugins/gramplet/StatsGramplet.py @@ -36,6 +36,14 @@ from Utils import media_path_full import DateHandler import gen +#------------------------------------------------------------------------ +# +# Constants +# +#------------------------------------------------------------------------ + +_YIELD_INTERVAL = 200 + #------------------------------------------------------------------------ # # Gramplet class @@ -58,7 +66,7 @@ class StatsGramplet(Gramplet): def main(self): self.set_text(_("Processing...")) database = self.dbstate.db - personList = database.get_person_handles(sort_handles=False) + personList = database.iter_person_handles() familyList = database.get_family_handles() with_photos = 0 @@ -73,7 +81,7 @@ class StatsGramplet(Gramplet): namelist = [] notfound = [] - pobjects = len(database.get_media_object_handles()) + pobjects = database.get_number_of_media_objects() for photo_id in database.get_media_object_handles(): photo = database.get_object_from_handle(photo_id) fullname = media_path_full(database, photo.get_path()) @@ -82,8 +90,7 @@ class StatsGramplet(Gramplet): except: notfound.append(photo.get_path()) - cnt = 0 - for person_handle in personList: + for cnt, person_handle in enumerate(personList): person = database.get_person_from_handle(person_handle) if not person: continue @@ -92,16 +99,17 @@ class StatsGramplet(Gramplet): with_photos = with_photos + 1 total_photos = total_photos + length - person = database.get_person_from_handle(person_handle) names = [person.get_primary_name()] + person.get_alternate_names() for name in names: if name.get_first_name() == "" or name.get_group_name() == "": incomp_names = incomp_names + 1 if name.get_group_name() not in namelist: namelist.append(name.get_group_name()) + if ((not person.get_main_parents_family_handle()) and (not len(person.get_family_handle_list()))): disconnected = disconnected + 1 + birth_ref = person.get_birth_ref() if birth_ref: birth = database.get_event_from_handle(birth_ref.ref) @@ -109,22 +117,22 @@ class StatsGramplet(Gramplet): missing_bday = missing_bday + 1 else: missing_bday = missing_bday + 1 + if person.get_gender() == gen.lib.Person.FEMALE: females = females + 1 elif person.get_gender() == gen.lib.Person.MALE: males = males + 1 else: unknowns += 1 - if cnt % 200 == 0: + if not cnt % _YIELD_INTERVAL: yield True - cnt += 1 self.clear_text() self.append_text(_("Individuals") + "\n") self.append_text("----------------------------\n") self.link(_("Number of individuals") + ":", 'Filter', 'all people') - self.append_text(" %s" % len(personList)) + self.append_text(" %s" % database.get_number_of_people()) self.append_text("\n") self.link("%s:" % _("Males"), 'Filter', 'males') self.append_text(" %s" % males) diff --git a/src/plugins/gramplet/SurnameCloudGramplet.py b/src/plugins/gramplet/SurnameCloudGramplet.py index 51ba38c56..50eecfebd 100644 --- a/src/plugins/gramplet/SurnameCloudGramplet.py +++ b/src/plugins/gramplet/SurnameCloudGramplet.py @@ -27,6 +27,14 @@ from DataViews import register, Gramplet from TransUtils import sgettext as _ import Config +#------------------------------------------------------------------------ +# +# Constants +# +#------------------------------------------------------------------------ + +_YIELD_INTERVAL = 350 + #------------------------------------------------------------------------ # # Local functions @@ -70,11 +78,10 @@ class SurnameCloudGramplet(Gramplet): def main(self): self.set_text(_("Processing...") + "\n") yield True - people = self.dbstate.db.get_person_handles(sort_handles=False) + people = self.dbstate.db.iter_person_handles() surnames = {} representative_handle = {} - cnt = 0 - for person_handle in people: + for cnt, person_handle in enumerate(people): person = self.dbstate.db.get_person_from_handle(person_handle) if person: allnames = [person.get_primary_name()] + person.get_alternate_names() @@ -82,32 +89,29 @@ class SurnameCloudGramplet(Gramplet): for surname in allnames: surnames[surname] = surnames.get(surname, 0) + 1 representative_handle[surname] = person_handle - if cnt % 350 == 0: + if not cnt % _YIELD_INTERVAL: yield True - cnt += 1 + total_people = cnt surname_sort = [] total = 0 - cnt = 0 - for surname in surnames: + for cnt, surname in enumerate(surnames): surname_sort.append( (surnames[surname], surname) ) total += surnames[surname] - if cnt % 350 == 0: + if not cnt % _YIELD_INTERVAL: yield True - cnt += 1 + total_surnames = cnt - surname_sort.sort(lambda a,b: -cmp(a,b)) + surname_sort.sort(reverse=True) cloud_names = [] cloud_values = [] - cnt = 0 - for (count, surname) in surname_sort: + for cnt, (count, surname) in enumerate(surname_sort): cloud_names.append( (count, surname) ) cloud_values.append( count ) - cnt += 1 - cloud_names.sort(lambda a,b: cmp(a[1], b[1])) + + cloud_names.sort(key=lambda k:k[1]) counts = list(set(cloud_values)) - counts.sort() - counts.reverse() + counts.sort(reverse=True) line = 0 ### All done! # Now, find out how many we can display without going over top_size: diff --git a/src/plugins/gramplet/TopSurnamesGramplet.py b/src/plugins/gramplet/TopSurnamesGramplet.py index 2714a7dac..ef6b8a2af 100644 --- a/src/plugins/gramplet/TopSurnamesGramplet.py +++ b/src/plugins/gramplet/TopSurnamesGramplet.py @@ -27,6 +27,14 @@ from DataViews import register, Gramplet from TransUtils import sgettext as _ import Config +#------------------------------------------------------------------------ +# +# Constants +# +#------------------------------------------------------------------------ + +_YIELD_INTERVAL = 350 + #------------------------------------------------------------------------ # # Gramplet class @@ -54,11 +62,11 @@ class TopSurnamesGramplet(Gramplet): def main(self): self.set_text(_("Processing...") + "\n") - people = self.dbstate.db.get_person_handles(sort_handles=False) + people = self.dbstate.db.iter_person_handles() surnames = {} representative_handle = {} - cnt = 0 - for person_handle in people: + + for cnt, person_handle in enumerate(people): person = self.dbstate.db.get_person_from_handle(person_handle) if person: allnames = [person.get_primary_name()] + person.get_alternate_names() @@ -66,32 +74,28 @@ class TopSurnamesGramplet(Gramplet): for surname in allnames: surnames[surname] = surnames.get(surname, 0) + 1 representative_handle[surname] = person_handle - if cnt % 350 == 0: + if not cnt % _YIELD_INTERVAL: yield True - cnt += 1 + total_people = cnt surname_sort = [] total = 0 - cnt = 0 - for surname in surnames: + + for cnt, surname in enumerate(surnames): surname_sort.append( (surnames[surname], surname) ) total += surnames[surname] - if cnt % 350 == 0: + if not cnt % _YIELD_INTERVAL: yield True - cnt += 1 + total_surnames = cnt - surname_sort.sort(lambda a,b: -cmp(a,b)) + surname_sort.sort(reverse=True) line = 0 ### All done! self.set_text("") + nosurname = Config.get(Config.NO_SURNAME_TEXT) for (count, surname) in surname_sort: - if len(surname) == 0: - text = "%s, %d%% (%d)\n" % (Config.get(Config.NO_SURNAME_TEXT), - int((float(count)/total) * 100), - count) - else: - text = "%s, %d%% (%d)\n" % (surname, int((float(count)/total) * 100), - count) + text = "%s, " % (surname if surname else nosurname) + text += "%d%% (%d)\n" % (int((float(count)/total) * 100), count) self.append_text(" %d. " % (line + 1)) self.link(text, 'Surname', representative_handle[surname]) line += 1 diff --git a/src/plugins/graph/GVRelGraph.py b/src/plugins/graph/GVRelGraph.py index e88ab83e7..9bbe75dfd 100644 --- a/src/plugins/graph/GVRelGraph.py +++ b/src/plugins/graph/GVRelGraph.py @@ -153,7 +153,7 @@ class RelGraphReport(Report): def write_report(self): self.person_handles = self._filter.apply(self.database, - self.database.get_person_handles(sort_handles=False)) + self.database.iter_person_handles()) if len(self.person_handles) > 1: self.add_persons_and_families() @@ -164,9 +164,9 @@ class RelGraphReport(Report): children" person_dict = {} # Hash people in a dictionary for faster inclusion checking + for person_handle in self.person_handles: person_dict[person_handle] = 1 - for person_handle in self.person_handles: person = self.database.get_person_from_handle(person_handle) p_id = person.get_gramps_id() for fam_handle in person.get_parent_family_handle_list(): diff --git a/src/plugins/quickview/AttributeMatch.py b/src/plugins/quickview/AttributeMatch.py index 5994d3643..1aa9bfbe2 100644 --- a/src/plugins/quickview/AttributeMatch.py +++ b/src/plugins/quickview/AttributeMatch.py @@ -34,7 +34,7 @@ def run(database, document, attribute, value=None): sdoc.paragraph("") stab.columns(_("Person"), str(attribute)) matches = 0 - for person_handle in database.get_person_handles(sort_handles=False): + for person_handle in database.iter_person_handles(): person = database.get_person_from_handle(person_handle) matched = False for attr in person.attribute_list: diff --git a/src/plugins/quickview/FilterByName.py b/src/plugins/quickview/FilterByName.py index cbc5bb2f3..41dedff10 100644 --- a/src/plugins/quickview/FilterByName.py +++ b/src/plugins/quickview/FilterByName.py @@ -60,7 +60,7 @@ def run(database, document, filter_name, *args, **kwargs): matches = 0 if (filter_name == 'all people'): stab.columns(_("Person"), _("Birth Date"), _("Name type")) - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) stab.row(person, sdb.birth_date_obj(person), @@ -68,7 +68,7 @@ def run(database, document, filter_name, *args, **kwargs): matches += 1 elif (filter_name == 'males'): stab.columns(_("Person"), _("Birth Date"), _("Name type")) - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) if person.gender == Person.MALE: @@ -77,7 +77,7 @@ def run(database, document, filter_name, *args, **kwargs): matches += 1 elif (filter_name == 'females'): stab.columns(_("Person"), _("Birth Date"), _("Name type")) - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) if person.gender == Person.FEMALE: @@ -86,7 +86,7 @@ def run(database, document, filter_name, *args, **kwargs): matches += 1 elif (filter_name == 'people with unknown gender'): stab.columns(_("Person"), _("Birth Date"), _("Name type")) - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) if person.gender not in [Person.FEMALE, Person.MALE]: @@ -95,7 +95,7 @@ def run(database, document, filter_name, *args, **kwargs): matches += 1 elif (filter_name == 'people with incomplete names'): stab.columns(_("Person"), _("Birth Date"), _("Name type")) - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) for name in [person.get_primary_name()] + person.get_alternate_names(): @@ -105,7 +105,7 @@ def run(database, document, filter_name, *args, **kwargs): matches += 1 elif (filter_name == 'people with missing birth dates'): stab.columns(_("Person"), _("Type")) - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) if person: @@ -120,7 +120,7 @@ def run(database, document, filter_name, *args, **kwargs): matches += 1 elif (filter_name == 'disconnected people'): stab.columns(_("Person"), _("Birth Date"), _("Name type")) - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) if person: @@ -139,7 +139,7 @@ def run(database, document, filter_name, *args, **kwargs): matches += 1 elif (filter_name == 'unique surnames'): namelist = {} - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) if person: @@ -158,7 +158,7 @@ def run(database, document, filter_name, *args, **kwargs): name)) elif (filter_name == 'people with media'): stab.columns(_("Person"), _("Media count")) - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) if not person: @@ -169,7 +169,7 @@ def run(database, document, filter_name, *args, **kwargs): matches += 1 elif (filter_name == 'media references'): stab.columns(_("Person"), _("Reference")) - people = database.get_person_handles(sort_handles=False) + people = database.iter_person_handles() for person_handle in people: person = database.get_person_from_handle(person_handle) if not person: diff --git a/src/plugins/quickview/SameSurnames.py b/src/plugins/quickview/SameSurnames.py index 0eb3551d0..da5b3005d 100644 --- a/src/plugins/quickview/SameSurnames.py +++ b/src/plugins/quickview/SameSurnames.py @@ -115,13 +115,13 @@ def run(database, document, person): rule = IncompleteSurname([]) filter.add_rule(rule) people = filter.apply(database, - database.get_person_handles(sort_handles=False)) - matches = 0 - for person_handle in people: + database.iter_person_handles()) + + for matches, person_handle in enumerate(people): person = database.get_person_from_handle(person_handle) stab.row(person, sdb.birth_date_obj(person), str(person.get_primary_name().get_type())) - matches += 1 + sdoc.paragraph(ngettext("There is %d person with a matching name, or alternate name.\n" , "There are %d people with a matching name, or alternate name.\n" @@ -154,13 +154,12 @@ def run_given(database, document, person): rule = IncompleteGiven([]) filter.add_rule(rule) people = filter.apply(database, - database.get_person_handles(sort_handles=False)) - matches = 0 - for person_handle in people: + database.iter_person_handles()) + for matches, person_handle in enumerate(people): person = database.get_person_from_handle(person_handle) stab.row(person, sdb.birth_date_obj(person), str(person.get_primary_name().get_type())) - matches += 1 + sdoc.paragraph(ngettext("There is %d person with a matching name, or alternate name.\n" , "There are %d people with a matching name, or alternate name.\n" diff --git a/src/plugins/textreport/BirthdayReport.py b/src/plugins/textreport/BirthdayReport.py index 855f03c24..e841863c3 100644 --- a/src/plugins/textreport/BirthdayReport.py +++ b/src/plugins/textreport/BirthdayReport.py @@ -193,8 +193,9 @@ class CalendarReport(Report): This method runs through the data, and collects the relevant dates and text. """ - people = self.database.get_person_handles(sort_handles=False) - self.progress.set_pass(_('Applying Filter...'), len(people)) + people = self.database.iter_person_handles() + self.progress.set_pass(_('Applying Filter...'), + self.database.get_number_of_people()) people = self.filter.apply(self.database, people, self.progress) pmgr = PluginManager.get_instance() rel_calc = pmgr.get_relationship_calculator() diff --git a/src/plugins/textreport/IndivComplete.py b/src/plugins/textreport/IndivComplete.py index 8fa1e30be..3c17ffa5a 100644 --- a/src/plugins/textreport/IndivComplete.py +++ b/src/plugins/textreport/IndivComplete.py @@ -379,18 +379,16 @@ class IndivCompleteReport(Report): self.doc.end_cell() def write_report(self): - plist = self.database.get_person_handles(sort_handles=False) + plist = self.database.iter_person_handles() if self.filter: ind_list = self.filter.apply(self.database,plist) else: ind_list = plist - count = 0 - for person_handle in ind_list: + for count, person_handle in enumerate(ind_list): self.person = self.database.get_person_from_handle( person_handle) self.write_person(count) - count = count + 1 def write_person(self,count): if count != 0: diff --git a/src/plugins/textreport/MarkerReport.py b/src/plugins/textreport/MarkerReport.py index aca1c10dc..e9aba646a 100644 --- a/src/plugins/textreport/MarkerReport.py +++ b/src/plugins/textreport/MarkerReport.py @@ -91,7 +91,7 @@ class MarkerReport(Report): self.write_notes() def write_people(self): - plist = self.database.get_person_handles(sort_handles=False) + plist = self.database.iter_person_handles() FilterClass = GenericFilterFactory('Person') filter = FilterClass() filter.add_rule(Rules.Person.HasMarkerOf([self.marker])) diff --git a/src/plugins/textreport/Summary.py b/src/plugins/textreport/Summary.py index 7060ebb4b..9ad847521 100644 --- a/src/plugins/textreport/Summary.py +++ b/src/plugins/textreport/Summary.py @@ -99,11 +99,12 @@ class SummaryReport(Report): self.doc.write_text(_("Individuals")) self.doc.end_paragraph() - person_list = self.__db.get_person_handles(sort_handles=False) - for person_handle in person_list: + person_list = self.__db.iter_person_handles() + for num_people, person_handle in enumerate(person_list): person = self.__db.get_person_from_handle(person_handle) if not person: continue + num_people += 1 # Count people with media. length = len(person.get_media_list()) @@ -142,7 +143,7 @@ class SummaryReport(Report): namelist.append(name.get_surname()) self.doc.start_paragraph("SR-Normal") - self.doc.write_text(_("Number of individuals: %d") % len(person_list)) + self.doc.write_text(_("Number of individuals: %d") % num_people) self.doc.end_paragraph() self.doc.start_paragraph("SR-Normal") diff --git a/src/plugins/tool/CalculateEstimatedDates.py b/src/plugins/tool/CalculateEstimatedDates.py index 0d9e1b91d..55c1ce0ba 100644 --- a/src/plugins/tool/CalculateEstimatedDates.py +++ b/src/plugins/tool/CalculateEstimatedDates.py @@ -160,7 +160,8 @@ class CalcToolManagedWindow(PluginWindows.ToolManagedWindowBatch): self.filter_option = self.options.menu.get_option_by_name('filter') self.filter = self.filter_option.get_filter() # the actual filter people = self.filter.apply(self.db, - self.db.get_person_handles(sort_handles=False)) + self.db.iter_person_handles()) + num_people = self.db.get_number_of_people() source_text = self.options.handler.options_dict['source_text'] add_birth = self.options.handler.options_dict['add_birth'] add_death = self.options.handler.options_dict['add_death'] @@ -174,7 +175,7 @@ class CalcToolManagedWindow(PluginWindows.ToolManagedWindowBatch): if remove_old: self.results_write(_("Replacing...\n")) self.progress.set_pass((_("Removing '%s'...") % source_text), - len(people)) + num_people) for person_handle in people: self.progress.step() pupdate = 0 @@ -216,7 +217,7 @@ class CalcToolManagedWindow(PluginWindows.ToolManagedWindowBatch): if add_birth or add_death: self.results_write(_("Calculating...\n")) self.progress.set_pass(_('Calculating estimated dates...'), - len(people)) + num_people) source = self.get_or_create_source(source_text) for person_handle in people: self.progress.step() diff --git a/src/plugins/tool/ChangeNames.py b/src/plugins/tool/ChangeNames.py index 9ad2a879f..eab2231b4 100644 --- a/src/plugins/tool/ChangeNames.py +++ b/src/plugins/tool/ChangeNames.py @@ -107,7 +107,7 @@ class ChangeNames(Tool.BatchTool, ManagedWindow.ManagedWindow): s1 = 0 if namesplitSP[0].lower() in prefix_list: s1 = 1 - for x in range(len(namesplitSP)-s1): + for x in xrange(len(namesplitSP)-s1): # check if any subsurname is not cap notcap = False if namesplitSP[s1+x] != namesplitSP[s1+x].capitalize(): @@ -121,7 +121,7 @@ class ChangeNames(Tool.BatchTool, ManagedWindow.ManagedWindow): # check if first string is in prefix_list, if so test for cap if namesplitSP[0].lower() in prefix_list: namesplitHY[0] = namesplitHY[0].replace(namesplitSP[0],'').strip() - for x in range(len(namesplitHY)): + for x in xrange(len(namesplitHY)): # check if any subsurname is not cap notcap = False if namesplitHY[x] != namesplitHY[x].capitalize(): @@ -234,7 +234,7 @@ class ChangeNames(Tool.BatchTool, ManagedWindow.ManagedWindow): for node in self.iter_list if self.model.get_value(node,0)] - for handle in self.db.get_person_handles(): + for handle in self.db.iter_person_handles(): change = False person = self.db.get_person_from_handle(handle) for name in [person.get_primary_name()] + person.get_alternate_names(): diff --git a/src/plugins/tool/EventCmp.py b/src/plugins/tool/EventCmp.py index af36b2b91..93badaf4c 100644 --- a/src/plugins/tool/EventCmp.py +++ b/src/plugins/tool/EventCmp.py @@ -176,7 +176,7 @@ class EventComparison(Tool.Tool,ManagedWindow.ManagedWindow): progress_bar.set_pass(_('Selecting people'),1) plist = cfilter.apply(self.db, - self.db.get_person_handles(sort_handles=False)) + self.db.iter_person_handles()) progress_bar.step() progress_bar.close() diff --git a/src/plugins/tool/EventNames.py b/src/plugins/tool/EventNames.py index 10838cca7..2c39b7f90 100644 --- a/src/plugins/tool/EventNames.py +++ b/src/plugins/tool/EventNames.py @@ -83,7 +83,7 @@ class EventNames(Tool.BatchTool, ManagedWindow.ManagedWindow): self.change = False counter = 0 - for handle in self.db.get_person_handles(): + for handle in self.db.iter_person_handles(): person = self.db.get_person_from_handle(handle) for event_ref in person.get_event_ref_list(): if event_ref.get_role() == gen.lib.EventRoleType.PRIMARY: diff --git a/src/plugins/tool/FindDupes.py b/src/plugins/tool/FindDupes.py index 1b04addba..dde339ea1 100644 --- a/src/plugins/tool/FindDupes.py +++ b/src/plugins/tool/FindDupes.py @@ -187,13 +187,12 @@ class Merge(Tool.Tool,ManagedWindow.ManagedWindow): males = {} females = {} - self.person_list = self.db.get_person_handles(sort_handles=False) - length = len(self.person_list) + length = self.db.get_number_of_people() self.progress.set_pass(_('Pass 1: Building preliminary lists'), length) - for p1_id in self.person_list: + for p1_id in self.db.iter_person_handles(): self.progress.step() p1 = self.db.get_person_from_handle(p1_id) key = self.gen_key(p1.get_primary_name().get_surname()) @@ -211,7 +210,7 @@ class Merge(Tool.Tool,ManagedWindow.ManagedWindow): self.progress.set_pass(_('Pass 2: Calculating potential matches'), length) - for p1key in self.person_list: + for p1key in self.db.iter_person_handles(): self.progress.step() p1 = self.db.get_person_from_handle(p1key) @@ -221,9 +220,9 @@ class Merge(Tool.Tool,ManagedWindow.ManagedWindow): else: remaining = females[key] - index = 0 + #index = 0 for p2key in remaining: - index += 1 + #index += 1 if p1key == p2key: continue p2 = self.db.get_person_from_handle(p2key) diff --git a/src/plugins/tool/NotRelated.py b/src/plugins/tool/NotRelated.py index 7944e84f5..7a390cdc7 100644 --- a/src/plugins/tool/NotRelated.py +++ b/src/plugins/tool/NotRelated.py @@ -333,7 +333,7 @@ class NotRelated(Tool.ActivePersonTool, ManagedWindow.ManagedWindow) : self.numberOfUnrelatedPeople, self.numberOfPeopleInDatabase) # loop through everyone in the database - for handle in self.db.get_person_handles(False): + for handle in self.db.iter_person_handles(): self.progress.step() diff --git a/src/plugins/tool/PatchNames.py b/src/plugins/tool/PatchNames.py index ba20f0edb..b83a02ac3 100644 --- a/src/plugins/tool/PatchNames.py +++ b/src/plugins/tool/PatchNames.py @@ -122,7 +122,7 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow): self.progress.set_pass(_('Analyzing names'), self.db.get_number_of_people()) - for key in self.db.get_person_handles(sort_handles=False): + for key in self.db.iter_person_handles(): person = self.db.get_person_from_handle(key) name = person.get_primary_name() diff --git a/src/plugins/tool/SortEvents.py b/src/plugins/tool/SortEvents.py index dced3bae3..36b7fcacd 100644 --- a/src/plugins/tool/SortEvents.py +++ b/src/plugins/tool/SortEvents.py @@ -110,9 +110,9 @@ class SortEvents(PluginWindows.ToolManagedWindowBatch): Sort the personal events associated with the selected people. """ people_handles = self.filter.apply(self.db, - self.db.get_person_handles(sort_handles=False)) + self.db.iter_person_handles()) self.progress.set_pass(_("Sorting personal events..."), - len(people_handles)) + self.db.get_number_of_people()) family_handles = [] for handle in people_handles: person = self.db.get_person_from_handle(handle) diff --git a/src/plugins/tool/SoundGen.py b/src/plugins/tool/SoundGen.py index 2c237c7ad..73cd3147a 100644 --- a/src/plugins/tool/SoundGen.py +++ b/src/plugins/tool/SoundGen.py @@ -76,7 +76,7 @@ class SoundGen(Tool.Tool, ManagedWindow.ManagedWindow): names = [] person = None - for person_handle in self.db.get_person_handles(sort_handles=False): + for person_handle in self.db.iter_person_handles(): person = self.db.get_person_from_handle(person_handle) lastname = person.get_primary_name().get_surname() if lastname not in names: diff --git a/src/plugins/tool/Verify.py b/src/plugins/tool/Verify.py index 24dc69ad9..18cc6a885 100644 --- a/src/plugins/tool/Verify.py +++ b/src/plugins/tool/Verify.py @@ -316,7 +316,7 @@ class Verify(Tool.Tool, ManagedWindow, UpdateCallback): def run_tool(self,cli=False): - person_handles = self.db.get_person_handles(sort_handles=False) + person_handles = self.db.iter_person_handles() for option, value in \ self.options.handler.options_dict.iteritems(): diff --git a/src/plugins/webreport/NarrativeWeb.py b/src/plugins/webreport/NarrativeWeb.py index 47dbcd181..977ec1346 100644 --- a/src/plugins/webreport/NarrativeWeb.py +++ b/src/plugins/webreport/NarrativeWeb.py @@ -1736,7 +1736,7 @@ class MediaPage(BasePage): # TODO. Mixup url and path # path = convert_disk_path_to_url(path) url = self.report.build_url_fname(path, None, self.up) - hyper += Html('img', src=url, alt=html_escape(self.page_title) + hyper += Html('img', src=url, alt=html_escape(self.page_title)) if target_exists: mediadisplay += hyper else: @@ -4186,8 +4186,9 @@ class NavWebReport(Report): """ # gets the person list and applies the requested filter - ind_list = self.database.get_person_handles(sort_handles=False) - self.progress.set_pass(_('Applying Filter...'), len(ind_list)) + + ind_list = self.database.iter_person_handles() + self.progress.set_pass(_('Applying Filter...'), self.database.get_number_of_people()) ind_list = self.filter.apply(self.database, ind_list, self.progress) return ind_list diff --git a/src/plugins/webreport/WebCal.py b/src/plugins/webreport/WebCal.py index 325fe5dee..f55c8bc34 100644 --- a/src/plugins/webreport/WebCal.py +++ b/src/plugins/webreport/WebCal.py @@ -1078,8 +1078,8 @@ class WebCalReport(Report): This method runs through the data, and collects the relevant dates and text. """ - people = self.database.get_person_handles(sort_handles=False) - self.progress.set_pass(_('Applying Filter...'), len(people)) + people = self.database.iter_person_handles() + self.progress.set_pass(_('Applying Filter...'), self.database.get_number_of_people()) people = self.filter.apply(self.database, people, self.progress) self.progress.set_pass(_("Reading database..."), len(people))