0005501: Gedcom with embedded and linked notes creates duplicate IDs. The translate parameter is removed from IdMapper, so that IDs are always translated. This still means that import attempts to preserve the IDs in the GEDCOM file (unless there are collisions).

svn: r18803
This commit is contained in:
Tim G L Lyons 2012-01-31 18:25:17 +00:00
parent d1d19a2a17
commit 3b42cdf51f

View File

@ -1622,30 +1622,13 @@ class IdFinder(object):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class IdMapper(object): class IdMapper(object):
def __init__(self, trans, find_next, id2user_format, translate): def __init__(self, trans, find_next, id2user_format):
self.translate = translate
self.trans = trans self.trans = trans
self.find_next = find_next self.find_next = find_next
self.id2user_format = id2user_format self.id2user_format = id2user_format
self.swap = {} self.swap = {}
def __getitem__(self, gid): def __getitem__(self, gid):
if self.translate:
return self.get_translate(gid)
else:
return self.no_translate(gid)
def clean(self, gid):
temp = gid.strip()
if len(temp) > 1 and temp[0] == '@' and temp[-1] == '@':
temp = temp[1:-1]
temp = self.id2user_format(temp)
return temp
def no_translate(self, gid):
return self.clean(gid)
def get_translate(self, gid):
gid = self.clean(gid) gid = self.clean(gid)
if gid in self.swap: if gid in self.swap:
return self.swap[gid] return self.swap[gid]
@ -1657,6 +1640,13 @@ class IdMapper(object):
self.swap[gid] = new_val self.swap[gid] = new_val
return new_val return new_val
def clean(self, gid):
temp = gid.strip()
if len(temp) > 1 and temp[0] == '@' and temp[-1] == '@':
temp = temp[1:-1]
temp = self.id2user_format(temp)
return temp
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GedcomParser # GedcomParser
@ -1751,33 +1741,27 @@ class GedcomParser(UpdateCallback):
self.pid_map = IdMapper( self.pid_map = IdMapper(
self.dbase.id_trans, self.dbase.id_trans,
self.dbase.find_next_person_gramps_id, self.dbase.find_next_person_gramps_id,
self.dbase.id2user_format, self.dbase.id2user_format)
self.dbase.get_number_of_people())
self.fid_map = IdMapper( self.fid_map = IdMapper(
self.dbase.fid_trans, self.dbase.fid_trans,
self.dbase.find_next_family_gramps_id, self.dbase.find_next_family_gramps_id,
self.dbase.fid2user_format, self.dbase.fid2user_format)
self.dbase.get_number_of_families())
self.sid_map = IdMapper( self.sid_map = IdMapper(
self.dbase.sid_trans, self.dbase.sid_trans,
self.dbase.find_next_source_gramps_id, self.dbase.find_next_source_gramps_id,
self.dbase.sid2user_format, self.dbase.sid2user_format)
self.dbase.get_number_of_sources())
self.oid_map = IdMapper( self.oid_map = IdMapper(
self.dbase.oid_trans, self.dbase.oid_trans,
self.dbase.find_next_object_gramps_id, self.dbase.find_next_object_gramps_id,
self.dbase.oid2user_format, self.dbase.oid2user_format)
self.dbase.get_number_of_media_objects())
self.rid_map = IdMapper( self.rid_map = IdMapper(
self.dbase.rid_trans, self.dbase.rid_trans,
self.dbase.find_next_repository_gramps_id, self.dbase.find_next_repository_gramps_id,
self.dbase.rid2user_format, self.dbase.rid2user_format)
self.dbase.get_number_of_repositories())
self.nid_map = IdMapper( self.nid_map = IdMapper(
self.dbase.nid_trans, self.dbase.nid_trans,
self.dbase.find_next_note_gramps_id, self.dbase.find_next_note_gramps_id,
self.dbase.nid2user_format, self.dbase.nid2user_format)
self.dbase.get_number_of_notes())
self.gid2id = {} self.gid2id = {}
self.oid2id = {} self.oid2id = {}