Fixed some GEDCOM import with photos

svn: r461
This commit is contained in:
Don Allingham 2001-10-12 05:10:38 +00:00
parent 0695f265e6
commit d999584b47

View File

@ -361,6 +361,8 @@ class GedcomParser:
self.source.setAuthor(matches[2] + self.parse_continue_data(2)) self.source.setAuthor(matches[2] + self.parse_continue_data(2))
elif matches[1] == "PUBL": elif matches[1] == "PUBL":
self.source.setPubInfo(matches[2] + self.parse_continue_data(2)) self.source.setPubInfo(matches[2] + self.parse_continue_data(2))
elif matches[1] == "OBJE":
pass
elif matches[1] == "NOTE": elif matches[1] == "NOTE":
if matches[2] and matches[2][0] != "@": if matches[2] and matches[2][0] != "@":
note = matches[1] + self.parse_continue_data(1) note = matches[1] + self.parse_continue_data(1)
@ -426,7 +428,7 @@ class GedcomParser:
noteobj.set(text + self.parse_continue_data(1)) noteobj.set(text + self.parse_continue_data(1))
self.parse_note_data(1) self.parse_note_data(1)
elif matches[2] == "OBJE": elif matches[2] == "OBJE":
self.ignore_sub_junk(1) self.ignore_sub_junk(2)
elif matches[1] == "TRLR": elif matches[1] == "TRLR":
self.backup() self.backup()
return return
@ -763,6 +765,8 @@ class GedcomParser:
file = matches[2] file = matches[2]
elif matches[1] == "NOTE": elif matches[1] == "NOTE":
note = matches[2] + self.parse_continue_data(level+1) note = matches[2] + self.parse_continue_data(level+1)
elif matches[1][0] == "_":
self.ignore_sub_junk(level+1)
elif int(matches[0]) < level: elif int(matches[0]) < level:
self.backup() self.backup()
break break
@ -787,7 +791,51 @@ class GedcomParser:
db.addObject(photo) db.addObject(photo)
oref = ObjectRef() oref = ObjectRef()
oref.setReference(photo) oref.setReference(photo)
self.person.addPhoto(photo) self.person.addPhoto(oref)
else:
self.warn(_("Could not import %s: currently an unknown file type") % \
file + "\n")
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def parse_source_object(self,source,level):
form = ""
file = ""
title = ""
note = ""
while 1:
matches = self.get_next()
if matches[1] == "FORM":
form = string.lower(matches[2])
elif matches[1] == "TITL":
title = matches[2]
elif matches[1] == "FILE":
file = matches[2]
elif matches[1] == "NOTE":
note = matches[2] + self.parse_continue_data(level+1)
elif int(matches[0]) < level:
self.backup()
break
else:
self.barf(level+1)
if form in photo_types:
path = find_file(file,self.dir_path)
if path == "":
self.warn(_("Could not import %s: either the file could not be found, or it was not a valid image")\
% file + "\n")
else:
photo = Photo()
photo.setPath(path)
photo.setDescription(title)
photo.setMimeType(utils.get_mime_type(path))
db.addObject(photo)
oref = ObjectRef()
oref.setReference(photo)
source.addPhoto(oref)
else: else:
self.warn(_("Could not import %s: currently an unknown file type") % \ self.warn(_("Could not import %s: currently an unknown file type") % \
file + "\n") file + "\n")
@ -817,24 +865,22 @@ class GedcomParser:
break break
else: else:
self.barf(level+1) self.barf(level+1)
if form == "url": if form in photo_types:
pass
# url = Url(file,title)
# self.family.addUrl(url)
elif form in photo_types:
path = find_file(file,self.dir_path) path = find_file(file,self.dir_path)
if path == "": if path == "":
self.warn("Could not import %s: the file could not be found\n" % \ self.warn("Could not import %s: the file could not be found\n" % file)
file)
else: else:
photo = Photo() photo = Photo()
photo.setPath(path) photo.setPath(path)
photo.setDescription(title) photo.setDescription(title)
photo.setMimeType(utils.get_mime_type(path))
db.addObject(photo)
oref = ObjectRef()
oref.setReference(photo)
self.family.addPhoto(photo) self.family.addPhoto(photo)
else: else:
self.warn("Could not import %s: current an unknown file type\n" % \ self.warn("Could not import %s: current an unknown file type\n" % file)
file)
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# #
@ -1089,6 +1135,11 @@ class GedcomParser:
d.set(date) d.set(date)
source.setDate(d) source.setDate(d)
source.setText(text) source.setText(text)
elif matches[1] == "OBJE":
if matches[2] and matches[2][0] == '@':
self.barf(2)
else:
self.parse_source_object(source,level+1)
elif matches[1] == "QUAY": elif matches[1] == "QUAY":
val = int(matches[2]) val = int(matches[2])
if val > 1: if val > 1:
@ -1156,7 +1207,7 @@ class GedcomParser:
name.setSurname(matches[2]) name.setSurname(matches[2])
elif matches[1] == "NSFX": elif matches[1] == "NSFX":
name.setSuffix(matches[2]) name.setSuffix(matches[2])
elif matches[1] == "NICK": elif matches[1] == "NICK" or matches[1] == "_AKA":
self.person.setNickName(matches[2]) self.person.setNickName(matches[2])
elif matches[1] == "SOUR": elif matches[1] == "SOUR":
source_ref = SourceRef() source_ref = SourceRef()