* src/plugins/ImportGeneWeb.py: Bugfixes (convert to new api); Add support for some more geneweb features

svn: r7550
This commit is contained in:
Martin Hawlisch 2006-11-04 20:52:09 +00:00
parent 7b53213fa4
commit 7dae010f95
2 changed files with 65 additions and 23 deletions

View File

@ -1,3 +1,7 @@
2006-11-04 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/plugins/ImportGeneWeb.py: Bugfixes (convert to new api);
Add support for some more geneweb features
2006-11-03 Alex Roitman <shura@gramps-project.org> 2006-11-03 Alex Roitman <shura@gramps-project.org>
* configure.in: Bump up the version. * configure.in: Bump up the version.
* src/Editors/_EditLdsOrd.py (update_parent_label): Spurious * src/Editors/_EditLdsOrd.py (update_parent_label): Spurious

View File

@ -60,7 +60,7 @@ from DateHandler import parser as _dp
from PluginUtils import register_import from PluginUtils import register_import
from htmlentitydefs import name2codepoint from htmlentitydefs import name2codepoint
_date_parse = re.compile('([~?<>]+)?([0-9/]+)([J|H|F])?(\.\.)?([0-9/]+)?([J|H|F])?') _date_parse = re.compile('([kmes~?<>]+)?([0-9/]+)([J|H|F])?(\.\.)?([0-9/]+)?([J|H|F])?')
_text_parse = re.compile('0\((.*)\)') _text_parse = re.compile('0\((.*)\)')
_mod_map = { _mod_map = {
@ -176,7 +176,7 @@ class GeneWebParser:
elif fields[0] == "end": elif fields[0] == "end":
self.current_mode = None self.current_mode = None
else: else:
print "Token >%s< unknown. line %d skipped: %s" % (fields[0],self.lineno,line) print "parse_geneweb_file(): Token >%s< unknown. line %d skipped: %s" % (fields[0],self.lineno,line)
except Errors.GedcomError, err: except Errors.GedcomError, err:
self.errmsg(str(err)) self.errmsg(str(err))
@ -247,6 +247,12 @@ class GeneWebParser:
fields = matches.groups()[1].split(" ") fields = matches.groups()[1].split(" ")
if fields: if fields:
(idx,asso_p) = self.parse_person(fields,0,RelLib.Person.UNKNOWN,None) (idx,asso_p) = self.parse_person(fields,0,RelLib.Person.UNKNOWN,None)
pref = RelLib.PersonRef()
pref.set_relation(matches.groups()[0])
print("TODO: Handle association types properly")
pref.set_reference_handle(asso_p.get_handle())
rel_person.add_person_ref(pref)
self.db.commit_person(rel_person,self.trans)
else: else:
print "Invalid name of person in line %d" % self.lineno print "Invalid name of person in line %d" % self.lineno
else: else:
@ -268,13 +274,29 @@ class GeneWebParser:
def read_witness_line(self,line,fields): def read_witness_line(self,line,fields):
self.debug("Witness:") self.debug("Witness:")
print "TODO: Connect witnesses to family"
if fields[1] == "m:": if fields[1] == "m:":
self.parse_person(fields,2,RelLib.Person.MALE,None) (idx,wit_p) = self.parse_person(fields,2,RelLib.Person.MALE,None)
elif fields[1] == "f:": elif fields[1] == "f:":
self.parse_person(fields,2,RelLib.Person.FEMALE,None) (idx,wit_p) = self.parse_person(fields,2,RelLib.Person.FEMALE,None)
else: else:
self.parse_person(fields,1,None,None) (idx,wit_p) = self.parse_person(fields,1,None,None)
if wit_p:
mev = None
# search marriage event
for evr in self.current_family.get_event_ref_list():
ev = self.db.get_event_from_handle(evr.get_reference_handle())
if ev.get_type() == RelLib.EventType.MARRIAGE:
mev = ev # found.
if not mev: # No marriage event found create a new one
mev = self.create_event(RelLib.EventType.MARRIAGE, None, None, None, None)
mar_ref = RelLib.EventRef()
mar_ref.set_reference_handle(mev.get_handle())
self.current_family.add_event_ref(mar_ref)
wit_ref = RelLib.EventRef()
wit_ref.set_role(RelLib.EventRoleType(RelLib.EventRoleType.WITNESS))
wit_ref.set_reference_handle(mev.get_handle())
wit_p.add_event_ref(wit_ref)
self.db.commit_person(wit_p,self.trans)
return None return None
def read_children_lines(self): def read_children_lines(self):
@ -392,7 +414,7 @@ class GeneWebParser:
#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 "Unknown field: '%s' in line %d!" %(fields[idx],self.lineno) print "parse_marriage(): Unknown field: '%s' in line %d!" %(fields[idx],self.lineno)
idx = idx + 1 idx = idx + 1
while idx < len(fields) and mariageDataRe.match(fields[idx]): while idx < len(fields) and mariageDataRe.match(fields[idx]):
@ -423,12 +445,15 @@ class GeneWebParser:
self.debug(" Are not married.") self.debug(" Are not married.")
married = 0 married = 0
idx = idx + 1 idx = idx + 1
elif fields[idx] == "#noment":
self.debug(" Not mentioned.")
idx = idx + 1
elif fields[idx] == "#eng": elif fields[idx] == "#eng":
self.debug(" Are engaged.") self.debug(" Are engaged.")
engaged = 1 engaged = 1
idx = idx + 1 idx = idx + 1
else: else:
print "Unknown field '%s'for mariage in line %d!" % (fields[idx],self.lineno) print "parse_marriage(): Unknown field '%s'for mariage in line %d!" % (fields[idx],self.lineno)
idx = idx + 1 idx = idx + 1
if mar_date or mar_place or mar_source: if mar_date or mar_place or mar_source:
@ -489,8 +514,8 @@ class GeneWebParser:
if person.get_gender() == RelLib.Person.UNKNOWN and gender != None: if person.get_gender() == RelLib.Person.UNKNOWN and gender != None:
person.set_gender(gender) person.set_gender(gender)
self.db.commit_person(person,self.trans) self.db.commit_person(person,self.trans)
personDataRe = re.compile("^[0-9<>~#\[({!].*$") personDataRe = re.compile("^[kmes0-9<>~#\[({!].*$")
dateRe = re.compile("^[0-9~<>?]+.*$") dateRe = re.compile("^[kmes0-9~<>?]+.*$")
source = None source = None
birth_date = None birth_date = None
@ -504,6 +529,7 @@ class GeneWebParser:
death_date = None death_date = None
death_place = None death_place = None
death_source = None death_source = None
death_cause = None
crem_date = None crem_date = None
bur_date = None bur_date = None
@ -539,7 +565,7 @@ class GeneWebParser:
occu = self.create_event(RelLib.EventType.OCCUPATION,self.decode(fields[idx])) occu = self.create_event(RelLib.EventType.OCCUPATION,self.decode(fields[idx]))
occu_ref = RelLib.EventRef() occu_ref = RelLib.EventRef()
occu_ref.set_reference_handle(occu.get_handle()) occu_ref.set_reference_handle(occu.get_handle())
person.add_event_handle(occu_ref) person.add_event_ref(occu_ref)
idx += 1 idx += 1
elif fields[idx] == '#alias': elif fields[idx] == '#alias':
idx += 1 idx += 1
@ -622,6 +648,12 @@ class GeneWebParser:
idx += 1 idx += 1
elif fields[idx] == '#apriv': elif fields[idx] == '#apriv':
self.debug("This is a private record") self.debug("This is a private record")
person.set_privacy(True)
idx += 1
elif fields[idx] == '#h':
self.debug("This is a restricted record")
#TODO: Gramps does currently not feature this level
person.set_privacy(True)
idx += 1 idx += 1
elif dateRe.match( fields[idx]): elif dateRe.match( fields[idx]):
if not birth_date: if not birth_date:
@ -630,9 +662,18 @@ class GeneWebParser:
else: else:
self.debug("Death Date: %s" % fields[idx]) self.debug("Death Date: %s" % fields[idx])
death_date = self.parse_date(self.decode(fields[idx])) death_date = self.parse_date(self.decode(fields[idx]))
if fields[idx][0] == "k":
death_cause = "Killed"
elif fields[idx][0] == "m":
death_cause = "Murdered"
elif fields[idx][0] == "e":
death_cause = "Executed"
elif fields[idx][0] == "d":
death_cause = "Disappeared"
#TODO: Set special death types more properly
idx += 1 idx += 1
else: else:
print "Unknown field '%s' for person in line %d!" % (fields[idx],self.lineno) print "parse_person(): Unknown field '%s' for person in line %d!" % (fields[idx],self.lineno)
idx += 1 idx += 1
if public_name: if public_name:
@ -645,17 +686,11 @@ class GeneWebParser:
name.set_surname(surname) name.set_surname(surname)
person.set_primary_name(name) person.set_primary_name(name)
i = 0
for aka in nick_names: for aka in nick_names:
if i == 0: name = RelLib.Attribute()
person.set_nick_name(aka) name.set_type(RelLib.AttributeType(RelLib.AttributeType.NICKNAME))
else: name.set_value(aka)
name = RelLib.Name() person.add_attribute(name)
name.set_type(RelLib.NameType(RelLib.NameType.AKA))
name.set_first_name(aka)
name.set_surname(surname)
person.add_alternate_name(name)
i = i + 1
for aka in firstname_aliases: for aka in firstname_aliases:
name = RelLib.Name() name = RelLib.Name()
@ -696,8 +731,11 @@ class GeneWebParser:
babt_ref.set_reference_handle( babt.get_handle()) babt_ref.set_reference_handle( babt.get_handle())
person.add_event_ref( babt_ref) person.add_event_ref( babt_ref)
if death_date or death_place or death_source: if death_date or death_place or death_source or death_cause:
death = self.create_event(RelLib.EventType.DEATH, None, death_date, death_place, death_source) death = self.create_event(RelLib.EventType.DEATH, None, death_date, death_place, death_source)
if death_cause:
death.set_description(death_cause)
self.db.commit_event(death,self.trans)
death_ref = RelLib.EventRef() death_ref = RelLib.EventRef()
death_ref.set_reference_handle( death.get_handle()) death_ref.set_reference_handle( death.get_handle())
person.set_death_ref( death_ref) person.set_death_ref( death_ref)