2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-28 11:11:40 +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-08-06 09:41:52 +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
|
|
|
|
#
|
2003-12-02 08:05:49 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"Export to GEDCOM"
|
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-23 05:26:57 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import re
|
2005-08-18 11:28:28 +05:30
|
|
|
import shutil
|
2007-08-08 09:54:49 +05:30
|
|
|
import string
|
2006-03-21 11:53:45 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".WriteGedcom")
|
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-01-15 10:55:50 +05:30
|
|
|
import RelLib
|
2002-12-30 06:12:47 +05:30
|
|
|
import const
|
2005-12-21 16:57:05 +05:30
|
|
|
import _GedcomInfo as GedcomInfo
|
2003-06-18 08:20:30 +05:30
|
|
|
import Errors
|
2004-10-11 04:52:12 +05:30
|
|
|
import Utils
|
2007-08-25 10:33:23 +05:30
|
|
|
import ExportOptions
|
2007-08-13 05:30:16 +05:30
|
|
|
from QuestionDialog import ErrorDialog, WarningDialog
|
|
|
|
from BasicUtils import UpdateCallback, name_displayer
|
2002-12-30 06:12:47 +05:30
|
|
|
|
2007-02-03 22:41:05 +05:30
|
|
|
try:
|
|
|
|
import Config
|
2007-02-04 23:07:36 +05:30
|
|
|
HAVE_CONFIG = True
|
2007-02-03 22:41:05 +05:30
|
|
|
except:
|
|
|
|
log.warn("No Config module available using defaults.")
|
2007-02-04 23:07:36 +05:30
|
|
|
HAVE_CONFIG = False
|
2007-02-03 22:41:05 +05:30
|
|
|
|
2006-03-21 11:53:45 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GEDCOM tags representing attributes that may take a parameter, value or
|
|
|
|
# description on the same line as the tag
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-08-22 09:17:51 +05:30
|
|
|
personalAttributeTakesParam = set(
|
|
|
|
["CAST", "DSCR", "EDUC", "IDNO", "NATI", "NCHI",
|
|
|
|
"NMR", "OCCU", "PROP", "RELI", "SSN", "TITL"])
|
2006-03-21 11:53:45 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Calendar month names
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-06-10 05:29:03 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
_hmonth = [
|
2007-08-06 09:41:52 +05:30
|
|
|
"", "ELUL", "TSH", "CSH", "KSL", "TVT", "SHV", "ADR",
|
2002-10-20 19:55:16 +05:30
|
|
|
"ADS", "NSN", "IYR", "SVN", "TMZ", "AAV", "ELL" ]
|
|
|
|
|
|
|
|
_fmonth = [
|
2007-08-06 09:41:52 +05:30
|
|
|
"", "VEND", "BRUM", "FRIM", "NIVO", "PLUV", "VENT",
|
2002-10-20 19:55:16 +05:30
|
|
|
"GERM", "FLOR", "PRAI", "MESS", "THER", "FRUC", "COMP"]
|
|
|
|
|
|
|
|
_month = [
|
2007-08-06 09:41:52 +05:30
|
|
|
"", "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
|
2002-10-20 19:55:16 +05:30
|
|
|
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ]
|
|
|
|
|
|
|
|
_calmap = {
|
2007-08-06 09:41:52 +05:30
|
|
|
RelLib.Date.CAL_HEBREW : (_hmonth, '@#DHEBREW@'),
|
|
|
|
RelLib.Date.CAL_FRENCH : (_fmonth, '@#DFRENCH R@'),
|
|
|
|
RelLib.Date.CAL_JULIAN : (_month, '@#DJULIAN@'),
|
2002-10-20 19:55:16 +05:30
|
|
|
}
|
|
|
|
|
2002-12-29 11:14:35 +05:30
|
|
|
_caldef = {
|
2007-08-06 09:41:52 +05:30
|
|
|
RelLib.Date.MOD_ABOUT : "ABT",
|
|
|
|
RelLib.Date.MOD_BEFORE : "BEF",
|
|
|
|
RelLib.Date.MOD_AFTER : "AFT",
|
2002-12-29 11:14:35 +05:30
|
|
|
}
|
|
|
|
|
2006-04-06 07:12:14 +05:30
|
|
|
lds_ord_name = {
|
2007-08-06 09:41:52 +05:30
|
|
|
RelLib.LdsOrd.BAPTISM : 'BAPL',
|
|
|
|
RelLib.LdsOrd.ENDOWMENT : 'ENDL',
|
|
|
|
RelLib.LdsOrd.SEAL_TO_PARENTS : 'SLGC',
|
|
|
|
RelLib.LdsOrd.SEAL_TO_SPOUSE : 'SGLS',
|
|
|
|
RelLib.LdsOrd.CONFIRMATION : 'CONL',
|
2006-04-06 07:12:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
lds_status = {
|
2007-08-06 09:41:52 +05:30
|
|
|
RelLib.LdsOrd.STATUS_BIC : "BIC",
|
|
|
|
RelLib.LdsOrd.STATUS_CANCELED : "CANCELED",
|
|
|
|
RelLib.LdsOrd.STATUS_CHILD : "CHILD",
|
|
|
|
RelLib.LdsOrd.STATUS_CLEARED : "CLEARED",
|
|
|
|
RelLib.LdsOrd.STATUS_COMPLETED : "COMPLETED",
|
|
|
|
RelLib.LdsOrd.STATUS_DNS : "DNS",
|
|
|
|
RelLib.LdsOrd.STATUS_INFANT : "INFANT",
|
|
|
|
RelLib.LdsOrd.STATUS_PRE_1970 : "PRE-1970",
|
|
|
|
RelLib.LdsOrd.STATUS_QUALIFIED : "QUALIFIED",
|
|
|
|
RelLib.LdsOrd.STATUS_DNS_CAN : "DNS/CAN",
|
|
|
|
RelLib.LdsOrd.STATUS_STILLBORN : "STILLBORN",
|
|
|
|
RelLib.LdsOrd.STATUS_SUBMITTED : "SUBMITTED" ,
|
|
|
|
RelLib.LdsOrd.STATUS_UNCLEARED : "UNCLEARED",
|
2006-04-06 07:12:14 +05:30
|
|
|
}
|
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
LANGUAGES = {
|
|
|
|
'cs' : 'Czech', 'da' : 'Danish', 'nl' : 'Dutch',
|
|
|
|
'en' : 'English', 'eo' : 'Esperanto', 'fi' : 'Finnish',
|
|
|
|
'fr' : 'French', 'de' : 'German', 'hu' : 'Hungarian',
|
|
|
|
'it' : 'Italian', 'lt' : 'Latvian', 'lv' : 'Lithuanian',
|
|
|
|
'no' : 'Norwegian', 'po' : 'Polish', 'pt' : 'Portuguese',
|
|
|
|
'ro' : 'Romanian', 'sk' : 'Slovak', 'es' : 'Spanish',
|
|
|
|
'sv' : 'Swedish', 'ru' : 'Russian',
|
|
|
|
}
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-12-30 06:12:47 +05:30
|
|
|
_get_int = re.compile('([0-9]+)')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-05-23 05:26:57 +05:30
|
|
|
mime2ged = {
|
2007-08-06 09:41:52 +05:30
|
|
|
"image/bmp" : "bmp",
|
|
|
|
"image/gif" : "gif",
|
|
|
|
"image/jpeg" : "jpeg",
|
|
|
|
"image/x-pcx" : "pcx",
|
|
|
|
"image/tiff" : "tiff",
|
2006-05-23 05:26:57 +05:30
|
|
|
"audio/x-wav" : "wav"
|
|
|
|
}
|
2006-06-17 00:08:06 +05:30
|
|
|
|
|
|
|
quay_map = {
|
2007-08-06 09:41:52 +05:30
|
|
|
RelLib.SourceRef.CONF_VERY_HIGH : 3,
|
|
|
|
RelLib.SourceRef.CONF_HIGH : 2,
|
|
|
|
RelLib.SourceRef.CONF_LOW : 1,
|
|
|
|
RelLib.SourceRef.CONF_VERY_LOW : 0,
|
2007-08-25 10:33:23 +05:30
|
|
|
}
|
2006-06-17 00:08:06 +05:30
|
|
|
|
2004-07-12 05:23:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-08-06 09:41:52 +05:30
|
|
|
def sort_by_gramps_id(first, second):
|
2007-08-13 05:30:16 +05:30
|
|
|
return cmp(first.gramps_id, second.gramps_id)
|
2004-07-12 05:23:02 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-08-06 09:41:52 +05:30
|
|
|
def make_date(subdate, calendar, mode):
|
2002-10-20 19:55:16 +05:30
|
|
|
retval = ""
|
2007-08-06 09:41:52 +05:30
|
|
|
(day, mon, year, sl) = subdate
|
2004-06-10 05:29:03 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
(mmap, prefix) = _calmap.get(calendar, (_month, ""))
|
2004-10-16 10:40:35 +05:30
|
|
|
|
|
|
|
if year < 0:
|
|
|
|
year = -year
|
|
|
|
bc = " B.C."
|
|
|
|
else:
|
|
|
|
bc = ""
|
2004-06-10 05:29:03 +05:30
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
if day == 0:
|
2002-10-20 19:55:16 +05:30
|
|
|
try:
|
2004-09-17 09:00:04 +05:30
|
|
|
if mon == 0:
|
2007-08-06 09:41:52 +05:30
|
|
|
retval = '%d%s' % (year, bc)
|
2004-09-17 09:00:04 +05:30
|
|
|
elif year == 0:
|
2002-12-29 11:14:35 +05:30
|
|
|
retval = '(%s)' % mmap[mon]
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2007-08-06 09:41:52 +05:30
|
|
|
retval = "%s %d%s" % (mmap[mon], year, bc)
|
2002-10-20 19:55:16 +05:30
|
|
|
except IndexError:
|
|
|
|
print "Month index error - %d" % mon
|
2007-08-06 09:41:52 +05:30
|
|
|
retval = '%d%s' % (year, bc)
|
2004-09-17 09:00:04 +05:30
|
|
|
elif mon == 0:
|
2007-08-06 09:41:52 +05:30
|
|
|
retval = '%d%s' % (year, bc)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
try:
|
|
|
|
month = mmap[mon]
|
2004-09-17 09:00:04 +05:30
|
|
|
if year == 0:
|
2007-08-06 09:41:52 +05:30
|
|
|
retval = "(%d %s)" % (day, month)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2007-08-06 09:41:52 +05:30
|
|
|
retval = "%d %s %d%s" % (day, month, year, bc)
|
2002-10-20 19:55:16 +05:30
|
|
|
except IndexError:
|
|
|
|
print "Month index error - %d" % mon
|
2007-08-06 09:41:52 +05:30
|
|
|
retval = "%d%s" % (year, bc)
|
2002-12-29 11:14:35 +05:30
|
|
|
|
|
|
|
if prefix:
|
|
|
|
retval = "%s %s" % (prefix, retval)
|
2004-06-10 05:29:03 +05:30
|
|
|
|
2002-12-29 11:14:35 +05:30
|
|
|
if _caldef.has_key(mode):
|
2007-08-06 09:41:52 +05:30
|
|
|
retval = "%s %s" % (_caldef[mode], retval)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-06-10 05:29:03 +05:30
|
|
|
return retval
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-08-06 09:41:52 +05:30
|
|
|
def writeData(database, person):
|
|
|
|
GedcomWriter(database, person)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-08 09:54:49 +05:30
|
|
|
def breakup(txt, limit):
|
2007-08-14 09:32:18 +05:30
|
|
|
"""
|
|
|
|
Breaks a line of text into a list of strings that conform to the
|
|
|
|
maximum length specified, while breaking words in the middle of a word
|
|
|
|
to avoid issues with spaces.
|
|
|
|
"""
|
2007-08-08 09:54:49 +05:30
|
|
|
data = []
|
2007-08-20 08:45:13 +05:30
|
|
|
original = txt
|
2007-08-09 10:05:06 +05:30
|
|
|
while limit < len(txt)+1:
|
2007-08-08 09:54:49 +05:30
|
|
|
idx = limit-1
|
2007-08-20 08:45:13 +05:30
|
|
|
while txt[idx-1] in string.whitespace or txt[idx] in string.whitespace :
|
2007-08-08 09:54:49 +05:30
|
|
|
idx -= 1
|
2007-08-20 08:45:13 +05:30
|
|
|
data.append(txt[:idx])
|
|
|
|
txt = txt[idx:]
|
2007-08-08 09:54:49 +05:30
|
|
|
if len(txt) > 0:
|
|
|
|
data.append(txt)
|
|
|
|
return data
|
|
|
|
|
2006-05-21 09:44:47 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GedcomWriter class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-16 09:17:58 +05:30
|
|
|
class GedcomWriter(UpdateCallback):
|
2007-08-06 09:41:52 +05:30
|
|
|
def __init__(self, database, person, cl=0, filename="", option_box=None,
|
2006-03-01 11:46:36 +05:30
|
|
|
callback=None):
|
2007-08-06 09:41:52 +05:30
|
|
|
UpdateCallback.__init__(self, callback)
|
2006-05-16 09:17:58 +05:30
|
|
|
|
2004-07-11 11:33:07 +05:30
|
|
|
self.db = database
|
|
|
|
self.person = person
|
|
|
|
self.option_box = option_box
|
|
|
|
self.cl = cl
|
|
|
|
self.filename = filename
|
|
|
|
|
2006-05-23 05:26:57 +05:30
|
|
|
if option_box:
|
|
|
|
setup_func = self.gui_setup
|
2004-07-11 11:33:07 +05:30
|
|
|
else:
|
2006-05-23 05:26:57 +05:30
|
|
|
setup_func = self.cli_setup
|
|
|
|
|
|
|
|
# Run setup, bail out if status is not Ture
|
|
|
|
if not setup_func():
|
|
|
|
return
|
|
|
|
|
|
|
|
self.flist = set()
|
|
|
|
self.slist = set()
|
|
|
|
self.rlist = set()
|
2007-08-09 10:05:06 +05:30
|
|
|
self.nlist = set()
|
2004-07-11 11:33:07 +05:30
|
|
|
|
2006-05-23 05:26:57 +05:30
|
|
|
# Collect needed families
|
|
|
|
for handle in list(self.plist):
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
for family_handle in person.get_family_handle_list():
|
2006-06-23 00:02:16 +05:30
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2006-05-23 05:26:57 +05:30
|
|
|
self.flist.add(family_handle)
|
2007-08-06 09:41:52 +05:30
|
|
|
|
2007-08-09 10:05:06 +05:30
|
|
|
def __writeln(self, level, token, textlines="", limit=72):
|
|
|
|
if textlines:
|
|
|
|
textlist = textlines.split('\n')
|
|
|
|
token_level = level
|
|
|
|
for text in textlist:
|
|
|
|
if limit:
|
|
|
|
prefix = "\n%d CONC " % (level + 1)
|
2007-08-10 09:23:48 +05:30
|
|
|
txt = prefix.join(breakup(text, limit))
|
2007-08-09 10:05:06 +05:30
|
|
|
else:
|
2007-08-10 09:23:48 +05:30
|
|
|
txt = text
|
2007-08-09 10:05:06 +05:30
|
|
|
self.g.write("%d %s %s\n" % (token_level, token, txt))
|
|
|
|
token_level = level+1
|
|
|
|
token = "CONT"
|
2007-08-06 09:41:52 +05:30
|
|
|
else:
|
|
|
|
self.g.write("%d %s\n" % (level, token))
|
2004-07-11 11:33:07 +05:30
|
|
|
|
2006-05-23 05:26:57 +05:30
|
|
|
def gui_setup(self):
|
|
|
|
# Get settings from the options store/dialog
|
|
|
|
self.option_box.parse_options()
|
|
|
|
|
|
|
|
self.restrict = self.option_box.restrict
|
2007-08-25 10:33:23 +05:30
|
|
|
self.private = self.option_box.private
|
|
|
|
|
|
|
|
if self.private:
|
2007-08-28 09:27:56 +05:30
|
|
|
from _PrivateProxyDb import PrivateProxyDb
|
|
|
|
self.db = PrivateProxyDb(self.db)
|
|
|
|
|
|
|
|
if self.restrict:
|
|
|
|
from _LivingProxyDb import LivingProxyDb
|
|
|
|
self.db = LivingProxyDb(self.db, LivingProxyDb.MODE_RESTRICT)
|
2006-05-23 05:26:57 +05:30
|
|
|
|
|
|
|
if self.option_box.cfilter == None:
|
|
|
|
self.plist = set(self.db.get_person_handles(sort_handles=False))
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
self.plist = set(self.option_box.cfilter.apply(
|
2007-08-06 09:41:52 +05:30
|
|
|
self.db, self.db.get_person_handles(sort_handles=False)))
|
2006-05-23 05:26:57 +05:30
|
|
|
return True
|
|
|
|
except Errors.FilterError, msg:
|
2007-08-06 09:41:52 +05:30
|
|
|
(m1, m2) = msg.messages()
|
|
|
|
ErrorDialog(m1, m2)
|
2006-05-23 05:26:57 +05:30
|
|
|
return False
|
|
|
|
|
|
|
|
def cli_setup(self):
|
|
|
|
# use default settings
|
2003-05-21 02:01:16 +05:30
|
|
|
self.restrict = 0
|
2007-08-25 10:33:23 +05:30
|
|
|
self.private = 0
|
2003-05-21 02:01:16 +05:30
|
|
|
|
2006-05-23 05:26:57 +05:30
|
|
|
self.plist = set(self.db.get_person_handles(sort_handles=False))
|
2003-05-21 02:01:16 +05:30
|
|
|
|
2006-05-23 05:26:57 +05:30
|
|
|
return True
|
2003-05-21 02:01:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def export_data(self, filename):
|
2004-07-11 11:33:07 +05:30
|
|
|
|
2003-11-03 17:28:15 +05:30
|
|
|
self.dirname = os.path.dirname (filename)
|
2002-10-20 19:55:16 +05:30
|
|
|
try:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.g = open(filename, "w")
|
|
|
|
except IOError, msg:
|
2003-03-21 09:55:55 +05:30
|
|
|
msg2 = _("Could not create %s") % filename
|
2007-08-06 09:41:52 +05:30
|
|
|
ErrorDialog(msg2, str(msg))
|
2004-07-14 07:14:04 +05:30
|
|
|
return 0
|
2002-10-20 19:55:16 +05:30
|
|
|
except:
|
2003-03-21 09:55:55 +05:30
|
|
|
ErrorDialog(_("Could not create %s") % filename)
|
2004-07-14 07:14:04 +05:30
|
|
|
return 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
self.set_total(len(self.plist) + len(self.flist))
|
|
|
|
|
|
|
|
self.__write_header(filename)
|
|
|
|
self.__write_submitter()
|
|
|
|
self.__write_individuals()
|
|
|
|
self.__write_families()
|
|
|
|
self.__write_sources()
|
|
|
|
self.__write_repos()
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_notes()
|
2007-08-06 09:41:52 +05:30
|
|
|
|
|
|
|
self.__writeln(0, "TRLR")
|
|
|
|
self.g.close()
|
|
|
|
return 1
|
|
|
|
|
|
|
|
def __write_header(self, filename):
|
|
|
|
"""
|
2007-08-08 09:54:49 +05:30
|
|
|
Writes the GEDCOM header.
|
|
|
|
|
|
|
|
HEADER:=
|
|
|
|
n HEAD {1:1}
|
2007-08-13 09:10:36 +05:30
|
|
|
+1 SOUR <APPROVED_SYSTEM_ID> {1:1}
|
|
|
|
+2 VERS <VERSION_NUMBER> {0:1}
|
|
|
|
+2 NAME <NAME_OF_PRODUCT> {0:1}
|
|
|
|
+2 CORP <NAME_OF_BUSINESS> {0:1} # Not used
|
|
|
|
+3 <<ADDRESS_STRUCTURE>> {0:1} # Not used
|
|
|
|
+2 DATA <NAME_OF_SOURCE_DATA> {0:1} # Not used
|
|
|
|
+3 DATE <PUBLICATION_DATE> {0:1} # Not used
|
|
|
|
+3 COPR <COPYRIGHT_SOURCE_DATA> {0:1} # Not used
|
|
|
|
+1 DEST <RECEIVING_SYSTEM_NAME> {0:1*} # Not used
|
|
|
|
+1 DATE <TRANSMISSION_DATE> {0:1}
|
|
|
|
+2 TIME <TIME_VALUE> {0:1}
|
|
|
|
+1 SUBM @XREF:SUBM@ {1:1}
|
|
|
|
+1 SUBN @XREF:SUBN@ {0:1}
|
|
|
|
+1 FILE <FILE_NAME> {0:1}
|
|
|
|
+1 COPR <COPYRIGHT_GEDCOM_FILE> {0:1}
|
2007-08-08 09:54:49 +05:30
|
|
|
+1 GEDC {1:1}
|
2007-08-13 09:10:36 +05:30
|
|
|
+2 VERS <VERSION_NUMBER> {1:1}
|
|
|
|
+2 FORM <GEDCOM_FORM> {1:1}
|
|
|
|
+1 CHAR <CHARACTER_SET> {1:1}
|
|
|
|
+2 VERS <VERSION_NUMBER> {0:1}
|
|
|
|
+1 LANG <LANGUAGE_OF_TEXT> {0:1}
|
2007-08-08 09:54:49 +05:30
|
|
|
+1 PLAC {0:1}
|
2007-08-13 09:10:36 +05:30
|
|
|
+2 FORM <PLACE_HIERARCHY> {1:1}
|
|
|
|
+1 NOTE <GEDCOM_CONTENT_DESCRIPTION> {0:1}
|
2007-08-08 09:54:49 +05:30
|
|
|
+2 [CONT|CONC] <GEDCOM_CONTENT_DESCRIPTION> {0:M}
|
2007-08-06 09:41:52 +05:30
|
|
|
"""
|
2007-08-08 09:54:49 +05:30
|
|
|
(year, mon, day, hour, min, sec, x, y, z) = time.localtime(time.time())
|
|
|
|
date_str = "%d %s %d" % (day, _month[mon], year)
|
|
|
|
time_str = "%02d:%02d:%02d" % (hour, min, sec)
|
|
|
|
rname = self.db.get_researcher().get_name()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(0, "HEAD")
|
|
|
|
self.__writeln(1, "SOUR", "GRAMPS")
|
|
|
|
self.__writeln(2, "VERS", const.version)
|
|
|
|
self.__writeln(2, "NAME", "GRAMPS")
|
|
|
|
self.__writeln(1, "DATE", date_str)
|
2007-08-08 09:54:49 +05:30
|
|
|
self.__writeln(2, "TIME", time_str)
|
|
|
|
self.__writeln(1, "SUBM", "@SUBM@")
|
|
|
|
self.__writeln(1, "FILE", filename)
|
|
|
|
self.__writeln(1, "COPR", 'Copyright (c) %d %s.' % (year, rname))
|
|
|
|
self.__writeln(1, "GEDC")
|
|
|
|
self.__writeln(2, "VERS", "5.5")
|
|
|
|
self.__writeln(2, "FORM", 'LINEAGE-LINKED')
|
2007-08-10 09:23:48 +05:30
|
|
|
self.__writeln(1, "CHAR", "UTF-8")
|
2007-08-13 09:10:36 +05:30
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
# write the language string if the current LANG variable
|
|
|
|
# matches something we know about.
|
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
lang = os.getenv('LANG')
|
|
|
|
if lang and len(lang) >= 2:
|
|
|
|
lang_code = LANGUAGES.get(lang[0:2])
|
|
|
|
if lang_code:
|
|
|
|
self.__writeln(1, 'LANG', lang_code)
|
2007-08-06 09:41:52 +05:30
|
|
|
|
|
|
|
def __write_submitter(self):
|
|
|
|
"""
|
2007-08-13 09:10:36 +05:30
|
|
|
n @<XREF:SUBM>@ SUBM {1:1}
|
|
|
|
+1 NAME <SUBMITTER_NAME> {1:1}
|
|
|
|
+1 <<ADDRESS_STRUCTURE>> {0:1}
|
|
|
|
+1 <<MULTIMEDIA_LINK>> {0:M} # not used
|
|
|
|
+1 LANG <LANGUAGE_PREFERENCE> {0:3} # not used
|
|
|
|
+1 RFN <SUBMITTER_REGISTERED_RFN> {0:1} # not used
|
|
|
|
+1 RIN <AUTOMATED_RECORD_ID> {0:1} # not used
|
|
|
|
+1 <<CHANGE_DATE>> {0:1} # not used
|
2007-08-06 09:41:52 +05:30
|
|
|
"""
|
2004-02-14 11:10:30 +05:30
|
|
|
owner = self.db.get_researcher()
|
2007-08-06 09:41:52 +05:30
|
|
|
(name, addr, city, stae, ctry, post, phon, mail) = owner.get()
|
|
|
|
if not name :
|
|
|
|
name = u'Not Provided'
|
|
|
|
if not addr :
|
|
|
|
addr = u'Not Provided'
|
2007-02-07 16:10:56 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(0, "@SUBM@", "SUBM")
|
|
|
|
self.__writeln(1, "NAME", name)
|
|
|
|
self.__writeln(1, "ADDR", addr)
|
2007-08-08 09:54:49 +05:30
|
|
|
if city and stae and post:
|
|
|
|
self.__writeln(2, "CONT", "%s, %s %s" % (city, stae, post))
|
2007-08-15 09:02:08 +05:30
|
|
|
else:
|
|
|
|
self.__writeln(2, "CONT", u"Not Provided")
|
2007-08-08 09:54:49 +05:30
|
|
|
if city:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, "CITY", city)
|
2007-08-08 09:54:49 +05:30
|
|
|
if stae:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, "STAE", stae)
|
2007-08-08 09:54:49 +05:30
|
|
|
if post:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, "POST", post)
|
2007-08-08 09:54:49 +05:30
|
|
|
if ctry:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, "CTRY", ctry)
|
2007-08-08 09:54:49 +05:30
|
|
|
if phon:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(1, "PHON", phon)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def __write_individuals(self):
|
|
|
|
"""
|
|
|
|
INDIVIDUAL RECORDS
|
|
|
|
"""
|
2004-08-22 22:00:43 +05:30
|
|
|
sorted = []
|
2006-05-23 05:26:57 +05:30
|
|
|
for handle in self.plist:
|
|
|
|
person = self.db.get_person_from_handle (handle)
|
2007-08-08 09:54:49 +05:30
|
|
|
data = (person.get_gramps_id (), handle)
|
2004-10-06 09:12:54 +05:30
|
|
|
sorted.append (data)
|
2004-08-22 22:00:43 +05:30
|
|
|
sorted.sort()
|
2007-08-06 09:41:52 +05:30
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
for data in sorted:
|
2007-08-28 09:27:56 +05:30
|
|
|
self.__write_person(self.db.get_person_from_handle(data[1]))
|
2006-03-01 11:46:36 +05:30
|
|
|
self.update()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def __write_person(self, person):
|
|
|
|
"""
|
|
|
|
Writes out a single person
|
2007-08-09 10:05:06 +05:30
|
|
|
|
|
|
|
n @XREF:INDI@ INDI {1:1}
|
2007-08-13 09:10:36 +05:30
|
|
|
+1 RESN <RESTRICTION_NOTICE> {0:1} # not used
|
|
|
|
+1 <<PERSONAL_NAME_STRUCTURE>> {0:M}
|
|
|
|
+1 SEX <SEX_VALUE> {0:1}
|
|
|
|
+1 <<INDIVIDUAL_EVENT_STRUCTURE>> {0:M}
|
|
|
|
+1 <<INDIVIDUAL_ATTRIBUTE_STRUCTURE>> {0:M}
|
|
|
|
+1 <<LDS_INDIVIDUAL_ORDINANCE>> {0:M}
|
|
|
|
+1 <<CHILD_TO_FAMILY_LINK>> {0:M}
|
|
|
|
+1 <<SPOUSE_TO_FAMILY_LINK>> {0:M}
|
|
|
|
+1 SUBM @<XREF:SUBM>@ {0:M}
|
|
|
|
+1 <<ASSOCIATION_STRUCTURE>> {0:M}
|
|
|
|
+1 ALIA @<XREF:INDI>@ {0:M}
|
|
|
|
+1 ANCI @<XREF:SUBM>@ {0:M}
|
|
|
|
+1 DESI @<XREF:SUBM>@ {0:M}
|
|
|
|
+1 <<SOURCE_CITATION>> {0:M}
|
|
|
|
+1 <<MULTIMEDIA_LINK>> {0:M} ,*
|
|
|
|
+1 <<NOTE_STRUCTURE>> {0:M}
|
|
|
|
+1 RFN <PERMANENT_RECORD_FILE_NUMBER> {0:1}
|
|
|
|
+1 AFN <ANCESTRAL_FILE_NUMBER> {0:1}
|
|
|
|
+1 REFN <USER_REFERENCE_NUMBER> {0:M}
|
|
|
|
+2 TYPE <USER_REFERENCE_TYPE> {0:1}
|
|
|
|
+1 RIN <AUTOMATED_RECORD_ID> {0:1}
|
|
|
|
+1 <<CHANGE_DATE>> {0:1}
|
2007-08-06 09:41:52 +05:30
|
|
|
"""
|
|
|
|
self.__writeln(0, "@%s@" % person.get_gramps_id(), "INDI")
|
|
|
|
|
|
|
|
self.__write_names(person)
|
|
|
|
self.__write_gender(person)
|
|
|
|
self.__write_person_event_ref('BIRT', person.get_birth_ref())
|
|
|
|
self.__write_person_event_ref('DEAT', person.get_death_ref())
|
|
|
|
self.__write_remaining_events(person)
|
|
|
|
self.__write_attributes(person)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_lds_ords(person, 1)
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__write_child_families(person)
|
|
|
|
self.__write_parent_families(person)
|
2007-08-13 09:10:36 +05:30
|
|
|
self.__write_assoc(person, 1)
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__write_person_sources(person)
|
2007-08-13 05:30:16 +05:30
|
|
|
self.__write_addresses(person)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_photos(person.get_media_list(), 1)
|
2007-08-15 09:02:08 +05:30
|
|
|
self.__write_url_list(person, 1)
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_note_references(person.get_note_list(), 1)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_change(person.get_change_time(), 1)
|
2007-08-06 09:41:52 +05:30
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
def __write_assoc(self, person, level):
|
|
|
|
"""
|
|
|
|
n ASSO @<XREF:INDI>@ {0:M}
|
|
|
|
+1 TYPE <RECORD_TYPE> {1:1}
|
|
|
|
+1 RELA <RELATION_IS_DESCRIPTOR> {1:1}
|
|
|
|
+1 <<NOTE_STRUCTURE>> {0:M}
|
|
|
|
+1 <<SOURCE_CITATION>> {0:M}
|
|
|
|
"""
|
|
|
|
for ref in person.get_person_ref_list():
|
|
|
|
person = self.db.get_person_from_handle(ref.ref)
|
|
|
|
self.__writeln(level, "ASSO", "@%s@" % person.get_gramps_id())
|
|
|
|
self.__writeln(level+1, "TYPE", ref.get_relation())
|
|
|
|
self.__write_note_references(ref.get_note_list(), level+1)
|
|
|
|
self.__write_source_references(ref.get_source_references, level+1)
|
|
|
|
|
2007-08-09 10:05:06 +05:30
|
|
|
def __write_note_references(self, notelist, level):
|
|
|
|
for note_handle in notelist:
|
|
|
|
note = self.db.get_note_from_handle(note_handle)
|
|
|
|
self.__writeln(level, 'NOTE', '@%s@' % note.get_gramps_id())
|
|
|
|
self.nlist.add(note_handle)
|
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def __write_names(self, person):
|
2007-08-09 10:05:06 +05:30
|
|
|
nicknames = [ attr.get_value() for attr in person.get_attribute_list()
|
|
|
|
if int(attr.get_type()) == RelLib.AttributeType.NICKNAME ]
|
|
|
|
if len(nicknames) > 0:
|
|
|
|
nickname = nicknames[0]
|
|
|
|
else:
|
|
|
|
nickname = ""
|
2007-08-06 09:41:52 +05:30
|
|
|
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_person_name(person.get_primary_name(), nickname)
|
|
|
|
for name in person.get_alternate_names():
|
|
|
|
self.__write_person_name(name, "")
|
2007-08-06 09:41:52 +05:30
|
|
|
|
|
|
|
def __write_gender(self, person):
|
|
|
|
if person.get_gender() == RelLib.Person.MALE:
|
|
|
|
self.__writeln(1, "SEX", "M")
|
|
|
|
elif person.get_gender() == RelLib.Person.FEMALE:
|
|
|
|
self.__writeln(1, "SEX", "F")
|
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
def __write_lds_ords(self, obj, level):
|
|
|
|
for lds_ord in obj.get_lds_ord_list():
|
|
|
|
self.write_ord(lds_ord, level)
|
2007-08-06 09:41:52 +05:30
|
|
|
|
|
|
|
def __write_remaining_events(self, person):
|
|
|
|
|
2007-08-15 09:44:19 +05:30
|
|
|
ad = False
|
2007-08-06 09:41:52 +05:30
|
|
|
for event_ref in person.get_event_ref_list():
|
|
|
|
event = self.db.get_event_from_handle(event_ref.ref)
|
|
|
|
etype = int(event.get_type())
|
|
|
|
|
|
|
|
if etype in (RelLib.EventType.BIRTH, RelLib.EventType.DEATH):
|
|
|
|
continue
|
|
|
|
|
2007-08-22 09:17:51 +05:30
|
|
|
val = GedcomInfo.personalConstantEvents.get(etype, "")
|
2007-08-06 09:41:52 +05:30
|
|
|
|
2007-08-15 09:44:19 +05:30
|
|
|
if val and val.strip():
|
2007-08-06 09:41:52 +05:30
|
|
|
if val in personalAttributeTakesParam:
|
|
|
|
if event.get_description().strip():
|
|
|
|
self.__writeln(1, val, event.get_description())
|
|
|
|
else:
|
|
|
|
self.__writeln(1, val)
|
|
|
|
else:
|
|
|
|
if (not event.get_date_object().is_empty()) \
|
|
|
|
or event.get_place_handle():
|
|
|
|
self.__writeln(1, val)
|
|
|
|
else:
|
|
|
|
self.__writeln(1, val, 'Y')
|
|
|
|
if event.get_description().strip():
|
|
|
|
self.__writeln(2, 'TYPE', event.get_description())
|
|
|
|
else:
|
2007-08-21 09:47:12 +05:30
|
|
|
self.__writeln(1, 'EVEN')
|
2007-08-06 09:41:52 +05:30
|
|
|
if val.strip():
|
|
|
|
self.__writeln(2, 'TYPE', val)
|
|
|
|
else:
|
|
|
|
self.__writeln(2, 'TYPE', str(event.get_type()))
|
2007-08-23 09:21:05 +05:30
|
|
|
descr = event.get_description()
|
|
|
|
if descr:
|
|
|
|
self.__writeln(2, 'NOTE', "Description: " + descr)
|
2007-08-06 09:41:52 +05:30
|
|
|
|
|
|
|
self.dump_event_stats(event, event_ref)
|
2006-05-21 09:44:47 +05:30
|
|
|
|
2007-08-15 09:44:19 +05:30
|
|
|
self.__write_adoption_record(person)
|
2007-08-06 09:41:52 +05:30
|
|
|
|
|
|
|
def __write_adoption_record(self, person):
|
2007-08-15 09:44:19 +05:30
|
|
|
|
|
|
|
adopt_records = []
|
|
|
|
|
|
|
|
for family in [ self.db.get_family_from_handle(fh)
|
|
|
|
for fh in person.get_parent_family_handle_list() ]:
|
2007-08-06 09:41:52 +05:30
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
if child_ref.ref == person.handle:
|
|
|
|
if child_ref.mrel == RelLib.ChildRefType.ADOPTED \
|
|
|
|
or child_ref.frel == RelLib.ChildRefType.ADOPTED:
|
2007-08-15 09:44:19 +05:30
|
|
|
adopt_records.append((family, child_ref.frel, child_ref.mrel))
|
|
|
|
|
|
|
|
for (fam, frel, mrel) in adopt_records:
|
|
|
|
self.__writeln(1, 'ADOP', 'Y')
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'FAMC', '@%s@' % fam.get_gramps_id())
|
|
|
|
if mrel == frel:
|
|
|
|
self.__writeln(3, 'ADOP', 'BOTH')
|
|
|
|
elif mrel == RelLib.ChildRefType.ADOPTED:
|
|
|
|
self.__writeln(3, 'ADOP', 'WIFE')
|
|
|
|
else:
|
|
|
|
self.__writeln(3, 'ADOP', 'HUSB')
|
|
|
|
|
|
|
|
def __write_attributes(self, person):
|
2007-08-19 08:55:07 +05:30
|
|
|
|
|
|
|
# filter out the Nicknames, since they have already been
|
|
|
|
# processed.
|
|
|
|
|
|
|
|
attr_list = [ attr for attr in person.get_attribute_list()
|
|
|
|
if attr.get_type() != RelLib.AttributeType.NICKNAME ]
|
|
|
|
|
|
|
|
for attr in attr_list:
|
2007-08-06 09:41:52 +05:30
|
|
|
|
|
|
|
t = int(attr.get_type())
|
|
|
|
name = GedcomInfo.personalConstantAttributes.get(t)
|
|
|
|
key = str(attr.get_type())
|
|
|
|
value = attr.get_value().strip().replace('\r', ' ')
|
|
|
|
|
2007-08-16 10:00:49 +05:30
|
|
|
if key in ("AFN", "RFN", "REFN", "_UID"):
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(1, name, value)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if key == "RESN":
|
|
|
|
self.__writeln(1, 'RESN')
|
|
|
|
continue
|
|
|
|
|
|
|
|
if name and name.strip():
|
|
|
|
self.__writeln(1, name, value)
|
2007-08-23 09:21:05 +05:30
|
|
|
elif value:
|
|
|
|
self.__writeln(1, 'FACT', value)
|
|
|
|
self.__writeln(2, 'TYPE', key)
|
2007-08-06 09:41:52 +05:30
|
|
|
else:
|
2007-08-23 09:21:05 +05:30
|
|
|
continue
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_note_references(attr.get_note_list(), 2)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_source_references(attr.get_source_references(), 2)
|
2007-08-06 09:41:52 +05:30
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
def __write_source_references(self, ref_list, level):
|
|
|
|
for srcref in ref_list:
|
|
|
|
self.write_source_ref(level, srcref)
|
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def __write_addresses(self, person):
|
|
|
|
for addr in person.get_address_list():
|
|
|
|
self.__writeln(1, 'RESI')
|
2007-08-13 05:30:16 +05:30
|
|
|
self.print_date(2, addr.get_date_object())
|
|
|
|
self.__writeln(2, "ADDR", addr.get_street())
|
|
|
|
if addr.get_city():
|
|
|
|
self.__writeln(3, 'CITY', addr.get_city())
|
|
|
|
if addr.get_state():
|
|
|
|
self.__writeln(3, 'STAE', addr.get_state())
|
|
|
|
if addr.get_postal_code():
|
|
|
|
self.__writeln(3, 'POST', addr.get_postal_code())
|
|
|
|
if addr.get_country():
|
|
|
|
self.__writeln(3, 'CTRY', addr.get_country())
|
|
|
|
if addr.get_phone():
|
|
|
|
self.__writeln(2, 'PHON', addr.get_phone())
|
2007-08-14 09:32:18 +05:30
|
|
|
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_note_references(addr.get_note_list(), 2)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_source_references(addr.get_source_references(), 2)
|
2007-08-06 09:41:52 +05:30
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
def __write_photos(self, media_list, level):
|
2007-08-25 10:33:23 +05:30
|
|
|
for photo in media_list:
|
|
|
|
self.__write_photo(photo, level)
|
2007-08-06 09:41:52 +05:30
|
|
|
|
|
|
|
def __write_child_families(self, person):
|
|
|
|
hndl_list = [ hndl for hndl in person.get_parent_family_handle_list() \
|
|
|
|
if hndl and hndl in self.flist ]
|
|
|
|
|
|
|
|
for family_handle in hndl_list:
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
|
|
|
family_id = family.get_gramps_id()
|
|
|
|
self.__writeln(1, 'FAMC', '@%s@' % family_id)
|
|
|
|
|
|
|
|
def __write_parent_families(self, person):
|
|
|
|
for family_handle in person.get_family_handle_list():
|
|
|
|
if family_handle in self.flist:
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
|
|
|
self.__writeln(1, 'FAMS', '@%s@' % family.get_gramps_id())
|
|
|
|
|
|
|
|
def __write_person_sources(self, person):
|
|
|
|
for srcref in person.get_source_references():
|
|
|
|
self.write_source_ref(1, srcref)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-15 09:02:08 +05:30
|
|
|
def __write_url_list(self, obj, level):
|
|
|
|
"""
|
|
|
|
n OBJE {1:1}
|
|
|
|
+1 FORM <MULTIMEDIA_FORMAT> {1:1}
|
|
|
|
+1 TITL <DESCRIPTIVE_TITLE> {0:1}
|
|
|
|
+1 FILE <MULTIMEDIA_FILE_REFERENCE> {1:1}
|
|
|
|
+1 <<NOTE_STRUCTURE>> {0:M}
|
|
|
|
"""
|
|
|
|
for url in obj.get_url_list():
|
|
|
|
self.__writeln(level, 'OBJE')
|
|
|
|
self.__writeln(level+1, 'FORM', 'URL')
|
2007-08-13 05:30:16 +05:30
|
|
|
if url.get_description():
|
2007-08-15 09:02:08 +05:30
|
|
|
self.__writeln(level+1, 'TITL', url.get_description())
|
|
|
|
if url.get_path():
|
|
|
|
self.__writeln(level+1, 'FILE', url.get_path())
|
2004-06-10 05:29:03 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def __write_families(self):
|
2004-08-23 04:41:30 +05:30
|
|
|
sorted = []
|
2007-08-06 09:41:52 +05:30
|
|
|
|
2006-05-23 05:26:57 +05:30
|
|
|
for family_handle in self.flist:
|
2004-08-11 22:30:38 +05:30
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2007-08-14 09:32:18 +05:30
|
|
|
data = (family.get_gramps_id(), family_handle)
|
2004-10-06 09:12:54 +05:30
|
|
|
sorted.append (data)
|
2004-08-23 04:41:30 +05:30
|
|
|
sorted.sort ()
|
2007-08-08 09:54:49 +05:30
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
for (gramps_id, family_handle) in sorted:
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2007-08-13 09:10:36 +05:30
|
|
|
self.__write_family(family)
|
2004-06-10 05:29:03 +05:30
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
def __write_family_reference(self, token, person_handle):
|
2007-08-14 09:32:18 +05:30
|
|
|
if person_handle != None and person_handle in self.plist:
|
2007-08-13 09:10:36 +05:30
|
|
|
person = self.db.get_person_from_handle(person_handle)
|
|
|
|
gramps_id = person.get_gramps_id()
|
|
|
|
self.__writeln(1, token, '@%s@' % gramps_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
def __write_family(self, family):
|
2006-06-07 10:13:18 +05:30
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
gramps_id = family.get_gramps_id()
|
|
|
|
family_handle = family.get_handle()
|
2006-06-07 10:13:18 +05:30
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
self.__writeln(0, '@%s@' % gramps_id, 'FAM' )
|
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_family_reference('HUSB', family.get_father_handle())
|
|
|
|
self.__write_family_reference('WIFE', family.get_mother_handle())
|
2007-08-13 09:10:36 +05:30
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_lds_ords(family, 1)
|
|
|
|
self.__write_family_events(family)
|
2007-07-06 08:45:26 +05:30
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
self.__write_family_attributes(family.get_attribute_list(), 1)
|
2007-08-16 10:00:49 +05:30
|
|
|
|
|
|
|
|
|
|
|
child_list = [ self.db.get_person_from_handle(cref.ref).get_gramps_id()
|
|
|
|
for cref in family.get_child_ref_list()
|
|
|
|
if cref.ref in self.plist]
|
|
|
|
child_list.sort()
|
|
|
|
|
|
|
|
for gid in child_list:
|
|
|
|
self.__writeln(1, 'CHIL', '@%s@' % gid)
|
2004-06-10 05:29:03 +05:30
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
self.__write_source_references(family.get_source_references(), 1)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_photos(family.get_media_list(), 1)
|
2007-08-13 09:10:36 +05:30
|
|
|
self.__write_note_references(family.get_note_list(), 1)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_change(family.get_change_time(), 1)
|
2007-08-13 09:10:36 +05:30
|
|
|
self.update()
|
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
def __write_family_events(self, family):
|
|
|
|
|
|
|
|
for event_ref in [ ref for ref in family.get_event_ref_list()]:
|
|
|
|
event = self.db.get_event_from_handle(event_ref.ref)
|
|
|
|
if not event:
|
|
|
|
continue
|
|
|
|
|
|
|
|
etype = int(event.get_type())
|
|
|
|
val = GedcomInfo.familyConstantEvents.get(etype)
|
|
|
|
|
|
|
|
if val:
|
|
|
|
if (not event.get_date_object().is_empty()) \
|
|
|
|
or event.get_place_handle():
|
|
|
|
self.__writeln(1, val)
|
|
|
|
else:
|
|
|
|
self.__writeln(1, val, 'Y')
|
|
|
|
|
|
|
|
if event.get_type() == RelLib.EventType.MARRIAGE:
|
|
|
|
ftype = family.get_relationship()
|
|
|
|
if ftype != RelLib.FamilyRelType.MARRIED and str(ftype):
|
|
|
|
self.__writeln(2, 'TYPE', str(ftype))
|
|
|
|
|
|
|
|
self.__write_family_event_attrs(event.get_attribute_list(), 2)
|
|
|
|
elif event.get_description().strip() != "":
|
|
|
|
self.__writeln(2, 'TYPE', event.get_description())
|
|
|
|
else:
|
|
|
|
self.__writeln(1, 'EVEN')
|
|
|
|
the_type = str(event.get_type())
|
|
|
|
if the_type:
|
|
|
|
self.__writeln(2, 'TYPE', the_type)
|
2007-08-23 09:21:05 +05:30
|
|
|
descr = event.get_description()
|
|
|
|
if descr:
|
|
|
|
self.__writeln(2, 'NOTE', "Description: " + descr)
|
2007-08-14 09:32:18 +05:30
|
|
|
|
|
|
|
self.dump_event_stats(event, event_ref)
|
|
|
|
|
|
|
|
|
|
|
|
def __write_family_event_attrs(self, attr_list, level):
|
|
|
|
for attr in attr_list:
|
|
|
|
if attr.get_type() == RelLib.AttributeType.FATHER_AGE:
|
|
|
|
self.__writeln(level, 'HUSB')
|
|
|
|
self.__writeln(level+1, 'AGE', attr.get_value())
|
|
|
|
elif attr.get_type() == RelLib.AttributeType.MOTHER_AGE:
|
|
|
|
self.__writeln(level, 'WIFE')
|
|
|
|
self.__writeln(level+1, 'AGE', attr.get_value())
|
|
|
|
|
2007-08-13 09:10:36 +05:30
|
|
|
def __write_family_attributes(self, attr_list, level):
|
|
|
|
|
|
|
|
for attr in attr_list:
|
|
|
|
|
|
|
|
t = int(attr.get_type())
|
|
|
|
name = GedcomInfo.familyConstantAttributes.get(t)
|
|
|
|
value = attr.get_value().replace('\r', ' ')
|
2007-08-16 10:00:49 +05:30
|
|
|
|
|
|
|
if t in ("AFN", "RFN", "REFN", "_UID"):
|
|
|
|
self.__writeln(1, t, value)
|
|
|
|
continue
|
2007-08-13 09:10:36 +05:30
|
|
|
|
|
|
|
if name and name.strip():
|
|
|
|
self.__writeln(1, name, value)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
the_name = str(attr.get_type())
|
|
|
|
self.__writeln(level, 'EVEN')
|
|
|
|
if value:
|
|
|
|
self.__writeln(level+1, 'TYPE', '%s %s' % (the_name, value))
|
|
|
|
else:
|
|
|
|
self.__writeln(level+1, 'TYPE', the_name)
|
|
|
|
|
|
|
|
self.__write_note_references(attr.get_note_list(), level+1)
|
|
|
|
self.__write_source_references(attr.get_source_references(), level+1)
|
2007-07-06 08:45:26 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def __write_sources(self):
|
2004-08-23 16:56:24 +05:30
|
|
|
sorted = []
|
2006-05-23 05:26:57 +05:30
|
|
|
for handle in self.slist:
|
2005-07-09 01:54:54 +05:30
|
|
|
source = self.db.get_source_from_handle(handle)
|
2005-05-24 18:38:06 +05:30
|
|
|
if not source:
|
|
|
|
continue
|
2007-08-16 10:00:49 +05:30
|
|
|
data = (source.get_gramps_id(), handle)
|
2004-10-06 09:12:54 +05:30
|
|
|
sorted.append (data)
|
2004-08-23 16:56:24 +05:30
|
|
|
sorted.sort ()
|
2006-05-23 05:26:57 +05:30
|
|
|
|
2007-08-16 10:00:49 +05:30
|
|
|
for (source_id, handle) in sorted:
|
|
|
|
source = self.db.get_source_from_handle(handle)
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(0, '@%s@' % source_id, 'SOUR')
|
2004-02-14 11:10:30 +05:30
|
|
|
if source.get_title():
|
2007-08-08 09:54:49 +05:30
|
|
|
self.__writeln(1, 'TITL', source.get_title())
|
2006-05-02 02:41:26 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if source.get_author():
|
2007-08-08 09:54:49 +05:30
|
|
|
self.__writeln(1, "AUTH", source.get_author())
|
2006-05-02 02:41:26 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if source.get_publication_info():
|
2007-08-08 09:54:49 +05:30
|
|
|
self.__writeln(1, "PUBL", source.get_publication_info())
|
2006-05-02 02:41:26 +05:30
|
|
|
|
2004-06-10 05:29:03 +05:30
|
|
|
if source.get_abbreviation():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(1, 'ABBR', source.get_abbreviation())
|
2007-08-08 09:54:49 +05:30
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_photos(source.get_media_list(), 1)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-05-22 05:02:34 +05:30
|
|
|
for reporef in source.get_reporef_list():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.write_reporef(reporef, 1)
|
2007-08-15 09:02:08 +05:30
|
|
|
break
|
2006-05-22 05:02:34 +05:30
|
|
|
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_note_references(source.get_note_list(), 1)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_change(source.get_change_time(), 1)
|
2007-08-09 10:05:06 +05:30
|
|
|
|
|
|
|
def __write_notes(self):
|
2007-08-16 10:00:49 +05:30
|
|
|
sorted = []
|
|
|
|
for handle in self.nlist:
|
|
|
|
note = self.db.get_note_from_handle(handle)
|
|
|
|
data = (note.get_gramps_id(), handle)
|
|
|
|
sorted.append (data)
|
|
|
|
sorted.sort ()
|
2007-08-09 10:05:06 +05:30
|
|
|
|
2007-08-16 10:00:49 +05:30
|
|
|
for (node_id, note_handle) in sorted:
|
2007-08-09 10:05:06 +05:30
|
|
|
note = self.db.get_note_from_handle(note_handle)
|
|
|
|
self.__write_note_record(note)
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2007-08-09 10:05:06 +05:30
|
|
|
def __write_note_record(self, note):
|
|
|
|
"""
|
2007-08-13 09:10:36 +05:30
|
|
|
n @<XREF:NOTE>@ NOTE <SUBMITTER_TEXT> {1:1}
|
2007-08-09 10:05:06 +05:30
|
|
|
+1 [ CONC | CONT] <SUBMITTER_TEXT> {0:M}
|
2007-08-13 09:10:36 +05:30
|
|
|
+1 <<SOURCE_CITATION>> {0:M}
|
|
|
|
+1 REFN <USER_REFERENCE_NUMBER> {0:M}
|
|
|
|
+2 TYPE <USER_REFERENCE_TYPE> {0:1}
|
|
|
|
+1 RIN <AUTOMATED_RECORD_ID> {0:1}
|
|
|
|
+1 <<CHANGE_DATE>> {0:1}
|
2007-08-09 10:05:06 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
self.__writeln(0, '@%s@' % note.get_gramps_id(), 'NOTE ' + note.get())
|
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def __write_repos(self):
|
2006-05-22 05:02:34 +05:30
|
|
|
sorted = []
|
|
|
|
for handle in self.rlist:
|
|
|
|
repo = self.db.get_repository_from_handle(handle)
|
|
|
|
repo_id = repo.get_gramps_id()
|
2007-08-16 10:00:49 +05:30
|
|
|
sorted.append((repo_id, handle))
|
2006-05-22 05:02:34 +05:30
|
|
|
|
|
|
|
sorted.sort()
|
2006-05-23 05:26:57 +05:30
|
|
|
|
|
|
|
slist = set()
|
2007-08-15 09:02:08 +05:30
|
|
|
|
|
|
|
# GEDCOM only allows for a single repository per source
|
|
|
|
|
2007-08-16 10:00:49 +05:30
|
|
|
for (repo_id, handle) in sorted:
|
|
|
|
repo = self.db.get_repository_from_handle(handle)
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(0, '@%s@' % repo_id, 'REPO' )
|
2006-05-22 05:02:34 +05:30
|
|
|
if repo.get_name():
|
2007-08-08 09:54:49 +05:30
|
|
|
self.__writeln(1, 'NAME', repo.get_name())
|
2006-05-22 05:02:34 +05:30
|
|
|
for addr in repo.get_address_list():
|
2007-08-08 09:54:49 +05:30
|
|
|
self.__writeln(1, "ADDR", addr.get_street())
|
2006-05-23 05:26:57 +05:30
|
|
|
if addr.get_city():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'CITY', addr.get_city())
|
2006-05-23 05:26:57 +05:30
|
|
|
if addr.get_state():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'STAE', addr.get_state())
|
2006-05-23 05:26:57 +05:30
|
|
|
if addr.get_postal_code():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'POST', addr.get_postal_code())
|
2006-05-23 05:26:57 +05:30
|
|
|
if addr.get_country():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'CTRY', addr.get_country())
|
2006-05-23 05:26:57 +05:30
|
|
|
if addr.get_phone():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(1, 'PHON', addr.get_phone())
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_note_references(repo.get_note_list(), 1)
|
2006-05-22 05:02:34 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def write_reporef(self, reporef, level):
|
2006-05-23 05:26:57 +05:30
|
|
|
|
2006-05-22 05:02:34 +05:30
|
|
|
if reporef.ref == None:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Append handle to the list for exporting REPOs later
|
|
|
|
self.rlist.add(reporef.ref)
|
|
|
|
|
|
|
|
repo = self.db.get_repository_from_handle(reporef.ref)
|
|
|
|
repo_id = repo.get_gramps_id()
|
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(level, 'REPO', '@%s@' % repo_id )
|
2006-05-22 05:02:34 +05:30
|
|
|
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_note_references(reporef.get_note_list(), level+1)
|
2006-05-22 05:02:34 +05:30
|
|
|
|
|
|
|
if reporef.get_call_number():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(level+1, 'CALN', reporef.get_call_number() )
|
2006-05-22 05:02:34 +05:30
|
|
|
if reporef.get_media_type():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(level+2, 'MEDI', str(reporef.get_media_type()))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def __write_person_event_ref(self, key, event_ref):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
if event_ref:
|
|
|
|
event = self.db.get_event_from_handle(event_ref.ref)
|
2007-08-08 09:54:49 +05:30
|
|
|
if (not event.get_date_object().is_empty()) \
|
|
|
|
or event.get_place_handle():
|
|
|
|
self.__writeln(1, key)
|
|
|
|
else:
|
|
|
|
self.__writeln(1, key, 'Y')
|
|
|
|
if event.get_description().strip() != "":
|
|
|
|
self.__writeln(2, 'TYPE', event.get_description())
|
|
|
|
self.dump_event_stats(event, event_ref)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-14 09:32:18 +05:30
|
|
|
def __write_change(self, timeval, level):
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(level, 'CHAN')
|
2004-08-24 09:18:15 +05:30
|
|
|
time_val = time.localtime(timeval)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__writeln(level+1, 'DATE', '%d %s %d' % (
|
|
|
|
time_val[2], _month[time_val[1]], time_val[0]))
|
|
|
|
self.__writeln(level+2, 'TIME', '%02d:%02d:%02d' % (
|
|
|
|
time_val[3], time_val[4], time_val[5]))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def dump_event_stats(self, event, event_ref):
|
2004-02-14 11:10:30 +05:30
|
|
|
dateobj = event.get_date_object()
|
2007-08-13 05:30:16 +05:30
|
|
|
self.print_date(2, dateobj)
|
2005-12-06 12:08:09 +05:30
|
|
|
place = None
|
2007-08-06 09:41:52 +05:30
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
if event.get_place_handle():
|
2005-12-06 12:08:09 +05:30
|
|
|
place = self.db.get_place_from_handle(event.get_place_handle())
|
2007-08-06 09:41:52 +05:30
|
|
|
self.write_place(place, 2)
|
|
|
|
|
2006-08-16 08:01:29 +05:30
|
|
|
for attr in event.get_attribute_list():
|
|
|
|
t = attr.get_type()
|
|
|
|
if t == RelLib.AttributeType.CAUSE:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'CAUS', attr.get_value())
|
2006-08-16 08:01:29 +05:30
|
|
|
elif t == RelLib.AttributeType.AGENCY:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'AGNC', attr.get_value())
|
|
|
|
|
2006-08-16 08:01:29 +05:30
|
|
|
for attr in event_ref.get_attribute_list():
|
|
|
|
t = attr.get_type()
|
|
|
|
if t == RelLib.AttributeType.AGE:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'AGE', attr.get_value())
|
2006-08-16 08:01:29 +05:30
|
|
|
elif t == RelLib.AttributeType.FATHER_AGE:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'HUSB')
|
|
|
|
self.__writeln(3, 'AGE', attr.get_value())
|
2006-08-16 08:01:29 +05:30
|
|
|
elif t == RelLib.AttributeType.MOTHER_AGE:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'WIFE')
|
|
|
|
self.__writeln(3, 'AGE', attr.get_value())
|
|
|
|
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_note_references(event.get_note_list(), 1)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_source_references(event.get_source_references(), 2)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-25 10:33:23 +05:30
|
|
|
self.__write_photos(event.get_media_list(), 2)
|
|
|
|
if place:
|
|
|
|
self.__write_photos(place.get_media_list(), 2)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-04-06 07:12:14 +05:30
|
|
|
def write_ord(self, ord, index):
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(index, lds_ord_name[ord.get_type()])
|
2007-08-13 05:30:16 +05:30
|
|
|
self.print_date(index + 1, ord.get_date_object())
|
2004-07-28 07:59:07 +05:30
|
|
|
if ord.get_family_handle():
|
2006-05-23 05:26:57 +05:30
|
|
|
family_handle = ord.get_family_handle()
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
|
|
|
if family:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(index+1, 'FAMC', '@%s@' % family.get_gramps_id())
|
2004-02-14 11:10:30 +05:30
|
|
|
if ord.get_temple():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(index+1, 'TEMP', ord.get_temple())
|
2004-07-28 07:59:07 +05:30
|
|
|
if ord.get_place_handle():
|
2006-05-23 05:26:57 +05:30
|
|
|
self.write_place(
|
2007-08-06 09:41:52 +05:30
|
|
|
self.db.get_place_from_handle(ord.get_place_handle()), 2)
|
2006-04-06 07:12:14 +05:30
|
|
|
if ord.get_status() != RelLib.LdsOrd.STATUS_NONE:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'STAT', lds_status[ord.get_status()])
|
2007-08-09 10:05:06 +05:30
|
|
|
|
|
|
|
self.__write_note_references(ord.get_note_list(), index+1)
|
2007-08-14 09:32:18 +05:30
|
|
|
self.__write_source_references(ord.get_source_references(), index+1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-13 05:30:16 +05:30
|
|
|
def print_date(self, level, date):
|
2002-10-20 19:55:16 +05:30
|
|
|
start = date.get_start_date()
|
2006-02-04 03:33:53 +05:30
|
|
|
if start != RelLib.Date.EMPTY:
|
2004-09-17 09:00:04 +05:30
|
|
|
cal = date.get_calendar()
|
|
|
|
mod = date.get_modifier()
|
2006-02-04 03:33:53 +05:30
|
|
|
if date.get_modifier() == RelLib.Date.MOD_SPAN:
|
2006-05-23 05:26:57 +05:30
|
|
|
val = "FROM %s TO %s" % (
|
2007-08-06 09:41:52 +05:30
|
|
|
make_date(start, cal, mod),
|
|
|
|
make_date(date.get_stop_date(), cal, mod))
|
2006-02-04 03:33:53 +05:30
|
|
|
elif date.get_modifier() == RelLib.Date.MOD_RANGE:
|
2006-05-23 05:26:57 +05:30
|
|
|
val = "BET %s AND %s" % (
|
2007-08-06 09:41:52 +05:30
|
|
|
make_date(start, cal, mod),
|
|
|
|
make_date(date.get_stop_date(), cal, mod))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2007-08-06 09:41:52 +05:30
|
|
|
val = make_date(start, cal, mod)
|
2007-08-13 05:30:16 +05:30
|
|
|
self.__writeln(level, 'DATE', val)
|
2005-07-09 01:54:54 +05:30
|
|
|
elif date.get_text():
|
2007-08-13 05:30:16 +05:30
|
|
|
self.__writeln(level, 'DATE', date.get_text())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-09 10:05:06 +05:30
|
|
|
def __write_person_name(self, name, nick):
|
|
|
|
"""
|
2007-08-13 09:10:36 +05:30
|
|
|
n NAME <NAME_PERSONAL> {1:1}
|
|
|
|
+1 NPFX <NAME_PIECE_PREFIX> {0:1}
|
|
|
|
+1 GIVN <NAME_PIECE_GIVEN> {0:1}
|
|
|
|
+1 NICK <NAME_PIECE_NICKNAME> {0:1}
|
|
|
|
+1 SPFX <NAME_PIECE_SURNAME_PREFIX {0:1}
|
|
|
|
+1 SURN <NAME_PIECE_SURNAME> {0:1}
|
|
|
|
+1 NSFX <NAME_PIECE_SUFFIX> {0:1}
|
|
|
|
+1 <<SOURCE_CITATION>> {0:M}
|
|
|
|
+1 <<NOTE_STRUCTURE>> {0:M}
|
2007-08-09 10:05:06 +05:30
|
|
|
"""
|
|
|
|
firstname = name.get_first_name().strip()
|
|
|
|
patron = name.get_patronymic().strip()
|
|
|
|
if patron:
|
|
|
|
firstname = "%s %s" % (first, patron)
|
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
surname = name.get_surname().replace('/', '?')
|
|
|
|
surprefix = name.get_surname_prefix().replace('/', '?')
|
|
|
|
suffix = name.get_suffix()
|
|
|
|
title = name.get_title()
|
2002-10-20 19:55:16 +05:30
|
|
|
if suffix == "":
|
2007-08-06 09:41:52 +05:30
|
|
|
if surprefix == "":
|
|
|
|
self.__writeln(1, 'NAME', '%s/%s/' % (firstname, surname))
|
2002-12-04 10:28:07 +05:30
|
|
|
else:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(1, 'NAME', '%s/%s %s/' % (firstname, surprefix, surname))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2007-08-06 09:41:52 +05:30
|
|
|
if surprefix == "":
|
|
|
|
self.__writeln(1, 'NAME', '%s/%s/ %s' % (firstname, surname, suffix))
|
2002-12-04 10:28:07 +05:30
|
|
|
else:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(1, 'NAME', '%s/%s %s/ %s' % (firstname, surprefix,
|
|
|
|
surname, suffix))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
if firstname:
|
|
|
|
self.__writeln(2, 'GIVN', firstname)
|
2007-08-13 05:30:16 +05:30
|
|
|
if surprefix:
|
|
|
|
self.__writeln(2, 'SPFX', surprefix)
|
|
|
|
if surname:
|
|
|
|
self.__writeln(2, 'SURN', surname)
|
2002-12-04 10:28:07 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if name.get_suffix():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'NSFX', suffix)
|
2004-02-14 11:10:30 +05:30
|
|
|
if name.get_title():
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'NPFX', title)
|
2002-12-30 06:12:47 +05:30
|
|
|
if nick:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(2, 'NICK', nick)
|
2007-08-14 09:32:18 +05:30
|
|
|
|
|
|
|
self.__write_source_references(name.get_source_references(), 2)
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__write_note_references(name.get_note_list(), 2)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def write_source_ref(self, level, ref):
|
2007-08-09 10:05:06 +05:30
|
|
|
"""
|
2007-08-13 09:10:36 +05:30
|
|
|
n SOUR @<XREF:SOUR>@ /* pointer to source record */ {1:1}
|
|
|
|
+1 PAGE <WHERE_WITHIN_SOURCE> {0:1}
|
|
|
|
+1 EVEN <EVENT_TYPE_CITED_FROM> {0:1}
|
|
|
|
+2 ROLE <ROLE_IN_EVENT> {0:1}
|
2007-08-09 10:05:06 +05:30
|
|
|
+1 DATA {0:1}
|
2007-08-13 09:10:36 +05:30
|
|
|
+2 DATE <ENTRY_RECORDING_DATE> {0:1}
|
|
|
|
+2 TEXT <TEXT_FROM_SOURCE> {0:M}
|
2007-08-09 10:05:06 +05:30
|
|
|
+3 [ CONC | CONT ] <TEXT_FROM_SOURCE> {0:M}
|
2007-08-13 09:10:36 +05:30
|
|
|
+1 QUAY <CERTAINTY_ASSESSMENT> {0:1}
|
|
|
|
+1 <<MULTIMEDIA_LINK>> {0:M} ,*
|
|
|
|
+1 <<NOTE_STRUCTURE>> {0:M}
|
2007-08-09 10:05:06 +05:30
|
|
|
"""
|
2006-05-23 05:26:57 +05:30
|
|
|
|
|
|
|
src_handle = ref.get_reference_handle()
|
|
|
|
if src_handle == None:
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
2003-01-03 08:49:50 +05:30
|
|
|
|
2006-05-23 05:26:57 +05:30
|
|
|
src = self.db.get_source_from_handle(src_handle)
|
|
|
|
self.slist.add(src_handle)
|
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
# Reference to the source
|
|
|
|
self.__writeln(level, "SOUR", "@%s@" % src.get_gramps_id())
|
|
|
|
if ref.get_page() != "":
|
2007-08-09 10:05:06 +05:30
|
|
|
self.__writeln(level+1, 'PAGE', ref.get_page())
|
|
|
|
|
|
|
|
conf = min(ref.get_confidence_level(), RelLib.SourceRef.CONF_VERY_HIGH)
|
2007-08-06 09:41:52 +05:30
|
|
|
if conf != RelLib.SourceRef.CONF_NORMAL and conf != -1:
|
2007-08-08 09:54:49 +05:30
|
|
|
self.__writeln(level+1, "QUAY", str(quay_map[conf]))
|
2006-06-17 00:08:06 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
if len(ref.get_note_list()) > 0:
|
2007-07-18 09:47:30 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
note_list = [ self.db.get_note_from_handle(h) for h in ref.get_note_list() ]
|
|
|
|
note_list = [ n for n in note_list
|
|
|
|
if n.get_type() == RelLib.NoteType.SOURCE_TEXT]
|
2007-07-18 09:47:30 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
if note_list:
|
|
|
|
ref_text = note_list[0].get()
|
|
|
|
else:
|
|
|
|
ref_text = ""
|
2007-07-18 09:47:30 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
if ref_text != "" or not ref.get_date_object().is_empty():
|
|
|
|
self.__writeln(level+1, 'DATA')
|
|
|
|
if ref_text != "":
|
2007-08-15 09:02:08 +05:30
|
|
|
self.__writeln(level+2, "TEXT", ref_text)
|
2007-08-13 05:30:16 +05:30
|
|
|
self.print_date(level+2, ref.get_date_object())
|
2007-07-18 09:47:30 +05:30
|
|
|
|
2007-08-13 05:30:16 +05:30
|
|
|
note_list = [ self.db.get_note_from_handle(h) for h in ref.get_note_list() ]
|
|
|
|
note_list = [ n.handle for n in note_list
|
|
|
|
if n.get_type() != RelLib.NoteType.SOURCE_TEXT]
|
|
|
|
self.__write_note_references(note_list, level+1)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2007-08-15 09:02:08 +05:30
|
|
|
def __write_photo(self, photo, level):
|
|
|
|
"""
|
|
|
|
n OBJE {1:1}
|
|
|
|
+1 FORM <MULTIMEDIA_FORMAT> {1:1}
|
|
|
|
+1 TITL <DESCRIPTIVE_TITLE> {0:1}
|
|
|
|
+1 FILE <MULTIMEDIA_FILE_REFERENCE> {1:1}
|
|
|
|
+1 <<NOTE_STRUCTURE>> {0:M}
|
|
|
|
"""
|
2005-12-06 12:08:09 +05:30
|
|
|
photo_obj_id = photo.get_reference_handle()
|
|
|
|
photo_obj = self.db.get_object_from_handle(photo_obj_id)
|
|
|
|
if photo_obj:
|
|
|
|
mime = photo_obj.get_mime_type()
|
2007-08-15 09:02:08 +05:30
|
|
|
form = mime2ged.get(mime, mime)
|
|
|
|
path = photo_obj.get_path()
|
2007-08-25 10:33:23 +05:30
|
|
|
imgdir = path
|
2005-12-06 12:08:09 +05:30
|
|
|
if not os.path.isfile(path):
|
|
|
|
return
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(level, 'OBJE')
|
2005-12-06 12:08:09 +05:30
|
|
|
if form:
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(level+1, 'FORM', form)
|
|
|
|
self.__writeln(level+1, 'TITL', photo_obj.get_description())
|
2007-08-25 10:33:23 +05:30
|
|
|
self.__writeln(level+1, 'FILE', path)
|
2007-08-09 10:05:06 +05:30
|
|
|
|
|
|
|
self.__write_note_references(photo_obj.get_note_list(), level+1)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2007-08-06 09:41:52 +05:30
|
|
|
def write_place(self, place, level):
|
2005-12-06 12:08:09 +05:30
|
|
|
place_name = place.get_title()
|
2007-08-06 09:41:52 +05:30
|
|
|
self.__writeln(level, "PLAC", place_name.replace('\r', ' '))
|
2007-08-25 03:24:06 +05:30
|
|
|
long = place.get_longitude()
|
|
|
|
lat = place.get_latitude()
|
|
|
|
if long and lat:
|
|
|
|
self.__writeln(level+1, "MAP")
|
|
|
|
self.__writeln(level+2, 'LATI', lat)
|
|
|
|
self.__writeln(level+2, 'LONG', long)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-08-06 09:41:52 +05:30
|
|
|
def exportData(database, filename, person, option_box, callback=None):
|
2004-07-11 05:01:28 +05:30
|
|
|
ret = 0
|
|
|
|
try:
|
2007-08-06 09:41:52 +05:30
|
|
|
gw = GedcomWriter(database, person, 0, filename, option_box, callback)
|
2004-07-14 07:14:04 +05:30
|
|
|
ret = gw.export_data(filename)
|
2006-12-11 09:40:46 +05:30
|
|
|
except Errors.DatabaseError, msg:
|
2007-08-06 09:41:52 +05:30
|
|
|
ErrorDialog(_("Export failed"), str(msg))
|
2004-07-11 05:01:28 +05:30
|
|
|
return ret
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-02-20 04:03:24 +05:30
|
|
|
_title = _('GE_DCOM')
|
2004-07-11 05:01:28 +05:30
|
|
|
_description = _('GEDCOM is used to transfer data between genealogy programs. '
|
2004-07-14 07:14:04 +05:30
|
|
|
'Most genealogy software will accept a GEDCOM file as input. ')
|
2007-08-25 10:33:23 +05:30
|
|
|
_config = (_('GEDCOM export options'), ExportOptions.WriterOptionBox)
|
2004-07-11 05:01:28 +05:30
|
|
|
_filename = 'ged'
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import register_export
|
2007-08-06 09:41:52 +05:30
|
|
|
register_export(exportData, _title, _description, _config, _filename)
|