2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-01-27 04:28:49 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
2003-11-24 02:25:14 +05:30
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Contains the interface to allow a database to get written using
|
|
|
|
GRAMPS' XML file format.
|
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# load standard python libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import time
|
|
|
|
import shutil
|
|
|
|
import os
|
2003-04-20 09:22:54 +05:30
|
|
|
import codecs
|
2006-12-12 02:39:25 +05:30
|
|
|
from xml.sax.saxutils import escape
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".WriteXML")
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# load GRAMPS libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
2003-02-24 10:21:57 +05:30
|
|
|
import RelLib
|
2002-10-21 06:48:07 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2006-01-27 12:24:35 +05:30
|
|
|
from _GrampsDbBase import \
|
|
|
|
PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\
|
|
|
|
MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY
|
2006-05-16 09:17:58 +05:30
|
|
|
from BasicUtils import UpdateCallback
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Attempt to load the GZIP library. Some version of python do not seem
|
|
|
|
# to be compiled with this available.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
try:
|
|
|
|
import gzip
|
|
|
|
_gzip_ok = 1
|
|
|
|
except:
|
|
|
|
_gzip_ok = 0
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-10-08 00:39:05 +05:30
|
|
|
_xml_version = "1.1.3"
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-09-02 04:27:57 +05:30
|
|
|
# table for skipping control chars from XML
|
2006-10-11 09:14:09 +05:30
|
|
|
strip_dict = dict.fromkeys(range(9)+range(12,20))
|
2006-09-02 04:27:57 +05:30
|
|
|
|
2006-12-12 02:39:25 +05:30
|
|
|
|
|
|
|
def escxml(d):
|
2006-12-12 04:31:09 +05:30
|
|
|
return escape(d, { '"' : '"' } )
|
2006-12-12 02:39:25 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-07-11 11:38:35 +05:30
|
|
|
def exportData(database, filename, person, callback=None):
|
2004-07-09 23:49:47 +05:30
|
|
|
ret = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
if os.path.isfile(filename):
|
2003-06-04 02:48:23 +05:30
|
|
|
try:
|
2004-02-01 08:46:23 +05:30
|
|
|
shutil.copyfile(filename, filename + ".bak")
|
2003-06-04 02:48:23 +05:30
|
|
|
shutil.copystat(filename, filename + ".bak")
|
|
|
|
except:
|
|
|
|
pass
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-07-01 09:39:55 +05:30
|
|
|
compress = _gzip_ok == 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
g = XmlWriter(database,callback,0,compress)
|
|
|
|
t = time.time()
|
|
|
|
ret = g.write(filename)
|
2004-07-09 23:49:47 +05:30
|
|
|
return ret
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def quick_write(database, filename,callback=None):
|
|
|
|
g = XmlWriter(database,callback,0,1)
|
|
|
|
g.write(filename)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-16 09:17:58 +05:30
|
|
|
class XmlWriter(UpdateCallback):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Writes a database to the XML file.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,db,callback,strip_photos,compress=1):
|
|
|
|
"""
|
2003-04-20 09:22:54 +05:30
|
|
|
Initializes, but does not write, an XML file.
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
db - database to write
|
|
|
|
callback - function to provide progress indication
|
2006-03-01 10:34:22 +05:30
|
|
|
strip_photos - remove paths off of media object paths
|
2006-10-29 10:06:08 +05:30
|
|
|
> 0: do not touch the paths
|
|
|
|
> 1: remove everything expect the filename
|
|
|
|
> 2: remove leading slash
|
2002-10-20 19:55:16 +05:30
|
|
|
compress - attempt to compress the database
|
|
|
|
"""
|
2006-05-16 09:17:58 +05:30
|
|
|
UpdateCallback.__init__(self,callback)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.compress = compress
|
|
|
|
self.db = db
|
|
|
|
self.strip_photos = strip_photos
|
|
|
|
|
|
|
|
def write(self,filename):
|
|
|
|
"""
|
2003-04-20 09:22:54 +05:30
|
|
|
Write the database to the specified file.
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
2004-02-01 08:46:23 +05:30
|
|
|
base = os.path.dirname(filename)
|
|
|
|
if os.path.isdir(base):
|
|
|
|
if not os.access(base,os.W_OK) or not os.access(base,os.R_OK):
|
|
|
|
ErrorDialog(_('Failure writing %s') % filename,
|
2006-01-27 12:24:35 +05:30
|
|
|
_("The database cannot be saved because you do "
|
|
|
|
"not have permission to write to the directory. "
|
2004-02-01 08:46:23 +05:30
|
|
|
"Please make sure you have write access to the "
|
|
|
|
"directory and try again."))
|
2004-07-09 23:49:47 +05:30
|
|
|
return 0
|
2004-02-01 08:46:23 +05:30
|
|
|
|
|
|
|
if os.path.exists(filename):
|
|
|
|
if not os.access(filename,os.W_OK):
|
|
|
|
ErrorDialog(_('Failure writing %s') % filename,
|
2006-01-27 12:24:35 +05:30
|
|
|
_("The database cannot be saved because you do "
|
|
|
|
"not have permission to write to the file. "
|
2004-02-01 08:46:23 +05:30
|
|
|
"Please make sure you have write access to the "
|
|
|
|
"file and try again."))
|
2004-07-09 23:49:47 +05:30
|
|
|
return 0
|
2004-02-01 08:46:23 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.fileroot = os.path.dirname(filename)
|
2006-07-04 11:20:24 +05:30
|
|
|
try:
|
|
|
|
if self.compress:
|
|
|
|
try:
|
|
|
|
g = gzip.open(filename,"wb")
|
|
|
|
except:
|
|
|
|
g = open(filename,"w")
|
|
|
|
else:
|
2003-04-20 09:22:54 +05:30
|
|
|
g = open(filename,"w")
|
2006-07-04 11:20:24 +05:30
|
|
|
except IOError,msg:
|
|
|
|
ErrorDialog(_('Failure writing %s') % filename,msg)
|
|
|
|
return 0
|
2004-02-01 08:46:23 +05:30
|
|
|
|
2003-04-20 09:22:54 +05:30
|
|
|
self.g = codecs.getwriter("utf8")(g)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.write_xml_data()
|
2003-04-20 09:22:54 +05:30
|
|
|
g.close()
|
2004-07-09 23:49:47 +05:30
|
|
|
return 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def write_handle(self,handle):
|
|
|
|
"""
|
2003-04-20 09:22:54 +05:30
|
|
|
Write the database to the specified file handle.
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
if self.compress:
|
|
|
|
try:
|
2003-04-20 09:22:54 +05:30
|
|
|
g = gzip.GzipFile(mode="wb",fileobj=handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
except:
|
2003-04-20 09:22:54 +05:30
|
|
|
g = handle
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2003-04-20 09:22:54 +05:30
|
|
|
g = handle
|
|
|
|
|
|
|
|
self.g = codecs.getwriter("utf8")(g)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.write_xml_data()
|
2004-07-09 23:49:47 +05:30
|
|
|
g.close()
|
2005-02-20 04:03:24 +05:30
|
|
|
return 1
|
2003-04-20 09:22:54 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def write_xml_data(self):
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
date = time.localtime(time.time())
|
2004-02-14 11:10:30 +05:30
|
|
|
owner = self.db.get_researcher()
|
2006-05-16 09:17:58 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
person_len = self.db.get_number_of_people()
|
2006-05-16 09:17:58 +05:30
|
|
|
family_len = self.db.get_number_of_families()
|
|
|
|
event_len = self.db.get_number_of_events()
|
|
|
|
source_len = self.db.get_number_of_sources()
|
|
|
|
place_len = self.db.get_number_of_places()
|
|
|
|
repo_len = self.db.get_number_of_repositories()
|
|
|
|
obj_len = self.db.get_number_of_media_objects()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-05-16 09:17:58 +05:30
|
|
|
self.set_total(person_len+family_len+event_len+source_len
|
|
|
|
+place_len+repo_len+obj_len)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-10-14 08:43:52 +05:30
|
|
|
self.g.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write('<!DOCTYPE database '
|
|
|
|
'PUBLIC "-//GRAMPS//DTD GRAMPS XML %s//EN"\n'
|
|
|
|
'"http://gramps-project.org/xml/%s/grampsxml.dtd">\n'
|
|
|
|
% (_xml_version,_xml_version))
|
|
|
|
self.g.write('<database xmlns="http://gramps-project.org/xml/%s/">\n'
|
|
|
|
% _xml_version)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" <header>\n")
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write(' <created date="%04d-%02d-%02d\"' %
|
|
|
|
(date[0],date[1],date[2]) )
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" version=\"" + const.version + "\"")
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write("/>\n")
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" <researcher>\n")
|
2004-02-14 11:10:30 +05:30
|
|
|
self.write_line("resname",owner.get_name(),3)
|
|
|
|
self.write_line("resaddr",owner.get_address(),3)
|
|
|
|
self.write_line("rescity",owner.get_city(),3)
|
|
|
|
self.write_line("resstate",owner.get_state(),3)
|
|
|
|
self.write_line("rescountry",owner.get_country(),3)
|
|
|
|
self.write_line("respostal",owner.get_postal_code(),3)
|
|
|
|
self.write_line("resphone",owner.get_phone(),3)
|
|
|
|
self.write_line("resemail",owner.get_email(),3)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" </researcher>\n")
|
|
|
|
self.g.write(" </header>\n")
|
|
|
|
|
2006-07-28 01:41:56 +05:30
|
|
|
# First write name formats: we need to know all formats
|
|
|
|
# by the time we get to person's names
|
|
|
|
self.write_name_formats()
|
|
|
|
|
2006-01-29 10:42:01 +05:30
|
|
|
if event_len > 0:
|
|
|
|
self.g.write(" <events>\n")
|
|
|
|
sorted_keys = self.db.get_gramps_ids(EVENT_KEY)
|
|
|
|
sorted_keys.sort ()
|
|
|
|
for gramps_id in sorted_keys:
|
|
|
|
event = self.db.get_event_from_gramps_id(gramps_id)
|
|
|
|
self.write_event(event,2)
|
2006-03-01 10:34:22 +05:30
|
|
|
self.update()
|
2006-01-29 10:42:01 +05:30
|
|
|
self.g.write(" </events>\n")
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
if person_len > 0:
|
|
|
|
self.g.write(" <people")
|
2004-02-14 11:10:30 +05:30
|
|
|
person = self.db.get_default_person()
|
2002-10-20 19:55:16 +05:30
|
|
|
if person:
|
2006-01-28 06:13:27 +05:30
|
|
|
self.g.write(' default="%s" home="_%s"' %
|
2006-01-27 07:43:17 +05:30
|
|
|
(person.gramps_id,person.handle))
|
2006-01-28 06:13:27 +05:30
|
|
|
self.g.write('>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-01-27 12:24:35 +05:30
|
|
|
sorted_keys = self.db.get_gramps_ids(PERSON_KEY)
|
|
|
|
sorted_keys.sort()
|
|
|
|
|
|
|
|
for gramps_id in sorted_keys:
|
|
|
|
person = self.db.get_person_from_gramps_id(gramps_id)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_person(person,2)
|
2006-03-01 10:34:22 +05:30
|
|
|
self.update()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" </people>\n")
|
|
|
|
|
|
|
|
if family_len > 0:
|
|
|
|
self.g.write(" <families>\n")
|
2006-01-27 12:24:35 +05:30
|
|
|
sorted_keys = self.db.get_gramps_ids(FAMILY_KEY)
|
2004-08-22 18:15:47 +05:30
|
|
|
sorted_keys.sort ()
|
2006-01-27 12:24:35 +05:30
|
|
|
for gramps_id in sorted_keys:
|
|
|
|
family = self.db.get_family_from_gramps_id(gramps_id)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_family(family,2)
|
2006-03-01 10:34:22 +05:30
|
|
|
self.update()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" </families>\n")
|
|
|
|
|
|
|
|
if source_len > 0:
|
|
|
|
self.g.write(" <sources>\n")
|
2006-01-27 12:24:35 +05:30
|
|
|
keys = self.db.get_gramps_ids(SOURCE_KEY)
|
2003-06-19 15:19:43 +05:30
|
|
|
keys.sort ()
|
|
|
|
for key in keys:
|
2006-01-27 12:24:35 +05:30
|
|
|
source = self.db.get_source_from_gramps_id(key)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_source(source,2)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" </sources>\n")
|
|
|
|
|
|
|
|
if place_len > 0:
|
|
|
|
self.g.write(" <places>\n")
|
2006-01-27 12:24:35 +05:30
|
|
|
keys = self.db.get_gramps_ids(PLACE_KEY)
|
2003-06-19 15:19:43 +05:30
|
|
|
keys.sort ()
|
|
|
|
for key in keys:
|
2006-01-28 02:08:33 +05:30
|
|
|
# try:
|
|
|
|
place = self.db.get_place_from_gramps_id(key)
|
|
|
|
self.write_place_obj(place,2)
|
2006-03-01 10:34:22 +05:30
|
|
|
self.update()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" </places>\n")
|
|
|
|
|
2006-01-28 02:08:33 +05:30
|
|
|
if obj_len > 0:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" <objects>\n")
|
2006-01-27 12:24:35 +05:30
|
|
|
sorted_keys = self.db.get_gramps_ids(MEDIA_KEY)
|
2004-08-22 21:49:45 +05:30
|
|
|
sorted_keys.sort ()
|
2006-01-27 12:24:35 +05:30
|
|
|
for gramps_id in sorted_keys:
|
|
|
|
obj = self.db.get_object_from_gramps_id(gramps_id)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_object(obj,2)
|
2006-03-01 10:34:22 +05:30
|
|
|
self.update()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" </objects>\n")
|
|
|
|
|
2006-01-28 02:08:33 +05:30
|
|
|
if repo_len > 0:
|
|
|
|
self.g.write(" <repositories>\n")
|
|
|
|
keys = self.db.get_gramps_ids(REPOSITORY_KEY)
|
|
|
|
keys.sort ()
|
|
|
|
for key in keys:
|
|
|
|
repo = self.db.get_repository_from_gramps_id(key)
|
|
|
|
self.write_repository(repo,2)
|
2006-03-01 10:34:22 +05:30
|
|
|
self.update()
|
2006-01-28 02:08:33 +05:30
|
|
|
self.g.write(" </repositories>\n")
|
|
|
|
|
2006-05-19 03:47:51 +05:30
|
|
|
# Data is written, now write bookmarks.
|
|
|
|
self.write_bookmarks()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.g.write("</database>\n")
|
|
|
|
|
2006-05-19 03:47:51 +05:30
|
|
|
def write_bookmarks(self):
|
|
|
|
bm_person_len = len(self.db.bookmarks)
|
|
|
|
bm_family_len = len(self.db.family_bookmarks)
|
|
|
|
bm_event_len = len(self.db.event_bookmarks)
|
|
|
|
bm_source_len = len(self.db.source_bookmarks)
|
|
|
|
bm_place_len = len(self.db.place_bookmarks)
|
|
|
|
bm_repo_len = len(self.db.repo_bookmarks)
|
|
|
|
bm_obj_len = len(self.db.media_bookmarks)
|
|
|
|
|
|
|
|
bm_len = bm_person_len + bm_family_len + bm_event_len \
|
|
|
|
+ bm_source_len + bm_place_len + bm_repo_len + bm_obj_len
|
|
|
|
|
|
|
|
if bm_len > 0:
|
|
|
|
self.g.write(" <bookmarks>\n")
|
|
|
|
|
|
|
|
for handle in self.db.get_bookmarks():
|
|
|
|
self.g.write(' <bookmark target="person" hlink="_%s"/>\n'
|
|
|
|
% handle )
|
|
|
|
for handle in self.db.get_family_bookmarks():
|
|
|
|
self.g.write(' <bookmark target="family" hlink="_%s"/>\n'
|
|
|
|
% handle )
|
|
|
|
for handle in self.db.get_event_bookmarks():
|
|
|
|
self.g.write(' <bookmark target="event" hlink="_%s"/>\n'
|
|
|
|
% handle )
|
|
|
|
for handle in self.db.get_source_bookmarks():
|
|
|
|
self.g.write(' <bookmark target="source" hlink="_%s"/>\n'
|
|
|
|
% handle )
|
|
|
|
for handle in self.db.get_place_bookmarks():
|
|
|
|
self.g.write(' <bookmark target="place" hlink="_%s"/>\n'
|
|
|
|
% handle )
|
|
|
|
for handle in self.db.get_media_bookmarks():
|
|
|
|
self.g.write(' <bookmark target="media" hlink="_%s"/>\n'
|
|
|
|
% handle )
|
|
|
|
for handle in self.db.get_repo_bookmarks():
|
|
|
|
self.g.write(' <bookmark target="repository" hlink="_%s"/>\n'
|
|
|
|
% handle )
|
|
|
|
self.g.write(" </bookmarks>\n")
|
|
|
|
|
2006-07-06 23:16:46 +05:30
|
|
|
def write_name_formats(self):
|
|
|
|
if len(self.db.name_formats) > 0:
|
|
|
|
self.g.write(" <name-formats>\n")
|
2006-07-27 23:14:02 +05:30
|
|
|
for number,name,fmt_str,active in self.db.name_formats:
|
|
|
|
self.g.write('%s<format number="%d" name="%s" '
|
|
|
|
'fmt_str="%s" active="%d"/>\n'
|
|
|
|
% (' ',number,name,fmt_str,int(active)) )
|
2006-07-06 23:16:46 +05:30
|
|
|
self.g.write(" </name-formats>\n")
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def fix(self,line):
|
2006-11-25 06:32:26 +05:30
|
|
|
try:
|
|
|
|
l = unicode(line)
|
|
|
|
except:
|
|
|
|
l = unicode(str(line),errors='replace')
|
|
|
|
l = l.strip().translate(strip_dict)
|
2006-12-12 02:39:25 +05:30
|
|
|
return escxml(l)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-12-10 09:19:53 +05:30
|
|
|
def write_note(self,val,noteobj,indent=0):
|
|
|
|
if not noteobj:
|
|
|
|
return
|
|
|
|
text = noteobj.get()
|
|
|
|
if not text:
|
|
|
|
return
|
|
|
|
if indent != 0:
|
|
|
|
self.g.write(" " * indent)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
format = noteobj.get_format()
|
2003-12-29 21:25:08 +05:30
|
|
|
if format:
|
|
|
|
self.g.write('<%s format="%d">' % (val,format))
|
|
|
|
else:
|
|
|
|
self.g.write('<%s>' % val)
|
2005-03-10 05:34:50 +05:30
|
|
|
self.g.write(self.fix(text.rstrip()))
|
2003-12-10 09:19:53 +05:30
|
|
|
self.g.write("</%s>\n" % val)
|
2004-07-09 23:49:47 +05:30
|
|
|
|
2003-12-10 09:19:53 +05:30
|
|
|
def write_text(self,val,text,indent=0):
|
|
|
|
if not text:
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
|
|
|
if indent != 0:
|
|
|
|
self.g.write(" " * indent)
|
|
|
|
|
2003-12-10 09:19:53 +05:30
|
|
|
self.g.write('<%s>' % val)
|
2005-03-10 05:34:50 +05:30
|
|
|
self.g.write(self.fix(text.rstrip()))
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("</%s>\n" % val)
|
2004-07-09 23:49:47 +05:30
|
|
|
|
2006-01-28 02:08:33 +05:30
|
|
|
def write_person(self,person,index=1):
|
|
|
|
sp = " "*index
|
|
|
|
self.write_primary_tag("person",person,index)
|
|
|
|
if person.get_gender() == RelLib.Person.MALE:
|
|
|
|
self.write_line("gender","M",index+1)
|
|
|
|
elif person.get_gender() == RelLib.Person.FEMALE:
|
|
|
|
self.write_line("gender","F",index+1)
|
|
|
|
else:
|
|
|
|
self.write_line("gender","U",index+1)
|
|
|
|
self.dump_name(person.get_primary_name(),False,index+1)
|
|
|
|
for name in person.get_alternate_names():
|
|
|
|
self.dump_name(name,True,index+1)
|
|
|
|
|
2006-05-25 09:38:05 +05:30
|
|
|
#self.dump_event_ref(person.get_birth_ref(),index+1)
|
|
|
|
#self.dump_event_ref(person.get_death_ref(),index+1)
|
2006-01-28 02:08:33 +05:30
|
|
|
for event_ref in person.get_event_ref_list():
|
|
|
|
self.dump_event_ref(event_ref,index+1)
|
|
|
|
|
2006-04-06 08:04:58 +05:30
|
|
|
for lds_ord in person.lds_ord_list:
|
|
|
|
self.dump_ordinance(lds_ord,index+1)
|
2006-01-28 02:08:33 +05:30
|
|
|
|
|
|
|
self.write_media_list(person.get_media_list(),index+1)
|
|
|
|
|
|
|
|
self.write_address_list(person,index+1)
|
|
|
|
self.write_attribute_list(person.get_attribute_list())
|
|
|
|
self.write_url_list(person.get_url_list(),index+1)
|
|
|
|
|
2006-04-14 01:04:07 +05:30
|
|
|
for family_handle in person.get_parent_family_handle_list():
|
2006-04-19 07:53:08 +05:30
|
|
|
self.write_ref("childof",family_handle,index+1)
|
2006-01-28 02:08:33 +05:30
|
|
|
|
|
|
|
for family_handle in person.get_family_handle_list():
|
|
|
|
self.write_ref("parentin",family_handle,index+1)
|
|
|
|
|
2006-04-19 07:53:08 +05:30
|
|
|
for person_ref in person.get_person_ref_list():
|
|
|
|
self.dump_person_ref(person_ref,index+1)
|
|
|
|
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_note("note",person.get_note_object(),index+1)
|
|
|
|
for s in person.get_source_references():
|
|
|
|
self.dump_source_ref(s,index+2)
|
|
|
|
self.g.write("%s</person>\n" % sp)
|
|
|
|
|
|
|
|
def write_family(self,family,index=1):
|
|
|
|
sp = " "*index
|
|
|
|
self.write_family_handle(family,index)
|
|
|
|
fhandle = family.get_father_handle()
|
|
|
|
mhandle = family.get_mother_handle()
|
|
|
|
if fhandle:
|
|
|
|
self.write_ref("father",fhandle,index+1)
|
|
|
|
if mhandle:
|
|
|
|
self.write_ref("mother",mhandle,index+1)
|
|
|
|
for event_ref in family.get_event_ref_list():
|
|
|
|
self.dump_event_ref(event_ref,3)
|
2006-04-06 08:04:58 +05:30
|
|
|
for lds_ord in family.lds_ord_list:
|
|
|
|
self.dump_ordinance(lds_ord,index+1)
|
2006-01-28 02:08:33 +05:30
|
|
|
|
|
|
|
self.write_media_list(family.get_media_list(),index+1)
|
|
|
|
|
2006-04-19 07:53:08 +05:30
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
self.dump_child_ref(child_ref,index+1)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_attribute_list(family.get_attribute_list())
|
|
|
|
self.write_note("note",family.get_note_object(),index+1)
|
|
|
|
for s in family.get_source_references():
|
|
|
|
self.dump_source_ref(s,index+1)
|
|
|
|
self.g.write("%s</family>\n" % sp)
|
|
|
|
|
|
|
|
def write_source(self,source,index=1):
|
|
|
|
sp = " "*index
|
|
|
|
self.write_primary_tag("source",source,index)
|
|
|
|
self.write_force_line("stitle",source.get_title(),index+1)
|
|
|
|
self.write_line("sauthor",source.get_author(),index+1)
|
|
|
|
self.write_line("spubinfo",source.get_publication_info(),index+1)
|
|
|
|
self.write_line("sabbrev",source.get_abbreviation(),index+1)
|
|
|
|
if source.get_note() != "":
|
|
|
|
self.write_note("note",source.get_note_object(),index+1)
|
|
|
|
self.write_media_list(source.get_media_list(),index+1)
|
|
|
|
self.write_data_map(source.get_data_map())
|
2006-01-28 09:53:37 +05:30
|
|
|
self.write_reporef_list(source.get_reporef_list(),index+1)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.g.write("%s</source>\n" % sp)
|
|
|
|
|
|
|
|
def write_repository(self,repo,index=1):
|
|
|
|
sp = " "*index
|
|
|
|
self.write_primary_tag("repository",repo,index)
|
|
|
|
#name
|
2006-01-28 06:13:27 +05:30
|
|
|
self.write_line('rname',repo.name,index+1)
|
2006-04-19 09:27:10 +05:30
|
|
|
rtype = repo.type.xml_str()
|
2006-01-28 02:08:33 +05:30
|
|
|
if rtype:
|
|
|
|
self.write_line('type',rtype,index+1)
|
|
|
|
#address list
|
|
|
|
self.write_address_list(repo,index+1)
|
|
|
|
# url list
|
|
|
|
self.write_url_list(repo.get_url_list(),index+1)
|
2006-01-28 09:53:37 +05:30
|
|
|
if repo.get_note() != "":
|
|
|
|
self.write_note("note",repo.get_note_object(),index+1)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.g.write("%s</repository>\n" % sp)
|
|
|
|
|
|
|
|
def write_address_list(self,obj,index=1):
|
|
|
|
if len(obj.get_address_list()) == 0:
|
|
|
|
return
|
|
|
|
sp = " "*index
|
|
|
|
for address in obj.get_address_list():
|
|
|
|
self.g.write('%s<address%s>\n' % (sp,conf_priv(address)))
|
|
|
|
self.write_date(address.get_date_object(),index+2)
|
|
|
|
self.write_line("street",address.get_street(),index+2)
|
|
|
|
self.write_line("city",address.get_city(),index+2)
|
2006-10-08 00:39:05 +05:30
|
|
|
self.write_line("county",address.get_county(),index+2)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_line("state",address.get_state(),index+2)
|
|
|
|
self.write_line("country",address.get_country(),index+2)
|
|
|
|
self.write_line("postal",address.get_postal_code(),index+2)
|
|
|
|
self.write_line("phone",address.get_phone(),index+2)
|
|
|
|
if address.get_note() != "":
|
|
|
|
self.write_note("note",address.get_note_object(),index+2)
|
|
|
|
for s in address.get_source_references():
|
|
|
|
self.dump_source_ref(s,index+2)
|
|
|
|
self.g.write('%s</address>\n' % sp)
|
2003-02-24 10:21:57 +05:30
|
|
|
|
2006-04-19 07:53:08 +05:30
|
|
|
def dump_person_ref(self,personref,index=1):
|
|
|
|
if not personref or not personref.ref:
|
|
|
|
return
|
|
|
|
sp = " "*index
|
|
|
|
priv_text = conf_priv(personref)
|
2006-11-28 12:32:26 +05:30
|
|
|
rel_text = ' rel="%s"' % personref.get_relation()
|
2006-04-19 07:53:08 +05:30
|
|
|
|
|
|
|
sreflist = personref.get_source_references()
|
|
|
|
if (len(sreflist) == 0) and personref.get_note() =="":
|
|
|
|
self.write_ref('personref',personref.ref,index,close=True,
|
|
|
|
extra_text=priv_text+rel_text)
|
|
|
|
else:
|
|
|
|
self.write_ref('personref',personref.ref,index,close=False,
|
|
|
|
extra_text=priv_text+rel_text)
|
|
|
|
for sref in sreflist:
|
|
|
|
self.dump_source_ref(sref,index+1)
|
|
|
|
self.write_note("note",personref.get_note_object(),index+1)
|
|
|
|
self.g.write('%s</personref>\n' % sp)
|
|
|
|
|
|
|
|
def dump_child_ref(self,childref,index=1):
|
|
|
|
if not childref or not childref.ref:
|
|
|
|
return
|
|
|
|
sp = " "*index
|
|
|
|
priv_text = conf_priv(childref)
|
|
|
|
if childref.frel.is_default():
|
|
|
|
frel_text = ''
|
|
|
|
else:
|
2006-12-12 02:39:25 +05:30
|
|
|
frel_text = ' frel="%s"' % escxml(childref.frel.xml_str())
|
2006-04-19 07:53:08 +05:30
|
|
|
if childref.mrel.is_default():
|
|
|
|
mrel_text = ''
|
|
|
|
else:
|
2006-12-12 02:39:25 +05:30
|
|
|
mrel_text = ' mrel="%s"' % escxml(childref.mrel.xml_str())
|
2006-04-19 07:53:08 +05:30
|
|
|
sreflist = childref.get_source_references()
|
|
|
|
if (len(sreflist) == 0) and childref.get_note() =="":
|
|
|
|
self.write_ref('childref',childref.ref,index,close=True,
|
2006-04-19 10:44:37 +05:30
|
|
|
extra_text=priv_text+mrel_text+frel_text)
|
2006-04-19 07:53:08 +05:30
|
|
|
else:
|
|
|
|
self.write_ref('childref',childref.ref,index,close=False,
|
2006-04-19 10:44:37 +05:30
|
|
|
extra_text=priv_text+mrel_text+frel_text)
|
2006-04-19 07:53:08 +05:30
|
|
|
for sref in sreflist:
|
|
|
|
self.dump_source_ref(sref,index+1)
|
|
|
|
self.write_note("note",childref.get_note_object(),index+1)
|
|
|
|
self.g.write('%s</childref>\n' % sp)
|
|
|
|
|
2006-01-27 07:43:17 +05:30
|
|
|
def dump_event_ref(self,eventref,index=1):
|
|
|
|
if not eventref or not eventref.ref:
|
|
|
|
return
|
2006-01-28 02:08:33 +05:30
|
|
|
sp = " "*index
|
2006-01-27 07:43:17 +05:30
|
|
|
priv_text = conf_priv(eventref)
|
2006-12-12 02:39:25 +05:30
|
|
|
role = escxml(eventref.role.xml_str())
|
2006-01-27 07:43:17 +05:30
|
|
|
if role:
|
|
|
|
role_text = ' role="%s"' % role
|
|
|
|
else:
|
|
|
|
role_text = ''
|
|
|
|
|
2006-08-16 02:29:12 +05:30
|
|
|
attribute_list = eventref.get_attribute_list()
|
|
|
|
if (attribute_list == []) and (eventref.get_note() == ""):
|
2006-01-27 12:24:35 +05:30
|
|
|
self.write_ref('eventref',eventref.ref,index,
|
|
|
|
close=True,extra_text=priv_text+role_text)
|
2006-01-27 07:43:17 +05:30
|
|
|
else:
|
2006-01-27 12:24:35 +05:30
|
|
|
self.write_ref('eventref',eventref.ref,index,
|
|
|
|
close=False,extra_text=priv_text+role_text)
|
2006-08-16 02:29:12 +05:30
|
|
|
self.write_attribute_list(attribute_list,index+1)
|
2006-01-27 07:43:17 +05:30
|
|
|
self.write_note("note",eventref.get_note_object(),index+1)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.g.write('%s</eventref>\n' % sp)
|
2006-01-27 07:43:17 +05:30
|
|
|
|
|
|
|
def write_event(self,event,index=1):
|
2006-01-29 10:42:01 +05:30
|
|
|
if not event:
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
|
|
|
|
2006-01-27 07:43:17 +05:30
|
|
|
self.write_primary_tag("event",event,2)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
sp = " " * index
|
2006-04-20 23:50:55 +05:30
|
|
|
etype = event.get_type().xml_str()
|
2006-01-27 07:43:17 +05:30
|
|
|
self.g.write(' %s<type>%s</type>\n' % (sp,self.fix(etype)) )
|
2004-02-14 11:10:30 +05:30
|
|
|
self.write_date(event.get_date_object(),index+1)
|
2004-07-28 07:59:07 +05:30
|
|
|
self.write_ref("place",event.get_place_handle(),index+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.write_line("description",event.get_description(),index+1)
|
2006-08-16 02:29:12 +05:30
|
|
|
self.write_attribute_list(event.get_attribute_list(),index+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
if event.get_note():
|
|
|
|
self.write_note("note",event.get_note_object(),index+1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
for s in event.get_source_references():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.dump_source_ref(s,index+1)
|
2004-06-03 11:05:30 +05:30
|
|
|
self.write_media_list(event.get_media_list(),index+1)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("%s</event>\n" % sp)
|
|
|
|
|
2006-04-06 08:04:58 +05:30
|
|
|
def dump_ordinance(self,ord,index=1):
|
|
|
|
|
2006-05-24 10:58:33 +05:30
|
|
|
name = ord.type2xml()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
sp = " " * index
|
|
|
|
sp2 = " " * (index+1)
|
2006-05-24 10:58:33 +05:30
|
|
|
self.g.write('%s<lds_ord type="%s">\n' % (sp,name))
|
2004-02-14 11:10:30 +05:30
|
|
|
dateobj = ord.get_date_object()
|
2005-01-16 09:30:35 +05:30
|
|
|
if dateobj and not dateobj.is_empty():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_date(dateobj,index+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
if ord.get_temple():
|
2006-05-24 10:58:33 +05:30
|
|
|
self.g.write('%s<temple val="%s"/>\n'
|
|
|
|
% (sp2,self.fix(ord.get_temple())))
|
2004-07-28 07:59:07 +05:30
|
|
|
self.write_ref("place",ord.get_place_handle(),index+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
if ord.get_status() != 0:
|
2006-05-24 10:58:33 +05:30
|
|
|
self.g.write('%s<status val="%s"/>\n' % (sp2,ord.status2xml()))
|
2004-07-28 07:59:07 +05:30
|
|
|
if ord.get_family_handle():
|
2005-01-16 09:30:35 +05:30
|
|
|
self.g.write('%s<sealed_to hlink="%s"/>\n' %
|
2006-05-24 10:58:33 +05:30
|
|
|
(sp2,"_"+ord.get_family_handle()))
|
2004-02-14 11:10:30 +05:30
|
|
|
if ord.get_note() != "":
|
|
|
|
self.write_note("note",ord.get_note_object(),index+1)
|
|
|
|
for s in ord.get_source_references():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.dump_source_ref(s,index+1)
|
|
|
|
self.g.write('%s</lds_ord>\n' % sp)
|
|
|
|
|
|
|
|
def dump_source_ref(self,source_ref,index=1):
|
2006-05-23 05:26:57 +05:30
|
|
|
source = self.db.get_source_from_handle(
|
|
|
|
source_ref.get_reference_handle())
|
2002-10-20 19:55:16 +05:30
|
|
|
if source:
|
2004-02-14 11:10:30 +05:30
|
|
|
p = source_ref.get_page()
|
2005-03-28 10:28:28 +05:30
|
|
|
c = source_ref.get_note()
|
2004-02-14 11:10:30 +05:30
|
|
|
t = source_ref.get_text()
|
2005-03-23 05:29:51 +05:30
|
|
|
d = source_ref.get_date_object()
|
2004-02-14 11:10:30 +05:30
|
|
|
q = source_ref.get_confidence_level()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(" " * index)
|
2004-02-14 11:10:30 +05:30
|
|
|
if p == "" and c == "" and t == "" and d.is_empty() and q == 2:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write('<sourceref hlink="%s"/>\n' % ("_"+source.get_handle()))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
if q == 2:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write('<sourceref hlink="%s">\n' % ("_"+source.get_handle()))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write('<sourceref hlink="%s" conf="%d">\n' % ("_"+source.get_handle(),q))
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_line("spage",p,index+1)
|
2003-12-10 09:19:53 +05:30
|
|
|
self.write_text("scomments",c,index+1)
|
|
|
|
self.write_text("stext",t,index+1)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_date(d,index+1)
|
|
|
|
self.g.write("%s</sourceref>\n" % (" " * index))
|
|
|
|
|
2006-01-27 07:43:17 +05:30
|
|
|
def write_ref(self,tagname,handle,index=1,close=True,extra_text=''):
|
|
|
|
if handle:
|
|
|
|
if close:
|
|
|
|
close_tag = "/"
|
|
|
|
else:
|
|
|
|
close_tag = ""
|
2006-01-28 02:08:33 +05:30
|
|
|
sp = " "*index
|
2006-01-27 07:43:17 +05:30
|
|
|
self.g.write('%s<%s hlink="_%s"%s%s>\n'
|
2006-01-28 02:08:33 +05:30
|
|
|
% (sp,tagname,handle,extra_text,close_tag))
|
2006-01-27 07:43:17 +05:30
|
|
|
|
|
|
|
def write_primary_tag(self,tagname,obj,index=1):
|
|
|
|
if not obj:
|
|
|
|
return
|
2006-01-28 02:08:33 +05:30
|
|
|
sp = " "*index
|
2006-04-20 23:50:55 +05:30
|
|
|
marker = obj.get_marker().xml_str()
|
2006-01-27 07:43:17 +05:30
|
|
|
if marker:
|
2006-12-12 02:39:25 +05:30
|
|
|
marker_text = ' marker="%s"' % escxml(marker)
|
2006-01-27 07:43:17 +05:30
|
|
|
else:
|
|
|
|
marker_text = ''
|
|
|
|
priv_text = conf_priv(obj)
|
|
|
|
change_text = ' change="%d"' % obj.get_change_time()
|
2006-01-28 06:13:27 +05:30
|
|
|
handle_id_text = ' id="%s" handle="_%s"' % (obj.gramps_id,obj.handle)
|
2006-01-28 02:08:33 +05:30
|
|
|
obj_text = '%s<%s' % (sp,tagname)
|
2006-01-27 07:43:17 +05:30
|
|
|
|
|
|
|
self.g.write(obj_text + handle_id_text + priv_text + marker_text +
|
|
|
|
change_text + '>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
def write_family_handle(self,family,index=1):
|
2006-01-28 02:08:33 +05:30
|
|
|
sp = " "*index
|
2006-01-27 07:43:17 +05:30
|
|
|
self.write_primary_tag('family',family,index)
|
2002-10-20 19:55:16 +05:30
|
|
|
if family:
|
2006-12-12 02:39:25 +05:30
|
|
|
rel = escxml(family.get_relationship().xml_str())
|
2002-10-20 19:55:16 +05:30
|
|
|
if rel != "":
|
2006-01-28 06:13:27 +05:30
|
|
|
self.g.write(' %s<rel type="%s"/>\n' % (sp,rel) )
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-12-04 10:28:07 +05:30
|
|
|
def write_last(self,name,indent=1):
|
2004-02-19 10:35:43 +05:30
|
|
|
p = name.get_surname_prefix()
|
|
|
|
n = name.get_surname()
|
2004-10-04 09:58:58 +05:30
|
|
|
g = name.get_group_as()
|
|
|
|
self.g.write('%s<last' % (' '*indent))
|
2002-12-04 10:28:07 +05:30
|
|
|
if p:
|
2004-10-04 09:58:58 +05:30
|
|
|
self.g.write(' prefix="%s"' % p)
|
|
|
|
if g:
|
|
|
|
self.g.write(' group="%s"' % g)
|
|
|
|
self.g.write('>%s</last>\n' % self.fix(n))
|
2002-12-04 10:28:07 +05:30
|
|
|
|
2006-01-27 07:43:17 +05:30
|
|
|
def write_line(self,tagname,value,indent=1):
|
2002-10-20 19:55:16 +05:30
|
|
|
if value:
|
2006-01-27 07:43:17 +05:30
|
|
|
self.g.write('%s<%s>%s</%s>\n' %
|
|
|
|
(' '*indent,tagname,self.fix(value),tagname))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
def get_iso_date(self,date):
|
|
|
|
if date[2] == 0:
|
|
|
|
y = "????"
|
|
|
|
else:
|
|
|
|
y = "%04d" % date[2]
|
|
|
|
|
|
|
|
if date[1] == 0:
|
|
|
|
if date[0] == 0:
|
|
|
|
m = ""
|
|
|
|
else:
|
|
|
|
m = "-??"
|
|
|
|
else:
|
|
|
|
m = "-%02d" % (date[1])
|
|
|
|
if date[0] == 0:
|
|
|
|
d = ''
|
|
|
|
else:
|
|
|
|
d = "-%02d" % date[0]
|
2005-12-06 12:08:09 +05:30
|
|
|
ret = "%s%s%s" % (y,m,d)
|
|
|
|
# If the result does not contain anything beyond dashes
|
|
|
|
# and question marks then it's as good as empty
|
|
|
|
if ret.replace('-','').replace('?','') == '':
|
|
|
|
ret = ''
|
|
|
|
return ret
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def write_date(self,date,indent=1):
|
|
|
|
sp = ' '*indent
|
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
cal= date.get_calendar()
|
2006-02-04 03:33:53 +05:30
|
|
|
if cal != RelLib.Date.CAL_GREGORIAN:
|
|
|
|
calstr = ' cformat="%s"' % RelLib.Date.calendar_names[cal]
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
calstr = ''
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
qual = date.get_quality()
|
2006-02-04 03:33:53 +05:30
|
|
|
if qual == RelLib.Date.QUAL_ESTIMATED:
|
2005-12-06 12:08:09 +05:30
|
|
|
qual_str = ' quality="estimated"'
|
2006-02-04 03:33:53 +05:30
|
|
|
elif qual == RelLib.Date.QUAL_CALCULATED:
|
2005-12-06 12:08:09 +05:30
|
|
|
qual_str = ' quality="calculated"'
|
|
|
|
else:
|
|
|
|
qual_str = ""
|
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
mode = date.get_modifier()
|
|
|
|
|
|
|
|
if date.is_compound():
|
|
|
|
d1 = self.get_iso_date(date.get_start_date())
|
|
|
|
d2 = self.get_iso_date(date.get_stop_date())
|
2005-12-06 12:08:09 +05:30
|
|
|
if d1 != "" or d2 != "":
|
|
|
|
self.g.write('%s<daterange start="%s" stop="%s"%s%s/>\n'
|
|
|
|
% (sp,d1,d2,qual_str,calstr))
|
2006-02-04 03:33:53 +05:30
|
|
|
elif mode != RelLib.Date.MOD_TEXTONLY:
|
2005-12-06 12:08:09 +05:30
|
|
|
date_str = self.get_iso_date(date.get_start_date())
|
|
|
|
if date_str == "":
|
|
|
|
return
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-02-04 03:33:53 +05:30
|
|
|
if mode == RelLib.Date.MOD_BEFORE:
|
2005-12-06 12:08:09 +05:30
|
|
|
mode_str = ' type="before"'
|
2006-02-04 03:33:53 +05:30
|
|
|
elif mode == RelLib.Date.MOD_AFTER:
|
2005-12-06 12:08:09 +05:30
|
|
|
mode_str = ' type="after"'
|
2006-02-04 03:33:53 +05:30
|
|
|
elif mode == RelLib.Date.MOD_ABOUT:
|
2005-12-06 12:08:09 +05:30
|
|
|
mode_str = ' type="about"'
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2005-12-06 12:08:09 +05:30
|
|
|
mode_str = ""
|
|
|
|
|
|
|
|
self.g.write('%s<dateval val="%s"%s%s%s/>\n'
|
|
|
|
% (sp,date_str,mode_str,qual_str,calstr))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write('%s<datestr val="%s"/>\n'
|
|
|
|
%(sp,self.fix(date.get_text())))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def write_force_line(self,label,value,indent=1):
|
|
|
|
if value != None:
|
|
|
|
self.g.write('%s<%s>%s</%s>\n' % (' '*indent,label,self.fix(value),label))
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def dump_name(self,name,alternative=False,index=1):
|
2002-10-20 19:55:16 +05:30
|
|
|
sp = " "*index
|
2006-04-19 10:44:37 +05:30
|
|
|
name_type = name.get_type().xml_str()
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write('%s<name' % sp)
|
|
|
|
if alternative:
|
|
|
|
self.g.write(' alt="1"')
|
2004-08-23 04:46:57 +05:30
|
|
|
if name_type:
|
2006-12-12 02:39:25 +05:30
|
|
|
self.g.write(' type="%s"' % escxml(name_type))
|
2004-10-04 09:58:58 +05:30
|
|
|
if name.get_privacy() != 0:
|
|
|
|
self.g.write(' priv="%d"' % name.get_privacy())
|
|
|
|
if name.get_sort_as() != 0:
|
|
|
|
self.g.write(' sort="%d"' % name.get_sort_as())
|
|
|
|
if name.get_display_as() != 0:
|
|
|
|
self.g.write(' display="%d"' % name.get_display_as())
|
|
|
|
self.g.write('>\n')
|
2004-02-14 11:10:30 +05:30
|
|
|
self.write_line("first",name.get_first_name(),index+1)
|
2006-05-08 09:11:57 +05:30
|
|
|
self.write_line("call",name.get_call_name(),index+1)
|
2002-12-04 10:28:07 +05:30
|
|
|
self.write_last(name,index+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.write_line("suffix",name.get_suffix(),index+1)
|
2004-10-04 09:58:58 +05:30
|
|
|
self.write_line("patronymic",name.get_patronymic(),index+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.write_line("title",name.get_title(),index+1)
|
2005-03-07 05:17:26 +05:30
|
|
|
if name.date:
|
|
|
|
self.write_date(name.date,4)
|
2004-02-14 11:10:30 +05:30
|
|
|
if name.get_note() != "":
|
|
|
|
self.write_note("note",name.get_note_object(),index+1)
|
|
|
|
for s in name.get_source_references():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.dump_source_ref(s,index+1)
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write('%s</name>\n' % sp)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def append_value(self,orig,val):
|
|
|
|
if orig:
|
|
|
|
return "%s, %s" % (orig,val)
|
|
|
|
else:
|
|
|
|
return val
|
|
|
|
|
|
|
|
def build_place_title(self,loc):
|
|
|
|
"Builds a title from a location"
|
|
|
|
city = self.fix(loc.get_city())
|
2006-09-24 10:07:59 +05:30
|
|
|
street = self.fix(loc.get_street())
|
2002-10-20 19:55:16 +05:30
|
|
|
parish = self.fix(loc.get_parish())
|
|
|
|
state = self.fix(loc.get_state())
|
|
|
|
country = self.fix(loc.get_country())
|
|
|
|
county = self.fix(loc.get_county())
|
|
|
|
|
|
|
|
value = ""
|
|
|
|
|
2006-09-24 10:07:59 +05:30
|
|
|
if street:
|
|
|
|
value = street
|
2002-10-20 19:55:16 +05:30
|
|
|
if city:
|
2006-09-24 10:07:59 +05:30
|
|
|
value = self.append_value(value,city)
|
2002-10-20 19:55:16 +05:30
|
|
|
if parish:
|
|
|
|
value = self.append_value(value,parish)
|
|
|
|
if county:
|
|
|
|
value = self.append_value(value,county)
|
|
|
|
if state:
|
|
|
|
value = self.append_value(value,state)
|
|
|
|
if country:
|
|
|
|
value = self.append_value(value,country)
|
|
|
|
return value
|
|
|
|
|
|
|
|
def dump_location(self,loc):
|
|
|
|
"Writes the location information to the output file"
|
2006-01-27 12:24:35 +05:30
|
|
|
if loc.is_empty():
|
|
|
|
return
|
2002-10-20 19:55:16 +05:30
|
|
|
city = self.fix(loc.get_city())
|
|
|
|
parish = self.fix(loc.get_parish())
|
|
|
|
state = self.fix(loc.get_state())
|
|
|
|
country = self.fix(loc.get_country())
|
|
|
|
county = self.fix(loc.get_county())
|
2004-10-06 09:12:54 +05:30
|
|
|
zip_code = self.fix(loc.get_postal_code())
|
2003-12-09 11:32:36 +05:30
|
|
|
phone = self.fix(loc.get_phone())
|
2006-09-24 10:07:59 +05:30
|
|
|
street = self.fix(loc.get_street())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.g.write(' <location')
|
2006-09-24 10:07:59 +05:30
|
|
|
if street:
|
|
|
|
self.g.write(' street="%s"' % street)
|
2002-10-20 19:55:16 +05:30
|
|
|
if city:
|
|
|
|
self.g.write(' city="%s"' % city)
|
|
|
|
if parish:
|
|
|
|
self.g.write(' parish="%s"' % parish)
|
|
|
|
if county:
|
|
|
|
self.g.write(' county="%s"' % county)
|
|
|
|
if state:
|
|
|
|
self.g.write(' state="%s"' % state)
|
|
|
|
if country:
|
|
|
|
self.g.write(' country="%s"' % country)
|
2004-10-06 09:12:54 +05:30
|
|
|
if zip_code:
|
|
|
|
self.g.write(' postal="%s"' % zip_code)
|
2003-12-09 11:32:36 +05:30
|
|
|
if phone:
|
|
|
|
self.g.write(' phone="%s"' % phone)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write('/>\n')
|
|
|
|
|
|
|
|
def write_attribute_list(self, list, indent=3):
|
|
|
|
sp = ' ' * indent
|
|
|
|
for attr in list:
|
|
|
|
self.g.write('%s<attribute%s type="%s" value="%s"' % \
|
2006-12-12 02:39:25 +05:30
|
|
|
(sp,conf_priv(attr),escxml(attr.get_type().xml_str()),
|
2004-02-14 11:10:30 +05:30
|
|
|
self.fix(attr.get_value())))
|
|
|
|
slist = attr.get_source_references()
|
|
|
|
note = attr.get_note()
|
2002-10-20 19:55:16 +05:30
|
|
|
if note == "" and len(slist) == 0:
|
|
|
|
self.g.write('/>\n')
|
|
|
|
else:
|
|
|
|
self.g.write('>\n')
|
2004-02-14 11:10:30 +05:30
|
|
|
for s in attr.get_source_references():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.dump_source_ref(s,indent+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.write_note("note",attr.get_note_object(),4)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write('%s</attribute>\n' % sp)
|
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def write_media_list(self,list,indent=3):
|
2002-10-20 19:55:16 +05:30
|
|
|
sp = ' '*indent
|
|
|
|
for photo in list:
|
2004-07-28 07:59:07 +05:30
|
|
|
mobj_id = photo.get_reference_handle()
|
2005-12-06 12:08:09 +05:30
|
|
|
self.g.write('%s<objref hlink="%s"' % (sp,"_"+mobj_id))
|
2004-02-14 11:10:30 +05:30
|
|
|
if photo.get_privacy():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write(' priv="1"')
|
2004-02-14 11:10:30 +05:30
|
|
|
proplist = photo.get_attribute_list()
|
2004-06-03 11:05:30 +05:30
|
|
|
refslist = photo.get_source_references()
|
|
|
|
if len(proplist) == 0 and len(refslist) == 0 \
|
|
|
|
and photo.get_note() == "":
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("/>\n")
|
|
|
|
else:
|
|
|
|
self.g.write(">\n")
|
|
|
|
self.write_attribute_list(proplist,indent+1)
|
2004-06-03 11:05:30 +05:30
|
|
|
for ref in refslist:
|
|
|
|
self.dump_source_ref(ref,indent+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.write_note("note",photo.get_note_object(),indent+1)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write('%s</objref>\n' % sp)
|
|
|
|
|
2004-11-23 10:45:37 +05:30
|
|
|
def write_data_map(self,datamap,indent=3):
|
|
|
|
if len(datamap) == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
sp = ' '*indent
|
|
|
|
for key in datamap.keys():
|
2006-01-28 09:53:37 +05:30
|
|
|
self.g.write('%s<data_item key="%s" value="%s"/>\n' %
|
2006-10-07 04:33:56 +05:30
|
|
|
(sp,self.fix(key),self.fix(datamap[key])))
|
2004-11-23 10:45:37 +05:30
|
|
|
|
2006-01-28 02:08:33 +05:30
|
|
|
def write_reporef_list(self,rrlist,index=1):
|
2006-01-27 12:24:35 +05:30
|
|
|
for reporef in rrlist:
|
|
|
|
if not reporef or not reporef.ref:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if reporef.call_number == "":
|
|
|
|
callno_text = ''
|
|
|
|
else:
|
|
|
|
callno_text = ' callno="%s"' % reporef.call_number
|
|
|
|
|
2006-04-20 23:50:55 +05:30
|
|
|
mtype = reporef.media_type.xml_str()
|
2006-01-27 12:24:35 +05:30
|
|
|
if mtype:
|
2006-12-12 02:39:25 +05:30
|
|
|
type_text = ' medium="%s"' % escxml(mtype)
|
2006-01-27 12:24:35 +05:30
|
|
|
else:
|
|
|
|
type_text = ''
|
|
|
|
|
|
|
|
if reporef.get_note() == "":
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_ref('reporef',reporef.ref,index,
|
2006-01-27 12:24:35 +05:30
|
|
|
close=True,extra_text=callno_text+type_text)
|
|
|
|
else:
|
|
|
|
self.write_ref('reporef',reporef.ref,index,
|
|
|
|
close=False,extra_text=callno_text+type_text)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_note("note",reporef.get_note_object(),index+1)
|
|
|
|
sp = " "*index
|
|
|
|
self.g.write('%s</reporef>\n' % sp)
|
2006-01-27 12:24:35 +05:30
|
|
|
|
2006-01-28 02:08:33 +05:30
|
|
|
def write_url_list(self,list,index=1):
|
|
|
|
sp = " "*index
|
2002-10-20 19:55:16 +05:30
|
|
|
for url in list:
|
2006-04-19 10:44:37 +05:30
|
|
|
url_type = url.get_type().xml_str()
|
2006-01-27 12:24:35 +05:30
|
|
|
if url_type:
|
2006-12-12 02:39:25 +05:30
|
|
|
type_text = ' type="%s"' % escxml(url_type)
|
2006-01-27 12:24:35 +05:30
|
|
|
else:
|
|
|
|
type_text = ''
|
|
|
|
priv_text = conf_priv(url)
|
2002-10-20 19:55:16 +05:30
|
|
|
if url.get_description() != "":
|
2006-01-27 12:24:35 +05:30
|
|
|
desc_text = ' description="%s"' % self.fix(
|
|
|
|
url.get_description())
|
|
|
|
else:
|
|
|
|
desc_text = ''
|
|
|
|
path_text = ' href="%s"' % self.fix(url.get_path())
|
2006-01-28 02:08:33 +05:30
|
|
|
self.g.write('%s<url%s%s%s%s/>\n' % \
|
|
|
|
(sp,priv_text,path_text,type_text,desc_text))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-01-28 02:08:33 +05:30
|
|
|
def write_place_obj(self,place,index=1):
|
|
|
|
self.write_primary_tag("placeobj",place,index)
|
2006-01-27 12:24:35 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
title = self.fix(place.get_title())
|
2004-10-06 09:12:54 +05:30
|
|
|
longitude = self.fix(place.get_longitude())
|
2002-10-20 19:55:16 +05:30
|
|
|
lat = self.fix(place.get_latitude())
|
2004-10-06 09:12:54 +05:30
|
|
|
handle = place.get_gramps_id()
|
2002-10-20 19:55:16 +05:30
|
|
|
main_loc = place.get_main_location()
|
2006-01-27 12:24:35 +05:30
|
|
|
llen = len(place.get_alternate_locations()) \
|
|
|
|
+ len(place.get_url_list()) + \
|
|
|
|
len(place.get_media_list()) + \
|
|
|
|
len(place.get_source_references())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
ml_empty = main_loc.is_empty()
|
2004-02-14 11:10:30 +05:30
|
|
|
note = place.get_note()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if title == "":
|
|
|
|
title = self.fix(self.build_place_title(place.get_main_location()))
|
2006-01-30 03:09:36 +05:30
|
|
|
self.write_line("ptitle",title,index+1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-10-06 09:12:54 +05:30
|
|
|
if longitude or lat:
|
2006-01-28 02:08:33 +05:30
|
|
|
self.g.write('%s<coord long="%s" lat="%s"/>\n'
|
|
|
|
% (" "*(index+1),longitude,lat))
|
2002-10-20 19:55:16 +05:30
|
|
|
self.dump_location(main_loc)
|
|
|
|
for loc in place.get_alternate_locations():
|
|
|
|
self.dump_location(loc)
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_media_list(place.get_media_list(),index+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.write_url_list(place.get_url_list())
|
2002-10-20 19:55:16 +05:30
|
|
|
if note != "":
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_note("note",place.get_note_object(),index+1)
|
2004-02-14 11:10:30 +05:30
|
|
|
for s in place.get_source_references():
|
2006-01-28 02:08:33 +05:30
|
|
|
self.dump_source_ref(s,index+1)
|
|
|
|
self.g.write("%s</placeobj>\n" % (" "*index))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-01-28 02:08:33 +05:30
|
|
|
def write_object(self,obj,index=1):
|
|
|
|
self.write_primary_tag("object",obj,index)
|
2004-10-06 09:12:54 +05:30
|
|
|
handle = obj.get_gramps_id()
|
2004-08-23 04:46:57 +05:30
|
|
|
mime_type = obj.get_mime_type()
|
|
|
|
path = obj.get_path()
|
2006-01-27 12:24:35 +05:30
|
|
|
desc = obj.get_description()
|
|
|
|
if desc:
|
|
|
|
desc_text = ' description="%s"' % self.fix(desc)
|
|
|
|
else:
|
|
|
|
desc_text = ''
|
2006-03-01 10:34:22 +05:30
|
|
|
if self.strip_photos == 1:
|
2002-10-20 19:55:16 +05:30
|
|
|
path = os.path.basename(path)
|
2006-09-13 00:51:40 +05:30
|
|
|
elif self.strip_photos == 2 and (len(path)>0 and os.path.isabs(path)):
|
|
|
|
drive,path = os.path.splitdrive(path)
|
2006-03-01 10:34:22 +05:30
|
|
|
path = path[1:]
|
|
|
|
|
2006-01-28 02:08:33 +05:30
|
|
|
self.g.write('%s<file src="%s" mime="%s"%s/>\n'
|
2006-09-02 04:27:57 +05:30
|
|
|
% (" "*(index+1),self.fix(path),mime_type,desc_text))
|
2006-01-27 12:24:35 +05:30
|
|
|
self.write_attribute_list(obj.get_attribute_list())
|
|
|
|
if obj.get_note() != "":
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_note("note",obj.get_note_object(),index+1)
|
2004-11-06 09:01:34 +05:30
|
|
|
dval = obj.get_date_object()
|
2006-01-27 12:24:35 +05:30
|
|
|
if not dval.is_empty():
|
2006-01-28 02:08:33 +05:30
|
|
|
self.write_date(dval,index+1)
|
2006-01-27 12:24:35 +05:30
|
|
|
for s in obj.get_source_references():
|
2006-01-28 02:08:33 +05:30
|
|
|
self.dump_source_ref(s,index+1)
|
|
|
|
self.g.write("%s</object>\n" % (" "*index))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def sortById(first,second):
|
2004-08-01 09:51:31 +05:30
|
|
|
fid = first.get_gramps_id()
|
|
|
|
sid = second.get_gramps_id()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if fid < sid:
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return fid != sid
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def conf_priv(obj):
|
2004-02-14 11:10:30 +05:30
|
|
|
if obj.get_privacy() != 0:
|
|
|
|
return ' priv="%d"' % obj.get_privacy()
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
return ''
|
2004-07-01 09:39:55 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-07-09 23:49:47 +05:30
|
|
|
_title = _('GRAMPS _XML database')
|
|
|
|
_description = _('The GRAMPS XML database is a format used by older '
|
|
|
|
'versions of GRAMPS. It is read-write compatible with '
|
|
|
|
'the present GRAMPS database format.')
|
|
|
|
_config = None
|
|
|
|
_filename = 'gramps'
|
2004-07-01 09:39:55 +05:30
|
|
|
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import register_export
|
2004-07-09 23:49:47 +05:30
|
|
|
register_export(exportData,_title,_description,_config,_filename)
|