Protection from null objects

svn: r15506
This commit is contained in:
Doug Blank 2010-05-30 12:09:17 +00:00
parent 016d45b4a6
commit 204c4e1d24

View File

@ -141,6 +141,7 @@ def sort_handles_by_id(handle_list, handle_to_object):
sorted_list = []
for handle in handle_list:
obj = handle_to_object(handle)
if obj:
data = (obj.get_gramps_id(), handle)
sorted_list.append (data)
sorted_list.sort()
@ -409,6 +410,7 @@ class GedcomWriter(UpdateCallback):
sorted_list = []
for handle in phandles:
person = self.dbase.get_person_from_handle(handle)
if person:
data = (person.get_gramps_id(), handle)
sorted_list.append(data)
sorted_list.sort()
@ -444,6 +446,8 @@ class GedcomWriter(UpdateCallback):
+1 RIN <AUTOMATED_RECORD_ID> {0:1}
+1 <<CHANGE_DATE>> {0:1}
"""
if person is None:
return
self.__writeln(0, "@%s@" % person.get_gramps_id(), "INDI")
self.__names(person)
@ -472,6 +476,7 @@ class GedcomWriter(UpdateCallback):
"""
for ref in person.get_person_ref_list():
person = self.dbase.get_person_from_handle(ref.ref)
if person:
self.__writeln(level, "ASSO", "@%s@" % person.get_gramps_id())
self.__writeln(level+1, "RELA", ref.get_relation())
self.__note_references(ref.get_note_list(), level+1)
@ -486,6 +491,7 @@ class GedcomWriter(UpdateCallback):
"""
for note_handle in notelist:
note = self.dbase.get_note_from_handle(note_handle)
if note:
self.__writeln(level, 'NOTE', '@%s@' % note.get_gramps_id())
def __names(self, person):
@ -700,6 +706,7 @@ class GedcomWriter(UpdateCallback):
for hndl in person.get_parent_family_handle_list() ]
for family in family_list:
if family:
self.__writeln(1, 'FAMC', '@%s@' % family.get_gramps_id())
def __parent_families(self, person):
@ -713,6 +720,7 @@ class GedcomWriter(UpdateCallback):
for hndl in person.get_family_handle_list() ]
for family in family_list:
if family:
self.__writeln(1, 'FAMS', '@%s@' % family.get_gramps_id())
def __person_sources(self, person):
@ -770,6 +778,8 @@ class GedcomWriter(UpdateCallback):
+1 <<LDS_SPOUSE_SEALING>> {0:M}
+1 REFN <USER_REFERENCE_NUMBER> {0:M}
"""
if family is None:
return
gramps_id = family.get_gramps_id()
self.__writeln(0, '@%s@' % gramps_id, 'FAM' )
@ -807,6 +817,7 @@ class GedcomWriter(UpdateCallback):
"""
if person_handle:
person = self.dbase.get_person_from_handle(person_handle)
if person:
self.__writeln(1, token, '@%s@' % person.get_gramps_id())
def __family_events(self, family):
@ -951,7 +962,7 @@ class GedcomWriter(UpdateCallback):
+1 RIN <AUTOMATED_RECORD_ID> {0:1}
+1 <<CHANGE_DATE>> {0:1}
"""
if note:
self.__writeln(0, '@%s@' % note.get_gramps_id(), 'NOTE ' + note.get())
def __repos(self):
@ -1007,6 +1018,9 @@ class GedcomWriter(UpdateCallback):
return
repo = self.dbase.get_repository_from_handle(reporef.ref)
if repo is None:
return
repo_id = repo.get_gramps_id()
self.__writeln(level, 'REPO', '@%s@' % repo_id )
@ -1268,7 +1282,7 @@ class GedcomWriter(UpdateCallback):
note_list = [ self.dbase.get_note_from_handle(h)
for h in ref.get_note_list() ]
note_list = [ n.handle for n in note_list
if n.get_type() != gen.lib.NoteType.SOURCE_TEXT]
if n and n.get_type() != gen.lib.NoteType.SOURCE_TEXT]
self.__note_references(note_list, level+1)
def __photo(self, photo, level):