Use built-in functions to replace for loops:

Old code:

for x in y:
  f(x)

New Code:

map(f, y)

Also use defaultdict instead of simple dict when advantageous and use list comprehensions
instead of for loops where map() could be used but requires lambdas.


svn: r14135
This commit is contained in:
Gerald Britton 2010-01-25 17:45:21 +00:00
parent fbb8fa2a52
commit 8f0582df8a
49 changed files with 125 additions and 188 deletions

View File

@ -143,8 +143,7 @@ class DeepRelationshipPathBetween(Rule):
progress = None
self.__matches = set()
for path in paths:
self.__matches.update(path)
map(self.__matches.update, paths)
def reset(self):
self.__matches = set()

View File

@ -94,8 +94,8 @@ class PersonSidebarFilter(SidebarFilter):
self.filter_note = gtk.Entry()
self.filter_gender = gtk.combo_box_new_text()
for i in [ _('any'), _('male'), _('female'), _('unknown') ]:
self.filter_gender.append_text(i)
map(self.filter_gender.append_text,
[ _('any'), _('male'), _('female'), _('unknown') ])
self.filter_gender.set_active(0)
self.filter_regex = gtk.CheckButton(_('Use regular expressions'))

View File

@ -675,8 +675,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
# Date format:
obox = gtk.combo_box_new_text()
formats = DateHandler.get_date_formats()
for item in formats:
obox.append_text(item)
map(obox.append_text, formats)
active = config.get('preferences.date-format')
if active >= len(formats):
active = 0
@ -689,8 +688,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
# Calendar format on report:
obox = gtk.combo_box_new_text()
for item in gen.lib.Date.ui_calendar_names:
obox.append_text(item)
map(obox.append_text, gen.lib.Date.ui_calendar_names)
active = config.get('preferences.calendar-format-report')
if active >= len(formats):
active = 0
@ -704,8 +702,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
# Surname guessing:
obox = gtk.combo_box_new_text()
formats = _surname_styles
for item in formats:
obox.append_text(item)
map(obox.append_text, formats)
obox.set_active(config.get('behavior.surname-guessing'))
obox.connect('changed',
lambda obj: config.set('behavior.surname-guessing',
@ -719,8 +716,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
obox = gtk.combo_box_new_text()
formats = [_("Active person's name and ID"),
_("Relationship to home person")]
for item in formats:
obox.append_text(item)
map(obox.append_text, formats)
active = config.get('interface.statusbar')
if active < 2:
obox.set_active(0)

View File

@ -457,10 +457,8 @@ class MergePeople(object):
self.p2.get_source_references())
# media
for photo in self.p1.get_media_list():
new.add_media_reference(photo)
for photo in self.p2.get_media_list():
new.add_media_reference(photo)
map(new.add_media_reference, self.p1.get_media_list())
map(new.add_media_reference, self.p2.get_media_list())
# note
new.set_note_list(self.p1.get_note_list() +
@ -847,8 +845,7 @@ class MergePeople(object):
# merge family attributes
for xdata in src_family.get_attribute_list():
tgt_family.add_attribute(xdata)
map(tgt_family.add_attribute, src_family.get_attribute_list())
# merge family notes
tgt_family.set_note_list(tgt_family.get_note_list() +
@ -860,8 +857,7 @@ class MergePeople(object):
# merge multimedia objects
for photo in src_family.get_media_list():
tgt_family.add_media_reference(photo)
map(tgt_family.add_media_reference, src_family.get_media_list())
def adjust_family_pointers(self, tgt_family, src_family, trans):
"""

View File

@ -124,16 +124,13 @@ class MergePlaces(ManagedWindow.ManagedWindow):
self.p1.set_latitude(self.p2.get_latitude())
# Add URLs from P2 to P1
for url in self.p2.get_url_list():
self.p1.add_url(url)
map(self.p1.add_url, self.p2.get_url_list())
# Copy photos from P2 to P1
for photo in self.p2.get_media_list():
self.p1.add_media_reference(photo)
map(self.p1.add_media_reference, self.p2.get_media_list())
# Copy sources from P2 to P1
for source in self.p2.get_source_references():
self.p1.add_source_reference(source)
map(self.p1.add_source_reference, self.p2.get_source_references())
# Add notes from P2 to P1
self.p1.set_note_list(self.p1.get_note_list() +

View File

@ -144,8 +144,7 @@ class MergeSources(ManagedWindow.ManagedWindow):
self.s1.set_gramps_id(self.s2.get_gramps_id())
# Copy photos from src2 to src1
for photo in self.s2.get_media_list():
self.s1.add_media_reference(photo)
map(self.s1.add_media_reference, self.s2.get_media_list())
# Add notes from S2 to S1
self.s1.set_note_list(self.s1.get_note_list() + self.s2.get_note_list())

View File

@ -1750,8 +1750,7 @@ class RelationshipCalculator(object):
subscribed
"""
dbstate.disconnect(self.state_signal_key)
for key in self.signal_keys:
dbstate.db.disconnect(key)
map(dbstate.db.disconnect, self.signal_keys)
self.storemap = False
self.stored_map = None

View File

@ -1601,7 +1601,8 @@ class DbWriteBase(object):
self.set_default_person_handle(None)
# loop through the family list
for family_handle in filter(None, person.get_family_handle_list()):
for family_handle in person.get_family_handle_list():
if not family_handle: continue
family = self.get_family_from_handle(family_handle)

View File

@ -84,8 +84,7 @@ class NoteBase(object):
"""
if handle in self.note_list:
self.note_list.remove(handle)
for item in self.get_note_child_list():
item.remove_note(handle)
map(item.remove_note, self.get_note_child_list())
def get_note_child_list(self):
"""

View File

@ -140,8 +140,7 @@ class CallbackManager(object):
This method should always be called before a the callback methods
become invalid.
"""
for key in self.custom_signal_keys:
self.database.disconnect(key)
map(self.database.disconnect, self.custom_signal_keys)
self.custom_signal_keys = []
for key, value in self.__callbacks.iteritems():
if not value[1] is None:
@ -186,8 +185,7 @@ class CallbackManager(object):
for key in KEYS:
handles = ahandledict.get(key)
if handles:
for handle in handles:
self.__handles[key].remove(handle)
map(self.__handles[key].remove, handles)
def unregister_all(self):
"""

View File

@ -414,8 +414,7 @@ class EmbeddedList(ButtonTab):
# remove any existing columns, which would be stored in
# self.columns
for column in self.columns:
self.tree.remove_column(column)
map(self.tree.remove_column, self.columns)
self.columns = []
# loop through the values returned by column_order

View File

@ -125,12 +125,8 @@ class NameEmbedList(GroupEmbeddedList):
def set_default_name(self, name):
pname = self.person.get_primary_name()
self.person.set_primary_name(name)
remove = []
for altname in self.data:
if altname.is_equal(name):
remove.append(altname)
for altname in remove:
self.data.remove(altname)
remove = [altname for altname in self.data if altname.is_equal(name)]
map(self.data.remove, remove)
#only non empty name should move to alternative names
if not name.is_equal(gen.lib.Name()):
self.data.append(pname)

View File

@ -166,8 +166,7 @@ class ChildEmbedList(EmbeddedList):
self.rebuild()
def build_columns(self):
for column in self.columns:
self.tree.remove_column(column)
map(self.tree.remove_column, self.columns)
self.columns = []
for pair in self.column_order():

View File

@ -182,8 +182,9 @@ class EditPrimary(ManagedWindow.ManagedWindow, DbGUIElement):
"""
#cleanup callbackmanager of this editor
self._cleanup_callbacks()
for tab in [tab for tab in self.__tabs if hasattr(tab, 'callman')]:
tab._cleanup_callbacks()
for tab in self.__tabs:
if hasattr(tab, 'callman'):
tab._cleanup_callbacks()
def check_for_close(self, handles):
"""

View File

@ -212,8 +212,7 @@ class ObjEntry(object):
If True: remove icon and edit icon
"""
if self.add_edt is not None:
for i in self.add_edt.get_children():
self.add_edt.remove(i)
map(self.add_edt.remove, self.add_edt.get_children())
for i in self.share.get_children():
self.share.remove(i)

View File

@ -1056,8 +1056,7 @@ class FilterEditor(ManagedWindow.ManagedWindow):
# Remove what we found
filters = self.filterdb.get_filters(space)
for the_filter in filter_set:
filters.remove(the_filter)
map(filters.remove, filter_set)
def _find_dependent_filters(self, space, gfilter, filter_set):
"""

View File

@ -81,9 +81,7 @@ class GuiPluginManager(gen.utils.Callback):
gen.utils.Callback.__init__(self)
self.basemgr = BasePluginManager.get_instance()
self.__hidden_plugins = set([])
for id in config.get('plugin.hiddenplugins'):
self.__hidden_plugins.add(id)
self.__hidden_plugins = set(config.get('plugin.hiddenplugins'))
self.__hidden_changed()
def reload_plugins(self):

View File

@ -1065,8 +1065,7 @@ class ViewManager(CLIManager):
Disconnects the previous page, removing the old action groups
and removes the old UI components.
"""
for mergeid in self.merge_ids:
self.uimanager.remove_ui(mergeid)
map(self.uimanager.remove_ui, self.merge_ids)
if self.active_page:
self.active_page.set_inactive()

View File

@ -207,8 +207,7 @@ class ListView(NavigationView):
callback=self.filter_toggle_action)
def build_columns(self):
for column in self.columns:
self.list.remove_column(column)
map(self.list.remove_column, self.columns)
self.columns = []
@ -669,8 +668,7 @@ class ListView(NavigationView):
if self.active or \
(not self.dirty and not self._dirty_on_change_inactive):
cput = time.clock()
for handle in handle_list:
self.model.add_row_by_handle(handle)
map(self.model.add_row_by_handle, handle_list)
_LOG.debug(' ' + self.__class__.__name__ + ' row_add ' +
str(time.clock() - cput) + ' sec')
if self.active:
@ -689,8 +687,7 @@ class ListView(NavigationView):
if self.active or \
(not self.dirty and not self._dirty_on_change_inactive):
cput = time.clock()
for handle in handle_list:
self.model.update_row_by_handle(handle)
map(self.model.update_row_by_handle, handle_list)
_LOG.debug(' ' + self.__class__.__name__ + ' row_update ' +
str(time.clock() - cput) + ' sec')
# Ensure row is still selected after a change of postion in tree.

View File

@ -370,10 +370,9 @@ class RecordsReport(Report):
self.callname = menu.get_option_by_name('callname').get_value()
self.include = {}
for (text, varname, default) in RECORDS:
self.include[varname] = menu.get_option_by_name(varname).get_value()
self.include = dict([varname,
menu.get_option_by_name(varname).get_value()]
for (_1, varname, _3) in RECORDS)
def write_report(self):
"""

View File

@ -163,11 +163,11 @@ class RTFDoc(BaseDoc,TextDoc):
else:
self.font_type = '\\f1\\fs%d\\cf%d\\cb%d' % (size,fgindex,bgindex)
if f.get_bold():
self.font_type = self.font_type + "\\b"
self.font_type += "\\b"
if f.get_underline():
self.font_type = self.font_type + "\\ul"
self.font_type += "\\ul"
if f.get_italic():
self.font_type = self.font_type + "\\i"
self.font_type += "\\i"
# build paragraph information
@ -228,7 +228,7 @@ class RTFDoc(BaseDoc,TextDoc):
else:
if self.text == "":
self.write_text(" ")
self.text = self.text + '}'
self.text += '}'
#--------------------------------------------------------------------
#
@ -261,10 +261,10 @@ class RTFDoc(BaseDoc,TextDoc):
self.f.write('}')
def start_superscript(self):
self.text = self.text + '{{\*\updnprop5801}\up10 '
self.text += '{{\*\updnprop5801}\up10 '
def end_superscript(self):
self.text = self.text + '}'
self.text += '}'
#--------------------------------------------------------------------
#
@ -338,10 +338,10 @@ class RTFDoc(BaseDoc,TextDoc):
self.f.write('\\clbrdrr\\brdrs\\brdrw10\n')
table_width = float(self.paper.get_usable_width())
for cell in range(self.cell,self.cell+span):
self.cell_percent = self.cell_percent + float(self.tbl_style.get_column_width(cell))
self.cell_percent += float(self.tbl_style.get_column_width(cell))
cell_width = twips((table_width * self.cell_percent)/100.0)
self.f.write('\\cellx%d\\pard\intbl\n' % cell_width)
self.cell = self.cell+1
self.cell += 1
#--------------------------------------------------------------------
#
@ -464,12 +464,12 @@ class RTFDoc(BaseDoc,TextDoc):
text = text.replace('\n','\n\\par ')
if self.opened == 0:
self.opened = 1
self.text = self.text + '{%s ' % self.font_type
self.text += '{%s ' % self.font_type
for i in text:
if ord(i) > 127:
self.text = self.text + '\\\'%2x' % ord(i)
self.text += '\\\'%2x' % ord(i)
elif i == '{' or i == '}' :
self.text = self.text + '\\%s' % i
self.text += '\\%s' % i
else:
self.text = self.text + i
self.text += i

View File

@ -187,17 +187,14 @@ class FanChart(Report):
return
self.map[index-1] = person_handle
self.text[index-1] = []
subst = SubstKeywords(self.database,person_handle)
for line in self.display:
self.text[index-1].append(subst.replace(line))
self.text[index-1] = map(subst.replace, self.display)
style_sheet = self.doc.get_style_sheet()
self.font = style_sheet.get_paragraph_style('text_style').get_font()
for line in self.text[index-1]:
self.box_width = max(self.box_width,self.doc.string_width(self.font,line))
self.box_width = max(self.box_width,
self.doc.string_width(self.font,line))
self.lines = max(self.lines,len(self.text[index-1]))

View File

@ -448,10 +448,8 @@ class Extract(object):
def get_event_ages(self, data):
"return ages at given (person,event_handles)"
ages = []
person, event_handles = data
for event_handle in event_handles:
ages.append(self.estimate_age(person, event_handle))
ages = [self.estimate_age(person, h) for h in event_handles]
if ages:
return ages
return [_("Events missing")]
@ -582,9 +580,7 @@ class Extract(object):
def get_event_handles(self, person):
"return list of event handles for given person or None"
events = []
for event_ref in person.get_event_ref_list():
events.append(event_ref.ref)
events = [ref.ref for ref in person.get_event_ref_list()]
if events:
return (person, events)
@ -842,9 +838,7 @@ class StatisticsChart(Report):
pad = row_h * 0.5
# check maximum value
max_value = 0
for key in lookup:
max_value = max(data[key], max_value)
max_value = reduce(max, map(data.get, lookup), 0)
# horizontal area for the gfx bars
margin = 1.0
middle = width/2.0

View File

@ -140,8 +140,7 @@ class UnicodeWriter(object):
self.queue.truncate(0)
def writerows(self, rows):
for row in rows:
self.writerow(row)
map(self.writerow, rows)
def close(self):
self.stream.close()
@ -253,8 +252,8 @@ 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.iter_person_handles():
self.plist[p] = 1
self.plist.update([p, 1] for p in self.db.iter_person_handles())
# get the families for which these people are spouses:
self.flist = {}
for key in self.plist:

View File

@ -174,8 +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.iter_person_handles():
self.plist[p] = 1
self.plist.update([p, 1] for p in self.db.iter_person_handles())
self.flist = {}
for key in self.plist:

View File

@ -144,13 +144,13 @@ class CalendarWriter(object):
self.option_box.parse_options()
if self.option_box.cfilter is None:
for p in self.db.iter_person_handles():
self.plist[p] = 1
self.plist.udpate([p, 1]
for p in self.db.iter_person_handles())
else:
try:
for p in self.option_box.cfilter.apply(self.db,
self.db.iter_person_handles()):
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)

View File

@ -158,8 +158,7 @@ class CardWriter(object):
self.oldval = newval
def cl_setup(self):
for p in self.db.iter_person_handles():
self.plist[p] = 1
self.plist.update([p, 1] for p in self.db.iter_person_handles())
def writeln(self, text):
#self.g.write('%s\n' % (text.encode('iso-8859-1')))

View File

@ -1078,8 +1078,7 @@ class GrampsXmlWriter(UpdateCallback):
self.g.write('%s<coord long="%s" lat="%s"/>\n'
% (" "*(index+1), longitude, lat))
self.dump_location(main_loc)
for loc in place.get_alternate_locations():
self.dump_location(loc)
map(self.dump_location, place.get_alternate_locations())
self.write_media_list(place.get_media_list(), index+1)
self.write_url_list(place.get_url_list())
self.write_note_list(place.get_note_list(), index+1)

View File

@ -25,6 +25,7 @@ This Gramplet shows textual distributions of age breakdowns of various types.
"""
import locale
from collections import defaultdict
from gen.plug import Gramplet
from gen.ggettext import gettext as _
@ -80,9 +81,9 @@ class AgeStatsGramplet(Gramplet):
def main(self):
self.clear_text()
age_dict = {}
mother_dict = {}
father_dict = {}
age_dict = defaultdict(int)
mother_dict = defaultdict(int)
father_dict = defaultdict(int)
age_handles = [[]] * self.max_age
mother_handles = [[]] * self.max_mother_diff
father_handles = [[]] * self.max_father_diff
@ -105,7 +106,7 @@ class AgeStatsGramplet(Gramplet):
if death_date and birth_date and birth_date.get_year() != 0:
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_dict[age] += 1
age_handles[age].append(p.handle)
#else:
# print "Age out of range: %d for %s" % (age,
@ -138,7 +139,7 @@ class AgeStatsGramplet(Gramplet):
if bdate and birth_date and birth_date.get_year() != 0:
diff = birth_date.get_year() - bdate.get_year()
if diff >= 0 and diff < self.max_father_diff:
father_dict[diff] = father_dict.get(diff, 0) + 1
father_dict[diff] += 1
father_handles[diff].append(f_handle)
#else:
# print "Father diff out of range: %d for %s" % (diff,
@ -153,7 +154,7 @@ class AgeStatsGramplet(Gramplet):
if bdate and birth_date and birth_date.get_year() != 0:
diff = birth_date.get_year() - bdate.get_year()
if diff >= 0 and diff < self.max_mother_diff:
mother_dict[diff] = mother_dict.get(diff, 0) + 1
mother_dict[diff] += 1
mother_handles[diff].append(m_handle)
#else:
# print "Mother diff out of range: %d for %s" % (diff,

View File

@ -20,6 +20,7 @@
# $Id$
#
#
from collections import defaultdict
from gen.ggettext import gettext as _
from gen.plug import Gramplet
@ -58,7 +59,7 @@ class GivenNameCloudGramplet(Gramplet):
def main(self):
self.set_text(_("Processing...") + "\n")
yield True
givensubnames = {}
givensubnames = defaultdict(int)
representative_handle = {}
cnt = 0
@ -67,7 +68,7 @@ class GivenNameCloudGramplet(Gramplet):
allnames = set(name.get_first_name().strip() for name in allnames)
for givenname in allnames:
for givensubname in givenname.split():
givensubnames[givensubname] = givensubnames.get(givensubname, 0) + 1
givensubnames[givensubname] += 1
representative_handle[givensubname] = person.handle
cnt += 1
if not cnt % _YIELD_INTERVAL:
@ -98,9 +99,9 @@ class GivenNameCloudGramplet(Gramplet):
line = 0
### All done!
# Now, find out how many we can display without going over top_size:
totals = {}
totals = defaultdict(int)
for (count, givensubname) in cloud_names: # givensubname_sort:
totals[count] = totals.get(count, 0) + 1
totals[count] += 1
sums = sorted(totals, reverse=True)
total = 0
include_greater_than = 0

View File

@ -74,10 +74,10 @@ class PluginManagerGramplet(Gramplet):
row.append(line[1:].strip())
else:
state = "read"
types = {}
for row in rows:
types[row[1]] = 1
types = dict([row[1], 1] for row in rows)
self.set_text("")
# name, type, ver, desc, use, rating, contact, download
for type in types:
self.render_text("<b>%s Plugins</b>\n" % _(type))

View File

@ -18,6 +18,8 @@
# $Id$
from collections import defaultdict
#------------------------------------------------------------------------
#
# GRAMPS modules
@ -78,7 +80,7 @@ class SurnameCloudGramplet(Gramplet):
def main(self):
self.set_text(_("Processing...") + "\n")
yield True
surnames = {}
surnames = defaultdict(int)
representative_handle = {}
cnt = 0
@ -86,7 +88,7 @@ class SurnameCloudGramplet(Gramplet):
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
surnames[surname] += 1
representative_handle[surname] = person.handle
cnt += 1
if not cnt % _YIELD_INTERVAL:
@ -116,9 +118,9 @@ class SurnameCloudGramplet(Gramplet):
line = 0
### All done!
# Now, find out how many we can display without going over top_size:
totals = {}
totals = defaultdict(int)
for (count, givensubname) in cloud_names: # givensubname_sort:
totals[count] = totals.get(count, 0) + 1
totals[count] += 1
sums = sorted(totals, reverse=True)
total = 0
include_greater_than = 0

View File

@ -18,6 +18,8 @@
# $Id$
from collections import defaultdict
#------------------------------------------------------------------------
#
# GRAMPS modules
@ -62,7 +64,7 @@ class TopSurnamesGramplet(Gramplet):
def main(self):
self.set_text(_("Processing...") + "\n")
surnames = {}
surnames = defaultdict(int)
representative_handle = {}
cnt = 0
@ -70,7 +72,7 @@ class TopSurnamesGramplet(Gramplet):
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
surnames[surname] += 1
representative_handle[surname] = person.handle
cnt += 1
if not cnt % _YIELD_INTERVAL:

View File

@ -124,8 +124,7 @@ class UnicodeWriter(object):
self.queue.truncate(0)
def writerows(self, rows):
for row in rows:
self.writerow(row)
map(self.writerow, rows)
def close(self):
self.stream.close()

View File

@ -681,8 +681,7 @@ class GtkDocTable(GtkDocBaseElement):
new_table = GtkDocTable(self._style)
#add the split row
new_table.add_child(r2)
for row in self._children[row_index+1:]:
new_table.add_child(row)
map(new_table.add_child, self._children[row_index+1:])
del self._children[row_index+1:]
return (self, new_table), table_height
@ -1253,9 +1252,8 @@ class CairoDoc(BaseDoc, TextDoc, DrawDoc):
# we need to remember the column width list from the table style.
# this is an ugly hack, but got no better idea.
self._active_row_style = []
for i in range(style.get_columns()):
self._active_row_style.append(style.get_column_width(i))
self._active_row_style = map(style.get_column_width,
range(style.get_columns()))
def end_table(self):
self._active_element = self._active_element.get_parent()

View File

@ -2188,9 +2188,7 @@ class GedcomParser(UpdateCallback):
amap = personalConstantAttributes
self.attrs = amap.values()
self.gedattr = {}
for val, key in amap.iteritems():
self.gedattr[key] = val
self.gedattr = dict([key, val] for val, key in amap.iteritems())
self.search_paths = []
def parse_gedcom_file(self, use_trans=False):
@ -4294,8 +4292,7 @@ class GedcomParser(UpdateCallback):
place_handle = place.handle
place.set_main_location(location)
for note in note_list:
place.add_note(note)
map(place.add_note, note_list)
state.event.set_place_handle(place_handle)
self.dbase.commit_place(place, self.trans)

View File

@ -1715,8 +1715,7 @@ class DbGrdb(Callback):
self.emit(objtype + '-delete', (del_list, ))
def __do_del(self, del_list, func):
for handle in del_list:
func(handle)
map(func, del_list)
return del_list
def do_commit(self, add_list, db_map):

View File

@ -34,6 +34,7 @@ from gen.lib import Person
import DateHandler
import posixpath
from collections import defaultdict
from gen.ggettext import sgettext as _
from gen.ggettext import ngettext
@ -133,12 +134,12 @@ def run(database, document, filter_name, *args, **kwargs):
stab.row(family)
matches += 1
elif (filter_name == 'unique surnames'):
namelist = {}
namelist = defaultdict(int)
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
namelist[surname] += 1
stab.columns(_("Surname"), _("Count"))
for name in sorted(namelist):
stab.row(name, namelist[name])

View File

@ -315,7 +315,7 @@ class AllRelReport():
if isinstance(fam, list):
famstr = str(fam[0]+1)
for val in fam[1:] :
famstr = famstr + ', ' + str(val+1)
famstr += ', ' + str(val+1)
else:
famstr = str(fam+1)
sdoc.paragraph(_FMT_DET2 % (' ', par_str, birth_str, famstr))
@ -335,7 +335,6 @@ class AllRelReport():
sdoc.paragraph("")
sdoc.paragraph(_("The following problems were encountered:"))
for msg in msg_list :
sdoc.paragraph(msg)
map(sdoc.paragraph, msg_list)
sdoc.paragraph("")
sdoc.paragraph("")

View File

@ -149,8 +149,7 @@ class EndOfLineReport(Report):
self.write_generation_row(generation)
for person_handle, pedigrees in handles.iteritems():
self.write_person_row(person_handle)
for pedigree in pedigrees:
self.write_pedigree_row(pedigree)
map(self.write_pedigree_row, pedigrees)
self.doc.end_table()
def write_generation_row(self, generation):

View File

@ -274,8 +274,7 @@ class KinshipReport(Report):
mark = IndexMark(cap_title, INDEX_TYPE_TOC, 2)
self.doc.write_text(subtitle, mark)
self.doc.end_paragraph()
for person_handle in people_handles:
self.write_person(person_handle)
map(self.write_person, people_handles)
def write_person(self, person_handle):
"""

View File

@ -1301,9 +1301,8 @@ class CheckIntegrity(object):
bad_handles = [ item[1] for item in handle_list
if item[0] == 'Note' and
item[1] not in known_handles ]
for bad_handle in bad_handles:
person.remove_note(bad_handle)
if bad_handles:
map(person.remove_note, bad_handles)
self.db.commit_person(person, self.trans)
new_bad_handles = [handle for handle in bad_handles if handle
not in self.invalid_note_references]
@ -1318,9 +1317,8 @@ class CheckIntegrity(object):
bad_handles = [ item[1] for item in handle_list
if item[0] == 'Note' and
item[1] not in known_handles ]
for bad_handle in bad_handles:
family.remove_note(bad_handle)
if bad_handles:
map(family.remove_note, bad_handles)
self.db.commit_family(family, self.trans)
new_bad_handles = [handle for handle in bad_handles if handle
not in self.invalid_note_references]
@ -1335,9 +1333,8 @@ class CheckIntegrity(object):
bad_handles = [ item[1] for item in handle_list
if item[0] == 'Note' and
item[1] not in known_handles ]
for bad_handle in bad_handles:
place.remove_note(bad_handle)
if bad_handles:
map(place.remove_note, bad_handles)
self.db.commit_place(place, self.trans)
new_bad_handles = [handle for handle in bad_handles if handle
not in self.invalid_note_references]
@ -1355,6 +1352,7 @@ class CheckIntegrity(object):
for bad_handle in bad_handles:
source.remove_note(bad_handle)
if bad_handles:
map(source.remove_note, bad_handles)
self.db.commit_source(source, self.trans)
new_bad_handles = [handle for handle in bad_handles if handle
not in self.invalid_note_references]
@ -1369,9 +1367,8 @@ class CheckIntegrity(object):
bad_handles = [ item[1] for item in handle_list
if item[0] == 'Note' and
item[1] not in known_handles ]
for bad_handle in bad_handles:
obj.remove_note(bad_handle)
if bad_handles:
map(obj.remove_note, bad_handles)
self.db.commit_media_object(obj, self.trans)
new_bad_handles = [handle for handle in bad_handles if handle
not in self.invalid_note_references]
@ -1386,9 +1383,8 @@ class CheckIntegrity(object):
bad_handles = [ item[1] for item in handle_list
if item[0] == 'Note' and
item[1] not in known_handles ]
for bad_handle in bad_handles:
event.remove_note(bad_handle)
if bad_handles:
map(event.remove_note, bad_handles)
self.db.commit_event(event, self.trans)
new_bad_handles = [handle for handle in bad_handles if handle
not in self.invalid_note_references]
@ -1403,9 +1399,8 @@ class CheckIntegrity(object):
bad_handles = [ item[1] for item in handle_list
if item[0] == 'Note' and
item[1] not in known_handles ]
for bad_handle in bad_handles:
repo.remove_note(bad_handle)
if bad_handles:
map(repo.remove_note, bad_handles)
self.db.commit_repository(repo, self.trans)
new_bad_handles = [handle for handle in bad_handles if handle
not in self.invalid_note_references]

View File

@ -103,10 +103,9 @@ class TableReport(object):
def set_row(self,val):
self.row = val + 2
def write_table_head(self,data):
def write_table_head(self, data):
self.doc.start_row()
for item in data:
self.doc.write_cell(item)
map(self.doc.write_cell, data)
self.doc.end_row()
#------------------------------------------------------------------------

View File

@ -129,8 +129,7 @@ class PHPGedViewConnector(object):
result = []
types = []
if type == self.TYPE_ALL:
for entry in self.type_trans:
types.append(entry)
types.extend(self.type_trans)
else:
types.append(type)
for entry in types:

View File

@ -225,8 +225,8 @@ class FamilyView(ListView):
_('_Delete Item'), _('Cancel'))
if q.run():
self.uistate.set_busy_cursor(1)
for handle in self.selected_handles():
self.dbstate.db.remove_family_relationships(handle)
map(self.dbstate.db.remove_family_relationships,
self.selected_handles())
self.build_tree()
self.uistate.set_busy_cursor(0)

View File

@ -2039,8 +2039,7 @@ class GeoView(HtmlView):
self.vbox.destroy()
except: # pylint: disable-msg=W0704
pass # pylint: disable-msg=W0702
for child in self.hpaned.get_children(): # cleanup
self.hpaned.remove(child)
map(self.hpaned.remove, self.hpaned.get_children())
self.vbox = gtk.VBox()
self.hpaned.pack_start(self.vbox, True, True)
self.filter_sidebar = filter_class(self.dbstate, self.uistate,

View File

@ -1241,11 +1241,8 @@ class GrampletView(PageView):
qr_menu = rg_menu.get_submenu()
if qr_menu is not None:
rg_menu.remove_submenu()
names = []
for gramplet in self.closed_gramplets:
names.append(gramplet.title)
for opts in self.closed_opts:
names.append(opts["title"])
names = [gramplet.title for gramplet in self.closed_gramplets]
names.extend(opts["title"] for opts in self.closed_opts)
names.sort()
if len(names) > 0:
qr_menu = gtk.Menu()

View File

@ -405,10 +405,8 @@ class RelationshipView(NavigationView):
#reset the connects
self._change_db(db)
if self.child:
for old_child in self.vbox.get_children():
self.vbox.remove(old_child)
for old_child in self.header.get_children():
self.header.remove(old_child)
map(self.vbox.remove, self.vbox.get_children())
map(self.header.remove, self.header.get_children())
self.child = None
self.bookmarks.update_bookmarks(db.get_bookmarks())
if self.active:
@ -547,9 +545,7 @@ class RelationshipView(NavigationView):
def write_title(self, person):
for old_child in self.header.get_children():
self.header.remove(old_child)
map(self.header.remove, self.header.get_children())
table = gtk.Table(2, 3)
table.set_col_spacings(12)
table.set_row_spacings(0)

View File

@ -525,9 +525,7 @@ class WebCalReport(Report):
# An optional link to a home page
navs.append((self.home_link, _('html|Home'), add_home))
for month in range(1, 13):
navs.append((month, month, True))
navs.extend((month, month, True) for month in range(1,13))
# Add a link for year_glance() if requested
navs.append(('fullyearlinked', _('Year Glance'), self.fullyear))