2003-05-13 20:59:22 +05:30
|
|
|
#
|
2002-10-20 19:55:16 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-02-20 06:09:10 +05:30
|
|
|
# Copyright (C) 2000-2007 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.
|
|
|
|
#
|
2007-09-08 02:54:01 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2002-10-20 19:55:16 +05:30
|
|
|
# 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
|
2007-03-21 00:51:41 +05:30
|
|
|
import sys
|
2005-07-09 01:54:54 +05:30
|
|
|
import sets
|
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
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-27 18:33:41 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2006-03-03 05:53:04 +05:30
|
|
|
import Mime
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2004-08-24 09:18:15 +05:30
|
|
|
import Utils
|
2004-09-17 09:00:04 +05:30
|
|
|
import DateHandler
|
2007-06-28 11:11:40 +05:30
|
|
|
from BasicUtils import name_displayer
|
2008-02-19 01:37:09 +05:30
|
|
|
from gen.db.dbconst import (PERSON_KEY, FAMILY_KEY, SOURCE_KEY, EVENT_KEY,
|
|
|
|
MEDIA_KEY, PLACE_KEY, REPOSITORY_KEY, NOTE_KEY)
|
2006-05-11 11:46:45 +05:30
|
|
|
from BasicUtils import UpdateCallback
|
2008-02-25 10:02:11 +05:30
|
|
|
import _GrampsDbWriteXML
|
|
|
|
import const
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Try to detect the presence of gzip
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
try:
|
|
|
|
import gzip
|
2007-09-08 02:54:01 +05:30
|
|
|
GZIP_OK = True
|
2002-10-20 19:55:16 +05:30
|
|
|
except:
|
2007-09-08 02:54:01 +05:30
|
|
|
GZIP_OK = False
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
PERSON_RE = re.compile(r"\s*\<person\s(.*)$")
|
2006-02-02 20:23:31 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
CHILD_REL_MAP = {
|
2007-10-08 22:11:39 +05:30
|
|
|
"Birth" : gen.lib.ChildRefType(gen.lib.ChildRefType.BIRTH),
|
|
|
|
"Adopted" : gen.lib.ChildRefType(gen.lib.ChildRefType.ADOPTED),
|
|
|
|
"Stepchild" : gen.lib.ChildRefType(gen.lib.ChildRefType.STEPCHILD),
|
|
|
|
"Sponsored" : gen.lib.ChildRefType(gen.lib.ChildRefType.SPONSORED),
|
|
|
|
"Foster" : gen.lib.ChildRefType(gen.lib.ChildRefType.FOSTER),
|
|
|
|
"Unknown" : gen.lib.ChildRefType(gen.lib.ChildRefType.UNKNOWN),
|
2006-04-14 21:30:46 +05:30
|
|
|
}
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
EVENT_FAMILY_STR = _("%(event_name)s of %(family)s")
|
|
|
|
EVENT_PERSON_STR = _("%(event_name)s of %(person)s")
|
2006-04-16 10:07:02 +05:30
|
|
|
|
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
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-09-08 02:54:01 +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)
|
2008-02-29 04:02:40 +05:30
|
|
|
parser = GrampsParser(database, callback, change)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-18 06:58:35 +05:30
|
|
|
linecounter = LineParser(filename)
|
2007-09-08 02:54:01 +05:30
|
|
|
line_cnt = linecounter.get_count()
|
|
|
|
person_cnt = linecounter.get_person_count()
|
2005-12-18 06:58:35 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
read_only = database.readonly
|
2005-12-06 12:08:09 +05:30
|
|
|
database.readonly = False
|
2008-02-25 10:02:11 +05:30
|
|
|
|
|
|
|
xml_file = open_file(filename, cl)
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2008-02-25 10:02:11 +05:30
|
|
|
if xml_file is None or \
|
|
|
|
version_is_valid(xml_file, cl) is False:
|
2003-05-21 23:36:41 +05:30
|
|
|
if cl:
|
2007-03-21 00:51:41 +05:30
|
|
|
sys.exit(1)
|
2003-05-21 23:36:41 +05:30
|
|
|
else:
|
2004-10-06 09:12:54 +05:30
|
|
|
return
|
2008-02-25 10:02:11 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
try:
|
2008-02-25 10:02:11 +05:30
|
|
|
xml_file.seek(0)
|
2008-02-29 04:02:40 +05:30
|
|
|
info = parser.parse(xml_file, use_trans, line_cnt, person_cnt)
|
2007-09-08 02:54:01 +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()
|
2007-03-21 00:51:41 +05:30
|
|
|
sys.exit(1)
|
2003-05-21 23:36:41 +05:30
|
|
|
else:
|
2007-09-08 02:54:01 +05:30
|
|
|
ErrorDialog(_("Error reading %s") % filename, str(msg))
|
2003-05-21 23:36:41 +05:30
|
|
|
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."
|
2007-03-21 00:51:41 +05:30
|
|
|
sys.exit(1)
|
2003-05-21 23:36:41 +05:30
|
|
|
else:
|
2007-09-08 02:54:01 +05:30
|
|
|
ErrorDialog(_("Error reading %s") % filename,
|
2003-05-21 23:36:41 +05:30
|
|
|
_("The file is probably either corrupt or not a valid GRAMPS database."))
|
2004-10-06 09:12:54 +05:30
|
|
|
return
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
xml_file.close()
|
2004-06-27 23:38:19 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
database.readonly = read_only
|
2008-02-29 04:02:40 +05:30
|
|
|
|
|
|
|
return info
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2007-12-01 05:20:05 +05:30
|
|
|
## TODO - WITH MEDIA PATH, IS THIS STILL NEEDED?
|
|
|
|
## BETTER LEAVE ALL RELATIVE TO NEW RELATIVE PATH
|
|
|
|
## save_path is in .gramps/dbbase, no good place !
|
|
|
|
## # 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 = os.path.join(db_dir, db_base)
|
|
|
|
## first = not os.path.exists(img_dir)
|
|
|
|
##
|
|
|
|
## for m_id in database.get_media_object_handles():
|
|
|
|
## mobject = database.get_object_from_handle(m_id)
|
|
|
|
## oldfile = mobject.get_path()
|
|
|
|
## if oldfile and not os.path.isabs(oldfile):
|
|
|
|
## if first:
|
|
|
|
## os.mkdir(img_dir)
|
|
|
|
## first = 0
|
|
|
|
## newfile = os.path.join(img_dir, oldfile)
|
|
|
|
##
|
|
|
|
## try:
|
|
|
|
## oldfilename = os.path.join(basefile, oldfile)
|
|
|
|
## shutil.copyfile(oldfilename, newfile)
|
|
|
|
## try:
|
|
|
|
## shutil.copystat(oldfilename, newfile)
|
|
|
|
## except:
|
|
|
|
## pass
|
|
|
|
## mobject.set_path(newfile)
|
|
|
|
## 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):
|
2007-09-08 02:54:01 +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
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-29 04:02:40 +05:30
|
|
|
|
|
|
|
class ImportInfo:
|
|
|
|
"""
|
|
|
|
Class object that can hold information about the import
|
|
|
|
"""
|
|
|
|
keyorder = [PERSON_KEY, FAMILY_KEY, SOURCE_KEY, EVENT_KEY, MEDIA_KEY,
|
|
|
|
PLACE_KEY, REPOSITORY_KEY, NOTE_KEY]
|
|
|
|
key2data = {
|
|
|
|
PERSON_KEY : 0,
|
|
|
|
FAMILY_KEY : 1,
|
|
|
|
SOURCE_KEY: 2,
|
|
|
|
EVENT_KEY: 3,
|
|
|
|
MEDIA_KEY: 4,
|
|
|
|
PLACE_KEY: 5,
|
|
|
|
REPOSITORY_KEY: 6,
|
|
|
|
NOTE_KEY: 7
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""
|
|
|
|
Init of the import class.
|
|
|
|
|
|
|
|
This creates the datastructures to hold info
|
|
|
|
"""
|
|
|
|
self.data_mergeoverwrite = [{},{},{},{},{},{},{},{}]
|
|
|
|
self.data_newobject = [0,0,0,0,0,0,0,0]
|
|
|
|
self.data_relpath = False
|
|
|
|
|
|
|
|
|
|
|
|
def add(self, category, key, obj):
|
|
|
|
"""
|
|
|
|
Add info of a certain category. Key is one of the predefined keys,
|
|
|
|
while obj is an object of which information will be extracted
|
|
|
|
"""
|
|
|
|
if category == 'merge-overwrite':
|
|
|
|
self.data_mergeoverwrite[self.key2data[key]][obj.handle] = \
|
|
|
|
self._extract_mergeinfo(key, obj)
|
|
|
|
elif category == 'new-object':
|
|
|
|
self.data_newobject[self.key2data[key]] += 1
|
|
|
|
elif category == 'relative-path':
|
|
|
|
self.data_relpath = True
|
|
|
|
|
|
|
|
def _extract_mergeinfo(self, key, obj):
|
|
|
|
"""
|
|
|
|
Extract info from obj about 'merge-overwrite', Key is one of the
|
|
|
|
predefined keys.
|
|
|
|
"""
|
|
|
|
if key == PERSON_KEY:
|
|
|
|
return _(" %(id)s - %(text)s\n") % {'id': obj.gramps_id,
|
|
|
|
'text' : name_displayer.display(obj)
|
|
|
|
}
|
|
|
|
elif key == FAMILY_KEY :
|
|
|
|
return _(" Family %(id)s\n") % {'id': obj.gramps_id}
|
|
|
|
elif key ==SOURCE_KEY:
|
|
|
|
return _(" Source %(id)s\n") % {'id': obj.gramps_id}
|
|
|
|
elif key == EVENT_KEY:
|
|
|
|
return _(" Event %(id)s\n") % {'id': obj.gramps_id}
|
|
|
|
elif key == MEDIA_KEY:
|
|
|
|
return _(" Media Object %(id)s\n") % {'id': obj.gramps_id}
|
|
|
|
elif key == PLACE_KEY:
|
|
|
|
return _(" Place %(id)s\n") % {'id': obj.gramps_id}
|
|
|
|
elif key == REPOSITORY_KEY:
|
|
|
|
return _(" Repository %(id)s\n") % {'id': obj.gramps_id}
|
|
|
|
elif key == NOTE_KEY:
|
|
|
|
return _(" Note %(id)s\n") % {'id': obj.gramps_id}
|
|
|
|
|
|
|
|
def info_text(self):
|
|
|
|
"""
|
|
|
|
Construct an info message from the data in the class.
|
|
|
|
"""
|
|
|
|
key2string = {
|
|
|
|
PERSON_KEY : _(' People: %d\n'),
|
|
|
|
FAMILY_KEY : _(' Families: %d\n'),
|
|
|
|
SOURCE_KEY : _(' Sources: %d\n'),
|
|
|
|
EVENT_KEY : _(' Events: %d\n'),
|
|
|
|
MEDIA_KEY : _(' Media Objects: %d\n'),
|
|
|
|
PLACE_KEY : _(' Places: %d\n'),
|
|
|
|
REPOSITORY_KEY : _(' Repositories: %d\n'),
|
|
|
|
NOTE_KEY : _(' Notes: %d\n'),
|
|
|
|
}
|
|
|
|
txt = _("Number of new objects imported:\n")
|
|
|
|
for key in self.keyorder:
|
|
|
|
txt += key2string[key] % self.data_newobject[self.key2data[key]]
|
|
|
|
merged = False
|
|
|
|
for key in self.keyorder:
|
|
|
|
if self.data_mergeoverwrite[self.key2data[key]]:
|
|
|
|
merged = True
|
|
|
|
break
|
|
|
|
if merged:
|
|
|
|
txt += _("\n\nObjects merged-overwritten on import:\n")
|
|
|
|
for key in self.keyorder:
|
|
|
|
datakey = self.key2data[key]
|
|
|
|
for handle in self.data_mergeoverwrite[datakey].keys():
|
|
|
|
txt += self.data_mergeoverwrite[datakey][handle]
|
|
|
|
if self.data_relpath:
|
|
|
|
txt += _("\nMedia objects with relative paths have been\n"
|
|
|
|
"imported. These paths are considered relative to\n"
|
|
|
|
"the media directory you can set in the preferences,\n"
|
2008-04-17 23:49:27 +05:30
|
|
|
"or, if not set, relative to the user's directory.\n"
|
2008-02-29 04:02:40 +05:30
|
|
|
)
|
|
|
|
return txt
|
|
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
if GZIP_OK:
|
2005-12-18 06:58:35 +05:30
|
|
|
use_gzip = 1
|
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
f = gzip.open(filename, "r")
|
2005-12-18 06:58:35 +05:30
|
|
|
f.read(1)
|
|
|
|
f.close()
|
2007-09-08 02:54:01 +05:30
|
|
|
except IOError, msg:
|
2005-12-18 06:58:35 +05:30
|
|
|
use_gzip = 0
|
|
|
|
except ValueError, msg:
|
|
|
|
use_gzip = 1
|
|
|
|
else:
|
|
|
|
use_gzip = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
if use_gzip:
|
2007-09-08 02:54:01 +05:30
|
|
|
ofile = gzip.open(filename, "rb")
|
2005-12-18 06:58:35 +05:30
|
|
|
else:
|
2007-09-08 02:54:01 +05:30
|
|
|
ofile = open(filename, "r")
|
2005-12-18 06:58:35 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
for line in ofile:
|
2006-02-01 11:55:51 +05:30
|
|
|
self.count += 1
|
2007-09-08 02:54:01 +05:30
|
|
|
if PERSON_RE.match(line):
|
2006-02-02 20:23:31 +05:30
|
|
|
self.person_count += 1
|
2006-02-01 11:55:51 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
ofile.close()
|
2005-12-18 06:58:35 +05:30
|
|
|
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
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-11 11:46:45 +05:30
|
|
|
class GrampsParser(UpdateCallback):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-02-29 04:02:40 +05:30
|
|
|
def __init__(self, database, callback, change):
|
2007-09-08 02:54:01 +05:30
|
|
|
UpdateCallback.__init__(self, callback)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.stext_list = []
|
|
|
|
self.scomments_list = []
|
|
|
|
self.note_list = []
|
|
|
|
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 = {}
|
2007-02-21 08:08:21 +05:30
|
|
|
self.gid2nid = {}
|
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()
|
2008-02-29 04:02:40 +05:30
|
|
|
self.info = ImportInfo()
|
|
|
|
self.all_abs = True
|
2005-07-09 01:54:54 +05:30
|
|
|
cursor = database.get_place_cursor()
|
|
|
|
data = cursor.next()
|
|
|
|
while data:
|
2007-09-08 02:54:01 +05:30
|
|
|
(handle, val) = data
|
2005-07-09 01:54:54 +05:30
|
|
|
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
|
2008-04-09 03:13:58 +05:30
|
|
|
self.note_text = None
|
|
|
|
self.note_tags = []
|
2006-06-23 02:53:00 +05:30
|
|
|
self.in_witness = False
|
2004-04-11 08:07:13 +05:30
|
|
|
self.db = database
|
|
|
|
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 = ""
|
|
|
|
|
2007-12-01 05:20:05 +05:30
|
|
|
self.mediapath = ""
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
self.pmap = {}
|
|
|
|
self.fmap = {}
|
|
|
|
self.smap = {}
|
|
|
|
self.lmap = {}
|
|
|
|
self.media_file_map = {}
|
2006-07-28 01:41:56 +05:30
|
|
|
|
|
|
|
# List of new name formats and a dict for remapping them
|
|
|
|
self.name_formats = []
|
|
|
|
self.name_formats_map = {}
|
2007-09-08 02:54:01 +05:30
|
|
|
self.taken_name_format_numbers = [num[0]
|
|
|
|
for num in self.db.name_formats]
|
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
|
2004-08-24 09:18:15 +05:30
|
|
|
self.home = None
|
2007-10-08 22:11:39 +05:30
|
|
|
self.owner = gen.lib.Researcher()
|
2004-04-11 08:07:13 +05:30
|
|
|
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 = {}
|
2007-02-21 08:08:21 +05:30
|
|
|
self.nidswap = {}
|
2004-08-24 09:18:15 +05:30
|
|
|
self.eidswap = {}
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
self.func_map = {
|
2008-04-09 03:13:58 +05:30
|
|
|
"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),
|
|
|
|
"format": (self.start_format, None),
|
|
|
|
"name-formats": (None, None),
|
|
|
|
"child": (self.start_child, None),
|
|
|
|
"childof": (self.start_childof, None),
|
|
|
|
"childref": (self.start_childref, self.stop_childref),
|
|
|
|
"personref": (self.start_personref, self.stop_personref),
|
|
|
|
"city": (None, self.stop_city),
|
|
|
|
"county": (None, self.stop_county),
|
|
|
|
"country": (None, self.stop_country),
|
|
|
|
"comment": (None, self.stop_comment),
|
|
|
|
"created": (self.start_created, None),
|
|
|
|
"ref": (None, self.stop_ref),
|
|
|
|
"database": (self.start_database, self.stop_database),
|
|
|
|
"phone": (None, self.stop_phone),
|
|
|
|
"date": (None, self.stop_date),
|
|
|
|
"cause": (None, self.stop_cause),
|
2007-09-08 02:54:01 +05:30
|
|
|
"description": (None, self.stop_description),
|
2008-04-09 03:13:58 +05:30
|
|
|
"event": (self.start_event, self.stop_event),
|
|
|
|
"type": (None, self.stop_type),
|
|
|
|
"witness": (self.start_witness, self.stop_witness),
|
|
|
|
"eventref": (self.start_eventref, self.stop_eventref),
|
|
|
|
"data_item": (self.start_data_item, None),
|
|
|
|
"families": (None, self.stop_families),
|
|
|
|
"family": (self.start_family, self.stop_family),
|
|
|
|
"rel": (self.start_rel, None),
|
|
|
|
"region": (self.start_region, None),
|
|
|
|
"father": (self.start_father, None),
|
|
|
|
"first": (None, self.stop_first),
|
|
|
|
"call": (None, self.stop_call),
|
|
|
|
"gender": (None, self.stop_gender),
|
|
|
|
"header": (None, None),
|
|
|
|
"last": (self.start_last, self.stop_last),
|
|
|
|
"map": (self.start_namemap, None),
|
|
|
|
"mediapath": (None, self.stop_mediapath),
|
|
|
|
"mother": (self.start_mother, None),
|
|
|
|
"name": (self.start_name, self.stop_name),
|
|
|
|
"namemaps": (None, None),
|
|
|
|
"nick": (None, self.stop_nick),
|
|
|
|
"note": (self.start_note, self.stop_note),
|
|
|
|
"noteref": (self.start_noteref, None),
|
|
|
|
"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),
|
|
|
|
"file": (self.start_file, None),
|
|
|
|
"place": (self.start_place, self.stop_place),
|
|
|
|
"dateval": (self.start_dateval, None),
|
|
|
|
"daterange": (self.start_daterange, None),
|
|
|
|
"datespan": (self.start_datespan, None),
|
|
|
|
"datestr": (self.start_datestr, None),
|
|
|
|
"places": (None, self.stop_places),
|
|
|
|
"placeobj": (self.start_placeobj, self.stop_placeobj),
|
|
|
|
"ptitle": (None, self.stop_ptitle),
|
|
|
|
"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),
|
|
|
|
"patronymic": (None, self.stop_patronymic),
|
|
|
|
"pos": (self.start_pos, None),
|
|
|
|
"postal": (None, self.stop_postal),
|
|
|
|
"range": (self.start_range, None),
|
|
|
|
"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),
|
|
|
|
"tag": (self.start_tag, None),
|
|
|
|
"text": (None, self.stop_text),
|
|
|
|
"title": (None, self.stop_title),
|
|
|
|
"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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def find_person_by_gramps_id(self, gramps_id):
|
2004-06-27 08:40:06 +05:30
|
|
|
intid = self.gid2id.get(gramps_id)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = True
|
2004-06-27 08:40:06 +05:30
|
|
|
if intid:
|
2004-08-20 07:50:06 +05:30
|
|
|
person = self.db.get_person_from_handle(intid)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = False
|
2004-06-27 08:40:06 +05:30
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
person = gen.lib.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)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_person(person, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
#set correct change time
|
|
|
|
self.db.commit_person(person, self.trans, self.change)
|
2004-06-27 08:40:06 +05:30
|
|
|
self.gid2id[gramps_id] = intid
|
2008-02-29 04:02:40 +05:30
|
|
|
return person, new
|
2004-06-27 08:40:06 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def find_family_by_gramps_id(self, gramps_id):
|
2004-08-20 07:50:06 +05:30
|
|
|
intid = self.gid2fid.get(gramps_id)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = True
|
2004-08-20 07:50:06 +05:30
|
|
|
if intid:
|
|
|
|
family = self.db.get_family_from_handle(intid)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = False
|
2004-08-20 07:50:06 +05:30
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
family = gen.lib.Family()
|
2004-08-20 07:50:06 +05:30
|
|
|
family.set_handle(intid)
|
|
|
|
family.set_gramps_id(gramps_id)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_family(family, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_family(family, self.trans, self.change)
|
2004-08-20 07:50:06 +05:30
|
|
|
self.gid2fid[gramps_id] = intid
|
2008-02-29 04:02:40 +05:30
|
|
|
return family, new
|
2004-08-20 07:50:06 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def find_event_by_gramps_id(self, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
intid = self.gid2eid.get(gramps_id)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = True
|
2006-01-31 07:11:55 +05:30
|
|
|
if intid:
|
|
|
|
event = self.db.get_event_from_handle(intid)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = False
|
2006-01-31 07:11:55 +05:30
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
event = gen.lib.Event()
|
2006-01-31 07:11:55 +05:30
|
|
|
event.set_handle(intid)
|
|
|
|
event.set_gramps_id(gramps_id)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_event(event, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_event(event, self.trans, self.change)
|
2006-01-31 07:11:55 +05:30
|
|
|
self.gid2eid[gramps_id] = intid
|
2008-02-29 04:02:40 +05:30
|
|
|
return event, new
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def find_place_by_gramps_id(self, gramps_id):
|
2004-08-24 09:18:15 +05:30
|
|
|
intid = self.gid2pid.get(gramps_id)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = True
|
2004-08-24 09:18:15 +05:30
|
|
|
if intid:
|
|
|
|
place = self.db.get_place_from_handle(intid)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = False
|
2004-08-24 09:18:15 +05:30
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
place = gen.lib.Place()
|
2004-08-24 09:18:15 +05:30
|
|
|
place.set_handle(intid)
|
|
|
|
place.set_gramps_id(gramps_id)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_place(place, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_place(place, self.trans, self.change)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.gid2pid[gramps_id] = intid
|
2008-02-29 04:02:40 +05:30
|
|
|
return place, new
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def find_source_by_gramps_id(self, gramps_id):
|
2004-08-24 09:18:15 +05:30
|
|
|
intid = self.gid2sid.get(gramps_id)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = True
|
2004-08-24 09:18:15 +05:30
|
|
|
if intid:
|
|
|
|
source = self.db.get_source_from_handle(intid)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = False
|
2004-08-24 09:18:15 +05:30
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
source = gen.lib.Source()
|
2004-08-24 09:18:15 +05:30
|
|
|
source.set_handle(intid)
|
|
|
|
source.set_gramps_id(gramps_id)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_source(source, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_source(source, self.trans, self.change)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.gid2sid[gramps_id] = intid
|
2008-02-29 04:02:40 +05:30
|
|
|
return source, new
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def find_object_by_gramps_id(self, gramps_id):
|
2004-08-24 09:18:15 +05:30
|
|
|
intid = self.gid2oid.get(gramps_id)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = True
|
2004-08-24 09:18:15 +05:30
|
|
|
if intid:
|
|
|
|
obj = self.db.get_object_from_handle(intid)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = False
|
2004-08-24 09:18:15 +05:30
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
obj = gen.lib.MediaObject()
|
2004-08-24 09:18:15 +05:30
|
|
|
obj.set_handle(intid)
|
|
|
|
obj.set_gramps_id(gramps_id)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_object(obj, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_media_object(obj, self.trans, self.change)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.gid2oid[gramps_id] = intid
|
2008-02-29 04:02:40 +05:30
|
|
|
return obj, new
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def find_repository_by_gramps_id(self, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
intid = self.gid2rid.get(gramps_id)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = True
|
2006-01-31 07:11:55 +05:30
|
|
|
if intid:
|
|
|
|
repo = self.db.get_repository_from_handle(intid)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = False
|
2006-01-31 07:11:55 +05:30
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
repo = gen.lib.Repository()
|
2006-01-31 07:11:55 +05:30
|
|
|
repo.set_handle(intid)
|
|
|
|
repo.set_gramps_id(gramps_id)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_repository(repo, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_repository(repo, self.trans, self.change)
|
2006-01-31 07:11:55 +05:30
|
|
|
self.gid2rid[gramps_id] = intid
|
2008-02-29 04:02:40 +05:30
|
|
|
return repo, new
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def find_note_by_gramps_id(self, gramps_id):
|
2007-02-21 08:08:21 +05:30
|
|
|
intid = self.gid2nid.get(gramps_id)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = True
|
2007-02-21 08:08:21 +05:30
|
|
|
if intid:
|
|
|
|
note = self.db.get_note_from_handle(intid)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = False
|
2007-02-21 08:08:21 +05:30
|
|
|
else:
|
|
|
|
intid = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
note = gen.lib.Note()
|
2007-02-21 08:08:21 +05:30
|
|
|
note.set_handle(intid)
|
|
|
|
note.set_gramps_id(gramps_id)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_note(note, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_note(note, self.trans, self.change)
|
2007-02-21 08:08:21 +05:30
|
|
|
self.gid2nid[gramps_id] = intid
|
2008-02-29 04:02:40 +05:30
|
|
|
return note, new
|
2007-09-08 02:54:01 +05:30
|
|
|
|
|
|
|
def map_gid(self, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
if not self.idswap.get(gramps_id):
|
2007-09-08 02:54:01 +05:30
|
|
|
if self.db.has_gramps_id(PERSON_KEY, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.idswap[gramps_id] = self.db.find_next_person_gramps_id()
|
|
|
|
else:
|
|
|
|
self.idswap[gramps_id] = gramps_id
|
|
|
|
return self.idswap[gramps_id]
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def map_fid(self, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
if not self.fidswap.get(gramps_id):
|
2007-09-08 02:54:01 +05:30
|
|
|
if self.db.has_gramps_id(FAMILY_KEY, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def map_eid(self, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
if not self.eidswap.get(gramps_id):
|
2007-09-08 02:54:01 +05:30
|
|
|
if self.db.has_gramps_id(EVENT_KEY, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def map_pid(self, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
if not self.pidswap.get(gramps_id):
|
2007-09-08 02:54:01 +05:30
|
|
|
if self.db.has_gramps_id(PLACE_KEY, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def map_sid(self, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
if not self.sidswap.get(gramps_id):
|
2007-09-08 02:54:01 +05:30
|
|
|
if self.db.has_gramps_id(SOURCE_KEY, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def map_oid(self, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
if not self.oidswap.get(gramps_id):
|
2007-09-08 02:54:01 +05:30
|
|
|
if self.db.has_gramps_id(MEDIA_KEY, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def map_rid(self, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
if not self.ridswap.get(gramps_id):
|
2007-09-08 02:54:01 +05:30
|
|
|
if self.db.has_gramps_id(REPOSITORY_KEY, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.ridswap[gramps_id] = self.db.find_next_repository_gramps_id()
|
|
|
|
else:
|
|
|
|
self.ridswap[gramps_id] = gramps_id
|
|
|
|
return self.ridswap[gramps_id]
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def map_nid(self, gramps_id):
|
2007-02-21 08:08:21 +05:30
|
|
|
if not self.nidswap.get(gramps_id):
|
2007-09-08 02:54:01 +05:30
|
|
|
if self.db.has_gramps_id(NOTE_KEY, gramps_id):
|
2007-02-21 08:08:21 +05:30
|
|
|
self.nidswap[gramps_id] = self.db.find_next_note_gramps_id()
|
|
|
|
else:
|
|
|
|
self.nidswap[gramps_id] = gramps_id
|
|
|
|
return self.nidswap[gramps_id]
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def parse(self, ifile, use_trans=False, linecount=0, personcount=0):
|
2006-02-02 20:23:31 +05:30
|
|
|
if personcount < 1000:
|
|
|
|
no_magic = True
|
|
|
|
else:
|
|
|
|
no_magic = False
|
2007-09-08 02:54:01 +05:30
|
|
|
self.trans = self.db.transaction_begin("", batch=True, no_magic=no_magic)
|
2006-05-11 11:46:45 +05:30
|
|
|
self.set_total(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
|
2007-09-08 02:54:01 +05:30
|
|
|
self.p.ParseFile(ifile)
|
2006-03-07 04:00:17 +05:30
|
|
|
|
2006-07-28 01:41:56 +05:30
|
|
|
if len(self.name_formats) > 0:
|
|
|
|
# add new name formats to the existing table
|
|
|
|
self.db.name_formats += self.name_formats
|
|
|
|
# Register new formats
|
2007-06-28 11:11:40 +05:30
|
|
|
name_displayer.set_name_format(self.db.name_formats)
|
2006-07-28 01:41:56 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
self.db.set_researcher(self.owner)
|
2008-06-16 20:31:46 +05:30
|
|
|
if self.home is not None:
|
2008-02-29 04:02:40 +05:30
|
|
|
person = self.db.get_person_from_handle(self.home)
|
2006-02-01 11:55:51 +05:30
|
|
|
self.db.set_default_person_handle(person.handle)
|
2008-02-29 04:02:40 +05:30
|
|
|
|
2007-12-01 05:20:05 +05:30
|
|
|
#set media path, this should really do some parsing to convert eg
|
|
|
|
# windows path to unix ?
|
|
|
|
if self.mediapath:
|
|
|
|
oldpath = self.db.get_mediapath()
|
|
|
|
if not oldpath:
|
|
|
|
self.db.set_mediapath(self.mediapath)
|
|
|
|
elif not oldpath == self.mediapath:
|
|
|
|
ErrorDialog(_("Could not change media path"),
|
|
|
|
_("The opened file has media path %s, which conflicts with"
|
2008-02-29 04:02:40 +05:30
|
|
|
" the media path of the family tree you import into. "
|
|
|
|
"The original media path has been retained. Copy the "
|
|
|
|
"files to a correct directory or change the media "
|
|
|
|
"path in the Preferences."
|
2007-12-01 05:20:05 +05:30
|
|
|
) % self.mediapath )
|
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
|
2007-09-08 02:54:01 +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()
|
2008-02-29 04:02:40 +05:30
|
|
|
return self.info
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_lds_ord(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.ord = gen.lib.LdsOrd()
|
2006-05-24 10:58:33 +05:30
|
|
|
self.ord.set_type_from_xml(attrs['type'])
|
2007-05-12 04:01:39 +05:30
|
|
|
self.ord.private = bool(attrs.get("priv"))
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.person:
|
2006-04-06 08:04:58 +05:30
|
|
|
self.person.lds_ord_list.append(self.ord)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.family:
|
2006-05-24 10:58:33 +05:30
|
|
|
self.family.lds_ord_list.append(self.ord)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_temple(self, attrs):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.ord.set_temple(attrs['val'])
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_data_item(self, attrs):
|
|
|
|
self.source.set_data_item(attrs['key'], attrs['value'])
|
2004-11-23 10:45:37 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_status(self, attrs):
|
2006-05-24 10:58:33 +05:30
|
|
|
try:
|
|
|
|
# old xml with integer statuses
|
|
|
|
self.ord.set_status(int(attrs['val']))
|
|
|
|
except ValueError:
|
|
|
|
# string
|
|
|
|
self.ord.set_status_from_xml(attrs['val'])
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_sealed_to(self, attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_place(self, attrs):
|
2007-10-12 04:11:03 +05:30
|
|
|
"""A reference to a place in an object: event or lds_ord
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2007-10-12 04:11:03 +05:30
|
|
|
handle = attrs['hlink'].replace('_', '')
|
|
|
|
self.db.check_place_from_handle(handle, self.trans,
|
|
|
|
set_gid = False)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2007-10-12 04:11:03 +05:30
|
|
|
#legacy, before hlink there was ref
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_pid(attrs['ref'])
|
2008-02-29 04:02:40 +05:30
|
|
|
place, new = self.find_place_by_gramps_id(gramps_id)
|
2007-10-12 04:11:03 +05:30
|
|
|
handle = place.handle
|
|
|
|
|
|
|
|
if self.ord:
|
|
|
|
self.ord.set_place_handle(handle)
|
|
|
|
elif self.object:
|
|
|
|
self.object.set_place_handle(handle)
|
|
|
|
else:
|
|
|
|
self.event.set_place_handle(handle)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2007-09-08 02:54:01 +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:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.placeobj, new = self.db.find_place_from_handle(
|
2007-09-08 02:54:01 +05:30
|
|
|
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:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.placeobj, new = self.find_place_by_gramps_id(gramps_id)
|
2007-05-11 03:37:25 +05:30
|
|
|
|
|
|
|
self.placeobj.private = bool(attrs.get("priv"))
|
2008-02-29 04:02:40 +05:30
|
|
|
if new:
|
|
|
|
#keep change time from xml file
|
|
|
|
self.placeobj.change = int(attrs.get('change',self.change))
|
|
|
|
self.info.add('new-object', PLACE_KEY, self.placeobj)
|
|
|
|
else:
|
|
|
|
self.placeobj.change = self.change
|
|
|
|
self.info.add('merge-overwrite', PLACE_KEY, self.placeobj)
|
2007-05-11 03:37:25 +05:30
|
|
|
|
2006-01-30 03:09:36 +05:30
|
|
|
# GRAMPS LEGACY: title in the placeobj tag
|
2007-09-08 02:54:01 +05:30
|
|
|
self.placeobj.title = attrs.get('title', '')
|
2004-04-11 08:07:13 +05:30
|
|
|
self.locations = 0
|
2006-05-11 11:46:45 +05:30
|
|
|
self.update(self.p.CurrentLineNumber)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_location(self, attrs):
|
2004-04-11 08:07:13 +05:30
|
|
|
"""Bypass the function calls for this one, since it appears to
|
|
|
|
take up quite a bit of time"""
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
loc = gen.lib.Location()
|
2007-09-08 02:54:01 +05:30
|
|
|
loc.phone = attrs.get('phone', '')
|
|
|
|
loc.postal = attrs.get('postal', '')
|
|
|
|
loc.city = attrs.get('city', '')
|
|
|
|
loc.street = attrs.get('street', '')
|
|
|
|
loc.parish = attrs.get('parish', '')
|
|
|
|
loc.state = attrs.get('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
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_witness(self, attrs):
|
2006-01-29 10:42:01 +05:30
|
|
|
# Parse witnesses created by older gramps
|
2006-06-23 02:53:00 +05:30
|
|
|
self.in_witness = True
|
2005-05-11 19:57:32 +05:30
|
|
|
self.witness_comment = ""
|
2006-01-29 10:42:01 +05:30
|
|
|
if attrs.has_key('name'):
|
2007-10-08 22:11:39 +05:30
|
|
|
note = gen.lib.Note()
|
2007-02-20 06:09:10 +05:30
|
|
|
note.handle = Utils.create_id()
|
|
|
|
note.set(_("Witness name: %s") % attrs['name'])
|
2007-10-08 22:11:39 +05:30
|
|
|
note.type.set(gen.lib.NoteType.EVENT)
|
2007-05-10 00:57:15 +05:30
|
|
|
note.private = self.event.private
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_note(note, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
#set correct change time
|
|
|
|
self.db.commit_note(note, self.trans, self.change)
|
|
|
|
self.info.add('new-object', NOTE_KEY, note)
|
2007-02-20 06:09:10 +05:30
|
|
|
self.event.add_note(note.handle)
|
2006-01-29 10:42:01 +05:30
|
|
|
return
|
|
|
|
|
2006-01-31 07:11:55 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs['hlink'].replace('_', '')
|
2008-02-29 04:02:40 +05:30
|
|
|
person, new = self.db.find_person_from_handle(handle, self.trans)
|
2006-01-31 07:11:55 +05:30
|
|
|
except KeyError:
|
2006-06-23 02:53:00 +05:30
|
|
|
if attrs.has_key('ref'):
|
2008-02-29 04:02:40 +05:30
|
|
|
person, new = self.find_person_by_gramps_id(
|
|
|
|
self.map_gid(attrs["ref"]))
|
2006-06-23 02:53:00 +05:30
|
|
|
else:
|
|
|
|
person = None
|
|
|
|
|
2006-01-29 10:42:01 +05:30
|
|
|
# Add an EventRef from that person
|
|
|
|
# to this event using ROLE_WITNESS role
|
2006-06-23 02:53:00 +05:30
|
|
|
if person:
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2006-06-23 02:53:00 +05:30
|
|
|
event_ref.ref = self.event.handle
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref.role.set(gen.lib.EventRoleType.WITNESS)
|
2006-06-23 02:53:00 +05:30
|
|
|
person.event_ref_list.append(event_ref)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.commit_person(person, self.trans, self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_coord(self, attrs):
|
|
|
|
self.placeobj.lat = attrs.get('lat', '')
|
|
|
|
self.placeobj.long = attrs.get('long', '')
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +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.
|
2007-10-08 22:11:39 +05:30
|
|
|
self.event = gen.lib.Event()
|
2006-01-29 10:42:01 +05:30
|
|
|
self.event.handle = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
self.event.type = gen.lib.EventType()
|
2006-04-20 04:29:33 +05:30
|
|
|
self.event.type.set_from_xml_str(attrs['type'])
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_event(self.event, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
#set correct change time
|
|
|
|
self.db.commit_event(self.event, self.trans, self.change)
|
|
|
|
self.info.add('new-object', EVENT_KEY, self.event)
|
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
|
2006-05-11 11:46:45 +05:30
|
|
|
self.update(self.p.CurrentLineNumber)
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_eid(attrs["id"])
|
|
|
|
try:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.event, new = self.db.find_event_from_handle(
|
2007-09-08 02:54:01 +05:30
|
|
|
attrs['handle'].replace('_', ''), self.trans)
|
2006-01-31 07:11:55 +05:30
|
|
|
self.event.gramps_id = gramps_id
|
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.event, new = self.find_event_by_gramps_id(gramps_id)
|
2006-01-29 10:42:01 +05:30
|
|
|
self.event.private = bool(attrs.get("priv"))
|
2008-02-29 04:02:40 +05:30
|
|
|
if new:
|
|
|
|
#keep change time from xml file
|
|
|
|
self.event.change = int(attrs.get('change',self.change))
|
|
|
|
self.info.add('new-object', EVENT_KEY, self.event)
|
|
|
|
else:
|
|
|
|
self.event.change = self.change
|
|
|
|
self.info.add('merge-overwrite', EVENT_KEY, self.event)
|
2006-01-29 10:42:01 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_eventref(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.eventref = gen.lib.EventRef()
|
2007-09-08 02:54:01 +05:30
|
|
|
self.eventref.ref = attrs['hlink'].replace('_', '')
|
2006-01-29 10:42:01 +05:30
|
|
|
self.eventref.private = bool(attrs.get('priv'))
|
2006-04-23 00:38:47 +05:30
|
|
|
if attrs.has_key('role'):
|
|
|
|
self.eventref.role.set_from_xml_str(attrs['role'])
|
2006-10-30 06:23:17 +05:30
|
|
|
|
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-10-30 06:23:17 +05:30
|
|
|
if not event:
|
|
|
|
return
|
|
|
|
|
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
|
2007-10-08 22:11:39 +05:30
|
|
|
if (event.type == gen.lib.EventType.BIRTH) \
|
|
|
|
and (self.eventref.role == gen.lib.EventRoleType.PRIMARY) \
|
2008-06-16 20:31:46 +05:30
|
|
|
and (self.person.get_birth_ref() is None):
|
2006-05-24 01:25:35 +05:30
|
|
|
self.person.set_birth_ref(self.eventref)
|
2007-10-08 22:11:39 +05:30
|
|
|
elif (event.type == gen.lib.EventType.DEATH) \
|
|
|
|
and (self.eventref.role == gen.lib.EventRoleType.PRIMARY) \
|
2008-06-16 20:31:46 +05:30
|
|
|
and (self.person.get_death_ref() is None):
|
2006-05-24 01:25:35 +05:30
|
|
|
self.person.set_death_ref(self.eventref)
|
2006-01-29 10:42:01 +05:30
|
|
|
else:
|
|
|
|
self.person.add_event_ref(self.eventref)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_attribute(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.attribute = gen.lib.Attribute()
|
2006-01-29 10:42:01 +05:30
|
|
|
self.attribute.private = bool(attrs.get("priv"))
|
2007-10-08 22:11:39 +05:30
|
|
|
self.attribute.type = gen.lib.AttributeType()
|
2006-04-23 00:38:47 +05:30
|
|
|
if attrs.has_key('type'):
|
|
|
|
self.attribute.type.set_from_xml_str(attrs["type"])
|
2007-09-08 02:54: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)
|
2006-08-16 02:29:12 +05:30
|
|
|
elif self.event:
|
|
|
|
self.event.add_attribute(self.attribute)
|
|
|
|
elif self.eventref:
|
|
|
|
self.eventref.add_attribute(self.attribute)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.person:
|
|
|
|
self.person.add_attribute(self.attribute)
|
|
|
|
elif self.family:
|
|
|
|
self.family.add_attribute(self.attribute)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_address(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.address = gen.lib.Address()
|
2006-01-29 10:42:01 +05:30
|
|
|
self.address.private = bool(attrs.get("priv"))
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_bmark(self, attrs):
|
2006-05-19 03:47:51 +05:30
|
|
|
target = attrs.get('target')
|
|
|
|
if not target:
|
|
|
|
# Old XML. Can be either handle or id reference
|
|
|
|
# and this is guaranteed to be a person bookmark
|
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs['hlink'].replace('_', '')
|
|
|
|
self.db.check_person_from_handle(handle, self.trans)
|
2006-05-19 03:47:51 +05:30
|
|
|
except KeyError:
|
|
|
|
gramps_id = self.map_gid(attrs["ref"])
|
2008-02-29 04:02:40 +05:30
|
|
|
person, new = self.find_person_by_gramps_id(gramps_id)
|
2006-05-19 03:47:51 +05:30
|
|
|
handle = person.handle
|
|
|
|
self.db.bookmarks.append(handle)
|
|
|
|
return
|
|
|
|
|
|
|
|
# This is new XML, so we are guaranteed to have a handle ref
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs['hlink'].replace('_', '')
|
2007-09-29 17:49:23 +05:30
|
|
|
# Due to pre 2.2.9 bug, bookmarks might be handle of other object
|
|
|
|
# Make sure those are filtered out.
|
|
|
|
# Bookmarks are at end, so all handle must exist before we do bookmrks
|
2006-05-19 03:47:51 +05:30
|
|
|
if target == 'person':
|
2008-02-29 04:02:40 +05:30
|
|
|
if (self.db.get_person_from_handle(handle) is not None
|
2007-10-04 03:06:57 +05:30
|
|
|
and handle not in self.db.bookmarks.get() ):
|
2007-09-29 17:49:23 +05:30
|
|
|
self.db.bookmarks.append(handle)
|
2006-05-19 03:47:51 +05:30
|
|
|
elif target == 'family':
|
2008-02-29 04:02:40 +05:30
|
|
|
if (self.db.get_family_from_handle(handle) is not None
|
2007-10-04 03:06:57 +05:30
|
|
|
and handle not in self.db.family_bookmarks.get() ):
|
2007-09-29 17:49:23 +05:30
|
|
|
self.db.family_bookmarks.append(handle)
|
2006-05-19 03:47:51 +05:30
|
|
|
elif target == 'event':
|
2008-02-29 04:02:40 +05:30
|
|
|
if (self.db.get_event_from_handle(handle) is not None
|
2007-10-04 03:06:57 +05:30
|
|
|
and handle not in self.db.event_bookmarks.get() ):
|
2007-09-29 17:49:23 +05:30
|
|
|
self.db.event_bookmarks.append(handle)
|
2006-05-19 03:47:51 +05:30
|
|
|
elif target == 'source':
|
2008-02-29 04:02:40 +05:30
|
|
|
if (self.db.get_source_from_handle(handle) is not None
|
2007-10-04 03:06:57 +05:30
|
|
|
and handle not in self.db.source_bookmarks.get() ):
|
2007-09-29 17:49:23 +05:30
|
|
|
self.db.source_bookmarks.append(handle)
|
2006-05-19 03:47:51 +05:30
|
|
|
elif target == 'place':
|
2008-02-29 04:02:40 +05:30
|
|
|
if (self.db.get_place_from_handle(handle) is not None
|
2007-10-04 03:06:57 +05:30
|
|
|
and handle not in self.db.place_bookmarks.get() ):
|
2007-09-29 17:49:23 +05:30
|
|
|
self.db.place_bookmarks.append(handle)
|
2006-05-19 03:47:51 +05:30
|
|
|
elif target == 'media':
|
2008-02-29 04:02:40 +05:30
|
|
|
if (self.db.get_object_from_handle(handle) is not None
|
2007-10-04 03:06:57 +05:30
|
|
|
and handle not in self.db.media_bookmarks.get() ):
|
2007-09-29 17:49:23 +05:30
|
|
|
self.db.media_bookmarks.append(handle)
|
2006-05-19 03:47:51 +05:30
|
|
|
elif target == 'repository':
|
2008-02-29 04:02:40 +05:30
|
|
|
if (self.db.get_repository_from_handle(handle)
|
2007-10-04 03:06:57 +05:30
|
|
|
is not None and handle not in self.db.repo_bookmarks.get()):
|
2007-09-29 17:49:23 +05:30
|
|
|
self.db.repo_bookmarks.append(handle)
|
2007-03-28 03:17:18 +05:30
|
|
|
elif target == 'note':
|
2008-02-29 04:02:40 +05:30
|
|
|
if (self.db.get_note_from_handle(handle) is not None
|
2007-10-04 03:06:57 +05:30
|
|
|
and handle not in self.db.note_bookmarks.get() ):
|
2007-09-29 17:49:23 +05:30
|
|
|
self.db.note_bookmarks.append(handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_format(self, attrs):
|
2006-07-06 23:16:46 +05:30
|
|
|
number = int(attrs['number'])
|
|
|
|
name = attrs['name']
|
|
|
|
fmt_str = attrs['fmt_str']
|
2007-09-08 02:54:01 +05:30
|
|
|
active = bool(attrs.get('active', True))
|
2006-07-06 23:16:46 +05:30
|
|
|
|
2006-07-28 01:41:56 +05:30
|
|
|
if number in self.taken_name_format_numbers:
|
|
|
|
number = self.remap_name_format(number)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
self.name_formats.append((number, name, fmt_str, active))
|
2006-07-28 01:41:56 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def remap_name_format(self, old_number):
|
2006-07-28 01:41:56 +05:30
|
|
|
if self.name_formats_map.has_key(old_number): # This should not happen
|
|
|
|
return self.name_formats_map[old_number]
|
|
|
|
# Find the lowest new number not taken yet:
|
|
|
|
new_number = -1
|
|
|
|
while new_number in self.taken_name_format_numbers:
|
|
|
|
new_number -= 1
|
|
|
|
# Add this to the taken list
|
|
|
|
self.taken_name_format_numbers.append(new_number)
|
|
|
|
# Set up the mapping entry
|
|
|
|
self.name_formats_map[old_number] = new_number
|
|
|
|
# Return new number
|
|
|
|
return new_number
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_person(self, attrs):
|
2006-05-11 11:46:45 +05:30
|
|
|
self.update(self.p.CurrentLineNumber)
|
2004-08-04 10:23:29 +05:30
|
|
|
new_id = self.map_gid(attrs['id'])
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.person, new = self.db.find_person_from_handle(
|
2007-09-08 02:54:01 +05:30
|
|
|
attrs['handle'].replace('_', ''), self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.person.set_gramps_id(new_id)
|
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.person, new = self.find_person_by_gramps_id(new_id)
|
2004-10-11 02:46:44 +05:30
|
|
|
|
2007-05-11 03:37:25 +05:30
|
|
|
self.person.private = bool(attrs.get("priv"))
|
2008-02-29 04:02:40 +05:30
|
|
|
if new:
|
|
|
|
#keep change time from xml file
|
|
|
|
self.person.change = int(attrs.get('change',self.change))
|
|
|
|
self.info.add('new-object', PERSON_KEY, self.person)
|
|
|
|
else:
|
|
|
|
self.person.change = self.change
|
|
|
|
self.info.add('merge-overwrite', PERSON_KEY, self.person)
|
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
|
2007-10-08 22:11:39 +05:30
|
|
|
self.person.marker.set(gen.lib.MarkerType.COMPLETE)
|
2006-01-29 10:42:01 +05:30
|
|
|
else:
|
2007-09-08 02:54:01 +05:30
|
|
|
self.person.marker.set_from_xml_str(attrs.get("marker", ''))
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_people(self, attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
if attrs.has_key('home'):
|
2007-09-08 02:54:01 +05:30
|
|
|
self.home = attrs['home'].replace('_', '')
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_father(self, attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs['hlink'].replace('_', '')
|
2007-10-12 04:11:03 +05:30
|
|
|
#all persons exist before father tag is encountered
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.check_person_from_handle(handle, self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
person, new = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
|
2006-06-23 22:40:05 +05:30
|
|
|
handle = person.handle
|
2006-01-31 07:11:55 +05:30
|
|
|
self.family.set_father_handle(handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_mother(self, attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs['hlink'].replace('_', '')
|
2007-10-12 04:11:03 +05:30
|
|
|
#all persons exist before mother tag is encountered
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.check_person_from_handle(handle, self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
person, new = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
|
2006-06-23 22:40:05 +05:30
|
|
|
handle = person.handle
|
2006-01-31 07:11:55 +05:30
|
|
|
self.family.set_mother_handle(handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_child(self, attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs['hlink'].replace('_', '')
|
2008-02-29 04:02:40 +05:30
|
|
|
#all persons exist before child tag is encountered
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.check_person_from_handle(handle, self.trans)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
person, new = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
|
2006-06-23 22:40:05 +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
|
2007-09-08 02:54:01 +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(
|
2007-09-08 02:54:01 +05:30
|
|
|
self.childref_map[(self.family.handle, handle)])
|
2006-04-19 07:53:08 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_childref(self, attrs):
|
2006-04-19 07:53:08 +05:30
|
|
|
# Here we are handling the new XML, in which frel and mrel
|
2008-02-29 04:02:40 +05:30
|
|
|
# belong to the "childref" tag under family.
|
2007-10-08 22:11:39 +05:30
|
|
|
self.childref = gen.lib.ChildRef()
|
2007-09-08 02:54:01 +05:30
|
|
|
self.childref.ref = attrs['hlink'].replace('_', '')
|
2006-04-19 07:53:08 +05:30
|
|
|
self.childref.private = bool(attrs.get('priv'))
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
mrel = gen.lib.ChildRefType()
|
2006-04-23 00:38:47 +05:30
|
|
|
if attrs.get('mrel'):
|
|
|
|
mrel.set_from_xml_str(attrs['mrel'])
|
2007-10-08 22:11:39 +05:30
|
|
|
frel = gen.lib.ChildRefType()
|
2006-05-18 10:10:37 +05:30
|
|
|
if attrs.get('frel'):
|
2006-04-23 00:38:47 +05:30
|
|
|
frel.set_from_xml_str(attrs['frel'])
|
2006-04-19 07:53:08 +05:30
|
|
|
|
|
|
|
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-05-08 23:20:12 +05:30
|
|
|
self.family.add_child_ref(self.childref)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_personref(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.personref = gen.lib.PersonRef()
|
2007-09-08 02:54:01 +05:30
|
|
|
self.personref.ref = attrs['hlink'].replace('_', '')
|
2006-04-19 09:02:33 +05:30
|
|
|
self.personref.private = bool(attrs.get('priv'))
|
|
|
|
self.personref.rel = attrs['rel']
|
|
|
|
self.person.add_person_ref(self.personref)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_url(self, attrs):
|
2004-04-11 08:07:13 +05:30
|
|
|
if not attrs.has_key("href"):
|
|
|
|
return
|
2007-10-08 22:11:39 +05:30
|
|
|
url = gen.lib.Url()
|
2006-01-29 10:42:01 +05:30
|
|
|
url.path = attrs["href"]
|
2007-09-08 02:54:01 +05:30
|
|
|
url.set_description(attrs.get("description", ''))
|
2007-05-12 04:01:39 +05:30
|
|
|
url.private = bool(attrs.get('priv'))
|
2007-09-08 02:54:01 +05:30
|
|
|
url.type.set_from_xml_str(attrs.get('type', ''))
|
2006-01-29 10:42:01 +05:30
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_family(self, attrs):
|
2006-05-11 11:46:45 +05:30
|
|
|
self.update(self.p.CurrentLineNumber)
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_fid(attrs["id"])
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.family, new = self.db.find_family_from_handle(
|
2007-09-08 02:54:01 +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:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.family, new = self.find_family_by_gramps_id(gramps_id)
|
2007-05-11 03:37:25 +05:30
|
|
|
|
|
|
|
self.family.private = bool(attrs.get("priv"))
|
2008-02-29 04:02:40 +05:30
|
|
|
if new:
|
|
|
|
#keep change time from xml file
|
|
|
|
self.family.change = int(attrs.get('change',self.change))
|
|
|
|
self.info.add('new-object', FAMILY_KEY, self.family)
|
|
|
|
else:
|
|
|
|
self.family.change = self.change
|
|
|
|
self.info.add('merge-overwrite', FAMILY_KEY, self.family)
|
2007-05-11 03:37:25 +05:30
|
|
|
|
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-23 00:38:47 +05:30
|
|
|
if attrs.has_key('type'):
|
|
|
|
self.family.type.set_from_xml_str(attrs["type"])
|
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
|
2007-10-08 22:11:39 +05:30
|
|
|
self.family.marker.set(gen.lib.MarkerType.COMPLETE)
|
2006-01-29 10:42:01 +05:30
|
|
|
else:
|
2007-09-08 02:54:01 +05:30
|
|
|
self.family.marker.set_from_xml_str(attrs.get("marker", ''))
|
2006-01-29 10:42:01 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_rel(self, attrs):
|
2006-04-23 00:38:47 +05:30
|
|
|
if attrs.has_key('type'):
|
|
|
|
self.family.type.set_from_xml_str(attrs["type"])
|
2006-01-29 10:42:01 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_file(self, attrs):
|
2006-01-30 03:09:36 +05:30
|
|
|
self.object.mime = attrs['mime']
|
2007-04-12 17:21:53 +05:30
|
|
|
if attrs.has_key('description'):
|
|
|
|
self.object.desc = attrs['description']
|
|
|
|
else:
|
|
|
|
self.object.desc = ""
|
2008-02-29 04:02:40 +05:30
|
|
|
#keep value of path, no longer make absolute paths on import
|
|
|
|
src = attrs["src"]
|
2006-01-30 03:09:36 +05:30
|
|
|
if src:
|
|
|
|
self.object.path = src
|
2008-02-29 04:02:40 +05:30
|
|
|
if self.all_abs and not os.path.isabs(src):
|
|
|
|
self.all_abs = False
|
|
|
|
self.info.add('relative-path', None, None)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_childof(self, attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs["hlink"].replace('_', '')
|
2007-10-12 04:11:03 +05:30
|
|
|
self.db.check_family_from_handle(handle, self.trans,
|
|
|
|
set_gid = False)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
family, new = 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
|
2007-10-08 22:11:39 +05:30
|
|
|
mrel = gen.lib.ChildRefType()
|
|
|
|
frel = gen.lib.ChildRefType()
|
2006-04-23 00:38:47 +05:30
|
|
|
if attrs.has_key('mrel'):
|
2006-04-22 03:54:54 +05:30
|
|
|
mrel.set_from_xml_str(attrs['mrel'])
|
2006-04-23 00:38:47 +05:30
|
|
|
if attrs.has_key('frel'):
|
2006-04-22 03:54:54 +05:30
|
|
|
frel.set_from_xml_str(attrs['frel'])
|
2006-04-13 21:46:00 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
childref = gen.lib.ChildRef()
|
2006-04-19 10:44:37 +05:30
|
|
|
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)
|
2007-09-08 02:54:01 +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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_parentin(self, attrs):
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs["hlink"].replace('_', '')
|
2007-10-12 04:11:03 +05:30
|
|
|
self.db.check_family_from_handle(handle, self.trans,
|
|
|
|
set_gid = False)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
family, new = 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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_name(self, attrs):
|
2004-04-11 08:07:13 +05:30
|
|
|
if not self.in_witness:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.name = gen.lib.Name()
|
2006-07-25 05:31:08 +05:30
|
|
|
name_type = attrs['type']
|
2006-07-25 05:54:15 +05:30
|
|
|
# Mapping "Other Name" from gramps 2.0.x to Unknown
|
|
|
|
if (self.version_string=='1.0.0') and (name_type=='Other Name'):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.name.set_type(gen.lib.NameType.UNKNOWN)
|
2006-07-25 05:31:08 +05:30
|
|
|
else:
|
|
|
|
self.name.type.set_from_xml_str(name_type)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.name.private = bool(attrs.get("priv"))
|
2006-01-29 10:42:01 +05:30
|
|
|
self.alt_name = bool(attrs.get("alt"))
|
2006-06-15 01:50:39 +05:30
|
|
|
try:
|
2006-07-28 01:41:56 +05:30
|
|
|
sort_as = int(attrs["sort"])
|
|
|
|
display_as = int(attrs["display"])
|
|
|
|
|
|
|
|
# check if these pointers need to be remapped
|
|
|
|
# and set the name attributes
|
|
|
|
if self.name_formats_map.has_key(sort_as):
|
|
|
|
self.name.sort_as = self.name_formats_map[sort_as]
|
|
|
|
else:
|
|
|
|
self.name.sort_as = sort_as
|
|
|
|
if self.name_formats_map.has_key(display_as):
|
|
|
|
self.name.sort_as = self.name_formats_map[display_as]
|
|
|
|
else:
|
|
|
|
self.name_display_as = display_as
|
2006-06-15 01:50:39 +05:30
|
|
|
except KeyError:
|
|
|
|
pass
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-12-09 15:48:59 +05:30
|
|
|
def start_namemap(self, attrs):
|
|
|
|
type = attrs.get('type')
|
|
|
|
key = attrs['key']
|
|
|
|
value = attrs['value']
|
|
|
|
if type == 'group_as':
|
|
|
|
if self.db.has_name_group_key(key) :
|
|
|
|
present = self.db.get_name_group_mapping(key)
|
|
|
|
if not value == present:
|
|
|
|
msg = _("Your family tree groups name %s together"
|
|
|
|
" with %s, did not change this grouping to %s") % (
|
|
|
|
key, present, value)
|
|
|
|
self.errmsg(msg)
|
|
|
|
else:
|
|
|
|
self.db.set_name_group_mapping(key, value)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_last(self, attrs):
|
|
|
|
self.name.prefix = attrs.get('prefix', '')
|
|
|
|
self.name.group_as = attrs.get('group', '')
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2008-04-09 03:13:58 +05:30
|
|
|
def start_tag(self, attrs):
|
|
|
|
tagtype = gen.lib.StyledTextTagType()
|
|
|
|
tagtype.set_from_xml_str(attrs['name'])
|
|
|
|
|
|
|
|
try:
|
2008-04-23 19:06:43 +05:30
|
|
|
val = attrs['value']
|
|
|
|
tagvalue = gen.lib.StyledTextTagType.STYLE_TYPE[int(tagtype)](val)
|
2008-04-09 03:13:58 +05:30
|
|
|
except KeyError:
|
|
|
|
tagvalue = None
|
2008-04-23 19:06:43 +05:30
|
|
|
except ValueError:
|
|
|
|
return
|
2008-04-09 03:13:58 +05:30
|
|
|
|
|
|
|
self.note_tags.append(gen.lib.StyledTextTag(tagtype, tagvalue))
|
|
|
|
|
|
|
|
def start_range(self, attrs):
|
|
|
|
self.note_tags[-1].ranges.append((int(attrs['start']),
|
|
|
|
int(attrs['end'])))
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_note(self, attrs):
|
2007-02-20 06:09:10 +05:30
|
|
|
self.in_note = 0
|
2007-02-21 08:08:21 +05:30
|
|
|
if 'handle' in attrs:
|
2007-02-20 06:09:10 +05:30
|
|
|
# This is new note, with ID and handle already existing
|
|
|
|
self.update(self.p.CurrentLineNumber)
|
2007-02-21 08:08:21 +05:30
|
|
|
gramps_id = self.map_nid(attrs["id"])
|
2007-02-20 06:09:10 +05:30
|
|
|
try:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.note, new = self.db.find_note_from_handle(
|
2007-09-08 02:54:01 +05:30
|
|
|
attrs['handle'].replace('_', ''), self.trans)
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note.gramps_id = gramps_id
|
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.note, new = self.find_note_by_gramps_id(gramps_id)
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note.private = bool(attrs.get("priv"))
|
2008-02-29 04:02:40 +05:30
|
|
|
if new:
|
|
|
|
#keep change time from xml file
|
|
|
|
self.note.change = int(attrs.get('change',self.change))
|
|
|
|
self.info.add('new-object', NOTE_KEY, self.note)
|
|
|
|
else:
|
|
|
|
self.note.change = self.change
|
|
|
|
self.info.add('merge-overwrite', NOTE_KEY, self.note)
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.format = int(attrs.get('format', gen.lib.Note.FLOWED))
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note.type.set_from_xml_str(attrs['type'])
|
2008-04-09 03:13:58 +05:30
|
|
|
|
2008-04-23 19:06:43 +05:30
|
|
|
# Since StyledText was introduced (XML v1.3.0) the clear text
|
2008-04-09 03:13:58 +05:30
|
|
|
# part of the note is moved between <text></text> tags.
|
|
|
|
# To catch the different versions here we reset the note_text
|
|
|
|
# variable. It will be checked in stop_note() then.
|
|
|
|
self.note_text = None
|
|
|
|
self.note_tags = []
|
2007-02-21 08:08:21 +05:30
|
|
|
else:
|
|
|
|
# GRAMPS LEGACY: old notes that were written inside other objects
|
2007-05-10 00:57:15 +05:30
|
|
|
# We need to create a top-level note, it's type depends on
|
|
|
|
# the caller object, and inherits privacy from caller object
|
2007-02-21 08:08:21 +05:30
|
|
|
# On stop_note the reference to this note will be added
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note = gen.lib.Note()
|
2007-02-21 08:08:21 +05:30
|
|
|
self.note.handle = Utils.create_id()
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.format = int(attrs.get('format', gen.lib.Note.FLOWED))
|
2007-05-10 00:57:15 +05:30
|
|
|
if self.source_ref:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.SOURCEREF)
|
2007-05-12 04:01:39 +05:30
|
|
|
self.note.private = self.source_ref.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.address:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.ADDRESS)
|
2007-05-10 00:57:15 +05:30
|
|
|
self.note.private = self.address.private
|
|
|
|
elif self.ord:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.LDS)
|
2007-05-12 04:01:39 +05:30
|
|
|
self.note.private = self.ord.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.attribute:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.ATTRIBUTE)
|
2007-05-10 00:57:15 +05:30
|
|
|
self.note.private = self.attribute.private
|
|
|
|
elif self.object:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.MEDIA)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.note.private = self.object.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.objref:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.MEDIAREF)
|
2007-05-10 00:57:15 +05:30
|
|
|
self.note.private = self.objref.private
|
|
|
|
elif self.photo:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.MEDIA)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.note.private = self.photo.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.name:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.PERSONNAME)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.note.private = self.name.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.source:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.SOURCE)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.note.private = self.source.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.event:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.EVENT)
|
2007-05-10 00:57:15 +05:30
|
|
|
self.note.private = self.event.private
|
|
|
|
elif self.personref:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.ASSOCIATION)
|
2007-05-10 00:57:15 +05:30
|
|
|
self.note.private = self.personref.private
|
|
|
|
elif self.person:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.PERSON)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.note.private = self.person.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.childref:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.CHILDREF)
|
2007-05-10 00:57:15 +05:30
|
|
|
self.note.private = self.childref.private
|
|
|
|
elif self.family:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.FAMILY)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.note.private = self.family.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.placeobj:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.PLACE)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.note.private = self.placeobj.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.eventref:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.EVENTREF)
|
2007-05-10 00:57:15 +05:30
|
|
|
self.note.private = self.eventref.private
|
|
|
|
elif self.repo:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.REPO)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.note.private = self.repo.private
|
2007-05-10 00:57:15 +05:30
|
|
|
elif self.reporef:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.note.type.set(gen.lib.NoteType.REPOREF)
|
2007-07-18 04:14:24 +05:30
|
|
|
self.note.private = self.reporef.private
|
2007-05-10 00:57:15 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_note(self.note, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
#set correct change time
|
|
|
|
self.db.commit_note(self.note, self.trans, self.change)
|
|
|
|
self.info.add('new-object', NOTE_KEY, self.note)
|
2007-02-21 08:08:21 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_noteref(self, attrs):
|
|
|
|
handle = attrs['hlink'].replace('_', '')
|
2007-10-12 04:11:03 +05:30
|
|
|
self.db.check_note_from_handle(handle, self.trans, set_gid = False)
|
2007-02-21 08:08:21 +05:30
|
|
|
|
2007-02-21 08:24:12 +05:30
|
|
|
if self.source_ref:
|
|
|
|
self.source_ref.add_note(handle)
|
|
|
|
elif self.address:
|
2007-02-21 08:08:21 +05:30
|
|
|
self.address.add_note(handle)
|
|
|
|
elif self.ord:
|
|
|
|
self.ord.add_note(handle)
|
|
|
|
elif self.attribute:
|
|
|
|
self.attribute.add_note(handle)
|
|
|
|
elif self.object:
|
|
|
|
self.object.add_note(handle)
|
|
|
|
elif self.objref:
|
|
|
|
self.objref.add_note(handle)
|
|
|
|
elif self.photo:
|
|
|
|
self.photo.add_note(handle)
|
|
|
|
elif self.name:
|
|
|
|
self.name.add_note(handle)
|
|
|
|
elif self.source:
|
|
|
|
self.source.add_note(handle)
|
|
|
|
elif self.event:
|
|
|
|
self.event.add_note(handle)
|
|
|
|
elif self.personref:
|
|
|
|
self.personref.add_note(handle)
|
|
|
|
elif self.person:
|
|
|
|
self.person.add_note(handle)
|
|
|
|
elif self.childref:
|
|
|
|
self.childref.add_note(handle)
|
|
|
|
elif self.family:
|
|
|
|
self.family.add_note(handle)
|
|
|
|
elif self.placeobj:
|
|
|
|
self.placeobj.add_note(handle)
|
|
|
|
elif self.eventref:
|
|
|
|
self.eventref.add_note(handle)
|
|
|
|
elif self.repo:
|
|
|
|
self.repo.add_note(handle)
|
|
|
|
elif self.reporef:
|
|
|
|
self.reporef.add_note(handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_sourceref(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.source_ref = gen.lib.SourceRef()
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs["hlink"].replace('_', '')
|
2007-10-10 01:32:02 +05:30
|
|
|
#create source object to obtain handle, gid is set in start_source
|
|
|
|
self.db.check_source_from_handle(handle, self.trans,
|
|
|
|
set_gid = False)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
source, new = 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
|
2007-09-08 02:54:01 +05:30
|
|
|
self.source_ref.confidence = int(attrs.get("conf", self.conf))
|
2007-05-12 04:01:39 +05:30
|
|
|
self.source_ref.private = bool(attrs.get("priv"))
|
|
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_source(self, attrs):
|
2006-05-11 11:46:45 +05:30
|
|
|
self.update(self.p.CurrentLineNumber)
|
2007-10-12 04:11:03 +05:30
|
|
|
gramps_id = self.map_sid(attrs["id"]) #avoid double id's on import
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.source, new = self.db.find_source_from_handle(
|
2007-09-08 02:54:01 +05:30
|
|
|
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:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.source, new = self.find_source_by_gramps_id(gramps_id)
|
2007-05-11 03:37:25 +05:30
|
|
|
self.source.private = bool(attrs.get("priv"))
|
2008-02-29 04:02:40 +05:30
|
|
|
if new:
|
|
|
|
#keep change time from xml file
|
|
|
|
self.source.change = int(attrs.get('change',self.change))
|
|
|
|
self.info.add('new-object', SOURCE_KEY, self.source)
|
|
|
|
else:
|
|
|
|
self.source.change = self.change
|
|
|
|
self.info.add('merge-overwrite', SOURCE_KEY, self.source)
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_reporef(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.reporef = gen.lib.RepoRef()
|
2006-01-31 07:11:55 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs['hlink'].replace('_', '')
|
2007-10-12 04:22:00 +05:30
|
|
|
self.db.check_repository_from_handle(handle, self.trans,
|
2007-10-12 04:11:03 +05:30
|
|
|
set_gid = False)
|
2006-01-31 07:11:55 +05:30
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
repo, new = self.find_repository_by_gramps_id(self.map_rid(attrs['ref']))
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = repo.handle
|
|
|
|
|
|
|
|
self.reporef.ref = handle
|
2007-09-08 02:54:01 +05:30
|
|
|
self.reporef.call_number = attrs.get('callno', '')
|
2006-04-23 00:38:47 +05:30
|
|
|
self.reporef.media_type.set_from_xml_str(attrs['medium'])
|
2007-07-18 04:14:24 +05:30
|
|
|
self.reporef.private = bool(attrs.get("priv"))
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_objref(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.objref = gen.lib.MediaRef()
|
2004-08-24 09:18:15 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
handle = attrs['hlink'].replace('_', '')
|
2007-10-12 04:22:00 +05:30
|
|
|
self.db.check_object_from_handle(handle, self.trans,
|
2007-10-12 04:11:03 +05:30
|
|
|
set_gid = False)
|
2004-08-24 09:18:15 +05:30
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
obj, new = 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)
|
|
|
|
|
2007-10-02 01:25:48 +05:30
|
|
|
def start_region(self,attrs):
|
|
|
|
rect = (int(attrs.get('corner1_x')),
|
|
|
|
int(attrs.get('corner1_y')),
|
|
|
|
int(attrs.get('corner2_x')),
|
|
|
|
int(attrs.get('corner2_y')) )
|
|
|
|
self.objref.set_rectangle(rect)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
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:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.object, new = self.db.find_object_from_handle(
|
2007-09-08 02:54:01 +05:30
|
|
|
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:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.object, new = self.find_object_by_gramps_id(gramps_id)
|
|
|
|
|
|
|
|
self.object.private = bool(attrs.get("priv"))
|
|
|
|
if new:
|
|
|
|
#keep change time from xml file
|
|
|
|
self.object.change = int(attrs.get('change',self.change))
|
|
|
|
self.info.add('new-object', MEDIA_KEY, self.object)
|
|
|
|
else:
|
|
|
|
self.object.change = self.change
|
|
|
|
self.info.add('merge-overwrite', MEDIA_KEY, self.object)
|
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"...>
|
2007-09-08 02:54:01 +05:30
|
|
|
self.object.mime = attrs.get('mime', '')
|
|
|
|
self.object.desc = attrs.get('description', '')
|
|
|
|
src = attrs.get("src", '')
|
2006-09-12 09:39:53 +05:30
|
|
|
if src:
|
2006-01-29 10:42:01 +05:30
|
|
|
self.object.path = src
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_repo(self, attrs):
|
2006-01-31 07:11:55 +05:30
|
|
|
gramps_id = self.map_rid(attrs['id'])
|
|
|
|
try:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.repo, new = self.db.find_repository_from_handle(
|
2007-09-08 02:54:01 +05:30
|
|
|
attrs['handle'].replace('_', ''), self.trans)
|
2006-01-31 07:11:55 +05:30
|
|
|
self.repo.set_gramps_id(gramps_id)
|
|
|
|
except KeyError:
|
2008-02-29 04:02:40 +05:30
|
|
|
self.repo, new = self.find_repository_by_gramps_id(gramps_id)
|
2007-05-11 03:37:25 +05:30
|
|
|
|
|
|
|
self.repo.private = bool(attrs.get("priv"))
|
2008-02-29 04:02:40 +05:30
|
|
|
if new:
|
|
|
|
#keep change time from xml file
|
|
|
|
self.repo.change = int(attrs.get('change',self.change))
|
|
|
|
self.info.add('new-object', REPOSITORY_KEY, self.repo)
|
|
|
|
else:
|
|
|
|
self.repo.change = self.change
|
|
|
|
self.info.add('merge-overwrite', REPOSITORY_KEY, self.repo)
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_people(self, *tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
pass
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_database(self, *tag):
|
2006-05-11 11:46:45 +05:30
|
|
|
self.update(self.p.CurrentLineNumber)
|
2005-05-11 19:57:32 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_object(self, *tag):
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_media_object(self.object, self.trans,
|
|
|
|
self.object.get_change_time())
|
2004-04-11 08:07:13 +05:30
|
|
|
self.object = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_objref(self, *tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.objref = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_repo(self, *tag):
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_repository(self.repo, self.trans,
|
|
|
|
self.repo.get_change_time())
|
2006-01-31 07:11:55 +05:30
|
|
|
self.repo = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_reporef(self, *tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
self.reporef = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_photo(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.photo = gen.lib.MediaObject()
|
|
|
|
self.pref = gen.lib.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]))
|
2007-05-11 03:37:25 +05:30
|
|
|
self.photo.set_privacy(int(attrs[key]))
|
2004-04-11 08:07:13 +05:30
|
|
|
elif key == "src":
|
2006-09-12 09:39:53 +05:30
|
|
|
src = attrs["src"]
|
2008-02-29 04:02:40 +05:30
|
|
|
self.photo.set_path(src)
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
attr = gen.lib.Attribute()
|
2007-09-08 02:54:01 +05:30
|
|
|
attr.set_type(key)
|
|
|
|
attr.set_value(attrs[key])
|
|
|
|
self.photo.add_attribute(attr)
|
2006-03-03 05:53:04 +05:30
|
|
|
self.photo.set_mime_type(Mime.get_type(self.photo.get_path()))
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.add_object(self.photo, self.trans)
|
|
|
|
#set correct change time
|
|
|
|
self.db.commit_media_object(self.photo, self.trans, self.change)
|
|
|
|
self.info.add('new-object', MEDIA_KEY, self.photo)
|
2004-04-11 08:07:13 +05:30
|
|
|
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)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_daterange(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.start_compound_date(attrs, gen.lib.Date.MOD_RANGE)
|
2007-07-11 10:26:11 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_datespan(self, attrs):
|
2007-10-08 22:11:39 +05:30
|
|
|
self.start_compound_date(attrs, gen.lib.Date.MOD_SPAN)
|
2007-07-11 10:26:11 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_compound_date(self, attrs, mode):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.source_ref:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.source_ref.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.ord:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.ord.get_date_object()
|
2004-11-06 09:01:34 +05:30
|
|
|
elif self.object:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.object.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.address:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.address.get_date_object()
|
2005-03-07 05:17:26 +05:30
|
|
|
elif self.name:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.name.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = 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:
|
2007-09-08 02:54:01 +05:30
|
|
|
year = int(start[0])
|
2004-09-17 09:00:04 +05:30
|
|
|
except ValueError:
|
2007-09-08 02:54:01 +05:30
|
|
|
year = 0
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
month = int(start[1])
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
2007-09-08 02:54:01 +05:30
|
|
|
month = 0
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
day = int(start[2])
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
2007-09-08 02:54:01 +05:30
|
|
|
day = 0
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
rng_year = int(stop[0])
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
2007-09-08 02:54:01 +05:30
|
|
|
rng_year = 0
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
rng_month = int(stop[1])
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
2007-09-08 02:54:01 +05:30
|
|
|
rng_month = 0
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
rng_day = int(stop[2])
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
2007-09-08 02:54:01 +05:30
|
|
|
rng_day = 0
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
if attrs.has_key("cformat"):
|
2008-04-23 04:48:35 +05:30
|
|
|
cal = gen.lib.Date.calendar_names.index(attrs['calendar'])
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
cal = gen.lib.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':
|
2007-10-08 22:11:39 +05:30
|
|
|
qual = gen.lib.Date.QUAL_ESTIMATED
|
2005-12-06 12:08:09 +05:30
|
|
|
elif val == 'calculated':
|
2007-10-08 22:11:39 +05:30
|
|
|
qual = gen.lib.Date.QUAL_CALCULATED
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
qual = gen.lib.Date.QUAL_NONE
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
qual = gen.lib.Date.QUAL_NONE
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value.set(qual, mode, cal,
|
|
|
|
(day, month, year, False, rng_day,
|
|
|
|
rng_month, rng_year, False))
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_dateval(self, attrs):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.source_ref:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.source_ref.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.ord:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.ord.get_date_object()
|
2004-11-06 09:01:34 +05:30
|
|
|
elif self.object:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.object.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.address:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.address.get_date_object()
|
2005-03-07 05:17:26 +05:30
|
|
|
elif self.name:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.name.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.event.get_date_object()
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
bce = 1
|
2004-10-16 10:40:35 +05:30
|
|
|
val = attrs['val']
|
|
|
|
if val[0] == '-':
|
2007-09-08 02:54:01 +05:30
|
|
|
bce = -1
|
2004-10-16 10:40:35 +05:30
|
|
|
val = val[1:]
|
|
|
|
start = val.split('-')
|
2004-09-17 09:00:04 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
year = int(start[0])*bce
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
2007-09-08 02:54:01 +05:30
|
|
|
year = 0
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
month = int(start[1])
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
2007-09-08 02:54:01 +05:30
|
|
|
month = 0
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
day = int(start[2])
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
2007-09-08 02:54:01 +05:30
|
|
|
day = 0
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
if attrs.has_key("cformat"):
|
2007-10-08 22:11:39 +05:30
|
|
|
cal = gen.lib.Date.calendar_names.index(attrs['cformat'])
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
cal = gen.lib.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":
|
2007-10-08 22:11:39 +05:30
|
|
|
mod = gen.lib.Date.MOD_ABOUT
|
2004-09-17 09:00:04 +05:30
|
|
|
elif val == "after":
|
2007-10-08 22:11:39 +05:30
|
|
|
mod = gen.lib.Date.MOD_AFTER
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
mod = gen.lib.Date.MOD_BEFORE
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
mod = gen.lib.Date.MOD_NONE
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
if attrs.has_key('quality'):
|
|
|
|
val = attrs['quality']
|
|
|
|
if val == 'estimated':
|
2007-10-08 22:11:39 +05:30
|
|
|
qual = gen.lib.Date.QUAL_ESTIMATED
|
2005-12-06 12:08:09 +05:30
|
|
|
elif val == 'calculated':
|
2007-10-08 22:11:39 +05:30
|
|
|
qual = gen.lib.Date.QUAL_CALCULATED
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
qual = gen.lib.Date.QUAL_NONE
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
qual = gen.lib.Date.QUAL_NONE
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value.set(qual, mod, cal, (day, month, year, False))
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_datestr(self, attrs):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.source_ref:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.source_ref.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.ord:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.ord.get_date_object()
|
2004-11-06 09:01:34 +05:30
|
|
|
elif self.object:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.object.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.address:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.address.get_date_object()
|
2005-03-30 07:15:14 +05:30
|
|
|
elif self.name:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.name.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value = self.event.get_date_object()
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
date_value.set_as_text(attrs['val'])
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_created(self, attrs):
|
2004-04-11 08:07:13 +05:30
|
|
|
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
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_database(self, attrs):
|
2006-07-25 05:31:08 +05:30
|
|
|
try:
|
|
|
|
# This is a proper way to get the XML version
|
|
|
|
xmlns = attrs.get('xmlns')
|
|
|
|
self.version_string = xmlns.split('/')[4]
|
|
|
|
except:
|
|
|
|
# Before we had a proper DTD, the version was hard to determine
|
|
|
|
# so we're setting it to 1.0.0
|
|
|
|
self.version_string = '1.0.0'
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def start_pos(self, attrs):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.person.position = (int(attrs["x"]), int(attrs["y"]))
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_attribute(self, *tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.attribute = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
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 = ""
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
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:
|
2007-02-20 06:09:10 +05:30
|
|
|
text = self.witness_comment
|
2004-04-11 08:07:13 +05:30
|
|
|
elif tag.strip():
|
2007-02-20 06:09:10 +05:30
|
|
|
text = tag
|
|
|
|
else:
|
|
|
|
text = None
|
|
|
|
|
2008-06-16 20:31:46 +05:30
|
|
|
if text is not None:
|
2007-10-08 22:11:39 +05:30
|
|
|
note = gen.lib.Note()
|
2007-02-20 06:09:10 +05:30
|
|
|
note.handle = Utils.create_id()
|
|
|
|
note.set(_("Witness comment: %s") % text)
|
2007-10-08 22:11:39 +05:30
|
|
|
note.type.set(gen.lib.NoteType.EVENT)
|
2007-05-10 00:57:15 +05:30
|
|
|
note.private = self.event.private
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_note(note, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
#set correct change time
|
|
|
|
self.db.commit_note(note, self.trans, self.change)
|
|
|
|
self.info.add('new-object', NOTE_KEY, note)
|
2007-02-20 06:09:10 +05:30
|
|
|
self.event.add_note(note.handle)
|
2006-06-23 02:53:00 +05:30
|
|
|
self.in_witness = False
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_attr_type(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.attribute.set_type(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_attr_value(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.attribute.set_value(tag)
|
|
|
|
|
2007-09-08 02:54:01 +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
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_places(self, *tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.placeobj = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_photo(self, *tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.photo = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_ptitle(self, tag):
|
2006-01-30 03:09:36 +05:30
|
|
|
self.placeobj.title = tag
|
|
|
|
|
2007-09-08 02:54:01 +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
|
|
|
|
2008-01-05 03:11:49 +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
|
|
|
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_place(self.placeobj, self.trans,
|
|
|
|
self.placeobj.get_change_time())
|
2004-04-11 08:07:13 +05:30
|
|
|
self.placeobj = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_family(self, *tag):
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_family(self.family, self.trans,
|
|
|
|
self.family.get_change_time())
|
2004-04-11 08:07:13 +05:30
|
|
|
self.family = None
|
|
|
|
|
2007-09-08 02:54: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.set_from_xml_str(tag)
|
2006-01-29 10:42:01 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_childref(self, tag):
|
2006-04-19 07:53:08 +05:30
|
|
|
self.childref = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_personref(self, tag):
|
2006-04-19 09:02:33 +05:30
|
|
|
self.personref = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_eventref(self, tag):
|
2006-01-29 10:42:01 +05:30
|
|
|
self.eventref = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_event(self, *tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.family:
|
2007-10-08 22:11:39 +05:30
|
|
|
ref = gen.lib.EventRef()
|
2006-01-29 10:42:01 +05:30
|
|
|
ref.ref = self.event.handle
|
|
|
|
ref.private = self.event.private
|
2007-10-08 22:11:39 +05:30
|
|
|
ref.role.set(gen.lib.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:
|
2007-10-08 22:11:39 +05:30
|
|
|
ref = gen.lib.EventRef()
|
2006-01-29 10:42:01 +05:30
|
|
|
ref.ref = self.event.handle
|
|
|
|
ref.private = self.event.private
|
2007-10-08 22:11:39 +05:30
|
|
|
ref.role.set(gen.lib.EventRoleType.PRIMARY)
|
|
|
|
if (self.event.type == gen.lib.EventType.BIRTH) \
|
2008-06-16 20:31:46 +05:30
|
|
|
and (self.person.get_birth_ref() is None):
|
2006-05-29 08:30:07 +05:30
|
|
|
self.person.set_birth_ref(ref)
|
2007-10-08 22:11:39 +05:30
|
|
|
elif (self.event.type == gen.lib.EventType.DEATH) \
|
2008-06-16 20:31:46 +05:30
|
|
|
and (self.person.get_death_ref() is None):
|
2006-05-29 08:30:07 +05:30
|
|
|
self.person.set_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-26 07:14:03 +05:30
|
|
|
if self.event.get_description() == "" and \
|
2007-10-08 22:11:39 +05:30
|
|
|
self.event.get_type() != gen.lib.EventType.CUSTOM:
|
2006-04-26 07:14:03 +05:30
|
|
|
if self.family:
|
2007-09-08 02:54:01 +05:30
|
|
|
text = EVENT_FAMILY_STR % {
|
|
|
|
'event_name' : str(self.event.get_type()),
|
|
|
|
'family' : Utils.family_name(self.family, self.db),
|
2006-04-26 07:14:03 +05:30
|
|
|
}
|
|
|
|
elif self.person:
|
2007-09-08 02:54:01 +05:30
|
|
|
text = EVENT_PERSON_STR % {
|
|
|
|
'event_name' : str(self.event.get_type()),
|
|
|
|
'person' : name_displayer.display(self.person),
|
2006-04-26 07:14:03 +05:30
|
|
|
}
|
|
|
|
else:
|
|
|
|
text = u''
|
|
|
|
self.event.set_description(text)
|
2006-04-16 10:07:02 +05:30
|
|
|
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_event(self.event, self.trans,
|
|
|
|
self.event.get_change_time())
|
2004-04-11 08:07:13 +05:30
|
|
|
self.event = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
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
|
2007-10-08 22:11:39 +05:30
|
|
|
note = gen.lib.Note()
|
2007-02-20 06:09:10 +05:30
|
|
|
note.handle = Utils.create_id()
|
|
|
|
note.set(_("Witness name: %s") % tag)
|
2007-10-08 22:11:39 +05:30
|
|
|
note.type.set(gen.lib.NoteType.EVENT)
|
2007-05-10 00:57:15 +05:30
|
|
|
note.private = self.event.private
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_note(note, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
#set correct change time
|
|
|
|
self.db.commit_note(note, self.trans, self.change)
|
|
|
|
self.info.add('new-object', NOTE_KEY, note)
|
2007-02-20 06:09:10 +05:30
|
|
|
self.event.add_note(note.handle)
|
2006-01-29 10:42:01 +05:30
|
|
|
elif self.alt_name:
|
2005-12-06 12:08:09 +05:30
|
|
|
# former aka tag -- alternate name
|
|
|
|
if self.name.get_type() == "":
|
2007-10-08 22:11:39 +05:30
|
|
|
self.name.set_type(gen.lib.NameType.AKA)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.person.add_alternate_name(self.name)
|
|
|
|
else:
|
|
|
|
if self.name.get_type() == "":
|
2007-10-08 22:11:39 +05:30
|
|
|
self.name.set_type(gen.lib.NameType.BIRTH)
|
2005-12-06 12:08:09 +05:30
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_rname(self, tag):
|
2006-01-31 07:11:55 +05:30
|
|
|
# Repository name
|
|
|
|
self.repo.name = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_ref(self, tag):
|
2006-01-29 10:42:01 +05:30
|
|
|
# Parse witnesses created by older gramps
|
2008-02-29 04:02:40 +05:30
|
|
|
person, new = self.find_person_by_gramps_id(self.map_gid(tag))
|
2006-01-29 10:42:01 +05:30
|
|
|
# Add an EventRef from that person
|
|
|
|
# to this event using ROLE_WITNESS role
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2006-01-29 10:42:01 +05:30
|
|
|
event_ref.ref = self.event.handle
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref.role.set(gen.lib.EventRoleType.WITNESS)
|
2006-01-29 10:42:01 +05:30
|
|
|
person.event_ref_list.append(event_ref)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.commit_person(person, self.trans, self.change)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_place(self, tag):
|
2007-10-12 04:11:03 +05:30
|
|
|
"""end of a reference to place, should do nothing ...
|
|
|
|
Note, if we encounter <place>blabla</place> this method is called
|
|
|
|
with tag='blabla
|
|
|
|
"""
|
|
|
|
##place = None
|
|
|
|
##handle = None
|
2008-06-16 20:31:46 +05:30
|
|
|
##if self.place_ref is None: #todo, add place_ref in start and init
|
2007-10-12 04:11:03 +05:30
|
|
|
## #legacy cody? I see no reason for this, but it was present
|
|
|
|
## if self.place_map.has_key(tag):
|
|
|
|
## place = self.place_map[tag]
|
|
|
|
## handle = place.get_handle()
|
|
|
|
## place = None
|
|
|
|
## else:
|
|
|
|
## place = RelLib.Place()
|
|
|
|
## place.set_title(tag)
|
|
|
|
## handle = place.get_handle()
|
|
|
|
## if self.ord:
|
|
|
|
## self.ord.set_place_handle(handle)
|
|
|
|
## elif self.object:
|
|
|
|
## self.object.set_place_handle(handle)
|
|
|
|
## else:
|
|
|
|
## self.event.set_place_handle(handle)
|
|
|
|
## if place :
|
|
|
|
## self.db.commit_place(self.placeobj,self.trans,self.change)
|
|
|
|
##self.place_ref = None
|
|
|
|
pass
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_date(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if tag:
|
|
|
|
if self.address:
|
2007-09-08 02:54:01 +05:30
|
|
|
DateHandler.set_date(self.address, tag)
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2007-09-08 02:54:01 +05:30
|
|
|
DateHandler.set_date(self.event, tag)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_first(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.name.set_first_name(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_call(self, tag):
|
2006-05-08 09:11:57 +05:30
|
|
|
self.name.set_call_name(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_families(self, *tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.family = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_person(self, *tag):
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_person(self.person, self.trans,
|
|
|
|
self.person.get_change_time())
|
2004-04-11 08:07:13 +05:30
|
|
|
self.person = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_cause(self, tag):
|
2006-08-16 02:29:12 +05:30
|
|
|
# The old event's cause is now an attribute
|
2007-10-08 22:11:39 +05:30
|
|
|
attr = gen.lib.Attribute()
|
|
|
|
attr.set_type(gen.lib.AttributeType.CAUSE)
|
2006-08-16 02:29:12 +05:30
|
|
|
attr.set_value(tag)
|
|
|
|
self.event.add_attribute(attr)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_gender(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
t = tag
|
|
|
|
if t == "M":
|
2007-10-08 22:11:39 +05:30
|
|
|
self.person.set_gender (gen.lib.Person.MALE)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif t == "F":
|
2007-10-08 22:11:39 +05:30
|
|
|
self.person.set_gender (gen.lib.Person.FEMALE)
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
self.person.set_gender (gen.lib.Person.UNKNOWN)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_sourceref(self, *tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.source_ref = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_source(self, *tag):
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_source(self.source, self.trans,
|
|
|
|
self.source.get_change_time())
|
2004-04-11 08:07:13 +05:30
|
|
|
self.source = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
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
|
|
|
|
2007-09-08 02:54:01 +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
|
|
|
|
2007-09-08 02:54:01 +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
|
|
|
|
2007-09-08 02:54:01 +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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_county(self, tag):
|
2006-10-08 00:39:05 +05:30
|
|
|
self.address.county = tag
|
|
|
|
|
2007-09-08 02:54:01 +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
|
|
|
|
2007-09-08 02:54:01 +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
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_postal(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.address.set_postal_code(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_spage(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.source_ref.set_page(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_lds_ord(self, *tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.ord = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_spubinfo(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.source.set_publication_info(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_sabbrev(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.source.set_abbreviation(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_stext(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.use_p:
|
|
|
|
self.use_p = 0
|
2007-07-17 08:07:33 +05:30
|
|
|
text = fix_spaces(self.stext_list)
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2007-07-17 08:07:33 +05:30
|
|
|
text = tag
|
|
|
|
# This is old XML. We no longer have "text" attribute in soure_ref.
|
|
|
|
# So we create a new note, commit, and add the handle to note list.
|
2007-10-08 22:11:39 +05:30
|
|
|
note = gen.lib.Note()
|
2007-07-17 08:07:33 +05:30
|
|
|
note.handle = Utils.create_id()
|
|
|
|
note.private = self.source_ref.private
|
|
|
|
note.set(text)
|
2007-10-08 22:11:39 +05:30
|
|
|
note.type.set(gen.lib.NoteType.SOURCE_TEXT)
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.add_note(note, self.trans)
|
|
|
|
#set correct change time
|
|
|
|
self.db.commit_note(note, self.trans, self.change)
|
|
|
|
self.info.add('new-object', NOTE_KEY, note)
|
2007-07-17 08:07:33 +05:30
|
|
|
self.source_ref.add_note(note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_scomments(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.use_p:
|
|
|
|
self.use_p = 0
|
2007-02-20 06:09:10 +05:30
|
|
|
text = fix_spaces(self.scomments_list)
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
2007-02-20 06:09:10 +05:30
|
|
|
text = tag
|
2007-10-08 22:11:39 +05:30
|
|
|
note = gen.lib.Note()
|
2007-02-20 06:09:10 +05:30
|
|
|
note.handle = Utils.create_id()
|
2007-07-17 08:07:33 +05:30
|
|
|
note.private = self.source_ref.private
|
2007-02-20 06:09:10 +05:30
|
|
|
note.set(text)
|
2007-10-08 22:11:39 +05:30
|
|
|
note.type.set(gen.lib.NoteType.SOURCEREF)
|
2007-09-08 02:54:01 +05:30
|
|
|
self.db.add_note(note, self.trans)
|
2008-02-29 04:02:40 +05:30
|
|
|
#set correct change time
|
|
|
|
self.db.commit_note(note, self.trans, self.change)
|
|
|
|
self.info.add('new-object', NOTE_KEY, note)
|
2007-02-20 06:09:10 +05:30
|
|
|
self.source_ref.add_note(note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_last(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.name:
|
|
|
|
self.name.set_surname(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_suffix(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.name:
|
|
|
|
self.name.set_suffix(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_patronymic(self, tag):
|
2005-12-06 12:08:09 +05:30
|
|
|
if self.name:
|
|
|
|
self.name.set_patronymic(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_title(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.name:
|
|
|
|
self.name.set_title(tag)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_nick(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.person:
|
2007-10-08 22:11:39 +05:30
|
|
|
attr = gen.lib.Attribute()
|
|
|
|
attr.set_type(gen.lib.AttributeType.NICKNAME)
|
2006-05-06 02:46:24 +05:30
|
|
|
attr.set_value(tag)
|
|
|
|
self.person.add_attribute(attr)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2008-04-09 03:13:58 +05:30
|
|
|
def stop_text(self, tag):
|
|
|
|
self.note_text = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_note(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.in_note = 0
|
|
|
|
if self.use_p:
|
|
|
|
self.use_p = 0
|
|
|
|
text = fix_spaces(self.note_list)
|
2008-04-09 03:13:58 +05:30
|
|
|
elif self.note_text is not None:
|
|
|
|
text = self.note_text
|
2004-04-11 08:07:13 +05:30
|
|
|
else:
|
|
|
|
text = tag
|
2008-04-09 03:13:58 +05:30
|
|
|
|
|
|
|
self.note.set_styledtext(gen.lib.StyledText(text, self.note_tags))
|
2004-04-11 08:07:13 +05:30
|
|
|
|
|
|
|
if self.address:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.address.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.ord:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.ord.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.attribute:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.attribute.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.object:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.object.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.objref:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.objref.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.photo:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.photo.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.name:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.name.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.source:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.source.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.event:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.event.add_note(self.note.handle)
|
2006-04-19 09:02:33 +05:30
|
|
|
elif self.personref:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.personref.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.person:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.person.add_note(self.note.handle)
|
2006-04-19 07:53:08 +05:30
|
|
|
elif self.childref:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.childref.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.family:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.family.add_note(self.note.handle)
|
2004-04-11 08:07:13 +05:30
|
|
|
elif self.placeobj:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.placeobj.add_note(self.note.handle)
|
2006-01-29 10:42:01 +05:30
|
|
|
elif self.eventref:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.eventref.add_note(self.note.handle)
|
2006-01-31 07:11:55 +05:30
|
|
|
elif self.repo:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.repo.add_note(self.note.handle)
|
2006-01-31 07:11:55 +05:30
|
|
|
elif self.reporef:
|
2007-02-20 06:09:10 +05:30
|
|
|
self.reporef.add_note(self.note.handle)
|
|
|
|
|
2008-02-29 04:02:40 +05:30
|
|
|
self.db.commit_note(self.note, self.trans, self.note.get_change_time())
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note = None
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_research(self, tag):
|
2007-10-09 02:56:20 +05:30
|
|
|
self.owner.set_name(self.resname)
|
|
|
|
self.owner.set_address(self.resaddr)
|
|
|
|
self.owner.set_city(self.rescity)
|
|
|
|
self.owner.set_state(self.resstate)
|
|
|
|
self.owner.set_country(self.rescon)
|
|
|
|
self.owner.set_postal_code(self.respos)
|
|
|
|
self.owner.set_phone(self.resphone)
|
|
|
|
self.owner.set_email(self.resemail)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_resname(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.resname = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_resaddr(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.resaddr = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_rescity(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.rescity = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_resstate(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.resstate = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_rescountry(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.rescon = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_respostal(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.respos = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_resphone(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.resphone = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_resemail(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.resemail = tag
|
|
|
|
|
2007-12-01 05:20:05 +05:30
|
|
|
def stop_mediapath(self, tag):
|
|
|
|
self.mediapath = tag
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_ptag(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
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)
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def stop_aka(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
self.person.add_alternate_name(self.name)
|
|
|
|
if self.name.get_type() == "":
|
2007-10-08 22:11:39 +05:30
|
|
|
self.name.set_type(gen.lib.NameType.AKA)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.name = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def startElement(self, tag, attrs):
|
|
|
|
self.func_list[self.func_index] = (self.func, self.tlist)
|
2006-06-23 02:53:00 +05:30
|
|
|
self.func_index += 1
|
2004-04-11 08:07:13 +05:30
|
|
|
self.tlist = []
|
|
|
|
|
|
|
|
try:
|
2007-09-08 02:54:01 +05:30
|
|
|
f, self.func = self.func_map[tag]
|
2004-04-11 08:07:13 +05:30
|
|
|
if f:
|
|
|
|
f(attrs)
|
|
|
|
except KeyError:
|
2007-09-08 02:54:01 +05:30
|
|
|
self.func_map[tag] = (None, None)
|
2004-04-11 08:07:13 +05:30
|
|
|
self.func = None
|
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def endElement(self, tag):
|
2004-04-11 08:07:13 +05:30
|
|
|
if self.func:
|
2005-02-28 07:21:21 +05:30
|
|
|
self.func(''.join(self.tlist))
|
2006-06-23 02:53:00 +05:30
|
|
|
self.func_index -= 1
|
2007-09-08 02:54:01 +05:30
|
|
|
self.func, self.tlist = self.func_list[self.func_index]
|
2006-06-23 02:53:00 +05:30
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
def characters(self, data):
|
|
|
|
if self.func:
|
|
|
|
self.tlist.append(data)
|
|
|
|
|
2006-01-18 09:38:28 +05:30
|
|
|
|
2007-09-08 02:54:01 +05:30
|
|
|
def append_value(orig, val):
|
2004-04-11 08:07:13 +05:30
|
|
|
if orig:
|
2007-09-08 02:54:01 +05:30
|
|
|
return "%s, %s" % (orig, val)
|
2004-04-11 08:07:13 +05:30
|
|
|
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:
|
2007-09-08 02:54:01 +05:30
|
|
|
value = append_value(value, loc.city)
|
2006-01-31 07:11:55 +05:30
|
|
|
if loc.county:
|
2007-09-08 02:54:01 +05:30
|
|
|
value = append_value(value, loc.county)
|
2006-01-31 07:11:55 +05:30
|
|
|
if loc.state:
|
2007-09-08 02:54:01 +05:30
|
|
|
value = append_value(value, loc.state)
|
2006-01-31 07:11:55 +05:30
|
|
|
if loc.country:
|
2007-09-08 02:54:01 +05:30
|
|
|
value = append_value(value, loc.country)
|
2004-04-11 08:07:13 +05:30
|
|
|
return value
|
2008-02-25 10:02:11 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# VersionParser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class VersionParser:
|
|
|
|
"""
|
|
|
|
Utility class to quickly get the versions from an XML file.
|
|
|
|
"""
|
|
|
|
def __init__(self, xml_file):
|
|
|
|
"""
|
|
|
|
xml_file must be a file object that is already open.
|
|
|
|
"""
|
|
|
|
self.__p = ParserCreate()
|
|
|
|
self.__p.StartElementHandler = self.__element_handler
|
|
|
|
self.__gramps_version = 'unknown'
|
|
|
|
self.__xml_version = '1.0.0'
|
|
|
|
|
|
|
|
xml_file.seek(0)
|
|
|
|
self.__p.ParseFile(xml_file)
|
|
|
|
|
|
|
|
def __element_handler(self, tag, attrs):
|
|
|
|
" Handle XML elements "
|
|
|
|
if tag == "database" and attrs.has_key('xmlns'):
|
|
|
|
xmlns = attrs.get('xmlns')
|
|
|
|
self.__xml_version = xmlns.split('/')[4]
|
|
|
|
elif tag == "created" and attrs.has_key('version'):
|
|
|
|
self.__gramps_version = attrs.get('version')
|
|
|
|
|
|
|
|
def get_xmlns_version(self):
|
|
|
|
" Get the namespace version of the file "
|
|
|
|
return self.__xml_version
|
|
|
|
|
|
|
|
def get_gramps_version(self):
|
|
|
|
" Get the version of Gramps that created the file "
|
|
|
|
return self.__gramps_version
|
|
|
|
|
|
|
|
def open_file(filename, cli):
|
|
|
|
"""
|
|
|
|
Open the xml file.
|
|
|
|
Return a valid file handle if the file opened sucessfully.
|
|
|
|
Return None if the file was not able to be opened.
|
|
|
|
"""
|
|
|
|
if GZIP_OK:
|
|
|
|
use_gzip = True
|
|
|
|
try:
|
|
|
|
ofile = gzip.open(filename, "r")
|
|
|
|
ofile.read(1)
|
|
|
|
ofile.close()
|
|
|
|
except IOError, msg:
|
|
|
|
use_gzip = False
|
|
|
|
except ValueError, msg:
|
|
|
|
use_gzip = True
|
|
|
|
else:
|
|
|
|
use_gzip = False
|
|
|
|
|
|
|
|
try:
|
|
|
|
if use_gzip:
|
|
|
|
xml_file = gzip.open(filename, "rb")
|
|
|
|
else:
|
|
|
|
xml_file = open(filename, "r")
|
|
|
|
except IOError, msg:
|
|
|
|
if cli:
|
|
|
|
print "Error: %s could not be opened Exiting." % filename
|
|
|
|
print msg
|
|
|
|
else:
|
|
|
|
ErrorDialog(_("%s could not be opened") % filename, str(msg))
|
|
|
|
xml_file = None
|
|
|
|
except:
|
|
|
|
if cli:
|
|
|
|
print "Error: %s could not be opened. Exiting." % filename
|
|
|
|
else:
|
|
|
|
ErrorDialog(_("%s could not be opened") % filename)
|
|
|
|
xml_file = None
|
|
|
|
|
|
|
|
return xml_file
|
|
|
|
|
|
|
|
def version_is_valid(filename, cli):
|
|
|
|
"""
|
|
|
|
Validate the xml version.
|
|
|
|
"""
|
|
|
|
parser = VersionParser(filename)
|
|
|
|
|
|
|
|
if parser.get_xmlns_version() > _GrampsDbWriteXML.XML_VERSION:
|
|
|
|
msg = _("The .gramps file you are importing was made by version %s of "
|
|
|
|
"GRAMPS, while you are running an older version %s. "
|
2008-02-27 18:33:41 +05:30
|
|
|
"The file will not be imported. Please upgrade to the latest "
|
|
|
|
"version of GRAMPS and try again."
|
2008-02-25 10:02:11 +05:30
|
|
|
) % (parser.get_gramps_version(), const.VERSION)
|
|
|
|
if cli:
|
|
|
|
print msg
|
2008-02-27 18:33:41 +05:30
|
|
|
return False
|
2008-02-25 10:02:11 +05:30
|
|
|
else:
|
2008-02-27 18:33:41 +05:30
|
|
|
ErrorDialog(msg)
|
|
|
|
return False
|
2008-02-25 10:02:11 +05:30
|
|
|
|
|
|
|
return True
|