Bug 0003098: "Buri" event on GeneWeb file may break import into Gramps

svn: r13457
This commit is contained in:
Gerald Britton
2009-10-29 20:03:03 +00:00
parent 0757d0821c
commit 00bee4ee66

View File

@ -424,68 +424,67 @@ class GeneWebParser(object):
#while idx < len(fields) and not fields[idx][0] == "+": #while idx < len(fields) and not fields[idx][0] == "+":
while idx < len(fields) and not (fields[idx] and fields[idx][0] == "+"): while idx < len(fields) and not (fields[idx] and fields[idx][0] == "+"):
if fields[idx]: if fields[idx]:
print "parse_marriage(): Unknown field: '%s' in line %d!" %(fields[idx],self.lineno) print "parse_marriage(): Unknown field:", \
idx = idx + 1 "'%s' in line %d!" % (fields[idx], self.lineno)
idx += 1
while idx < len(fields) and mariageDataRe.match(fields[idx]): while idx < len(fields) and mariageDataRe.match(fields[idx]):
if fields[idx][0] == "+": field = fields[idx]
mar_date = self.parse_date(self.decode(fields[idx])) idx += 1
self.debug(" Married at: %s" % fields[idx]) if field.startswith("+"):
idx = idx + 1 mar_date = self.parse_date(self.decode(field))
elif fields[idx][0] == "-": self.debug(" Married at: %s" % field)
div_date = self.parse_date(self.decode(fields[idx])) elif field.startswith("-"):
self.debug(" Div at: %s" % fields[idx]) div_date = self.parse_date(self.decode(field))
idx = idx + 1 self.debug(" Div at: %s" % field)
elif fields[idx] == "#mp": elif field == "#mp" and idx < len(fields):
idx = idx + 1
mar_place = self.get_or_create_place(self.decode(fields[idx])) mar_place = self.get_or_create_place(self.decode(fields[idx]))
self.debug(" Marriage place: %s" % fields[idx]) self.debug(" Marriage place: %s" % fields[idx])
idx = idx + 1 idx += 1
elif fields[idx] == "#ms": elif field == "#ms" and idx < len(fields):
idx = idx + 1
mar_source = self.get_or_create_source(self.decode(fields[idx])) mar_source = self.get_or_create_source(self.decode(fields[idx]))
self.debug(" Marriage source: %s" % fields[idx]) self.debug(" Marriage source: %s" % fields[idx])
idx = idx + 1 idx += 1
elif fields[idx] == "#sep": elif field == "#sep" and idx < len(fields):
idx = idx + 1
sep_date = self.parse_date(self.decode(fields[idx])) sep_date = self.parse_date(self.decode(fields[idx]))
self.debug(" Seperated since: %s" % fields[idx]) self.debug(" Seperated since: %s" % fields[idx])
idx = idx + 1 idx += 1
elif fields[idx] == "#nm": elif field == "#nm":
self.debug(" Are not married.") self.debug(" Are not married.")
married = 0 married = 0
idx = idx + 1 elif field == "#noment":
elif fields[idx] == "#noment":
self.debug(" Not mentioned.") self.debug(" Not mentioned.")
idx = idx + 1 elif field == "#eng":
elif fields[idx] == "#eng":
self.debug(" Are engaged.") self.debug(" Are engaged.")
engaged = 1 engaged = 1
idx = idx + 1
else: else:
print "parse_marriage(): Unknown field '%s'for mariage in line %d!" % (fields[idx],self.lineno) print "parse_marriage(): Unknown field", \
idx = idx + 1 "'%s'for mariage in line %d!" % (field, self.lineno)
if mar_date or mar_place or mar_source: if mar_date or mar_place or mar_source:
mar = self.create_event(gen.lib.EventType.MARRIAGE, None, mar_date, mar_place, mar_source) mar = self.create_event(
gen.lib.EventType.MARRIAGE, None, mar_date, mar_place, mar_source)
mar_ref = gen.lib.EventRef() mar_ref = gen.lib.EventRef()
mar_ref.set_reference_handle(mar.get_handle()) mar_ref.set_reference_handle(mar.get_handle())
self.current_family.add_event_ref(mar_ref) self.current_family.add_event_ref(mar_ref)
if div_date: if div_date:
div = self.create_event(gen.lib.EventType.DIVORCE, None, div_date, None, None) div = self.create_event(
gen.lib.EventType.DIVORCE, None, div_date, None, None)
div_ref = gen.lib.EventRef() div_ref = gen.lib.EventRef()
div_ref.set_reference_handle(div.get_handle()) div_ref.set_reference_handle(div.get_handle())
self.current_family.add_event_ref(div_ref) self.current_family.add_event_ref(div_ref)
if sep_date or engaged: if sep_date or engaged:
sep = self.create_event(gen.lib.EventType.ENGAGEMENT, None, sep_date, None, None) sep = self.create_event(
gen.lib.EventType.ENGAGEMENT, None, sep_date, None, None)
sep_ref = gen.lib.EventRef() sep_ref = gen.lib.EventRef()
sep_ref.set_reference_handle(sep.get_handle()) sep_ref.set_reference_handle(sep.get_handle())
self.current_family.add_event_ref(sep_ref) self.current_family.add_event_ref(sep_ref)
if not married: if not married:
self.current_family.set_relationship(gen.lib.FamilyRelType(gen.lib.FamilyRelType.UNMARRIED)) self.current_family.set_relationship(
gen.lib.FamilyRelType(gen.lib.FamilyRelType.UNMARRIED))
self.db.commit_family(self.current_family,self.trans) self.db.commit_family(self.current_family,self.trans)
return idx return idx
@ -498,7 +497,7 @@ class GeneWebParser(object):
surname ="" surname =""
else: else:
surname = self.decode(fields[idx]) surname = self.decode(fields[idx])
idx = idx + 1 idx += 1
else: else:
surname = father_surname surname = father_surname
@ -507,12 +506,12 @@ class GeneWebParser(object):
firstname = "" firstname = ""
else: else:
firstname = self.decode(fields[idx]) firstname = self.decode(fields[idx])
idx = idx + 1 idx += 1
if idx < len(fields) and father_surname: if idx < len(fields) and father_surname:
noSurnameRe = re.compile("^[({\[~><?0-9#].*$") noSurnameRe = re.compile("^[({\[~><?0-9#].*$")
if not noSurnameRe.match(fields[idx]): if not noSurnameRe.match(fields[idx]):
surname = self.decode(fields[idx]) surname = self.decode(fields[idx])
idx = idx + 1 idx += 1
self.debug("Person: %s %s" % (firstname, surname)) self.debug("Person: %s %s" % (firstname, surname))
person = self.get_or_create_person(firstname,surname) person = self.get_or_create_person(firstname,surname)
@ -554,22 +553,22 @@ class GeneWebParser(object):
surname_aliases = [] surname_aliases = []
while idx < len(fields) and personDataRe.match(fields[idx]): while idx < len(fields) and personDataRe.match(fields[idx]):
if fields[idx][0] == '(': field = fields[idx]
self.debug("Public Name: %s" % fields[idx])
public_name = self.decode(fields[idx][1:-1])
idx += 1 idx += 1
elif fields[idx][0] == '{': if field.startswith('('):
self.debug("Firstsname Alias: %s" % fields[idx]) self.debug("Public Name: %s" % field)
firstname_aliases.append(self.decode(fields[idx][1:-1])) public_name = self.decode(field[1:-1])
idx += 1 elif field.startswith('{'):
elif fields[idx][0] == '[': self.debug("Firstsname Alias: %s" % field)
self.debug("Title: %s" % fields[idx]) firstname_aliases.append(self.decode(field[1:-1]))
titleparts = self.decode(fields[idx][1:-1]).split(":") elif field.startswith('['):
self.debug("Title: %s" % field)
titleparts = self.decode(field[1:-1]).split(":")
tname = ttitle = tplace = tstart = tend = tnth = None tname = ttitle = tplace = tstart = tend = tnth = None
try: try:
tname = titleparts[0] tname = titleparts[0]
ttitle = titleparts[1] ttitle = titleparts[1]
if( titleparts[2]): if titleparts[2]:
tplace = self.get_or_create_place(titleparts[2]) tplace = self.get_or_create_place(titleparts[2])
tstart = self.parse_date(titleparts[3]) tstart = self.parse_date(titleparts[3])
tend = self.parse_date(titleparts[4]) tend = self.parse_date(titleparts[4])
@ -577,8 +576,9 @@ class GeneWebParser(object):
except IndexError: # not all parts are written all the time except IndexError: # not all parts are written all the time
pass pass
if tnth: # Append title numer to title if tnth: # Append title numer to title
ttitle = "%s, %s" % (ttitle, tnth) ttitle += ", " + tnth
title = self.create_event(gen.lib.EventType.NOB_TITLE,ttitle,tstart,tplace) title = self.create_event(
gen.lib.EventType.NOB_TITLE, ttitle, tstart, tplace)
# TODO: Geneweb has a start date and an end date, and therefore # TODO: Geneweb has a start date and an end date, and therefore
# supprts stuff like: FROM about 1955 TO between 1998 and 1999 # supprts stuff like: FROM about 1955 TO between 1998 and 1999
# gramps only supports one single date ore range. # gramps only supports one single date ore range.
@ -590,131 +590,108 @@ class GeneWebParser(object):
title_ref = gen.lib.EventRef() title_ref = gen.lib.EventRef()
title_ref.set_reference_handle(title.get_handle()) title_ref.set_reference_handle(title.get_handle())
person.add_event_ref(title_ref) person.add_event_ref(title_ref)
idx += 1 elif field == '#nick' and idx < len(fields):
elif fields[idx] == '#nick':
idx += 1
self.debug("Nick Name: %s" % fields[idx]) self.debug("Nick Name: %s" % fields[idx])
nick_names.append(self.decode(fields[idx])) nick_names.append(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#occu': elif field == '#occu' and idx < len(fields):
idx += 1
self.debug("Occupation: %s" % fields[idx]) self.debug("Occupation: %s" % fields[idx])
occu = self.create_event(gen.lib.EventType.OCCUPATION,self.decode(fields[idx])) occu = self.create_event(
gen.lib.EventType.OCCUPATION, self.decode(fields[idx]))
occu_ref = gen.lib.EventRef() occu_ref = gen.lib.EventRef()
occu_ref.set_reference_handle(occu.get_handle()) occu_ref.set_reference_handle(occu.get_handle())
person.add_event_ref(occu_ref) person.add_event_ref(occu_ref)
idx += 1 idx += 1
elif fields[idx] == '#alias': elif field == '#alias' and idx < len(fields):
idx += 1
self.debug("Name Alias: %s" % fields[idx]) self.debug("Name Alias: %s" % fields[idx])
name_aliases.append(self.decode(fields[idx])) name_aliases.append(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#salias': elif field == '#salias' and idx < len(fields):
idx += 1
self.debug("Surname Alias: %s" % fields[idx]) self.debug("Surname Alias: %s" % fields[idx])
surname_aliases.append(self.decode(fields[idx])) surname_aliases.append(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#image': elif field == '#image' and idx < len(fields):
idx += 1
self.debug("Image: %s" % fields[idx]) self.debug("Image: %s" % fields[idx])
idx += 1 idx += 1
elif fields[idx] == '#src': elif field == '#src' and idx < len(fields):
idx += 1
self.debug("Source: %s" % fields[idx]) self.debug("Source: %s" % fields[idx])
source = self.get_or_create_source(self.decode(fields[idx])) source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#bs': elif field == '#bs' and idx < len(fields):
idx += 1
self.debug("Birth Source: %s" % fields[idx]) self.debug("Birth Source: %s" % fields[idx])
birth_source = self.get_or_create_source(self.decode(fields[idx])) birth_source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx][0] == '!': elif field[0] == '!':
self.debug("Baptize at: %s" % fields[idx]) self.debug("Baptize at: %s" % fields[idx])
bapt_date = self.parse_date(self.decode(fields[idx][1:])) bapt_date = self.parse_date(self.decode(fields[idx][1:]))
idx += 1 idx += 1
elif fields[idx] == '#bp': elif field == '#bp' and idx < len(fields):
idx += 1
self.debug("Birth Place: %s" % fields[idx]) self.debug("Birth Place: %s" % fields[idx])
birth_place = self.get_or_create_place(self.decode(fields[idx])) birth_place = self.get_or_create_place(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#pp': elif field == '#pp' and idx < len(fields):
idx += 1
self.debug("Baptize Place: %s" % fields[idx]) self.debug("Baptize Place: %s" % fields[idx])
bapt_place = self.get_or_create_place(self.decode(fields[idx])) bapt_place = self.get_or_create_place(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#ps': elif field == '#ps' and idx < len(fields):
idx += 1
self.debug("Baptize Source: %s" % fields[idx]) self.debug("Baptize Source: %s" % fields[idx])
bapt_source = self.get_or_create_source(self.decode(fields[idx])) bapt_source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#dp': elif field == '#dp' and idx < len(fields):
idx += 1
self.debug("Death Place: %s" % fields[idx]) self.debug("Death Place: %s" % fields[idx])
death_place = self.get_or_create_place(self.decode(fields[idx])) death_place = self.get_or_create_place(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#ds': elif field == '#ds' and idx < len(fields):
idx += 1
self.debug("Death Source: %s" % fields[idx]) self.debug("Death Source: %s" % fields[idx])
death_source = self.get_or_create_source(self.decode(fields[idx])) death_source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#buri': elif field == '#buri' and idx < len(fields):
idx += 1
self.debug("Burial Date: %s" % fields[idx]) self.debug("Burial Date: %s" % fields[idx])
try:
bur_date = self.parse_date(self.decode(fields[idx])) bur_date = self.parse_date(self.decode(fields[idx]))
except IndexError:
pass
idx += 1
elif fields[idx] == '#crem':
idx += 1 idx += 1
elif field == '#crem' and idx < len(fields):
self.debug("Cremention Date: %s" % fields[idx]) self.debug("Cremention Date: %s" % fields[idx])
crem_date = self.parse_date(self.decode(fields[idx])) crem_date = self.parse_date(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#rp': elif field == '#rp' and idx < len(fields):
idx += 1
self.debug("Burial Place: %s" % fields[idx]) self.debug("Burial Place: %s" % fields[idx])
bur_place = self.get_or_create_place(self.decode(fields[idx])) bur_place = self.get_or_create_place(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#rs': elif field == '#rs' and idx < len(fields):
idx += 1
self.debug("Burial Source: %s" % fields[idx]) self.debug("Burial Source: %s" % fields[idx])
bur_source = self.get_or_create_source(self.decode(fields[idx])) bur_source = self.get_or_create_source(self.decode(fields[idx]))
idx += 1 idx += 1
elif fields[idx] == '#apubl': elif field == '#apubl':
self.debug("This is a public record") self.debug("This is a public record")
idx += 1 elif field == '#apriv':
elif fields[idx] == '#apriv':
self.debug("This is a private record") self.debug("This is a private record")
person.set_privacy(True) person.set_privacy(True)
idx += 1 elif field == '#h':
elif fields[idx] == '#h':
self.debug("This is a restricted record") self.debug("This is a restricted record")
#TODO: Gramps does currently not feature this level #TODO: Gramps does currently not feature this level
person.set_privacy(True) person.set_privacy(True)
idx += 1 elif dateRe.match(field):
elif dateRe.match( fields[idx]):
if not birth_parsed: if not birth_parsed:
self.debug("Birth Date: %s" % fields[idx]) self.debug("Birth Date: %s" % field)
birth_date = self.parse_date(self.decode(fields[idx])) birth_date = self.parse_date(self.decode(field))
birth_parsed = True birth_parsed = True
else: else:
self.debug("Death Date: %s" % fields[idx]) self.debug("Death Date: %s" % field)
death_date = self.parse_date(self.decode(fields[idx])) death_date = self.parse_date(self.decode(field))
if fields[idx] == "mj": if field == "mj":
death_cause = "Died joung" death_cause = "Died joung"
elif fields[idx][0] == "k": elif field.startswith("k"):
death_cause = "Killed" death_cause = "Killed"
elif fields[idx][0] == "m": elif field.startswith("m"):
death_cause = "Murdered" death_cause = "Murdered"
elif fields[idx][0] == "e": elif field.startswith("e"):
death_cause = "Executed" death_cause = "Executed"
elif fields[idx][0] == "d": elif field.startswith("d"):
death_cause = "Disappeared" death_cause = "Disappeared"
#TODO: Set special death types more properly #TODO: Set special death types more properly
idx += 1
else: else:
print "parse_person(): Unknown field '%s' for person in line %d!" % (fields[idx],self.lineno) print "parse_person(): Unknown field", \
idx += 1 "'%s' for person in line %d!" % (field, self.lineno)
if public_name: if public_name:
name = person.get_primary_name() name = person.get_primary_name()