2004-09-25 04:12:21 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-01-19 10:00:40 +05:30
|
|
|
# Copyright (C) 2000-2006 Martin Hawlisch, Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2004-09-25 04:12:21 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
"Import from GeneWeb"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import re
|
|
|
|
import time
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
|
|
|
from gen.ggettext import ngettext
|
2004-09-25 04:12:21 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG = logging.getLogger(".ImportGeneWeb")
|
2006-03-05 10:01:24 +05:30
|
|
|
|
2004-09-25 04:12:21 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Errors
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2004-09-25 04:12:21 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2005-05-24 18:38:06 +05:30
|
|
|
from htmlentitydefs import name2codepoint
|
2004-09-25 04:12:21 +05:30
|
|
|
|
2006-11-05 02:22:09 +05:30
|
|
|
_date_parse = re.compile('([kmes~?<>]+)?([0-9/]+)([J|H|F])?(\.\.)?([0-9/]+)?([J|H|F])?')
|
2005-12-06 12:08:09 +05:30
|
|
|
_text_parse = re.compile('0\((.*)\)')
|
|
|
|
|
|
|
|
_mod_map = {
|
2007-10-08 22:11:39 +05:30
|
|
|
'>' : gen.lib.Date.MOD_AFTER,
|
|
|
|
'<' : gen.lib.Date.MOD_BEFORE,
|
|
|
|
'~' : gen.lib.Date.MOD_ABOUT,
|
2005-12-06 12:08:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_cal_map = {
|
2007-10-08 22:11:39 +05:30
|
|
|
'J' : gen.lib.Date.CAL_JULIAN,
|
|
|
|
'H' : gen.lib.Date.CAL_HEBREW,
|
|
|
|
'F' : gen.lib.Date.CAL_FRENCH,
|
2005-12-06 12:08:09 +05:30
|
|
|
}
|
|
|
|
|
2004-09-25 04:12:21 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def importData(database, filename, cb=None):
|
|
|
|
|
|
|
|
global callback
|
|
|
|
|
|
|
|
try:
|
|
|
|
g = GeneWebParser(database,filename)
|
|
|
|
except IOError,msg:
|
|
|
|
ErrorDialog(_("%s could not be opened\n") % filename,str(msg))
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
status = g.parse_geneweb_file()
|
|
|
|
except IOError,msg:
|
|
|
|
errmsg = _("%s could not be opened\n") % filename
|
|
|
|
ErrorDialog(errmsg,str(msg))
|
|
|
|
return
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
2005-05-11 19:34:47 +05:30
|
|
|
# For a description of the file format see
|
|
|
|
# http://cristal.inria.fr/~ddr/GeneWeb/en/gwformat.htm
|
2004-09-25 04:12:21 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class GeneWebParser(object):
|
2004-09-25 04:12:21 +05:30
|
|
|
def __init__(self, dbase, file):
|
|
|
|
self.db = dbase
|
|
|
|
self.f = open(file,"rU")
|
|
|
|
self.filename = file
|
2007-02-28 22:12:38 +05:30
|
|
|
self.encoding = 'iso-8859-1'
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
def get_next_line(self):
|
2005-04-11 16:40:50 +05:30
|
|
|
self.lineno += 1
|
2004-09-25 04:12:21 +05:30
|
|
|
line = self.f.readline()
|
|
|
|
if line:
|
2006-03-01 01:24:35 +05:30
|
|
|
try:
|
|
|
|
line = unicode(line.strip())
|
|
|
|
except UnicodeDecodeError:
|
2007-02-28 22:12:38 +05:30
|
|
|
line = unicode(line.strip(),self.encoding)
|
2004-09-25 04:12:21 +05:30
|
|
|
else:
|
|
|
|
line = None
|
|
|
|
return line
|
|
|
|
|
|
|
|
def parse_geneweb_file(self):
|
2006-01-19 10:00:40 +05:30
|
|
|
self.trans = self.db.transaction_begin("",batch=True)
|
2005-04-06 15:52:18 +05:30
|
|
|
self.db.disable_signals()
|
2004-09-25 04:12:21 +05:30
|
|
|
t = time.time()
|
2005-04-11 16:40:50 +05:30
|
|
|
self.lineno = 0
|
2004-09-25 04:12:21 +05:30
|
|
|
self.index = 0
|
|
|
|
self.fam_count = 0
|
|
|
|
self.indi_count = 0
|
|
|
|
|
|
|
|
self.fkeys = []
|
|
|
|
self.ikeys = {}
|
|
|
|
self.pkeys = {}
|
|
|
|
self.skeys = {}
|
|
|
|
|
|
|
|
self.current_mode = None
|
|
|
|
self.current_family = None
|
|
|
|
self.current_husband_handle = None
|
2005-04-11 16:40:50 +05:30
|
|
|
self.current_child_birthplace_handle = None
|
|
|
|
self.current_child_source_handle = None
|
2004-09-25 04:12:21 +05:30
|
|
|
try:
|
|
|
|
while 1:
|
|
|
|
line = self.get_next_line()
|
2008-06-16 20:31:46 +05:30
|
|
|
if line is None:
|
2004-09-25 04:12:21 +05:30
|
|
|
break
|
|
|
|
if line == "":
|
|
|
|
continue
|
|
|
|
|
|
|
|
fields = line.split(" ")
|
|
|
|
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("LINE: %s" %line)
|
2004-09-25 04:12:21 +05:30
|
|
|
if fields[0] == "fam":
|
2006-04-20 21:56:12 +05:30
|
|
|
self.current_mode = "fam"
|
2004-09-25 04:12:21 +05:30
|
|
|
self.read_family_line(line,fields)
|
2006-04-20 21:56:12 +05:30
|
|
|
elif fields[0] == "rel":
|
|
|
|
self.current_mode = "rel"
|
|
|
|
self.read_relationship_person(line,fields)
|
2004-09-25 04:12:21 +05:30
|
|
|
elif fields[0] == "src":
|
|
|
|
self.read_source_line(line,fields)
|
2007-02-28 22:12:38 +05:30
|
|
|
elif fields[0] in ("wit", "wit:"):
|
2004-09-25 04:12:21 +05:30
|
|
|
self.read_witness_line(line,fields)
|
|
|
|
elif fields[0] == "cbp":
|
|
|
|
self.read_children_birthplace_line(line,fields)
|
2005-04-11 16:40:50 +05:30
|
|
|
elif fields[0] == "csrc":
|
|
|
|
self.read_children_source_line(line,fields)
|
2006-04-20 21:56:12 +05:30
|
|
|
elif fields[0] == "beg" and self.current_mode == "fam":
|
2004-09-25 04:12:21 +05:30
|
|
|
self.read_children_lines()
|
2006-04-20 21:56:12 +05:30
|
|
|
elif fields[0] == "beg" and self.current_mode == "rel":
|
|
|
|
self.read_relation_lines()
|
2004-09-25 04:12:21 +05:30
|
|
|
elif fields[0] == "comm":
|
|
|
|
self.read_family_comment(line,fields)
|
|
|
|
elif fields[0] == "notes":
|
2007-02-28 22:12:38 +05:30
|
|
|
self.read_person_notes_lines(line,fields)
|
|
|
|
elif fields[0] == "notes-db":
|
|
|
|
self.read_database_notes_lines(line,fields)
|
2004-09-25 04:12:21 +05:30
|
|
|
elif fields[0] == "end":
|
|
|
|
self.current_mode = None
|
2007-02-28 22:12:38 +05:30
|
|
|
elif fields[0] == "encoding:":
|
|
|
|
self.encoding = fields[1]
|
2004-09-25 04:12:21 +05:30
|
|
|
else:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("parse_geneweb_file(): Token >%s< unknown. line %d skipped: %s" %
|
|
|
|
(fields[0],self.lineno,line))
|
2004-09-25 04:12:21 +05:30
|
|
|
except Errors.GedcomError, err:
|
|
|
|
self.errmsg(str(err))
|
|
|
|
|
|
|
|
t = time.time() - t
|
2009-02-02 22:43:02 +05:30
|
|
|
msg = ngettext('Import Complete: %d second','Import Complete: %d seconds', t ) % t
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
self.db.transaction_commit(self.trans,_("GeneWeb import"))
|
2005-04-06 15:52:18 +05:30
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.request_rebuild()
|
2004-09-25 04:12:21 +05:30
|
|
|
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug(msg)
|
|
|
|
LOG.debug("Families: %d" % len(self.fkeys))
|
|
|
|
LOG.debug("Individuals: %d" % len(self.ikeys))
|
2004-09-25 04:12:21 +05:30
|
|
|
return None
|
|
|
|
|
|
|
|
def read_family_line(self,line,fields):
|
|
|
|
self.current_husband_handle = None
|
2005-04-11 16:40:50 +05:30
|
|
|
self.current_child_birthplace_handle = None
|
|
|
|
self.current_child_source_handle = None
|
2007-10-08 22:11:39 +05:30
|
|
|
self.current_family = gen.lib.Family()
|
2004-09-25 04:12:21 +05:30
|
|
|
self.db.add_family(self.current_family,self.trans)
|
2006-04-20 21:56:12 +05:30
|
|
|
#self.db.commit_family(self.current_family,self.trans)
|
2004-09-25 04:12:21 +05:30
|
|
|
self.fkeys.append(self.current_family.get_handle())
|
|
|
|
idx = 1;
|
|
|
|
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("\nHusband:")
|
2008-02-24 19:25:55 +05:30
|
|
|
(idx, husband) = self.parse_person(fields,idx,gen.lib.Person.MALE,None)
|
2004-09-25 04:12:21 +05:30
|
|
|
if husband:
|
|
|
|
self.current_husband_handle = husband.get_handle()
|
|
|
|
self.current_family.set_father_handle(husband.get_handle())
|
|
|
|
self.db.commit_family(self.current_family,self.trans)
|
|
|
|
husband.add_family_handle(self.current_family.get_handle())
|
|
|
|
self.db.commit_person(husband,self.trans)
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Marriage:")
|
2004-09-25 04:12:21 +05:30
|
|
|
idx = self.parse_marriage(fields,idx)
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Wife:")
|
2007-10-08 22:11:39 +05:30
|
|
|
(idx,wife) = self.parse_person(fields,idx,gen.lib.Person.FEMALE,None)
|
2004-09-25 04:12:21 +05:30
|
|
|
if wife:
|
|
|
|
self.current_family.set_mother_handle(wife.get_handle())
|
|
|
|
self.db.commit_family(self.current_family,self.trans)
|
|
|
|
wife.add_family_handle(self.current_family.get_handle())
|
|
|
|
self.db.commit_person(wife,self.trans)
|
|
|
|
return None
|
2006-04-20 21:56:12 +05:30
|
|
|
|
|
|
|
def read_relationship_person(self,line,fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("\Relationships:")
|
2007-10-08 22:11:39 +05:30
|
|
|
(idx,person) = self.parse_person(fields,1,gen.lib.Person.UNKNOWN,None)
|
2006-04-20 21:56:12 +05:30
|
|
|
if person:
|
|
|
|
self.current_relationship_person_handle = person.get_handle()
|
|
|
|
|
|
|
|
def read_relation_lines(self):
|
|
|
|
if not self.current_relationship_person_handle:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Unknown person for relationship in line %d!" % self.lineno)
|
2006-04-20 21:56:12 +05:30
|
|
|
return None
|
|
|
|
rel_person = self.db.get_person_from_handle(self.current_relationship_person_handle)
|
|
|
|
while 1:
|
|
|
|
line = self.get_next_line()
|
2008-06-16 20:31:46 +05:30
|
|
|
if line is None or line == "end":
|
2006-04-20 21:56:12 +05:30
|
|
|
break
|
|
|
|
if line == "":
|
|
|
|
continue
|
|
|
|
|
|
|
|
# match relationship type and related person
|
|
|
|
line_re = re.compile("^- ([^:]+): (.*)$")
|
|
|
|
matches = line_re.match(line)
|
|
|
|
if matches:
|
|
|
|
#split related person into fields
|
|
|
|
fields = matches.groups()[1].split(" ")
|
|
|
|
if fields:
|
2007-10-08 22:11:39 +05:30
|
|
|
(idx,asso_p) = self.parse_person(fields,0,gen.lib.Person.UNKNOWN,None)
|
|
|
|
pref = gen.lib.PersonRef()
|
2006-11-05 02:22:09 +05:30
|
|
|
pref.set_relation(matches.groups()[0])
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("TODO: Handle association types properly")
|
2006-11-05 02:22:09 +05:30
|
|
|
pref.set_reference_handle(asso_p.get_handle())
|
|
|
|
rel_person.add_person_ref(pref)
|
|
|
|
self.db.commit_person(rel_person,self.trans)
|
2006-04-20 21:56:12 +05:30
|
|
|
else:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Invalid name of person in line %d" % self.lineno)
|
2006-04-20 21:56:12 +05:30
|
|
|
else:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Invalid relationship in line %d" % self.lineno)
|
2006-04-20 21:56:12 +05:30
|
|
|
break
|
|
|
|
self.current_mode = None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-09-25 04:12:21 +05:30
|
|
|
def read_source_line(self,line,fields):
|
|
|
|
if not self.current_family:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Unknown family of child in line %d!" % self.lineno)
|
2005-02-20 00:35:48 +05:30
|
|
|
return None
|
2004-09-25 04:12:21 +05:30
|
|
|
source = self.get_or_create_source(self.decode(fields[1]))
|
|
|
|
self.current_family.add_source_reference(source)
|
|
|
|
self.db.commit_family(self.current_family,self.trans)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def read_witness_line(self,line,fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Witness:")
|
2004-09-25 04:12:21 +05:30
|
|
|
if fields[1] == "m:":
|
2007-10-08 22:11:39 +05:30
|
|
|
(idx,wit_p) = self.parse_person(fields,2,gen.lib.Person.MALE,None)
|
2004-09-25 04:12:21 +05:30
|
|
|
elif fields[1] == "f:":
|
2007-10-08 22:11:39 +05:30
|
|
|
(idx,wit_p) = self.parse_person(fields,2,gen.lib.Person.FEMALE,None)
|
2004-09-25 04:12:21 +05:30
|
|
|
else:
|
2006-11-05 02:22:09 +05:30
|
|
|
(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())
|
2007-10-08 22:11:39 +05:30
|
|
|
if ev.get_type() == gen.lib.EventType.MARRIAGE:
|
2006-11-05 02:22:09 +05:30
|
|
|
mev = ev # found.
|
|
|
|
if not mev: # No marriage event found create a new one
|
2007-10-08 22:11:39 +05:30
|
|
|
mev = self.create_event(gen.lib.EventType.MARRIAGE, None, None, None, None)
|
|
|
|
mar_ref = gen.lib.EventRef()
|
2006-11-05 02:22:09 +05:30
|
|
|
mar_ref.set_reference_handle(mev.get_handle())
|
|
|
|
self.current_family.add_event_ref(mar_ref)
|
2007-10-08 22:11:39 +05:30
|
|
|
wit_ref = gen.lib.EventRef()
|
|
|
|
wit_ref.set_role(gen.lib.EventRoleType(gen.lib.EventRoleType.WITNESS))
|
2006-11-05 02:22:09 +05:30
|
|
|
wit_ref.set_reference_handle(mev.get_handle())
|
|
|
|
wit_p.add_event_ref(wit_ref)
|
|
|
|
self.db.commit_person(wit_p,self.trans)
|
2004-09-25 04:12:21 +05:30
|
|
|
return None
|
|
|
|
|
|
|
|
def read_children_lines(self):
|
|
|
|
father_surname = "Dummy"
|
|
|
|
if not self.current_husband_handle:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Unknown father for child in line %d!" % self.lineno)
|
2004-09-25 04:12:21 +05:30
|
|
|
return None
|
|
|
|
husb = self.db.get_person_from_handle(self.current_husband_handle)
|
|
|
|
father_surname = husb.get_primary_name().get_surname()
|
|
|
|
if not self.current_family:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Unknown family of child in line %d!" % self.lineno)
|
2005-02-20 00:35:48 +05:30
|
|
|
return None
|
2004-09-25 04:12:21 +05:30
|
|
|
while 1:
|
|
|
|
line = self.get_next_line()
|
2008-06-16 20:31:46 +05:30
|
|
|
if line is None:
|
2004-09-25 04:12:21 +05:30
|
|
|
break
|
|
|
|
if line == "":
|
|
|
|
continue
|
|
|
|
|
|
|
|
fields = line.split(" ")
|
|
|
|
if fields[0] == "-":
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Child:")
|
2004-09-25 04:12:21 +05:30
|
|
|
child = None
|
|
|
|
if fields[1] == "h":
|
2007-10-08 22:11:39 +05:30
|
|
|
(idx,child) = self.parse_person(fields,2,gen.lib.Person.MALE,father_surname)
|
2004-09-25 04:12:21 +05:30
|
|
|
elif fields[1] == "f":
|
2007-10-08 22:11:39 +05:30
|
|
|
(idx,child) = self.parse_person(fields,2,gen.lib.Person.FEMALE,father_surname)
|
2004-09-25 04:12:21 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
(idx,child) = self.parse_person(fields,1,gen.lib.Person.UNKNOWN,father_surname)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2004-09-25 04:12:21 +05:30
|
|
|
if child:
|
2007-10-08 22:11:39 +05:30
|
|
|
childref = gen.lib.ChildRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
childref.set_reference_handle(child.get_handle())
|
|
|
|
self.current_family.add_child_ref( childref)
|
2004-09-25 04:12:21 +05:30
|
|
|
self.db.commit_family(self.current_family,self.trans)
|
2006-04-20 21:56:12 +05:30
|
|
|
child.add_parent_family_handle( self.current_family.get_handle())
|
2005-04-11 16:40:50 +05:30
|
|
|
if self.current_child_birthplace_handle:
|
2006-04-20 21:56:12 +05:30
|
|
|
birth = None
|
|
|
|
birth_ref = child.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth = self.db.get_event_from_handle(birth_ref.ref)
|
2005-04-11 16:40:50 +05:30
|
|
|
if not birth:
|
2007-10-08 22:11:39 +05:30
|
|
|
birth = self.create_event(gen.lib.EventType.BIRTH)
|
|
|
|
birth_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
birth_ref.set_reference_handle(birth.get_handle())
|
|
|
|
child.set_birth_ref(birth_ref)
|
2005-04-11 16:40:50 +05:30
|
|
|
birth.set_place_handle(self.current_child_birthplace_handle)
|
|
|
|
self.db.commit_event(birth,self.trans)
|
|
|
|
if self.current_child_source_handle:
|
|
|
|
child.add_source_reference(self.current_child_source_handle)
|
2004-09-25 04:12:21 +05:30
|
|
|
self.db.commit_person(child,self.trans)
|
|
|
|
else:
|
|
|
|
break
|
2006-04-20 21:56:12 +05:30
|
|
|
self.current_mode = None
|
2004-09-25 04:12:21 +05:30
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def read_children_birthplace_line(self,line,fields):
|
2005-04-11 16:40:50 +05:30
|
|
|
cbp = self.get_or_create_place(self.decode(fields[1]))
|
|
|
|
if cbp:
|
|
|
|
self.current_child_birthplace_handle = cbp.get_handle()
|
|
|
|
return None
|
|
|
|
|
|
|
|
def read_children_source_line(self,line,fields):
|
|
|
|
csrc = self.get_or_create_source(self.decode(fields[1]))
|
|
|
|
self.current_child_source_handle = csrc
|
2004-09-25 04:12:21 +05:30
|
|
|
return None
|
|
|
|
|
|
|
|
def read_family_comment(self,line,fields):
|
|
|
|
if not self.current_family:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Unknown family of child in line %d!" % self.lineno)
|
2005-02-20 00:35:48 +05:30
|
|
|
return None
|
2007-10-08 22:11:39 +05:30
|
|
|
n = gen.lib.Note()
|
2007-02-28 22:12:38 +05:30
|
|
|
n.set(line)
|
|
|
|
self.db.add_note(n,self.trans)
|
|
|
|
self.current_family.add_note(n.handle)
|
2004-09-25 04:12:21 +05:30
|
|
|
self.db.commit_family(self.current_family,self.trans)
|
|
|
|
return None
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def _read_notes_lines(self, note_tag):
|
2004-09-25 04:12:21 +05:30
|
|
|
note_txt = ""
|
2006-03-01 01:24:35 +05:30
|
|
|
while True:
|
2004-09-25 04:12:21 +05:30
|
|
|
line = self.get_next_line()
|
2008-06-16 20:31:46 +05:30
|
|
|
if line is None:
|
2004-09-25 04:12:21 +05:30
|
|
|
break
|
|
|
|
|
|
|
|
fields = line.split(" ")
|
2007-02-28 22:12:38 +05:30
|
|
|
if fields[0] == "end" and fields[1] == note_tag:
|
2004-09-25 04:12:21 +05:30
|
|
|
break
|
|
|
|
elif fields[0] == "beg":
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if note_txt:
|
2005-12-06 12:08:09 +05:30
|
|
|
note_txt = note_txt + "\n" + line
|
2004-09-25 04:12:21 +05:30
|
|
|
else:
|
2005-12-06 12:08:09 +05:30
|
|
|
note_txt = note_txt + line
|
2004-09-25 04:12:21 +05:30
|
|
|
if note_txt:
|
2007-10-08 22:11:39 +05:30
|
|
|
n = gen.lib.Note()
|
2007-02-28 22:12:38 +05:30
|
|
|
n.set(note_txt)
|
|
|
|
self.db.add_note(n,self.trans)
|
|
|
|
return n.handle
|
2004-09-25 04:12:21 +05:30
|
|
|
return None
|
2007-02-28 22:12:38 +05:30
|
|
|
|
|
|
|
def read_person_notes_lines(self,line,fields):
|
|
|
|
(idx,person) = self.parse_person(fields,1,None,None)
|
|
|
|
note_handle = self._read_notes_lines( fields[0])
|
|
|
|
if note_handle:
|
|
|
|
person.add_note(note_handle)
|
|
|
|
self.db.commit_person(person,self.trans)
|
|
|
|
|
|
|
|
def read_database_notes_lines(self,line,fields):
|
|
|
|
note_handle = self._read_notes_lines( fields[0])
|
|
|
|
|
2004-09-25 04:12:21 +05:30
|
|
|
def parse_marriage(self,fields,idx):
|
|
|
|
mariageDataRe = re.compile("^[+#-0-9].*$")
|
|
|
|
|
|
|
|
mar_date = None
|
|
|
|
mar_place = None
|
|
|
|
mar_source = None
|
|
|
|
|
|
|
|
sep_date = None
|
|
|
|
div_date = None
|
|
|
|
|
|
|
|
married = 1
|
|
|
|
engaged = 0
|
|
|
|
|
|
|
|
# skip to marriage date in case person contained unmatches tokens
|
|
|
|
#Alex: this failed when fields[idx] was an empty line. Fixed.
|
2005-02-20 00:35:48 +05:30
|
|
|
#while idx < len(fields) and not fields[idx][0] == "+":
|
2004-09-25 04:12:21 +05:30
|
|
|
while idx < len(fields) and not (fields[idx] and fields[idx][0] == "+"):
|
2005-12-06 12:08:09 +05:30
|
|
|
if fields[idx]:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn(("parse_marriage(): Unknown field: " +
|
|
|
|
"'%s' in line %d!") % (fields[idx], self.lineno))
|
2009-10-30 01:33:03 +05:30
|
|
|
idx += 1
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
while idx < len(fields) and mariageDataRe.match(fields[idx]):
|
2009-10-30 01:33:03 +05:30
|
|
|
field = fields[idx]
|
|
|
|
idx += 1
|
|
|
|
if field.startswith("+"):
|
|
|
|
mar_date = self.parse_date(self.decode(field))
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug(" Married at: %s" % field)
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field.startswith("-"):
|
|
|
|
div_date = self.parse_date(self.decode(field))
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug(" Div at: %s" % field)
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == "#mp" and idx < len(fields):
|
2004-09-25 04:12:21 +05:30
|
|
|
mar_place = self.get_or_create_place(self.decode(fields[idx]))
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug(" Marriage place: %s" % fields[idx])
|
2009-10-30 01:33:03 +05:30
|
|
|
idx += 1
|
|
|
|
elif field == "#ms" and idx < len(fields):
|
2004-09-25 04:12:21 +05:30
|
|
|
mar_source = self.get_or_create_source(self.decode(fields[idx]))
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug(" Marriage source: %s" % fields[idx])
|
2009-10-30 01:33:03 +05:30
|
|
|
idx += 1
|
|
|
|
elif field == "#sep" and idx < len(fields):
|
2004-09-25 04:12:21 +05:30
|
|
|
sep_date = self.parse_date(self.decode(fields[idx]))
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug(" Seperated since: %s" % fields[idx])
|
2009-10-30 01:33:03 +05:30
|
|
|
idx += 1
|
|
|
|
elif field == "#nm":
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug(" Are not married.")
|
2004-09-25 04:12:21 +05:30
|
|
|
married = 0
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == "#noment":
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug(" Not mentioned.")
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == "#eng":
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug(" Are engaged.")
|
2004-09-25 04:12:21 +05:30
|
|
|
engaged = 1
|
|
|
|
else:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn(("parse_marriage(): Unknown field " +
|
|
|
|
"'%s'for mariage in line %d!") % (field, self.lineno))
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
if mar_date or mar_place or mar_source:
|
2009-10-30 01:33:03 +05:30
|
|
|
mar = self.create_event(
|
|
|
|
gen.lib.EventType.MARRIAGE, None, mar_date, mar_place, mar_source)
|
2007-10-08 22:11:39 +05:30
|
|
|
mar_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
mar_ref.set_reference_handle(mar.get_handle())
|
|
|
|
self.current_family.add_event_ref(mar_ref)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
if div_date:
|
2009-10-30 01:33:03 +05:30
|
|
|
div = self.create_event(
|
|
|
|
gen.lib.EventType.DIVORCE, None, div_date, None, None)
|
2007-10-08 22:11:39 +05:30
|
|
|
div_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
div_ref.set_reference_handle(div.get_handle())
|
|
|
|
self.current_family.add_event_ref(div_ref)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
if sep_date or engaged:
|
2009-10-30 01:33:03 +05:30
|
|
|
sep = self.create_event(
|
|
|
|
gen.lib.EventType.ENGAGEMENT, None, sep_date, None, None)
|
2007-10-08 22:11:39 +05:30
|
|
|
sep_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
sep_ref.set_reference_handle(sep.get_handle())
|
|
|
|
self.current_family.add_event_ref(sep_ref)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
if not married:
|
2009-10-30 01:33:03 +05:30
|
|
|
self.current_family.set_relationship(
|
|
|
|
gen.lib.FamilyRelType(gen.lib.FamilyRelType.UNMARRIED))
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
self.db.commit_family(self.current_family,self.trans)
|
|
|
|
return idx
|
|
|
|
|
|
|
|
def parse_person(self,fields,idx,gender,father_surname):
|
|
|
|
|
|
|
|
if not father_surname:
|
|
|
|
if not idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Missing surname of person in line %d!" % self.lineno)
|
2006-03-01 01:24:35 +05:30
|
|
|
surname =""
|
|
|
|
else:
|
|
|
|
surname = self.decode(fields[idx])
|
2009-10-30 01:33:03 +05:30
|
|
|
idx += 1
|
2004-09-25 04:12:21 +05:30
|
|
|
else:
|
|
|
|
surname = father_surname
|
|
|
|
|
|
|
|
if not idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Missing firstname of person in line %d!" % self.lineno)
|
2006-03-01 01:24:35 +05:30
|
|
|
firstname = ""
|
|
|
|
else:
|
|
|
|
firstname = self.decode(fields[idx])
|
2009-10-30 01:33:03 +05:30
|
|
|
idx += 1
|
2004-09-25 04:12:21 +05:30
|
|
|
if idx < len(fields) and father_surname:
|
|
|
|
noSurnameRe = re.compile("^[({\[~><?0-9#].*$")
|
2005-12-06 12:08:09 +05:30
|
|
|
if not noSurnameRe.match(fields[idx]):
|
2004-09-25 04:12:21 +05:30
|
|
|
surname = self.decode(fields[idx])
|
2009-10-30 01:33:03 +05:30
|
|
|
idx += 1
|
2004-09-25 04:12:21 +05:30
|
|
|
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Person: %s %s" % (firstname, surname))
|
2004-09-25 04:12:21 +05:30
|
|
|
person = self.get_or_create_person(firstname,surname)
|
2007-10-08 22:11:39 +05:30
|
|
|
name = gen.lib.Name()
|
|
|
|
name.set_type( gen.lib.NameType(gen.lib.NameType.BIRTH))
|
2004-09-25 04:12:21 +05:30
|
|
|
name.set_first_name(firstname)
|
|
|
|
name.set_surname(surname)
|
|
|
|
person.set_primary_name(name)
|
2008-06-16 20:31:46 +05:30
|
|
|
if person.get_gender() == gen.lib.Person.UNKNOWN and gender is not None:
|
2004-09-25 04:12:21 +05:30
|
|
|
person.set_gender(gender)
|
|
|
|
self.db.commit_person(person,self.trans)
|
2006-11-05 02:22:09 +05:30
|
|
|
personDataRe = re.compile("^[kmes0-9<>~#\[({!].*$")
|
|
|
|
dateRe = re.compile("^[kmes0-9~<>?]+.*$")
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
source = None
|
2006-11-09 12:40:26 +05:30
|
|
|
birth_parsed = False
|
2004-09-25 04:12:21 +05:30
|
|
|
birth_date = None
|
|
|
|
birth_place = None
|
|
|
|
birth_source = None
|
|
|
|
|
|
|
|
bapt_date = None
|
|
|
|
bapt_place = None
|
|
|
|
bapt_source = None
|
|
|
|
|
|
|
|
death_date = None
|
|
|
|
death_place = None
|
|
|
|
death_source = None
|
2006-11-05 02:22:09 +05:30
|
|
|
death_cause = None
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
crem_date = None
|
|
|
|
bur_date = None
|
|
|
|
bur_place = None
|
|
|
|
bur_source = None
|
|
|
|
|
|
|
|
public_name = None
|
|
|
|
firstname_aliases = []
|
|
|
|
nick_names = []
|
|
|
|
name_aliases = []
|
|
|
|
surname_aliases = []
|
|
|
|
|
|
|
|
while idx < len(fields) and personDataRe.match(fields[idx]):
|
2009-10-30 01:33:03 +05:30
|
|
|
field = fields[idx]
|
|
|
|
idx += 1
|
|
|
|
if field.startswith('('):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Public Name: %s" % field)
|
2009-10-30 01:33:03 +05:30
|
|
|
public_name = self.decode(field[1:-1])
|
|
|
|
elif field.startswith('{'):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Firstsname Alias: %s" % field)
|
2009-10-30 01:33:03 +05:30
|
|
|
firstname_aliases.append(self.decode(field[1:-1]))
|
|
|
|
elif field.startswith('['):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Title: %s" % field)
|
2009-10-30 01:33:03 +05:30
|
|
|
titleparts = self.decode(field[1:-1]).split(":")
|
2006-11-10 21:24:51 +05:30
|
|
|
tname = ttitle = tplace = tstart = tend = tnth = None
|
|
|
|
try:
|
|
|
|
tname = titleparts[0]
|
|
|
|
ttitle = titleparts[1]
|
2009-10-30 01:33:03 +05:30
|
|
|
if titleparts[2]:
|
2006-11-10 21:24:51 +05:30
|
|
|
tplace = self.get_or_create_place(titleparts[2])
|
|
|
|
tstart = self.parse_date(titleparts[3])
|
|
|
|
tend = self.parse_date(titleparts[4])
|
|
|
|
tnth = titleparts[5]
|
|
|
|
except IndexError: # not all parts are written all the time
|
|
|
|
pass
|
|
|
|
if tnth: # Append title numer to title
|
2009-10-30 01:33:03 +05:30
|
|
|
ttitle += ", " + tnth
|
|
|
|
title = self.create_event(
|
|
|
|
gen.lib.EventType.NOB_TITLE, ttitle, tstart, tplace)
|
2006-11-10 21:24:51 +05:30
|
|
|
# TODO: Geneweb has a start date and an end date, and therefore
|
|
|
|
# supprts stuff like: FROM about 1955 TO between 1998 and 1999
|
|
|
|
# gramps only supports one single date ore range.
|
|
|
|
if tname and tname != "*":
|
2007-10-08 22:11:39 +05:30
|
|
|
n = gen.lib.Note()
|
2007-02-28 22:12:38 +05:30
|
|
|
n.set(tname)
|
|
|
|
self.db.add_note(n,self.trans)
|
|
|
|
title.add_note( n.handle)
|
2007-10-08 22:11:39 +05:30
|
|
|
title_ref = gen.lib.EventRef()
|
2006-11-10 21:24:51 +05:30
|
|
|
title_ref.set_reference_handle(title.get_handle())
|
|
|
|
person.add_event_ref(title_ref)
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#nick' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Nick Name: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
nick_names.append(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#occu' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Occupation: %s" % fields[idx])
|
2009-10-30 01:33:03 +05:30
|
|
|
occu = self.create_event(
|
|
|
|
gen.lib.EventType.OCCUPATION, self.decode(fields[idx]))
|
2007-10-08 22:11:39 +05:30
|
|
|
occu_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
occu_ref.set_reference_handle(occu.get_handle())
|
2006-11-05 02:22:09 +05:30
|
|
|
person.add_event_ref(occu_ref)
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#alias' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Name Alias: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
name_aliases.append(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#salias' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Surname Alias: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
surname_aliases.append(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#image' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Image: %s" % fields[idx])
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#src' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Source: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
source = self.get_or_create_source(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#bs' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Birth Source: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
birth_source = self.get_or_create_source(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field[0] == '!':
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Baptize at: %s" % fields[idx])
|
2006-11-09 11:12:47 +05:30
|
|
|
bapt_date = self.parse_date(self.decode(fields[idx][1:]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#bp' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Birth Place: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
birth_place = self.get_or_create_place(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#pp' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Baptize Place: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
bapt_place = self.get_or_create_place(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#ps' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Baptize Source: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
bapt_source = self.get_or_create_source(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#dp' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Death Place: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
death_place = self.get_or_create_place(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#ds' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Death Source: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
death_source = self.get_or_create_source(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#buri' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Burial Date: %s" % fields[idx])
|
2009-10-30 01:33:03 +05:30
|
|
|
bur_date = self.parse_date(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#crem' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Cremention Date: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
crem_date = self.parse_date(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#rp' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Burial Place: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
bur_place = self.get_or_create_place(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#rs' and idx < len(fields):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Burial Source: %s" % fields[idx])
|
2004-09-25 04:12:21 +05:30
|
|
|
bur_source = self.get_or_create_source(self.decode(fields[idx]))
|
2005-12-06 12:08:09 +05:30
|
|
|
idx += 1
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#apubl':
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("This is a public record")
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#apriv':
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("This is a private record")
|
2006-11-05 02:22:09 +05:30
|
|
|
person.set_privacy(True)
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field == '#h':
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("This is a restricted record")
|
2006-11-05 02:22:09 +05:30
|
|
|
#TODO: Gramps does currently not feature this level
|
|
|
|
person.set_privacy(True)
|
2009-10-30 01:33:03 +05:30
|
|
|
elif dateRe.match(field):
|
2006-11-09 12:40:26 +05:30
|
|
|
if not birth_parsed:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Birth Date: %s" % field)
|
2009-10-30 01:33:03 +05:30
|
|
|
birth_date = self.parse_date(self.decode(field))
|
2006-11-09 12:40:26 +05:30
|
|
|
birth_parsed = True
|
2004-09-25 04:12:21 +05:30
|
|
|
else:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Death Date: %s" % field)
|
2009-10-30 01:33:03 +05:30
|
|
|
death_date = self.parse_date(self.decode(field))
|
|
|
|
if field == "mj":
|
2007-02-28 22:12:38 +05:30
|
|
|
death_cause = "Died joung"
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field.startswith("k"):
|
2006-11-05 02:22:09 +05:30
|
|
|
death_cause = "Killed"
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field.startswith("m"):
|
2006-11-05 02:22:09 +05:30
|
|
|
death_cause = "Murdered"
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field.startswith("e"):
|
2006-11-05 02:22:09 +05:30
|
|
|
death_cause = "Executed"
|
2009-10-30 01:33:03 +05:30
|
|
|
elif field.startswith("d"):
|
2006-11-05 02:22:09 +05:30
|
|
|
death_cause = "Disappeared"
|
|
|
|
#TODO: Set special death types more properly
|
2004-09-25 04:12:21 +05:30
|
|
|
else:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn(("parse_person(): Unknown field " +
|
|
|
|
"'%s' for person in line %d!") % (field, self.lineno))
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
if public_name:
|
|
|
|
name = person.get_primary_name()
|
2007-10-08 22:11:39 +05:30
|
|
|
name.set_type(gen.lib.NameType(gen.lib.NameType.BIRTH))
|
2004-09-25 04:12:21 +05:30
|
|
|
person.add_alternate_name(name)
|
2007-10-08 22:11:39 +05:30
|
|
|
name = gen.lib.Name()
|
|
|
|
name.set_type(gen.lib.NameType(gen.lib.NameType.AKA))
|
2004-09-25 04:12:21 +05:30
|
|
|
name.set_first_name(public_name)
|
|
|
|
name.set_surname(surname)
|
|
|
|
person.set_primary_name(name)
|
|
|
|
|
|
|
|
for aka in nick_names:
|
2007-10-08 22:11:39 +05:30
|
|
|
name = gen.lib.Attribute()
|
|
|
|
name.set_type(gen.lib.AttributeType(gen.lib.AttributeType.NICKNAME))
|
2006-11-05 02:22:09 +05:30
|
|
|
name.set_value(aka)
|
|
|
|
person.add_attribute(name)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
for aka in firstname_aliases:
|
2007-10-08 22:11:39 +05:30
|
|
|
name = gen.lib.Name()
|
|
|
|
name.set_type(gen.lib.NameType(gen.lib.NameType.AKA))
|
2004-09-25 04:12:21 +05:30
|
|
|
name.set_first_name(aka)
|
|
|
|
name.set_surname(surname)
|
|
|
|
person.add_alternate_name(name)
|
|
|
|
|
|
|
|
for aka in name_aliases:
|
2007-10-08 22:11:39 +05:30
|
|
|
name = gen.lib.Name()
|
|
|
|
name.set_type(gen.lib.NameType(gen.lib.NameType.AKA))
|
2004-09-25 04:12:21 +05:30
|
|
|
name.set_first_name(aka)
|
|
|
|
name.set_surname(surname)
|
|
|
|
person.add_alternate_name(name)
|
|
|
|
|
|
|
|
for aka in surname_aliases:
|
2007-10-08 22:11:39 +05:30
|
|
|
name = gen.lib.Name()
|
|
|
|
name.set_type(gen.lib.NameType(gen.lib.NameType.AKA))
|
2004-09-25 04:12:21 +05:30
|
|
|
if public_name:
|
|
|
|
name.set_first_name(public_name)
|
|
|
|
else:
|
|
|
|
name.set_first_name(firstname)
|
|
|
|
name.set_surname(aka)
|
|
|
|
person.add_alternate_name(name)
|
|
|
|
|
|
|
|
if source:
|
|
|
|
person.add_source_reference(source)
|
|
|
|
|
|
|
|
if birth_date or birth_place or birth_source:
|
2007-10-08 22:11:39 +05:30
|
|
|
birth = self.create_event(gen.lib.EventType.BIRTH, None, birth_date, birth_place, birth_source)
|
|
|
|
birth_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
birth_ref.set_reference_handle( birth.get_handle())
|
|
|
|
person.set_birth_ref( birth_ref)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
if bapt_date or bapt_place or bapt_source:
|
2007-10-08 22:11:39 +05:30
|
|
|
babt = self.create_event(gen.lib.EventType.BAPTISM, None, bapt_date, bapt_place, bapt_source)
|
|
|
|
babt_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
babt_ref.set_reference_handle( babt.get_handle())
|
|
|
|
person.add_event_ref( babt_ref)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
2006-11-05 02:22:09 +05:30
|
|
|
if death_date or death_place or death_source or death_cause:
|
2007-10-08 22:11:39 +05:30
|
|
|
death = self.create_event(gen.lib.EventType.DEATH, None, death_date, death_place, death_source)
|
2006-11-05 02:22:09 +05:30
|
|
|
if death_cause:
|
|
|
|
death.set_description(death_cause)
|
|
|
|
self.db.commit_event(death,self.trans)
|
2007-10-08 22:11:39 +05:30
|
|
|
death_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
death_ref.set_reference_handle( death.get_handle())
|
|
|
|
person.set_death_ref( death_ref)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
if bur_date:
|
2007-10-08 22:11:39 +05:30
|
|
|
bur = self.create_event(gen.lib.EventType.BURIAL, None, bur_date, bur_place, bur_source)
|
|
|
|
bur_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
bur_ref.set_reference_handle( bur.get_handle())
|
|
|
|
person.add_event_ref( bur_ref)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
if crem_date:
|
2007-10-08 22:11:39 +05:30
|
|
|
crem = self.create_event(gen.lib.EventType.CREMATION, None, crem_date, bur_place, bur_source)
|
|
|
|
crem_ref = gen.lib.EventRef()
|
2006-04-20 21:56:12 +05:30
|
|
|
crem_ref.set_reference_handle( crem.get_handle())
|
|
|
|
person.add_event_ref(crem_ref)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
self.db.commit_person(person,self.trans)
|
|
|
|
|
|
|
|
return (idx,person)
|
|
|
|
|
|
|
|
def parse_date(self,field):
|
2005-04-11 16:40:50 +05:30
|
|
|
if field == "0":
|
|
|
|
return None
|
2007-10-08 22:11:39 +05:30
|
|
|
date = gen.lib.Date()
|
2005-12-06 12:08:09 +05:30
|
|
|
matches = _text_parse.match(field)
|
|
|
|
if matches:
|
|
|
|
groups = matches.groups()
|
|
|
|
date.set_as_text(groups[0])
|
2007-10-08 22:11:39 +05:30
|
|
|
date.set_modifier(gen.lib.Date.MOD_TEXTONLY)
|
2005-12-06 12:08:09 +05:30
|
|
|
return date
|
|
|
|
|
|
|
|
matches = _date_parse.match(field)
|
|
|
|
if matches:
|
|
|
|
groups = matches.groups()
|
2007-10-08 22:11:39 +05:30
|
|
|
mod = _mod_map.get(groups[0],gen.lib.Date.MOD_NONE)
|
2005-12-06 12:08:09 +05:30
|
|
|
if groups[3] == "..":
|
2007-10-08 22:11:39 +05:30
|
|
|
mod = gen.lib.Date.MOD_SPAN
|
|
|
|
cal2 = _cal_map.get(groups[5],gen.lib.Date.CAL_GREGORIAN)
|
2005-12-06 12:08:09 +05:30
|
|
|
sub2 = self.sub_date(groups[4])
|
|
|
|
else:
|
|
|
|
sub2 = (0,0,0)
|
2007-10-08 22:11:39 +05:30
|
|
|
cal1 = _cal_map.get(groups[2],gen.lib.Date.CAL_GREGORIAN)
|
2005-12-06 12:08:09 +05:30
|
|
|
sub1 = self.sub_date(groups[1])
|
2007-10-08 22:11:39 +05:30
|
|
|
date.set(gen.lib.Date.QUAL_NONE,mod, cal1,
|
2009-07-20 12:18:40 +05:30
|
|
|
(sub1[0],sub1[1],sub1[2],0,sub2[0],sub2[1],sub2[2],0))
|
2005-12-06 12:08:09 +05:30
|
|
|
return date
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def sub_date(self,data):
|
|
|
|
vals = data.split('/')
|
|
|
|
if len(vals) == 1:
|
|
|
|
return (0,0,int(vals[0]))
|
|
|
|
elif len(vals) == 2:
|
|
|
|
return (0,int(vals[0]),int(vals[1]))
|
|
|
|
else:
|
|
|
|
return (int(vals[0]),int(vals[1]),int(vals[2]))
|
2004-09-25 04:12:21 +05:30
|
|
|
|
|
|
|
def create_event(self,type,desc=None,date=None,place=None,source=None):
|
2007-10-08 22:11:39 +05:30
|
|
|
event = gen.lib.Event()
|
2004-09-25 04:12:21 +05:30
|
|
|
if type:
|
2007-10-08 22:11:39 +05:30
|
|
|
event.set_type(gen.lib.EventType(type))
|
2004-09-25 04:12:21 +05:30
|
|
|
if desc:
|
|
|
|
event.set_description(desc)
|
|
|
|
if date:
|
|
|
|
event.set_date_object(date)
|
|
|
|
if place:
|
|
|
|
event.set_place_handle(place.get_handle())
|
|
|
|
if source:
|
|
|
|
event.add_source_reference(source)
|
|
|
|
self.db.add_event(event,self.trans)
|
|
|
|
self.db.commit_event(event,self.trans)
|
|
|
|
return event
|
|
|
|
|
|
|
|
def get_or_create_person(self,firstname,lastname):
|
|
|
|
person = None
|
|
|
|
mykey = firstname+lastname
|
2005-05-24 18:38:06 +05:30
|
|
|
if mykey in self.ikeys and firstname != "?" and lastname != "?":
|
2004-09-25 04:12:21 +05:30
|
|
|
person = self.db.get_person_from_handle(self.ikeys[mykey])
|
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
person = gen.lib.Person()
|
2004-09-25 04:12:21 +05:30
|
|
|
self.db.add_person(person,self.trans)
|
|
|
|
self.db.commit_person(person,self.trans)
|
|
|
|
self.ikeys[mykey] = person.get_handle()
|
|
|
|
return person
|
|
|
|
|
|
|
|
def get_or_create_place(self,place_name):
|
|
|
|
place = None
|
|
|
|
if place_name in self.pkeys:
|
2005-05-11 19:34:47 +05:30
|
|
|
place = self.db.get_place_from_handle(self.pkeys[place_name])
|
2004-09-25 04:12:21 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
place = gen.lib.Place()
|
2004-09-25 04:12:21 +05:30
|
|
|
place.set_title(place_name)
|
|
|
|
self.db.add_place(place,self.trans)
|
|
|
|
self.db.commit_place(place,self.trans)
|
|
|
|
self.pkeys[place_name] = place.get_handle()
|
|
|
|
return place
|
|
|
|
|
|
|
|
def get_or_create_source(self,source_name):
|
|
|
|
source = None
|
|
|
|
if source_name in self.skeys:
|
|
|
|
source = self.db.get_source_from_handle(self.skeys[source_name])
|
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
source = gen.lib.Source()
|
2004-09-25 04:12:21 +05:30
|
|
|
source.set_title(source_name)
|
|
|
|
self.db.add_source(source,self.trans)
|
|
|
|
self.db.commit_source(source,self.trans)
|
|
|
|
self.skeys[source_name] = source.get_handle()
|
2007-10-08 22:11:39 +05:30
|
|
|
sref = gen.lib.SourceRef()
|
2006-05-23 05:26:57 +05:30
|
|
|
sref.set_reference_handle(source.get_handle())
|
2004-09-25 04:12:21 +05:30
|
|
|
return sref
|
|
|
|
|
|
|
|
def decode(self,s):
|
2005-12-06 12:08:09 +05:30
|
|
|
s = s.replace('_',' ')
|
2005-05-24 18:38:06 +05:30
|
|
|
charref_re = re.compile('(&#)(x?)([0-9a-zA-Z]+)(;)')
|
|
|
|
for match in charref_re.finditer(s):
|
|
|
|
try:
|
|
|
|
if match.group(2): # HEX
|
|
|
|
nchar = unichr(int(match.group(3),16))
|
|
|
|
else: # Decimal
|
|
|
|
nchar = unichr(int(match.group(3)))
|
2008-02-24 19:25:55 +05:30
|
|
|
s = s.replace(match.group(0), nchar)
|
2005-05-24 18:38:06 +05:30
|
|
|
except UnicodeDecodeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# replace named entities
|
|
|
|
entref_re = re.compile('(&)([a-zA-Z]+)(;)')
|
|
|
|
for match in entref_re.finditer(s):
|
|
|
|
try:
|
|
|
|
if match.group(2) in name2codepoint:
|
|
|
|
nchar = unichr(name2codepoint[match.group(2)])
|
2008-02-24 19:25:55 +05:30
|
|
|
s = s.replace(match.group(0), nchar)
|
2005-05-24 18:38:06 +05:30
|
|
|
except UnicodeDecodeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return( s)
|
2004-09-25 04:12:21 +05:30
|
|
|
|
2006-04-20 21:56:12 +05:30
|
|
|
def debug( self, txt):
|
|
|
|
if enable_debug:
|
|
|
|
print txt
|