2003-05-13 20:59:22 +05:30
|
|
|
#
|
2002-10-20 19:55:16 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-01-29 10:42:01 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2002-10-20 19:55:16 +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
|
|
|
|
#
|
|
|
|
|
2004-01-17 12:21:49 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2005-07-09 01:54:54 +05:30
|
|
|
import sets
|
2003-05-06 20:46:04 +05:30
|
|
|
import shutil
|
2005-02-19 06:19:49 +05:30
|
|
|
from xml.parsers.expat import ExpatError, ParserCreate
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2006-02-02 20:23:31 +05:30
|
|
|
import re
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".ReadXML")
|
|
|
|
|
2006-01-29 10:42:01 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK+ Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-05-13 09:05:39 +05:30
|
|
|
from QuestionDialog import ErrorDialog, WarningDialog, MissingMediaDialog
|
2006-03-03 05:53:04 +05:30
|
|
|
import Mime
|
2004-04-11 08:07:13 +05:30
|
|
|
import RelLib
|
|
|
|
import const
|
2004-08-24 09:18:15 +05:30
|
|
|
import Utils
|
2004-09-17 09:00:04 +05:30
|
|
|
import DateHandler
|
2005-06-16 09:26:13 +05:30
|
|
|
import NameDisplay
|
2006-01-31 07:11:55 +05:30
|
|
|
from _GrampsDbBase import \
|
|
|
|
PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\
|
|
|
|
MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Try to detect the presence of gzip
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
try:
|
|
|
|
import gzip
|
|
|
|
gzip_ok = 1
|
|
|
|
except:
|
|
|
|
gzip_ok = 0
|
|
|
|
|
2006-02-02 20:23:31 +05:30
|
|
|
personRE = re.compile(r"\s*\<person\s(.*)$")
|
|
|
|
|
2006-04-14 21:30:46 +05:30
|
|
|
crel_map = {
|
|
|
|
"Birth" : RelLib.ChildRefType(RelLib.ChildRefType.BIRTH),
|
|
|
|
"Adopted" : RelLib.ChildRefType(RelLib.ChildRefType.ADOPTED),
|
|
|
|
"Stepchild" : RelLib.ChildRefType(RelLib.ChildRefType.STEPCHILD),
|
|
|
|
"Sponsored" : RelLib.ChildRefType(RelLib.ChildRefType.SPONSORED),
|
|
|
|
"Foster" : RelLib.ChildRefType(RelLib.ChildRefType.FOSTER),
|
|
|
|
"Unknown" : RelLib.ChildRefType(RelLib.ChildRefType.UNKNOWN),
|
|
|
|
}
|
|
|
|
|
2006-04-16 10:07:02 +05:30
|
|
|
_event_family_str = _("%(event_name)s of %(family)s")
|
|
|
|
_event_person_str = _("%(event_name)s of %(person)s")
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2003-05-06 20:46:04 +05:30
|
|
|
# Importing data into the currently open database.
|
|
|
|
# Must takes care of renaming media files according to their new IDs.
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-01-31 07:11:55 +05:30
|
|
|
def importData(database, filename, callback=None,cl=0,use_trans=False):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-03-28 07:58:04 +05:30
|
|
|
filename = os.path.normpath(filename)
|
2002-10-20 19:55:16 +05:30
|
|
|
basefile = os.path.dirname(filename)
|
|
|
|
database.smap = {}
|
|
|
|
database.pmap = {}
|
|
|
|
database.fmap = {}
|
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
change = os.path.getmtime(filename)
|
2004-10-23 09:26:48 +05:30
|
|
|
parser = GrampsParser(database,callback,basefile,change,filename)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-18 06:58:35 +05:30
|
|
|
linecounter = LineParser(filename)
|
|
|
|
lc = linecounter.get_count()
|
2006-02-02 20:23:31 +05:30
|
|
|
pc = linecounter.get_person_count()
|
2005-12-18 06:58:35 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
ro = database.readonly
|
|
|
|
database.readonly = False
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
if gzip_ok:
|
|
|
|
use_gzip = 1
|
|
|
|
try:
|
|
|
|
f = gzip.open(filename,"r")
|
|
|
|
f.read(1)
|
|
|
|
f.close()
|
|
|
|
except IOError,msg:
|
|
|
|
use_gzip = 0
|
2003-04-20 09:22:54 +05:30
|
|
|
except ValueError, msg:
|
|
|
|
use_gzip = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
use_gzip = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
if use_gzip:
|
|
|
|
xml_file = gzip.open(filename,"rb")
|
|
|
|
else:
|
|
|
|
xml_file = open(filename,"r")
|
|
|
|
except IOError,msg:
|
2003-05-21 23:36:41 +05:30
|
|
|
if cl:
|
|
|
|
print "Error: %s could not be opened Exiting." % filename
|
|
|
|
print msg
|
|
|
|
os._exit(1)
|
|
|
|
else:
|
|
|
|
ErrorDialog(_("%s could not be opened") % filename,str(msg))
|
2004-10-06 09:12:54 +05:30
|
|
|
return
|
2002-10-20 19:55:16 +05:30
|
|
|
except:
|
2003-05-21 23:36:41 +05:30
|
|
|
if cl:
|
|
|
|
print "Error: %s could not be opened. Exiting." % filename
|
|
|
|
os._exit(1)
|
|
|
|
else:
|
|
|
|
ErrorDialog(_("%s could not be opened") % filename)
|
2004-10-06 09:12:54 +05:30
|
|
|
return
|
2002-10-20 19:55:16 +05:30
|
|
|
try:
|
2006-02-02 20:23:31 +05:30
|
|
|
parser.parse(xml_file,use_trans,lc,pc)
|
2002-10-20 19:55:16 +05:30
|
|
|
except IOError,msg:
|
2003-05-21 23:36:41 +05:30
|
|
|
if cl:
|
|
|
|
print "Error reading %s" % filename
|
|
|
|
print msg
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
os._exit(1)
|
|
|
|
else:
|
|
|
|
ErrorDialog(_("Error reading %s") % filename,str(msg))
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
2004-10-06 09:12:54 +05:30
|
|
|
return
|
2005-02-19 06:19:49 +05:30
|
|
|
except ExpatError, msg:
|
2003-05-21 23:36:41 +05:30
|
|
|
if cl:
|
|
|
|
print "Error reading %s" % filename
|
|
|
|
print "The file is probably either corrupt or not a valid GRAMPS database."
|
|
|
|
os._exit(1)
|
|
|
|
else:
|
|
|
|
ErrorDialog(_("Error reading %s") % filename,
|
|
|
|
_("The file is probably either corrupt or not a valid GRAMPS database."))
|
2004-10-06 09:12:54 +05:30
|
|
|
return
|
2006-04-13 21:46:00 +05:30
|
|
|
# except:
|
|
|
|
# if cl:
|
|
|
|
# import traceback
|
|
|
|
# traceback.print_exc()
|
|
|
|
# os._exit(1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
xml_file.close()
|
2004-06-27 23:38:19 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
database.readonly = ro
|
|
|
|
|
2004-06-23 02:19:22 +05:30
|
|
|
# copy all local images into <database>.images directory
|
|
|
|
db_dir = os.path.abspath(os.path.dirname(database.get_save_path()))
|
|
|
|
db_base = os.path.basename(database.get_save_path())
|
|
|
|
img_dir = "%s/%s.images" % (db_dir,db_base)
|
|
|
|
first = not os.path.exists(img_dir)
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
for m_id in database.get_media_object_handles():
|
2004-08-07 10:46:57 +05:30
|
|
|
mobject = database.get_object_from_handle(m_id)
|
2004-06-23 02:19:22 +05:30
|
|
|
oldfile = mobject.get_path()
|
2005-03-07 05:17:26 +05:30
|
|
|
if oldfile and oldfile[0] != '/':
|
2004-06-23 02:19:22 +05:30
|
|
|
if first:
|
|
|
|
os.mkdir(img_dir)
|
|
|
|
first = 0
|
|
|
|
newfile = "%s/%s" % (img_dir,oldfile)
|
2004-08-25 08:32:25 +05:30
|
|
|
|
2004-06-23 02:19:22 +05:30
|
|
|
try:
|
|
|
|
oldfilename = "%s/%s" % (basefile,oldfile)
|
|
|
|
shutil.copyfile(oldfilename,newfile)
|
|
|
|
try:
|
|
|
|
shutil.copystat(oldfilename,newfile)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
mobject.set_path(newfile)
|
2004-08-25 08:32:25 +05:30
|
|
|
database.commit_media_object(mobject,None,change)
|
|
|
|
except (IOError,OSError),msg:
|
|
|
|
ErrorDialog(_('Could not copy file'),str(msg))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2004-04-11 08:07:13 +05:30
|
|
|
# Remove extraneous spaces
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def rs(text):
|
2005-02-28 07:21:21 +05:30
|
|
|
return ' '.join(text.split())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def fix_spaces(text_list):
|
2005-02-28 07:21:21 +05:30
|
|
|
return '\n'.join(map(rs,text_list))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-18 06:58:35 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class LineParser:
|
|
|
|
def __init__(self, filename):
|
|
|
|
|
|
|
|
self.count = 0
|
2006-02-02 20:23:31 +05:30
|
|
|
self.person_count = 0
|
2005-12-18 06:58:35 +05:30
|
|
|
|
|
|
|
if gzip_ok:
|
|
|
|
use_gzip = 1
|
|
|
|
try:
|
|
|
|
f = gzip.open(filename,"r")
|
|
|
|
f.read(1)
|
|
|
|
f.close()
|
|
|
|
except IOError,msg:
|
|
|
|
use_gzip = 0
|
|
|
|
except ValueError, msg:
|
|
|
|
use_gzip = 1
|
|
|
|
else:
|
|
|
|
use_gzip = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
if use_gzip:
|
|
|
|
f = gzip.open(filename,"rb")
|
|
|
|
else:
|
|
|
|
f = open(filename,"r")
|
|
|
|
|
2006-02-01 11:55:51 +05:30
|
|
|
for line in f:
|
|
|
|
self.count += 1
|
2006-02-02 20:23:31 +05:30
|
|
|
if personRE.match(line):
|
|
|
|
self.person_count += 1
|
2006-02-01 11:55:51 +05:30
|
|
|
|
2005-12-18 06:58:35 +05:30
|
|
|
f.close()
|
|
|
|
except:
|
|
|
|
self.count = 0
|
2006-02-02 20:23:31 +05:30
|
|
|
self.person_count = 0
|
2005-12-18 06:58:35 +05:30
|
|
|
|
|
|
|
def get_count(self):
|
|
|
|
return self.count
|
|
|
|
|
2006-02-02 20:23:31 +05:30
|
|
|
def get_person_count(self):
|
|
|
|
return self.person_count
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps database parsing class. Derived from SAX XML parser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class GrampsParser:
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-10-23 09:26:48 +05:30
|
|
|
def __init__(self,database,callback,base,change,filename):
|
|
|
|
self.filename = filename
|
2004-04-11 08:07:13 +05:30
|
|
|
self.stext_list = []
|
|
|
|
self.scomments_list = []
|
|
|
|
self.note_list = []
|
2006-01-18 09:38:28 +05:30
|
|
|
self.oldval = 0
|
2004-04-11 08:07:13 +05:30
|
|
|
self.tlist = []
|
|
|
|
self.conf = 2
|
2004-06-27 08:40:06 +05:30
|
|
|
self.gid2id = {}
|
2004-08-20 07:50:06 +05:30
|
|
|
self.gid2fid = {}
|
2006-01-31 07:11:55 +05:30
|
|
|
self.gid2eid = {}
|
2004-08-24 09:18:15 +05:30
|
|
|
self.gid2pid = {}
|
|
|
|
self.gid2oid = {}
|
|
|
|
self.gid2sid = {}
|
2006-01-31 07:11:55 +05:30
|
|
|
self.gid2rid = {}
|
2006-04-13 21:46:00 +05:30
|
|
|
self.childref_map = {}
|
2004-08-24 09:18:15 +05:30
|
|
|
self.change = change
|
2004-12-29 10:36:10 +05:30
|
|
|
self.dp = DateHandler.parser
|
2005-07-09 01:54:54 +05:30
|
|
|
self.place_names = sets.Set()
|
|
|
|
cursor = database.get_place_cursor()
|
|
|
|
data = cursor.next()
|
|
|
|
while data:
|
|
|
|
(handle,val) = data
|
|
|
|
self.place_names.add(val[2])
|
|
|
|
data = cursor.next()
|
|
|
|
cursor.close()
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
self.ord = None
|
|
|
|
self.objref = None
|
|
|
|
self.object = None
|
2006-01-31 07:11:55 +05:30
|
|
|
self.repo = None
|
|
|
|
self.reporef = None
|
2004-04-11 08:07:13 +05:30
|
|
|
self.pref = None
|
|
|
|
self.use_p = 0
|
|
|
|
self.in_note = 0
|
|
|
|
self.in_stext = 0
|
|
|
|
self.in_scomments = 0
|
|
|
|
self.in_witness = 0
|
|
|
|
self.db = database
|
|
|
|
self.base = base
|
|
|
|
self.photo = None
|
|
|
|
self.person = None
|
|
|
|
self.family = None
|
|
|
|
self.address = None
|
|
|
|
self.source = None
|
|
|
|
self.source_ref = None
|
|
|
|
self.attribute = None
|
|
|
|
self.placeobj = None
|
|
|
|
self.locations = 0
|
|
|
|
self.place_map = {}
|
|
|
|
|
|
|
|
self.resname = ""
|
|
|
|
self.resaddr = ""
|
|
|
|
self.rescity = ""
|
|
|
|
self.resstate = ""
|
|
|
|
self.rescon = ""
|
|
|
|
self.respos = ""
|
|
|
|
self.resphone = ""
|
|
|
|
self.resemail = ""
|
|
|
|
|
|
|
|
self.pmap = {}
|
|
|
|
self.fmap = {}
|
|
|
|
self.smap = {}
|
|
|
|
self.lmap = {}
|
|
|
|
self.media_file_map = {}
|
|
|
|
|
|
|
|
self.callback = callback
|
2006-03-01 05:56:29 +05:30
|
|
|
if '__call__' in dir(self.callback): # callback is really callable
|
|
|
|
self.update = self.update_real
|
|
|
|
else:
|
|
|
|
self.update = self.update_empty
|
2005-12-16 05:18:06 +05:30
|
|
|
self.increment = 100
|
2004-04-11 08:07:13 +05:30
|
|
|
self.event = None
|
2006-01-29 10:42:01 +05:30
|
|
|
self.eventref = None
|
2006-04-19 07:53:08 +05:30
|
|
|
self.childref = None
|
2006-04-19 10:00:55 +05:30
|
|
|
self.personref = None
|
2004-04-11 08:07:13 +05:30
|
|
|
self.name = None
|
|
|
|
self.tempDefault = None
|
2004-08-24 09:18:15 +05:30
|
|
|
self.home = None
|
2004-04-11 08:07:13 +05:30
|
|
|
self.owner = RelLib.Researcher()
|
|
|
|
self.func_list = [None]*50
|
|
|
|
self.func_index = 0
|
|
|
|
self.func = None
|
|
|
|
self.witness_comment = ""
|
2004-06-27 08:40:06 +05:30
|
|
|
self.idswap = {}
|
2004-08-20 07:50:06 +05:30
|
|
|
self.fidswap = {}
|
2006-01-31 07:11:55 +05:30
|
|
|
self.eidswap = {}
|
2004-08-24 09:18:15 +05:30
|
|
|
self.sidswap = {}
|
|
|
|
self.pidswap = {}
|
|
|
|
self.oidswap = {}
|
2006-01-31 07:11:55 +05:30
|
|
|
self.ridswap = {}
|
2004-08-24 09:18:15 +05:30
|
|
|
self.eidswap = {}
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
self.func_map = {
|
|
|
|
"address" : (self.start_address, self.stop_address),
|
|
|
|
"addresses" : (None,None),
|
|
|
|
"childlist" : (None,None),
|
|
|
|
"aka" : (self.start_name, self.stop_aka),
|
|
|
|
"attribute" : (self.start_attribute, self.stop_attribute),
|
|
|
|
"attr_type" : (None,self.stop_attr_type),
|
|
|
|
"attr_value" : (None,self.stop_attr_value),
|
|
|
|
"bookmark" : (self.start_bmark, None),
|
|
|
|
"bookmarks" : (None, None),
|
|
|
|
"child" : (self.start_child,None),
|
|
|
|
"childof" : (self.start_childof,None),
|
2006-04-19 07:53:08 +05:30
|
|
|
"childref" : (self.start_childref,self.stop_childref),
|
2006-04-19 09:02:33 +05:30
|
|
|
"personref" : (self.start_personref,self.stop_personref),
|
2004-04-11 08:07:13 +05:30
|
|
|
"city" : (None, self.stop_city),
|
|
|
|
"country" : (None, self.stop_country),
|
|
|
|
"comment" : (None, self.stop_comment),
|
|
|
|
"created" : (self.start_created, None),
|
|
|
|
"ref" : (None, self.stop_ref),
|
2005-05-11 19:57:32 +05:30
|
|
|
"database" : (None, self.stop_database),
|
2004-04-11 08:07:13 +05:30
|
|
|
"phone" : (None, self.stop_phone),
|
|
|
|
"date" : (None, self.stop_date),
|
|
|
|
"cause" : (None, self.stop_cause),
|
|
|
|
"description": (None, self.stop_description),
|
|
|
|
"event" : (self.start_event, self.stop_event),
|
2006-01-29 10:42:01 +05:30
|
|
|
"type" : (None, self.stop_type),
|
|
|
|
"witness" : (self.start_witness,self.stop_witness),
|
|
|
|
"eventref" : (self.start_eventref,self.stop_eventref),
|
2004-11-23 10:45:37 +05:30
|
|
|
"data_item" : (self.start_data_item, None),
|
2004-04-11 08:07:13 +05:30
|
|
|
"families" : (None, self.stop_families),
|
|
|
|
"family" : (self.start_family, self.stop_family),
|
2006-01-29 10:42:01 +05:30
|
|
|
"rel" : (self.start_rel, None),
|
2004-04-11 08:07:13 +05:30
|
|
|
"father" : (self.start_father, None),
|
|
|
|
"first" : (None, self.stop_first),
|
|
|
|
"gender" : (None, self.stop_gender),
|
|
|
|
"header" : (None, None),
|
|
|
|
"last" : (self.start_last, self.stop_last),
|
|
|
|
"mother" : (self.start_mother,None),
|
|
|
|
"name" : (self.start_name, self.stop_name),
|
|
|
|
"nick" : (None, self.stop_nick),
|
|
|
|
"note" : (self.start_note, self.stop_note),
|
|
|
|
"p" : (None, self.stop_ptag),
|
|
|
|
"parentin" : (self.start_parentin,None),
|
|
|
|
"people" : (self.start_people, self.stop_people),
|
|
|
|
"person" : (self.start_person, self.stop_person),
|
|
|
|
"img" : (self.start_photo, self.stop_photo),
|
|
|
|
"objref" : (self.start_objref, self.stop_objref),
|
|
|
|
"object" : (self.start_object, self.stop_object),
|
2006-01-30 03:09:36 +05:30
|
|
|
"file" : (self.start_file, None),
|
2004-04-11 08:07:13 +05:30
|
|
|
"place" : (self.start_place, self.stop_place),
|
|
|
|
"dateval" : (self.start_dateval, None),
|
|
|
|
"daterange" : (self.start_daterange, None),
|
|
|
|
"datestr" : (self.start_datestr, None),
|
|
|
|
"places" : (None, self.stop_places),
|
|
|
|
"placeobj" : (self.start_placeobj,self.stop_placeobj),
|
2006-01-30 03:09:36 +05:30
|
|
|
"ptitle" : (None,self.stop_ptitle),
|
2004-04-11 08:07:13 +05:30
|
|
|
"location" : (self.start_location,None),
|
|
|
|
"lds_ord" : (self.start_lds_ord, self.stop_lds_ord),
|
|
|
|
"temple" : (self.start_temple, None),
|
|
|
|
"status" : (self.start_status, None),
|
|
|
|
"sealed_to" : (self.start_sealed_to, None),
|
|
|
|
"coord" : (self.start_coord,None),
|
2005-12-06 12:08:09 +05:30
|
|
|
"patronymic" : (None, self.stop_patronymic),
|
2004-04-11 08:07:13 +05:30
|
|
|
"pos" : (self.start_pos, None),
|
|
|
|
"postal" : (None, self.stop_postal),
|
|
|
|
"researcher" : (None, self.stop_research),
|
|
|
|
"resname" : (None, self.stop_resname ),
|
|
|
|
"resaddr" : (None, self.stop_resaddr ),
|
|
|
|
"rescity" : (None, self.stop_rescity ),
|
|
|
|
"resstate" : (None, self.stop_resstate ),
|
|
|
|
"rescountry" : (None, self.stop_rescountry),
|
|
|
|
"respostal" : (None, self.stop_respostal),
|
|
|
|
"resphone" : (None, self.stop_resphone),
|
|
|
|
"resemail" : (None, self.stop_resemail),
|
|
|
|
"sauthor" : (None, self.stop_sauthor),
|
|
|
|
"sabbrev" : (None, self.stop_sabbrev),
|
|
|
|
"scomments" : (None, self.stop_scomments),
|
|
|
|
"source" : (self.start_source, self.stop_source),
|
|
|
|
"sourceref" : (self.start_sourceref, self.stop_sourceref),
|
|
|
|
"sources" : (None, None),
|
|
|
|
"spage" : (None, self.stop_spage),
|
|
|
|
"spubinfo" : (None, self.stop_spubinfo),
|
|
|
|
"state" : (None, self.stop_state),
|
|
|
|
"stext" : (None, self.stop_stext),
|
|
|
|
"stitle" : (None, self.stop_stitle),
|
|
|
|
"street" : (None, self.stop_street),
|
|
|
|
"suffix" : (None, self.stop_suffix),
|
|
|
|
"title" : (None, self.stop_title),
|
2006-01-31 07:11:55 +05:30
|
|
|
"url" : (self.start_url, None),
|
|
|
|
"repository" : (self.start_repo,self.stop_repo),
|
|
|
|
"reporef" : (self.start_reporef,self.stop_reporef),
|
|
|
|
"rname" : (None, self.stop_rname),
|
2005-06-03 10:04:21 +05:30
|
|
|
}
|
|
|
|
|
2004-06-27 08:40:06 +05:30
|
|
|
def find_person_by_gramps_id(self,gramps_id):
|
|
|
|
intid = self.gid2id.get(gramps_id)
|
|
|
|
if intid:
|
2004-08-20 07:50:06 +05:30
|
|
|
person = self.db.get_person_from_handle(intid)
|
2004-06-27 08:40:06 +05:30
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
2004-08-20 07:50:06 +05:30
|
|
|
person = RelLib.Person()
|
2004-07-28 07:59:07 +05:30
|
|
|
person.set_handle(intid)
|
2004-06-27 08:40:06 +05:30
|
|
|
person.set_gramps_id(gramps_id)
|
2005-04-19 09:50:17 +05:30
|
|
|
self.db.add_person(person,self.trans)
|
2004-06-27 08:40:06 +05:30
|
|
|
self.gid2id[gramps_id] = intid
|
|
|
|
return person
|
|
|
|
|
2004-08-20 07:50:06 +05:30
|
|
|
def find_family_by_gramps_id(self,gramps_id):
|
|
|
|
intid = self.gid2fid.get(gramps_id)
|
|
|
|
if intid:
|
|
|
|
family = self.db.get_family_from_handle(intid)
|
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
|
|
|
family = RelLib.Family()
|
|
|
|
family.set_handle(intid)
|
|
|
|
family.set_gramps_id(gramps_id)
|
2005-04-19 09:50:17 +05:30
|
|
|
self.db.add_family(family,self.trans)
|
2004-08-20 07:50:06 +05:30
|
|
|
self.gid2fid[gramps_id] = intid
|
|
|
|
return family
|
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def find_event_by_gramps_id(self,gramps_id):
|
|
|
|
intid = self.gid2eid.get(gramps_id)
|
|
|
|
if intid:
|
|
|
|
event = self.db.get_event_from_handle(intid)
|
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
|
|
|
event = RelLib.Event()
|
|
|
|
event.set_handle(intid)
|
|
|
|
event.set_gramps_id(gramps_id)
|
|
|
|
self.db.add_event(event,self.trans)
|
|
|
|
self.gid2eid[gramps_id] = intid
|
|
|
|
return event
|
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
def find_place_by_gramps_id(self,gramps_id):
|
|
|
|
intid = self.gid2pid.get(gramps_id)
|
|
|
|
if intid:
|
|
|
|
place = self.db.get_place_from_handle(intid)
|
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
|
|
|
place = RelLib.Place()
|
|
|
|
place.set_handle(intid)
|
|
|
|
place.set_gramps_id(gramps_id)
|
2005-04-19 09:50:17 +05:30
|
|
|
self.db.add_place(place,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.gid2pid[gramps_id] = intid
|
|
|
|
return place
|
|
|
|
|
|
|
|
def find_source_by_gramps_id(self,gramps_id):
|
|
|
|
intid = self.gid2sid.get(gramps_id)
|
|
|
|
if intid:
|
|
|
|
source = self.db.get_source_from_handle(intid)
|
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
|
|
|
source = RelLib.Source()
|
|
|
|
source.set_handle(intid)
|
|
|
|
source.set_gramps_id(gramps_id)
|
2005-04-19 09:50:17 +05:30
|
|
|
self.db.add_source(source,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.gid2sid[gramps_id] = intid
|
|
|
|
return source
|
|
|
|
|
|
|
|
def find_object_by_gramps_id(self,gramps_id):
|
|
|
|
intid = self.gid2oid.get(gramps_id)
|
|
|
|
if intid:
|
|
|
|
obj = self.db.get_object_from_handle(intid)
|
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
|
|
|
obj = RelLib.MediaObject()
|
|
|
|
obj.set_handle(intid)
|
|
|
|
obj.set_gramps_id(gramps_id)
|
2005-04-19 09:50:17 +05:30
|
|
|
self.db.add_object(obj,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.gid2oid[gramps_id] = intid
|
|
|
|
return obj
|
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def find_repository_by_gramps_id(self,gramps_id):
|
|
|
|
intid = self.gid2rid.get(gramps_id)
|
|
|
|
if intid:
|
|
|
|
repo = self.db.get_repository_from_handle(intid)
|
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
|
|
|
repo = RelLib.Repository()
|
|
|
|
repo.set_handle(intid)
|
|
|
|
repo.set_gramps_id(gramps_id)
|
|
|
|
self.db.add_repository(repo,self.trans)
|
|
|
|
self.gid2rid[gramps_id] = intid
|
|
|
|
return repo
|
|
|
|
|
|
|
|
def map_gid(self,gramps_id):
|
|
|
|
if not self.idswap.get(gramps_id):
|
|
|
|
if self.db.has_gramps_id(PERSON_KEY,gramps_id):
|
|
|
|
self.idswap[gramps_id] = self.db.find_next_person_gramps_id()
|
|
|
|
else:
|
|
|
|
self.idswap[gramps_id] = gramps_id
|
|
|
|
return self.idswap[gramps_id]
|
|
|
|
|
|
|
|
def map_fid(self,gramps_id):
|
|
|
|
if not self.fidswap.get(gramps_id):
|
|
|
|
if self.db.has_gramps_id(FAMILY_KEY,gramps_id):
|
|
|
|
self.fidswap[gramps_id] = self.db.find_next_family_gramps_id()
|
2004-06-27 08:40:06 +05:30
|
|
|
else:
|
2006-01-31 07:11:55 +05:30
|
|
|
self.fidswap[gramps_id] = gramps_id
|
|
|
|
return self.fidswap[gramps_id]
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def map_eid(self,gramps_id):
|
|
|
|
if not self.eidswap.get(gramps_id):
|
|
|
|
if self.db.has_gramps_id(EVENT_KEY,gramps_id):
|
|
|
|
self.eidswap[gramps_id] = self.db.find_next_event_gramps_id()
|
2004-08-20 07:50:06 +05:30
|
|
|
else:
|
2006-01-31 07:11:55 +05:30
|
|
|
self.eidswap[gramps_id] = gramps_id
|
|
|
|
return self.eidswap[gramps_id]
|
2004-08-20 07:50:06 +05:30
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def map_pid(self,gramps_id):
|
|
|
|
if not self.pidswap.get(gramps_id):
|
|
|
|
if self.db.has_gramps_id(PLACE_KEY,gramps_id):
|
|
|
|
self.pidswap[gramps_id] = self.db.find_next_place_gramps_id()
|
2004-08-24 09:18:15 +05:30
|
|
|
else:
|
2006-01-31 07:11:55 +05:30
|
|
|
self.pidswap[gramps_id] = gramps_id
|
|
|
|
return self.pidswap[gramps_id]
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def map_sid(self,gramps_id):
|
|
|
|
if not self.sidswap.get(gramps_id):
|
|
|
|
if self.db.has_gramps_id(SOURCE_KEY,gramps_id):
|
|
|
|
self.sidswap[gramps_id] = self.db.find_next_source_gramps_id()
|
2004-08-24 09:18:15 +05:30
|
|
|
else:
|
2006-01-31 07:11:55 +05:30
|
|
|
self.sidswap[gramps_id] = gramps_id
|
|
|
|
return self.sidswap[gramps_id]
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def map_oid(self,gramps_id):
|
|
|
|
if not self.oidswap.get(gramps_id):
|
|
|
|
if self.db.has_gramps_id(MEDIA_KEY,gramps_id):
|
|
|
|
self.oidswap[gramps_id] = self.db.find_next_object_gramps_id()
|
2004-08-24 09:18:15 +05:30
|
|
|
else:
|
2006-01-31 07:11:55 +05:30
|
|
|
self.oidswap[gramps_id] = gramps_id
|
|
|
|
return self.oidswap[gramps_id]
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def map_rid(self,gramps_id):
|
|
|
|
if not self.ridswap.get(gramps_id):
|
|
|
|
if self.db.has_gramps_id(REPOSITORY_KEY,gramps_id):
|
|
|
|
self.ridswap[gramps_id] = self.db.find_next_repository_gramps_id()
|
|
|
|
else:
|
|
|
|
self.ridswap[gramps_id] = gramps_id
|
|
|
|
return self.ridswap[gramps_id]
|
|
|
|
|
2006-02-02 20:23:31 +05:30
|
|
|
def parse(self,file,use_trans=False,linecount=0,personcount=0):
|
|
|
|
if personcount < 1000:
|
|
|
|
no_magic = True
|
|
|
|
else:
|
|
|
|
no_magic = False
|
|
|
|
self.trans = self.db.transaction_begin("",batch=True,no_magic=no_magic)
|
2005-12-18 06:58:35 +05:30
|
|
|
self.linecount = linecount
|
2005-04-05 05:22:46 +05:30
|
|
|
|
|
|
|
self.db.disable_signals()
|
|
|
|
|
2005-12-18 06:58:35 +05:30
|
|
|
self.p = ParserCreate()
|
|
|
|
self.p.StartElementHandler = self.startElement
|
|
|
|
self.p.EndElementHandler = self.endElement
|
|
|
|
self.p.CharacterDataHandler = self.characters
|
|
|
|
self.p.ParseFile(file)
|
2006-03-07 04:00:17 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
self.db.set_researcher(self.owner)
|
2004-08-24 09:18:15 +05:30
|
|
|
if self.home != None:
|
|
|
|
person = self.db.find_person_from_handle(self.home,self.trans)
|
2006-02-01 11:55:51 +05:30
|
|
|
self.db.set_default_person_handle(person.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.tempDefault != None:
|
2006-02-01 11:55:51 +05:30
|
|
|
gramps_id = self.map_gid(self.tempDefault)
|
|
|
|
person = self.find_person_by_gramps_id(gramps_id)
|
2004-06-27 08:40:06 +05:30
|
|
|
if person:
|
2006-02-01 11:55:51 +05:30
|
|
|
self.db.set_default_person_handle(person.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
for key in self.func_map.keys():
|
|
|
|
del self.func_map[key]
|
|
|
|
del self.func_map
|
|
|
|
del self.func_list
|
2005-12-18 06:58:35 +05:30
|
|
|
del self.p
|
2006-01-31 07:11:55 +05:30
|
|
|
self.db.transaction_commit(self.trans,_("GRAMPS XML import"))
|
2005-04-05 05:22:46 +05:30
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.request_rebuild()
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_lds_ord(self,attrs):
|
2004-10-06 09:12:54 +05:30
|
|
|
atype = attrs['type']
|
2004-04-11 08:07:13 +05:30
|
|
|
self.ord = RelLib.LdsOrd()
|
|
|
|
if self.person:
|
2004-10-06 09:12:54 +05:30
|
|
|
if atype == "baptism":
|
2006-04-06 08:04:58 +05:30
|
|
|
self.ord.set_type(RelLib.LdsOrd.BAPTISM)
|
2004-10-06 09:12:54 +05:30
|
|
|
elif atype == "endowment":
|
2006-04-06 08:04:58 +05:30
|
|
|
self.ord.set_type(RelLib.LdsOrd.ENDOWMENT)
|
2004-10-06 09:12:54 +05:30
|
|
|
elif atype == "sealed_to_parents":
|
2006-04-06 08:04:58 +05:30
|
|
|
self.ord.set_type(RelLib.LdsOrd.SEAL_TO_PARENTS)
|
|
|
|
self.person.lds_ord_list.append(self.ord)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.family:
|
2004-10-06 09:12:54 +05:30
|
|
|
if atype == "sealed_to_spouse":
|
2006-04-06 08:04:58 +05:30
|
|
|
self.ord.set_type(RelLib.LdsOrd.SEAL_TO_SPOUSES)
|
|
|
|
self.family.lds_ord_list.append(self.ord)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_temple(self,attrs):
|
|
|
|
self.ord.set_temple(attrs['val'])
|
|
|
|
|
2004-11-23 10:45:37 +05:30
|
|
|
def start_data_item(self,attrs):
|
|
|
|
self.source.set_data_item(attrs['key'],attrs['value'])
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_status(self,attrs):
|
|
|
|
self.ord.set_status(int(attrs['val']))
|
|
|
|
|
|
|
|
def start_sealed_to(self,attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = attrs['hlink'].replace('_','')
|
|
|
|
self.db.check_family_from_handle(handle,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_fid(attrs['ref'])
|
|
|
|
family = self.find_family_by_gramps_id(gramps_id)
|
|
|
|
handle = family.handle
|
|
|
|
self.ord.set_family_handle(handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_place(self,attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.placeobj = self.db.find_place_from_handle(
|
|
|
|
attrs['hlink'].replace('_',''),self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_pid(attrs['ref'])
|
|
|
|
self.placeobj = self.find_place_by_gramps_id(gramps_id)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_placeobj(self,attrs):
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_pid(attrs['id'])
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.placeobj = self.db.find_place_from_handle(
|
|
|
|
attrs['handle'].replace('_',''),self.trans)
|
2006-01-31 07:11:55 +05:30
|
|
|
self.placeobj.set_gramps_id(gramps_id)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2006-01-31 07:11:55 +05:30
|
|
|
self.placeobj = self.find_place_by_gramps_id(gramps_id)
|
2006-01-30 03:09:36 +05:30
|
|
|
# GRAMPS LEGACY: title in the placeobj tag
|
|
|
|
self.placeobj.title = attrs.get('title','')
|
2004-04-11 08:07:13 +05:30
|
|
|
self.locations = 0
|
2006-01-18 09:38:28 +05:30
|
|
|
self.update()
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_location(self,attrs):
|
|
|
|
"""Bypass the function calls for this one, since it appears to
|
|
|
|
take up quite a bit of time"""
|
|
|
|
|
|
|
|
loc = RelLib.Location()
|
2006-01-29 10:42:01 +05:30
|
|
|
loc.phone = attrs.get('phone','')
|
|
|
|
loc.postal = attrs.get('postal','')
|
|
|
|
loc.city = attrs.get('city','')
|
|
|
|
loc.parish = attrs.get('parish','')
|
|
|
|
loc.state = attrs.bet('state','')
|
|
|
|
loc.county = attrs.get('county','')
|
|
|
|
loc.country = attrs.get('country','')
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.locations > 0:
|
|
|
|
self.placeobj.add_alternate_locations(loc)
|
|
|
|
else:
|
|
|
|
self.placeobj.set_main_location(loc)
|
|
|
|
self.locations = self.locations + 1
|
|
|
|
|
|
|
|
def start_witness(self,attrs):
|
2006-01-29 10:42:01 +05:30
|
|
|
# Parse witnesses created by older gramps
|
2004-04-11 08:07:13 +05:30
|
|
|
self.in_witness = 1
|
2005-05-11 19:57:32 +05:30
|
|
|
self.witness_comment = ""
|
2006-01-29 10:42:01 +05:30
|
|
|
if attrs.has_key('name'):
|
|
|
|
note_text = self.event.get_note() + "\n" + \
|
|
|
|
_("Witness name: %s") % attrs['name']
|
|
|
|
self.event.set_note(note_text)
|
|
|
|
return
|
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
try:
|
|
|
|
handle = attrs['hlink'].replace('_','')
|
|
|
|
person = self.db.find_person_from_handle(handle,self.trans)
|
|
|
|
except KeyError:
|
2004-09-01 10:27:44 +05:30
|
|
|
person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
|
2006-01-29 10:42:01 +05:30
|
|
|
# Add an EventRef from that person
|
|
|
|
# to this event using ROLE_WITNESS role
|
|
|
|
event_ref = RelLib.EventRef()
|
|
|
|
event_ref.ref = self.event.handle
|
2006-04-20 06:14:44 +05:30
|
|
|
event_ref.role.set(RelLib.EventRoleType.WITNESS)
|
2006-01-29 10:42:01 +05:30
|
|
|
person.event_ref_list.append(event_ref)
|
|
|
|
self.db.commit_person(person,self.trans,self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_coord(self,attrs):
|
2006-01-29 10:42:01 +05:30
|
|
|
self.placeobj.lat = attrs.get('lat','')
|
|
|
|
self.placeobj.long = attrs.get('long','')
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_event(self,attrs):
|
2006-01-29 10:42:01 +05:30
|
|
|
if self.person or self.family:
|
|
|
|
# GRAMPS LEGACY: old events that were written inside
|
|
|
|
# person or family objects.
|
2006-01-31 07:11:55 +05:30
|
|
|
self.event = RelLib.Event()
|
2006-01-29 10:42:01 +05:30
|
|
|
self.event.handle = Utils.create_id()
|
2006-04-20 04:29:33 +05:30
|
|
|
self.event.type = RelLib.EventType()
|
|
|
|
self.event.type.set_from_xml_str(attrs['type'])
|
2006-01-31 07:11:55 +05:30
|
|
|
self.db.add_event(self.event,self.trans)
|
2005-06-03 10:04:21 +05:30
|
|
|
else:
|
2006-01-31 07:11:55 +05:30
|
|
|
# This is new event, with ID and handle already existing
|
|
|
|
self.update()
|
|
|
|
gramps_id = self.map_eid(attrs["id"])
|
|
|
|
try:
|
|
|
|
self.event = self.db.find_event_from_handle(
|
|
|
|
attrs['handle'].replace('_',''),self.trans)
|
|
|
|
self.event.gramps_id = gramps_id
|
|
|
|
except KeyError:
|
|
|
|
self.event = self.find_event_by_gramps_id(gramps_id)
|
2006-01-29 10:42:01 +05:30
|
|
|
self.event.conf = int(attrs.get("conf",2))
|
|
|
|
self.event.private = bool(attrs.get("priv"))
|
|
|
|
|
|
|
|
def start_eventref(self,attrs):
|
|
|
|
self.eventref = RelLib.EventRef()
|
|
|
|
self.eventref.ref = attrs['hlink'].replace('_','')
|
|
|
|
self.eventref.private = bool(attrs.get('priv'))
|
2006-04-20 06:14:44 +05:30
|
|
|
self.eventref.role.set_from_xml_str(attrs.get('role'))
|
2006-04-19 23:57:51 +05:30
|
|
|
# We count here on events being already parsed prior to parsing
|
|
|
|
# people or families. This code will fail if this is not true.
|
|
|
|
event = self.db.get_event_from_handle(self.eventref.ref)
|
2006-01-29 10:42:01 +05:30
|
|
|
if self.family:
|
2006-04-19 23:57:51 +05:30
|
|
|
event.personal = False
|
2006-01-29 10:42:01 +05:30
|
|
|
self.family.add_event_ref(self.eventref)
|
|
|
|
elif self.person:
|
2006-04-19 23:57:51 +05:30
|
|
|
event.personal = True
|
2006-04-20 09:04:07 +05:30
|
|
|
if event.type == RelLib.EventType.BIRTH:
|
2006-01-29 10:42:01 +05:30
|
|
|
self.person.birth_ref = self.eventref
|
2006-04-20 09:04:07 +05:30
|
|
|
elif event.type == RelLib.EventType.DEATH:
|
2006-01-29 10:42:01 +05:30
|
|
|
self.person.death_ref = self.eventref
|
|
|
|
else:
|
|
|
|
self.person.add_event_ref(self.eventref)
|
2006-04-19 23:57:51 +05:30
|
|
|
|
2006-01-29 10:42:01 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_attribute(self,attrs):
|
|
|
|
self.attribute = RelLib.Attribute()
|
2006-01-29 10:42:01 +05:30
|
|
|
self.attribute.conf = int(attrs.get("conf",2))
|
|
|
|
self.attribute.private = bool(attrs.get("priv"))
|
2006-04-21 23:45:23 +05:30
|
|
|
self.attribute.type = RelLib.AttributeType()
|
|
|
|
self.attribute.type.set_from_xml_str(attrs.get("type",''))
|
2006-01-29 10:42:01 +05:30
|
|
|
self.attribute.value = attrs.get("value",'')
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.photo:
|
|
|
|
self.photo.add_attribute(self.attribute)
|
|
|
|
elif self.object:
|
|
|
|
self.object.add_attribute(self.attribute)
|
|
|
|
elif self.objref:
|
|
|
|
self.objref.add_attribute(self.attribute)
|
|
|
|
elif self.person:
|
|
|
|
self.person.add_attribute(self.attribute)
|
|
|
|
elif self.family:
|
|
|
|
self.family.add_attribute(self.attribute)
|
|
|
|
|
|
|
|
def start_address(self,attrs):
|
|
|
|
self.address = RelLib.Address()
|
2006-01-29 10:42:01 +05:30
|
|
|
self.address.conf = int(attrs.get("conf",2))
|
|
|
|
self.address.private = bool(attrs.get("priv"))
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_bmark(self,attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = attrs['hlink'].replace('_','')
|
|
|
|
self.db.check_person_from_handle(handle,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_gid(attrs["ref"])
|
|
|
|
person = self.find_person_by_gramps_id(gramps_id)
|
|
|
|
handle = person.handle
|
|
|
|
self.db.bookmarks.append(handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_person(self,attrs):
|
2006-01-18 09:38:28 +05:30
|
|
|
self.update()
|
2004-08-04 10:23:29 +05:30
|
|
|
new_id = self.map_gid(attrs['id'])
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.person = self.db.find_person_from_handle(
|
|
|
|
attrs['handle'].replace('_',''),self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.person.set_gramps_id(new_id)
|
|
|
|
except KeyError:
|
|
|
|
self.person = self.find_person_by_gramps_id(new_id)
|
2004-10-11 02:46:44 +05:30
|
|
|
|
2006-01-29 10:42:01 +05:30
|
|
|
# Old and new markers: complete=1 and marker=word both have to work
|
|
|
|
if attrs.get('complete'): # this is only true for complete=1
|
2006-04-20 06:14:44 +05:30
|
|
|
self.person.marker.set(RelLib.MarkerType.COMPLETE)
|
2006-01-29 10:42:01 +05:30
|
|
|
else:
|
2006-04-20 06:14:44 +05:30
|
|
|
self.person.marker.set_from_xml_str(attrs.get("marker",''))
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_people(self,attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
if attrs.has_key('home'):
|
2005-12-06 12:08:09 +05:30
|
|
|
self.home = attrs['home'].replace('_','')
|
2004-09-17 09:00:04 +05:30
|
|
|
elif attrs.has_key("default"):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.tempDefault = attrs["default"]
|
|
|
|
|
|
|
|
def start_father(self,attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = attrs['hlink'].replace('_','')
|
|
|
|
self.db.check_person_from_handle(handle,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
|
|
|
person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = person_handle
|
|
|
|
self.family.set_father_handle(handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_mother(self,attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = attrs['hlink'].replace('_','')
|
|
|
|
self.db.check_person_from_handle(handle,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
|
|
|
person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = person_handle
|
|
|
|
self.family.set_mother_handle(handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_child(self,attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = attrs['hlink'].replace('_','')
|
|
|
|
self.db.check_person_from_handle(handle,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
|
|
|
person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = person_handle
|
2006-04-19 07:53:08 +05:30
|
|
|
|
|
|
|
# Here we are handling the old XML, in which
|
|
|
|
# frel and mrel belonged to the "childof" tag
|
|
|
|
# If that were the case then childref_map has the childref ready
|
2006-04-13 21:46:00 +05:30
|
|
|
if self.childref_map.has_key((self.family.handle,handle)):
|
2006-04-19 07:53:08 +05:30
|
|
|
self.family.add_child_ref(
|
|
|
|
self.childref_map[(self.family.handle,handle)])
|
|
|
|
|
|
|
|
def start_childref(self,attrs):
|
|
|
|
# Here we are handling the new XML, in which frel and mrel
|
|
|
|
# belong to the "child" tag under family.
|
2006-04-19 09:02:33 +05:30
|
|
|
self.childref = RelLib.ChildRef()
|
|
|
|
self.childref.ref = attrs['hlink'].replace('_','')
|
2006-04-19 07:53:08 +05:30
|
|
|
self.childref.private = bool(attrs.get('priv'))
|
|
|
|
|
|
|
|
mrel = RelLib.ChildRefType().set_from_xml_str(attrs.get('mrel'))
|
|
|
|
frel = RelLib.ChildRefType().set_from_xml_str(attrs.get('frel'))
|
|
|
|
|
|
|
|
if not mrel.is_default():
|
2006-04-19 09:02:33 +05:30
|
|
|
self.childref.set_mother_relation(mrel)
|
2006-04-19 09:27:10 +05:30
|
|
|
if not frel.is_default():
|
2006-04-19 09:02:33 +05:30
|
|
|
self.childref.set_father_relation(frel)
|
2006-04-19 07:53:08 +05:30
|
|
|
self.family.add_child_reference(self.childref)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2006-04-19 09:02:33 +05:30
|
|
|
def start_personref(self,attrs):
|
|
|
|
self.personref = RelLib.PersonRef()
|
|
|
|
self.personref.ref = attrs['hlink'].replace('_','')
|
|
|
|
self.personref.private = bool(attrs.get('priv'))
|
|
|
|
self.personref.rel = attrs['rel']
|
|
|
|
self.person.add_person_ref(self.personref)
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_url(self,attrs):
|
|
|
|
if not attrs.has_key("href"):
|
|
|
|
return
|
2006-01-29 10:42:01 +05:30
|
|
|
url = RelLib.Url()
|
|
|
|
url.path = attrs["href"]
|
|
|
|
url.description = attrs.get("description",'')
|
|
|
|
url.privacy = bool(attrs.get('priv'))
|
|
|
|
if self.person:
|
|
|
|
self.person.add_url(url)
|
|
|
|
elif self.placeobj:
|
|
|
|
self.placeobj.add_url(url)
|
2006-01-31 07:11:55 +05:30
|
|
|
elif self.repo:
|
|
|
|
self.repo.add_url(url)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_family(self,attrs):
|
2006-01-18 09:38:28 +05:30
|
|
|
self.update()
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_fid(attrs["id"])
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2005-04-19 09:50:17 +05:30
|
|
|
self.family = self.db.find_family_from_handle(
|
2005-12-06 12:08:09 +05:30
|
|
|
attrs['handle'].replace('_',''),self.trans)
|
2006-01-31 07:11:55 +05:30
|
|
|
self.family.set_gramps_id(gramps_id)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2006-01-31 07:11:55 +05:30
|
|
|
self.family = self.find_family_by_gramps_id(gramps_id)
|
2006-01-29 10:42:01 +05:30
|
|
|
# GRAMPS LEGACY: the type now belongs to <rel> tag
|
|
|
|
# Here we need to support old format of <family type="Married">
|
2006-04-19 23:57:51 +05:30
|
|
|
self.family.type = RelLib.FamilyRelType().set_from_xml_str(
|
|
|
|
attrs.get("type",'Unknown'))
|
2005-06-03 10:04:21 +05:30
|
|
|
|
2006-01-29 10:42:01 +05:30
|
|
|
# Old and new markers: complete=1 and marker=word both have to work
|
|
|
|
if attrs.get('complete'): # this is only true for complete=1
|
2006-04-20 06:14:44 +05:30
|
|
|
self.family.marker.set(RelLib.MarkerType.COMPLETE)
|
2006-01-29 10:42:01 +05:30
|
|
|
else:
|
2006-04-20 06:14:44 +05:30
|
|
|
self.family.marker.set_from_xml_str(attrs.get("marker",''))
|
2006-01-29 10:42:01 +05:30
|
|
|
|
|
|
|
def start_rel(self,attrs):
|
2006-04-19 23:57:51 +05:30
|
|
|
self.family.type = RelLib.FamilyRelType().set_from_xml_str(
|
|
|
|
attrs.get("type",'Unknown'))
|
2006-01-29 10:42:01 +05:30
|
|
|
|
|
|
|
def start_file(self,attrs):
|
2006-01-30 03:09:36 +05:30
|
|
|
self.object.mime = attrs['mime']
|
|
|
|
self.object.desc = attrs['description']
|
|
|
|
src = attrs["src"]
|
|
|
|
if src:
|
|
|
|
if src[0] != '/':
|
|
|
|
fullpath = os.path.abspath(self.filename)
|
|
|
|
src = os.path.dirname(fullpath) + '/' + src
|
|
|
|
self.object.path = src
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_childof(self,attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = attrs["hlink"].replace('_','')
|
|
|
|
self.db.check_family_from_handle(handle,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
|
|
|
family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"]))
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = family.handle
|
2006-04-13 21:46:00 +05:30
|
|
|
|
2006-04-19 07:53:08 +05:30
|
|
|
# Here we are handling the old XML, in which
|
|
|
|
# frel and mrel belonged to the "childof" tag
|
|
|
|
mrel = RelLib.ChildRefType().set_from_xml_str(attrs.get('mrel'))
|
|
|
|
frel = RelLib.ChildRefType().set_from_xml_str(attrs.get('frel'))
|
2006-04-13 21:46:00 +05:30
|
|
|
|
2006-04-19 10:44:37 +05:30
|
|
|
childref = RelLib.ChildRef()
|
|
|
|
childref.ref = self.person.handle
|
|
|
|
if not mrel.is_default():
|
2006-04-13 21:46:00 +05:30
|
|
|
childref.set_mother_relation(mrel)
|
2006-04-19 10:44:37 +05:30
|
|
|
if not frel.is_default():
|
2006-04-13 21:46:00 +05:30
|
|
|
childref.set_father_relation(frel)
|
2006-04-19 10:44:37 +05:30
|
|
|
self.childref_map[(handle,self.person.handle)] = childref
|
2006-04-13 21:46:00 +05:30
|
|
|
self.person.add_parent_family_handle(handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_parentin(self,attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = attrs["hlink"].replace('_','')
|
|
|
|
self.db.check_family_from_handle(handle,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
|
|
|
family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"]))
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = family.handle
|
|
|
|
self.person.add_family_handle(handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_name(self,attrs):
|
|
|
|
if not self.in_witness:
|
|
|
|
self.name = RelLib.Name()
|
2006-04-19 10:00:55 +05:30
|
|
|
self.name.type.set_from_xml_str(attrs.get('type'))
|
2006-01-29 10:42:01 +05:30
|
|
|
self.name.sort_as = int(attrs.get("sort",RelLib.Name.DEF))
|
|
|
|
self.name.display_as = int(attrs.get("display",RelLib.Name.DEF))
|
|
|
|
self.name.conf = int(attrs.get("conf",2))
|
|
|
|
self.name.set_private = bool(attrs.get("priv"))
|
|
|
|
self.alt_name = bool(attrs.get("alt"))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_last(self,attrs):
|
2006-01-29 10:42:01 +05:30
|
|
|
self.name.prefix = attrs.get('prefix','')
|
|
|
|
self.name.group_as = attrs.get('group','')
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_note(self,attrs):
|
|
|
|
self.in_note = 1
|
|
|
|
self.note = RelLib.Note()
|
2006-01-29 10:42:01 +05:30
|
|
|
self.note.format = int(attrs.get('format',0))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_sourceref(self,attrs):
|
|
|
|
self.source_ref = RelLib.SourceRef()
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = attrs["hlink"].replace('_','')
|
|
|
|
self.db.check_source_from_handle(handle,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
|
|
|
source = self.find_source_by_gramps_id(self.map_sid(attrs["ref"]))
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = source.handle
|
|
|
|
|
|
|
|
self.source_ref.ref = handle
|
2006-01-29 10:42:01 +05:30
|
|
|
self.source_ref.confidence = int(attrs.get("conf",self.conf))
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.photo:
|
|
|
|
self.photo.add_source_reference(self.source_ref)
|
|
|
|
elif self.ord:
|
|
|
|
self.ord.add_source_reference(self.source_ref)
|
2004-06-03 11:05:30 +05:30
|
|
|
elif self.attribute:
|
|
|
|
self.attribute.add_source_reference(self.source_ref)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.object:
|
|
|
|
self.object.add_source_reference(self.source_ref)
|
2004-06-03 11:05:30 +05:30
|
|
|
elif self.objref:
|
|
|
|
self.objref.add_source_reference(self.source_ref)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.event:
|
|
|
|
self.event.add_source_reference(self.source_ref)
|
|
|
|
elif self.address:
|
|
|
|
self.address.add_source_reference(self.source_ref)
|
|
|
|
elif self.name:
|
|
|
|
self.name.add_source_reference(self.source_ref)
|
|
|
|
elif self.placeobj:
|
|
|
|
self.placeobj.add_source_reference(self.source_ref)
|
2006-04-19 07:53:08 +05:30
|
|
|
elif self.childref:
|
|
|
|
self.childref.add_source_reference(self.source_ref)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.family:
|
|
|
|
self.family.add_source_reference(self.source_ref)
|
2006-04-19 09:02:33 +05:30
|
|
|
elif self.personref:
|
|
|
|
self.personref.add_source_reference(self.source_ref)
|
2004-06-03 11:05:30 +05:30
|
|
|
elif self.person:
|
|
|
|
self.person.add_source_reference(self.source_ref)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_source(self,attrs):
|
2006-01-18 09:38:28 +05:30
|
|
|
self.update()
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_sid(attrs["id"])
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.source = self.db.find_source_from_handle(
|
|
|
|
attrs['handle'].replace('_',''),self.trans)
|
2006-01-31 07:11:55 +05:30
|
|
|
self.source.set_gramps_id(gramps_id)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2006-01-31 07:11:55 +05:30
|
|
|
self.source = self.find_source_by_gramps_id(gramps_id)
|
|
|
|
|
|
|
|
def start_reporef(self,attrs):
|
|
|
|
self.reporef = RelLib.RepoRef()
|
|
|
|
try:
|
|
|
|
handle = attrs['hlink'].replace('_','')
|
|
|
|
self.db.check_repository_from_handle(handle,self.trans)
|
|
|
|
except KeyError:
|
|
|
|
repo = self.find_repo_by_gramps_id(self.map_rid(attrs['ref']))
|
|
|
|
handle = repo.handle
|
|
|
|
|
|
|
|
self.reporef.ref = handle
|
|
|
|
self.reporef.call_number = attrs.get('callno','')
|
2006-04-20 06:14:44 +05:30
|
|
|
self.reporef.media_type = RelLib.SourceMediaType().set_from_xml_str(
|
|
|
|
attrs.get('medium'))
|
2006-01-31 07:11:55 +05:30
|
|
|
# we count here on self.source being available
|
|
|
|
# reporefs can only be found within source
|
|
|
|
self.source.add_repo_reference(self.reporef)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_objref(self,attrs):
|
|
|
|
self.objref = RelLib.MediaRef()
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = attrs['hlink'].replace('_','')
|
|
|
|
self.db.check_object_from_handle(handle,self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
|
|
|
obj = self.find_object_by_gramps_id(self.map_oid(attrs['ref']))
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = obj.handle
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
self.objref.ref = handle
|
2006-01-29 10:42:01 +05:30
|
|
|
self.objref.private = bool(attrs.get('priv'))
|
2004-06-03 11:05:30 +05:30
|
|
|
if self.event:
|
|
|
|
self.event.add_media_reference(self.objref)
|
|
|
|
elif self.family:
|
2004-04-11 08:07:13 +05:30
|
|
|
self.family.add_media_reference(self.objref)
|
|
|
|
elif self.source:
|
|
|
|
self.source.add_media_reference(self.objref)
|
|
|
|
elif self.person:
|
|
|
|
self.person.add_media_reference(self.objref)
|
|
|
|
elif self.placeobj:
|
|
|
|
self.placeobj.add_media_reference(self.objref)
|
|
|
|
|
|
|
|
def start_object(self,attrs):
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_oid(attrs['id'])
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.object = self.db.find_object_from_handle(
|
|
|
|
attrs['handle'].replace('_',''),self.trans)
|
2006-01-31 07:11:55 +05:30
|
|
|
self.object.set_gramps_id(gramps_id)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2006-01-31 07:11:55 +05:30
|
|
|
self.object = self.find_object_by_gramps_id(gramps_id)
|
2006-01-29 10:42:01 +05:30
|
|
|
|
|
|
|
# GRAMPS LEGACY: src, mime, and description attributes
|
|
|
|
# now belong to the <file> tag. Here we are supporting
|
|
|
|
# the old format of <object src="blah"...>
|
2006-01-30 03:09:36 +05:30
|
|
|
self.object.mime = attrs.get('mime','')
|
|
|
|
self.object.desc = attrs.get('description','')
|
|
|
|
src = attrs.get("src",'')
|
2004-04-11 08:07:13 +05:30
|
|
|
if src:
|
2004-10-23 09:26:48 +05:30
|
|
|
if src[0] != '/':
|
|
|
|
fullpath = os.path.abspath(self.filename)
|
|
|
|
src = os.path.dirname(fullpath) + '/' + src
|
2006-01-29 10:42:01 +05:30
|
|
|
self.object.path = src
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def start_repo(self,attrs):
|
|
|
|
gramps_id = self.map_rid(attrs['id'])
|
|
|
|
try:
|
|
|
|
self.repo = self.db.find_repository_from_handle(
|
|
|
|
attrs['handle'].replace('_',''),self.trans)
|
|
|
|
self.repo.set_gramps_id(gramps_id)
|
|
|
|
except KeyError:
|
|
|
|
self.repo = self.find_repository_by_gramps_id(gramps_id)
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_people(self,*tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
pass
|
|
|
|
|
2005-05-11 19:57:32 +05:30
|
|
|
def stop_database(self,*tag):
|
2006-01-18 09:38:28 +05:30
|
|
|
self.update()
|
2005-05-11 19:57:32 +05:30
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_object(self,*tag):
|
2004-08-24 09:18:15 +05:30
|
|
|
self.db.commit_media_object(self.object,self.trans,self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.object = None
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_objref(self,*tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.objref = None
|
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def stop_repo(self,*tag):
|
|
|
|
self.db.commit_repository(self.repo,self.trans,self.change)
|
|
|
|
self.repo = None
|
|
|
|
|
|
|
|
def stop_reporef(self,*tag):
|
|
|
|
self.reporef = None
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def start_photo(self,attrs):
|
|
|
|
self.photo = RelLib.MediaObject()
|
|
|
|
self.pref = RelLib.MediaRef()
|
2004-07-28 07:59:07 +05:30
|
|
|
self.pref.set_reference_handle(self.photo.get_handle())
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
for key in attrs.keys():
|
|
|
|
if key == "descrip" or key == "description":
|
|
|
|
self.photo.set_description(attrs[key])
|
|
|
|
elif key == "priv":
|
|
|
|
self.pref.set_privacy(int(attrs[key]))
|
|
|
|
elif key == "src":
|
|
|
|
src = attrs["src"]
|
|
|
|
if src[0] != '/':
|
|
|
|
self.photo.set_path("%s/%s" % (self.base,src))
|
|
|
|
else:
|
|
|
|
self.photo.set_path(src)
|
|
|
|
else:
|
|
|
|
a = RelLib.Attribute()
|
|
|
|
a.set_type(key)
|
|
|
|
a.set_value(attrs[key])
|
|
|
|
self.photo.add_attribute(a)
|
2006-03-03 05:53:04 +05:30
|
|
|
self.photo.set_mime_type(Mime.get_type(self.photo.get_path()))
|
2004-04-11 08:07:13 +05:30
|
|
|
self.db.add_object(self.photo)
|
|
|
|
if self.family:
|
|
|
|
self.family.add_media_reference(self.pref)
|
|
|
|
elif self.source:
|
|
|
|
self.source.add_media_reference(self.pref)
|
|
|
|
elif self.person:
|
|
|
|
self.person.add_media_reference(self.pref)
|
|
|
|
elif self.placeobj:
|
|
|
|
self.placeobj.add_media_reference(self.pref)
|
|
|
|
|
|
|
|
def start_daterange(self,attrs):
|
|
|
|
if self.source_ref:
|
2005-03-23 05:29:51 +05:30
|
|
|
dv = self.source_ref.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.ord:
|
2004-09-17 09:00:04 +05:30
|
|
|
dv = self.ord.get_date_object()
|
2004-11-06 09:01:34 +05:30
|
|
|
elif self.object:
|
|
|
|
dv = self.object.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.address:
|
2004-09-17 09:00:04 +05:30
|
|
|
dv = self.address.get_date_object()
|
2005-03-07 05:17:26 +05:30
|
|
|
elif self.name:
|
|
|
|
dv = self.name.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2004-09-17 09:00:04 +05:30
|
|
|
dv = self.event.get_date_object()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
start = attrs['start'].split('-')
|
|
|
|
stop = attrs['stop'].split('-')
|
|
|
|
|
|
|
|
try:
|
|
|
|
y = int(start[0])
|
|
|
|
except ValueError:
|
|
|
|
y = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
m = int(start[1])
|
|
|
|
except:
|
|
|
|
m = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
d = int(start[2])
|
|
|
|
except:
|
|
|
|
d = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
ry = int(stop[0])
|
|
|
|
except:
|
|
|
|
ry = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
rm = int(stop[1])
|
|
|
|
except:
|
|
|
|
rm = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
rd = int(stop[2])
|
|
|
|
except:
|
|
|
|
rd = 0
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
if attrs.has_key("cformat"):
|
2006-02-04 03:33:53 +05:30
|
|
|
cal = RelLib.Date.calendar.index(attrs['calendar'])
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2006-02-04 03:33:53 +05:30
|
|
|
cal = RelLib.Date.CAL_GREGORIAN
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
if attrs.has_key('quality'):
|
|
|
|
val = attrs['quality']
|
|
|
|
if val == 'estimated':
|
2006-02-04 03:33:53 +05:30
|
|
|
qual = RelLib.Date.QUAL_ESTIMATED
|
2005-12-06 12:08:09 +05:30
|
|
|
elif val == 'calculated':
|
2006-02-04 03:33:53 +05:30
|
|
|
qual = RelLib.Date.QUAL_CALCULATED
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2006-02-04 03:33:53 +05:30
|
|
|
qual = RelLib.Date.QUAL_NONE
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2006-02-04 03:33:53 +05:30
|
|
|
qual = RelLib.Date.QUAL_NONE
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-02-04 03:33:53 +05:30
|
|
|
dv.set(qual,RelLib.Date.MOD_RANGE,cal,(d,m,y,False,rd,rm,ry,False))
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_dateval(self,attrs):
|
|
|
|
if self.source_ref:
|
2005-03-23 05:29:51 +05:30
|
|
|
dv = self.source_ref.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.ord:
|
2004-09-17 09:00:04 +05:30
|
|
|
dv = self.ord.get_date_object()
|
2004-11-06 09:01:34 +05:30
|
|
|
elif self.object:
|
|
|
|
dv = self.object.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.address:
|
2004-09-17 09:00:04 +05:30
|
|
|
dv = self.address.get_date_object()
|
2005-03-07 05:17:26 +05:30
|
|
|
elif self.name:
|
|
|
|
dv = self.name.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2004-09-17 09:00:04 +05:30
|
|
|
dv = self.event.get_date_object()
|
|
|
|
|
2004-10-16 10:40:35 +05:30
|
|
|
bc = 1
|
|
|
|
val = attrs['val']
|
|
|
|
if val[0] == '-':
|
|
|
|
bc = -1
|
|
|
|
val = val[1:]
|
|
|
|
start = val.split('-')
|
2004-09-17 09:00:04 +05:30
|
|
|
try:
|
2004-10-16 10:40:35 +05:30
|
|
|
y = int(start[0])*bc
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
|
|
|
y = 0
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
try:
|
|
|
|
m = int(start[1])
|
|
|
|
except:
|
|
|
|
m = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
d = int(start[2])
|
|
|
|
except:
|
|
|
|
d = 0
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
if attrs.has_key("cformat"):
|
2006-02-04 03:33:53 +05:30
|
|
|
cal = RelLib.Date.calendar_names.index(attrs['cformat'])
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2006-02-04 03:33:53 +05:30
|
|
|
cal = RelLib.Date.CAL_GREGORIAN
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
if attrs.has_key('type'):
|
|
|
|
val = attrs['type']
|
|
|
|
if val == "about":
|
2006-02-04 03:33:53 +05:30
|
|
|
mod = RelLib.Date.MOD_ABOUT
|
2004-09-17 09:00:04 +05:30
|
|
|
elif val == "after":
|
2006-02-04 03:33:53 +05:30
|
|
|
mod = RelLib.Date.MOD_AFTER
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2006-02-04 03:33:53 +05:30
|
|
|
mod = RelLib.Date.MOD_BEFORE
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2006-02-04 03:33:53 +05:30
|
|
|
mod = RelLib.Date.MOD_NONE
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
if attrs.has_key('quality'):
|
|
|
|
val = attrs['quality']
|
|
|
|
if val == 'estimated':
|
2006-02-04 03:33:53 +05:30
|
|
|
qual = RelLib.Date.QUAL_ESTIMATED
|
2005-12-06 12:08:09 +05:30
|
|
|
elif val == 'calculated':
|
2006-02-04 03:33:53 +05:30
|
|
|
qual = RelLib.Date.QUAL_CALCULATED
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2006-02-04 03:33:53 +05:30
|
|
|
qual = RelLib.Date.QUAL_NONE
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2006-02-04 03:33:53 +05:30
|
|
|
qual = RelLib.Date.QUAL_NONE
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
dv.set(qual,mod,cal,(d,m,y,False))
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_datestr(self,attrs):
|
|
|
|
if self.source_ref:
|
2005-03-23 05:29:51 +05:30
|
|
|
dv = self.source_ref.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.ord:
|
2004-09-17 09:00:04 +05:30
|
|
|
dv = self.ord.get_date_object()
|
2004-11-06 09:01:34 +05:30
|
|
|
elif self.object:
|
|
|
|
dv = self.object.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.address:
|
2004-09-17 09:00:04 +05:30
|
|
|
dv = self.address.get_date_object()
|
2005-03-30 07:15:14 +05:30
|
|
|
elif self.name:
|
|
|
|
dv = self.name.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2004-09-17 09:00:04 +05:30
|
|
|
dv = self.event.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
dv.set_as_text(attrs['val'])
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def start_created(self,attrs):
|
|
|
|
if attrs.has_key('sources'):
|
|
|
|
self.num_srcs = int(attrs['sources'])
|
|
|
|
else:
|
|
|
|
self.num_srcs = 0
|
|
|
|
if attrs.has_key('places'):
|
|
|
|
self.num_places = int(attrs['places'])
|
|
|
|
else:
|
|
|
|
self.num_places = 0
|
|
|
|
|
|
|
|
def start_pos(self,attrs):
|
|
|
|
self.person.position = (int(attrs["x"]), int(attrs["y"]))
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_attribute(self,*tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.attribute = None
|
|
|
|
|
|
|
|
def stop_comment(self,tag):
|
2006-01-29 10:42:01 +05:30
|
|
|
# Parse witnesses created by older gramps
|
2004-04-11 08:07:13 +05:30
|
|
|
if tag.strip():
|
|
|
|
self.witness_comment = tag
|
|
|
|
else:
|
|
|
|
self.witness_comment = ""
|
|
|
|
|
|
|
|
def stop_witness(self,tag):
|
2006-01-29 10:42:01 +05:30
|
|
|
# Parse witnesses created by older gramps
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.witness_comment:
|
2006-01-29 10:42:01 +05:30
|
|
|
note_text = self.event.get_note() + "\n" + \
|
|
|
|
_("Witness comment: %s") % self.witness_comment
|
|
|
|
self.event.set_note(note_text)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif tag.strip():
|
2006-01-29 10:42:01 +05:30
|
|
|
note_text = self.event.get_note() + "\n" + \
|
|
|
|
_("Witness comment: %s") % tag
|
|
|
|
self.event.set_note(note_text)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.in_witness = 0
|
|
|
|
|
|
|
|
def stop_attr_type(self,tag):
|
|
|
|
self.attribute.set_type(tag)
|
|
|
|
|
|
|
|
def stop_attr_value(self,tag):
|
|
|
|
self.attribute.set_value(tag)
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_address(self,*tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
if self.person:
|
|
|
|
self.person.add_address(self.address)
|
|
|
|
elif self.repo:
|
|
|
|
self.repo.add_address(self.address)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.address = None
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_places(self,*tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.placeobj = None
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_photo(self,*tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.photo = None
|
|
|
|
|
2006-01-30 03:09:36 +05:30
|
|
|
def stop_ptitle(self,tag):
|
|
|
|
self.placeobj.title = tag
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_placeobj(self,*tag):
|
2006-01-30 03:09:36 +05:30
|
|
|
if self.placeobj.title == "":
|
2004-04-11 08:07:13 +05:30
|
|
|
loc = self.placeobj.get_main_location()
|
2006-01-30 03:09:36 +05:30
|
|
|
self.placeobj.title = build_place_title(loc)
|
2005-07-09 01:54:54 +05:30
|
|
|
|
2006-01-30 03:09:36 +05:30
|
|
|
if self.placeobj.title in self.place_names:
|
|
|
|
self.placeobj.title += " [%s]" % self.placeobj.gramps_id
|
2005-07-09 01:54:54 +05:30
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
self.db.commit_place(self.placeobj,self.trans,self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.placeobj = None
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_family(self,*tag):
|
2004-08-24 09:18:15 +05:30
|
|
|
self.db.commit_family(self.family,self.trans,self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.family = None
|
|
|
|
|
2006-01-29 10:42:01 +05:30
|
|
|
def stop_type(self,tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
if self.event:
|
|
|
|
# Event type
|
2006-04-20 06:14:44 +05:30
|
|
|
self.event.type.set_from_xml_str(tag)
|
2006-01-31 07:11:55 +05:30
|
|
|
elif self.repo:
|
|
|
|
# Repository type
|
2006-04-19 09:27:10 +05:30
|
|
|
self.repo.type = RelLib.RepositoryType()
|
|
|
|
self.repo.type.set_from_xml_str(tag)
|
2006-01-29 10:42:01 +05:30
|
|
|
|
2006-04-19 07:53:08 +05:30
|
|
|
def stop_childref(self,tag):
|
|
|
|
self.childref = None
|
|
|
|
|
2006-04-19 09:02:33 +05:30
|
|
|
def stop_personref(self,tag):
|
|
|
|
self.personref = None
|
|
|
|
|
2006-01-29 10:42:01 +05:30
|
|
|
def stop_eventref(self,tag):
|
|
|
|
self.eventref = None
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_event(self,*tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.family:
|
2005-06-16 09:26:13 +05:30
|
|
|
ref = RelLib.EventRef()
|
2006-01-29 10:42:01 +05:30
|
|
|
ref.ref = self.event.handle
|
|
|
|
ref.private = self.event.private
|
2006-04-20 06:14:44 +05:30
|
|
|
ref.role.set(RelLib.EventRoleType.FAMILY)
|
2005-06-16 09:26:13 +05:30
|
|
|
self.family.add_event_ref(ref)
|
2006-01-29 10:42:01 +05:30
|
|
|
elif self.person:
|
2005-06-03 10:04:21 +05:30
|
|
|
ref = RelLib.EventRef()
|
2006-01-29 10:42:01 +05:30
|
|
|
ref.ref = self.event.handle
|
|
|
|
ref.private = self.event.private
|
2006-04-20 06:14:44 +05:30
|
|
|
ref.role.set(RelLib.EventRoleType.PRIMARY)
|
2006-04-20 09:04:07 +05:30
|
|
|
if self.event.type == RelLib.EventType.BIRTH:
|
2006-01-29 10:42:01 +05:30
|
|
|
self.person.birth_ref = ref
|
2006-04-20 09:04:07 +05:30
|
|
|
elif self.event.type == RelLib.EventType.DEATH:
|
2006-01-29 10:42:01 +05:30
|
|
|
self.person.death_ref = ref
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2005-06-03 10:04:21 +05:30
|
|
|
self.person.add_event_ref(ref)
|
2006-04-16 10:07:02 +05:30
|
|
|
|
2006-04-19 10:00:55 +05:30
|
|
|
## # FIXME: re-enable when event types are fixed.
|
|
|
|
## if self.event.get_description() == "" and \
|
|
|
|
## self.event.get_type()[0] != RelLib.Event.CUSTOM:
|
|
|
|
## if self.family:
|
|
|
|
## text = _event_family_str % {
|
|
|
|
## 'event_name' : Utils.family_events[self.event.get_type()[0]],
|
|
|
|
## 'family' : Utils.family_name(self.family,self.db),
|
|
|
|
## }
|
|
|
|
## else:
|
|
|
|
## text = _event_person_str % {
|
|
|
|
## 'event_name' : Utils.personal_events[self.event.get_type()[0]],
|
|
|
|
## 'person' : NameDisplay.displayer.display(self.person),
|
|
|
|
## }
|
|
|
|
## self.event.set_description(text)
|
2006-04-16 10:07:02 +05:30
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
self.db.commit_event(self.event,self.trans,self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.event = None
|
|
|
|
|
|
|
|
def stop_name(self,tag):
|
2006-01-29 10:42:01 +05:30
|
|
|
if self.in_witness:
|
2006-01-31 07:11:55 +05:30
|
|
|
# Parse witnesses created by older gramps
|
2006-01-29 10:42:01 +05:30
|
|
|
note_text = self.event.get_note() + "\n" + \
|
|
|
|
_("Witness name: %s") % tag
|
|
|
|
self.event.set_note(note_text)
|
|
|
|
elif self.alt_name:
|
2005-12-06 12:08:09 +05:30
|
|
|
# former aka tag -- alternate name
|
|
|
|
if self.name.get_type() == "":
|
|
|
|
self.name.set_type("Also Known As")
|
|
|
|
self.person.add_alternate_name(self.name)
|
|
|
|
else:
|
|
|
|
if self.name.get_type() == "":
|
|
|
|
self.name.set_type("Birth Name")
|
|
|
|
self.person.set_primary_name (self.name)
|
2005-06-03 10:04:21 +05:30
|
|
|
self.name = None
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
def stop_rname(self,tag):
|
|
|
|
# Repository name
|
|
|
|
self.repo.name = tag
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def stop_ref(self,tag):
|
2006-01-29 10:42:01 +05:30
|
|
|
# Parse witnesses created by older gramps
|
|
|
|
person = self.find_person_by_gramps_id(self.map_gid(tag))
|
|
|
|
# Add an EventRef from that person
|
|
|
|
# to this event using ROLE_WITNESS role
|
|
|
|
event_ref = RelLib.EventRef()
|
|
|
|
event_ref.ref = self.event.handle
|
2006-04-20 06:14:44 +05:30
|
|
|
event_ref.role.set(RelLib.EventRoleType.WITNESS)
|
2006-01-29 10:42:01 +05:30
|
|
|
person.event_ref_list.append(event_ref)
|
|
|
|
self.db.commit_person(person,self.trans,self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_place(self,tag):
|
|
|
|
if self.placeobj == None:
|
|
|
|
if self.place_map.has_key(tag):
|
|
|
|
self.placeobj = self.place_map[tag]
|
|
|
|
else:
|
|
|
|
self.placeobj = RelLib.Place()
|
|
|
|
self.placeobj.set_title(tag)
|
|
|
|
if self.ord:
|
2004-07-28 07:59:07 +05:30
|
|
|
self.ord.set_place_handle(self.placeobj.get_handle())
|
2004-11-06 09:01:34 +05:30
|
|
|
elif self.object:
|
|
|
|
self.object.set_place_handle(self.placeobj.get_handle())
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2004-07-28 07:59:07 +05:30
|
|
|
self.event.set_place_handle(self.placeobj.get_handle())
|
2004-08-24 09:18:15 +05:30
|
|
|
self.db.commit_place(self.placeobj,self.trans,self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.placeobj = None
|
|
|
|
|
|
|
|
def stop_date(self,tag):
|
|
|
|
if tag:
|
|
|
|
if self.address:
|
2005-08-09 10:11:20 +05:30
|
|
|
DateHandler.set_date(self.address,tag)
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2005-08-09 10:11:20 +05:30
|
|
|
DateHandler.set_date(self.event,tag)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_first(self,tag):
|
|
|
|
self.name.set_first_name(tag)
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_families(self,*tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.family = None
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_person(self,*tag):
|
2004-08-24 09:18:15 +05:30
|
|
|
self.db.commit_person(self.person,self.trans,self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.person = None
|
|
|
|
|
|
|
|
def stop_description(self,tag):
|
2006-01-29 10:42:01 +05:30
|
|
|
self.event.description = tag
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_cause(self,tag):
|
2006-01-29 10:42:01 +05:30
|
|
|
self.event.cause = tag
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_gender(self,tag):
|
|
|
|
t = tag
|
|
|
|
if t == "M":
|
2005-05-31 02:11:43 +05:30
|
|
|
self.person.set_gender (RelLib.Person.MALE)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif t == "F":
|
2005-05-31 02:11:43 +05:30
|
|
|
self.person.set_gender (RelLib.Person.FEMALE)
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2005-05-31 02:11:43 +05:30
|
|
|
self.person.set_gender (RelLib.Person.UNKNOWN)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_stitle(self,tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.source.title = tag
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_sourceref(self,*tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.source_ref = None
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_source(self,*tag):
|
2004-08-24 09:18:15 +05:30
|
|
|
self.db.commit_source(self.source,self.trans,self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.source = None
|
|
|
|
|
|
|
|
def stop_sauthor(self,tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.source.author = tag
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_phone(self,tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.address.phone = tag
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_street(self,tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.address.street = tag
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_city(self,tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.address.city = tag
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_state(self,tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.address.state = tag
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_country(self,tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.address.country = tag
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_postal(self,tag):
|
|
|
|
self.address.set_postal_code(tag)
|
|
|
|
|
|
|
|
def stop_spage(self,tag):
|
|
|
|
self.source_ref.set_page(tag)
|
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def stop_lds_ord(self,*tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.ord = None
|
|
|
|
|
|
|
|
def stop_spubinfo(self,tag):
|
|
|
|
self.source.set_publication_info(tag)
|
|
|
|
|
|
|
|
def stop_sabbrev(self,tag):
|
|
|
|
self.source.set_abbreviation(tag)
|
|
|
|
|
|
|
|
def stop_stext(self,tag):
|
|
|
|
if self.use_p:
|
|
|
|
self.use_p = 0
|
|
|
|
note = fix_spaces(self.stext_list)
|
|
|
|
else:
|
|
|
|
note = tag
|
|
|
|
self.source_ref.set_text(note)
|
|
|
|
|
|
|
|
def stop_scomments(self,tag):
|
|
|
|
if self.use_p:
|
|
|
|
self.use_p = 0
|
|
|
|
note = fix_spaces(self.scomments_list)
|
|
|
|
else:
|
|
|
|
note = tag
|
2005-03-28 10:28:28 +05:30
|
|
|
self.source_ref.set_note(note)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_last(self,tag):
|
|
|
|
if self.name:
|
|
|
|
self.name.set_surname(tag)
|
|
|
|
|
|
|
|
def stop_suffix(self,tag):
|
|
|
|
if self.name:
|
|
|
|
self.name.set_suffix(tag)
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def stop_patronymic(self,tag):
|
|
|
|
if self.name:
|
|
|
|
self.name.set_patronymic(tag)
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def stop_title(self,tag):
|
|
|
|
if self.name:
|
|
|
|
self.name.set_title(tag)
|
|
|
|
|
|
|
|
def stop_nick(self,tag):
|
|
|
|
if self.person:
|
|
|
|
self.person.set_nick_name(tag)
|
|
|
|
|
|
|
|
def stop_note(self,tag):
|
|
|
|
self.in_note = 0
|
|
|
|
if self.use_p:
|
|
|
|
self.use_p = 0
|
|
|
|
text = fix_spaces(self.note_list)
|
|
|
|
else:
|
|
|
|
text = tag
|
|
|
|
self.note.set(text)
|
|
|
|
|
|
|
|
if self.address:
|
|
|
|
self.address.set_note_object(self.note)
|
|
|
|
elif self.ord:
|
|
|
|
self.ord.set_note_object(self.note)
|
|
|
|
elif self.attribute:
|
|
|
|
self.attribute.set_note_object(self.note)
|
|
|
|
elif self.object:
|
|
|
|
self.object.set_note_object(self.note)
|
|
|
|
elif self.objref:
|
|
|
|
self.objref.set_note_object(self.note)
|
|
|
|
elif self.photo:
|
|
|
|
self.photo.set_note_object(self.note)
|
|
|
|
elif self.name:
|
|
|
|
self.name.set_note_object(self.note)
|
|
|
|
elif self.source:
|
|
|
|
self.source.set_note_object(self.note)
|
|
|
|
elif self.event:
|
|
|
|
self.event.set_note_object(self.note)
|
2006-04-19 09:02:33 +05:30
|
|
|
elif self.personref:
|
|
|
|
self.personref.set_note_object(self.note)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.person:
|
|
|
|
self.person.set_note_object(self.note)
|
2006-04-19 07:53:08 +05:30
|
|
|
elif self.childref:
|
|
|
|
self.childref.set_note_object(self.note)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.family:
|
|
|
|
self.family.set_note_object(self.note)
|
|
|
|
elif self.placeobj:
|
|
|
|
self.placeobj.set_note_object(self.note)
|
2006-01-29 10:42:01 +05:30
|
|
|
elif self.eventref:
|
|
|
|
self.eventref.set_note_object(self.note)
|
2006-01-31 07:11:55 +05:30
|
|
|
elif self.repo:
|
|
|
|
self.repo.set_note_object(self.note)
|
|
|
|
elif self.reporef:
|
|
|
|
self.reporef.set_note_object(self.note)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
def stop_research(self,tag):
|
|
|
|
self.owner.set(self.resname, self.resaddr, self.rescity, self.resstate,
|
|
|
|
self.rescon, self.respos, self.resphone, self.resemail)
|
|
|
|
|
|
|
|
def stop_resname(self,tag):
|
|
|
|
self.resname = tag
|
|
|
|
|
|
|
|
def stop_resaddr(self,tag):
|
|
|
|
self.resaddr = tag
|
|
|
|
|
|
|
|
def stop_rescity(self,tag):
|
|
|
|
self.rescity = tag
|
|
|
|
|
|
|
|
def stop_resstate(self,tag):
|
|
|
|
self.resstate = tag
|
|
|
|
|
|
|
|
def stop_rescountry(self,tag):
|
|
|
|
self.rescon = tag
|
|
|
|
|
|
|
|
def stop_respostal(self,tag):
|
|
|
|
self.respos = tag
|
|
|
|
|
|
|
|
def stop_resphone(self,tag):
|
|
|
|
self.resphone = tag
|
|
|
|
|
|
|
|
def stop_resemail(self,tag):
|
|
|
|
self.resemail = tag
|
|
|
|
|
|
|
|
def stop_ptag(self,tag):
|
|
|
|
self.use_p = 1
|
|
|
|
if self.in_note:
|
|
|
|
self.note_list.append(tag)
|
|
|
|
elif self.in_stext:
|
|
|
|
self.stext_list.append(tag)
|
|
|
|
elif self.in_scomments:
|
|
|
|
self.scomments_list.append(tag)
|
|
|
|
|
|
|
|
def stop_aka(self,tag):
|
|
|
|
self.person.add_alternate_name(self.name)
|
|
|
|
if self.name.get_type() == "":
|
|
|
|
self.name.set_type("Also Known As")
|
|
|
|
self.name = None
|
|
|
|
|
|
|
|
def startElement(self,tag,attrs):
|
|
|
|
|
|
|
|
self.func_list[self.func_index] = (self.func,self.tlist)
|
|
|
|
self.func_index = self.func_index + 1
|
|
|
|
self.tlist = []
|
|
|
|
|
|
|
|
try:
|
2004-06-23 02:19:22 +05:30
|
|
|
f,self.func = self.func_map[tag]
|
2004-04-11 08:07:13 +05:30
|
|
|
if f:
|
|
|
|
f(attrs)
|
|
|
|
except KeyError:
|
|
|
|
self.func_map[tag] = (None,None)
|
|
|
|
self.func = None
|
|
|
|
|
|
|
|
def endElement(self,tag):
|
|
|
|
if self.func:
|
2005-02-28 07:21:21 +05:30
|
|
|
self.func(''.join(self.tlist))
|
2004-04-11 08:07:13 +05:30
|
|
|
self.func_index = self.func_index - 1
|
|
|
|
self.func,self.tlist = self.func_list[self.func_index]
|
|
|
|
|
|
|
|
def characters(self, data):
|
|
|
|
if self.func:
|
|
|
|
self.tlist.append(data)
|
|
|
|
|
2006-03-01 05:56:29 +05:30
|
|
|
def update_empty(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def update_real(self):
|
2006-01-18 09:38:28 +05:30
|
|
|
line = self.p.CurrentLineNumber
|
|
|
|
newval = int(100*line/self.linecount)
|
|
|
|
if newval != self.oldval:
|
|
|
|
self.callback(newval)
|
|
|
|
self.oldval = newval
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def append_value(orig,val):
|
|
|
|
if orig:
|
|
|
|
return "%s, %s" % (orig,val)
|
|
|
|
else:
|
|
|
|
return val
|
|
|
|
|
|
|
|
def build_place_title(loc):
|
|
|
|
"Builds a title from a location"
|
|
|
|
value = ""
|
2006-01-31 07:11:55 +05:30
|
|
|
if loc.parish:
|
|
|
|
value = loc.parish
|
|
|
|
if loc.city:
|
|
|
|
value = append_value(value,loc.city)
|
|
|
|
if loc.county:
|
|
|
|
value = append_value(value,loc.county)
|
|
|
|
if loc.state:
|
|
|
|
value = append_value(value,loc.state)
|
|
|
|
if loc.country:
|
|
|
|
value = append_value(value,loc.country)
|
2004-04-11 08:07:13 +05:30
|
|
|
return value
|
2006-01-31 07:11:55 +05:30
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
|
|
|
import hotshot#, hotshot.stats
|
|
|
|
import const
|
|
|
|
from GrampsDb import gramps_db_factory, gramps_db_reader_factory
|
|
|
|
|
|
|
|
def callback(val):
|
|
|
|
print val
|
|
|
|
|
|
|
|
codeset = None
|
|
|
|
|
|
|
|
db_class = gramps_db_factory(const.app_gramps)
|
|
|
|
database = db_class()
|
|
|
|
database.load("test.grdb",lambda x: None, mode="w")
|
|
|
|
|
|
|
|
filename = os.path.normpath(sys.argv[1])
|
|
|
|
basefile = os.path.dirname(filename)
|
|
|
|
change = os.path.getmtime(filename)
|
|
|
|
|
|
|
|
parser = GrampsParser(database,callback,basefile,change,filename)
|
|
|
|
|
|
|
|
linecounter = LineParser(filename)
|
|
|
|
lc = linecounter.get_count()
|
|
|
|
|
|
|
|
xml_file = gzip.open(filename,"rb")
|
|
|
|
|
|
|
|
if True:
|
|
|
|
pr = hotshot.Profile('mystats.profile')
|
|
|
|
print "Start"
|
|
|
|
pr.runcall(parser.parse,xml_file,False,lc)
|
|
|
|
print "Finished"
|
|
|
|
pr.close()
|
|
|
|
## print "Loading profile"
|
|
|
|
## stats = hotshot.stats.load('mystats.profile')
|
|
|
|
## print "done"
|
|
|
|
## stats.strip_dirs()
|
|
|
|
## stats.sort_stats('time','calls')
|
|
|
|
## stats.print_stats(100)
|
|
|
|
else:
|
|
|
|
import time
|
|
|
|
t = time.time()
|
|
|
|
parser.parse(xml_file,False,lc)
|
|
|
|
print time.time() - t
|
|
|
|
|
|
|
|
xml_file.close()
|