2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2003-05-21 02:01:16 +05:30
|
|
|
# Copyright (C) 2000-2003 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
|
|
|
|
#
|
|
|
|
|
|
|
|
"Export to GEDCOM"
|
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import os
|
|
|
|
import string
|
|
|
|
import time
|
|
|
|
import re
|
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
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 GenericFilter
|
|
|
|
import const
|
|
|
|
import Utils
|
|
|
|
import Date
|
2003-01-08 10:28:00 +05:30
|
|
|
import Calendar
|
2003-01-10 10:51:32 +05:30
|
|
|
import Julian
|
|
|
|
import Hebrew
|
|
|
|
import FrenchRepublic
|
2003-01-15 10:55:50 +05:30
|
|
|
import GedcomInfo
|
2003-01-19 11:55:20 +05:30
|
|
|
import ansel_utf8
|
2003-01-10 10:51:32 +05:30
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
from intl import gettext as _
|
2003-03-21 09:55:55 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2002-12-30 06:12:47 +05:30
|
|
|
|
2003-01-19 11:55:20 +05:30
|
|
|
def keep_utf8(s):
|
|
|
|
return s
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Calendar month names
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
_hmonth = [
|
2003-01-15 10:55:50 +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 = [
|
|
|
|
"", "VEND", "BRUM", "FRIM", "NIVO", "PLUV", "VENT",
|
|
|
|
"GERM", "FLOR", "PRAI", "MESS", "THER", "FRUC", "COMP"]
|
|
|
|
|
|
|
|
_month = [
|
|
|
|
"", "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
|
|
|
|
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ]
|
|
|
|
|
|
|
|
_calmap = {
|
2003-01-10 10:51:32 +05:30
|
|
|
Hebrew.Hebrew.NAME : (_hmonth, '@#HEBREW@'),
|
|
|
|
FrenchRepublic.FrenchRepublic.NAME : (_fmonth, '@#FRENCH R@'),
|
|
|
|
Julian.Julian.NAME : (_month, '@#JULIAN@'),
|
2002-10-20 19:55:16 +05:30
|
|
|
}
|
|
|
|
|
2002-12-29 11:14:35 +05:30
|
|
|
_caldef = {
|
2003-01-08 10:28:00 +05:30
|
|
|
Calendar.ABOUT : "ABT",
|
|
|
|
Calendar.BEFORE : "BEF",
|
|
|
|
Calendar.AFTER : "AFT",
|
2002-12-29 11:14:35 +05:30
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def add_familys_sources(family,slist,private):
|
|
|
|
for event in family.getEventList():
|
|
|
|
if private and event.getPrivacy():
|
|
|
|
continue
|
|
|
|
for source_ref in event.getSourceRefList():
|
|
|
|
sbase = source_ref.getBase()
|
2002-12-30 06:12:47 +05:30
|
|
|
if sbase != None and not slist.has_key(sbase.getId()):
|
2002-10-20 19:55:16 +05:30
|
|
|
slist[sbase.getId()] = 1
|
|
|
|
for attr in family.getAttributeList():
|
|
|
|
if private and attr.getPrivacy():
|
|
|
|
continue
|
|
|
|
for source_ref in attr.getSourceRefList():
|
|
|
|
sbase = source_ref.getBase()
|
|
|
|
if sbase != None and not slist.has_key(sbase.getId()):
|
|
|
|
slist[sbase.getId()] = 1
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def add_persons_sources(person,slist,private):
|
|
|
|
elist = person.getEventList()[:]
|
|
|
|
|
|
|
|
elist.append(person.getBirth())
|
|
|
|
elist.append(person.getDeath())
|
|
|
|
for event in elist:
|
|
|
|
if private and event.getPrivacy():
|
|
|
|
continue
|
|
|
|
for source_ref in event.getSourceRefList():
|
|
|
|
sbase = source_ref.getBase()
|
|
|
|
if sbase != None and not slist.has_key(sbase.getId()):
|
|
|
|
slist[sbase.getId()] = 1
|
|
|
|
|
|
|
|
for event in person.getAddressList():
|
|
|
|
if private and event.getPrivacy():
|
|
|
|
continue
|
|
|
|
for source_ref in event.getSourceRefList():
|
|
|
|
sbase = source_ref.getBase()
|
|
|
|
if sbase != None and not slist.has_key(sbase.getId()):
|
|
|
|
slist[sbase.getId()] = 1
|
|
|
|
|
|
|
|
for event in person.getAttributeList():
|
|
|
|
if private and event.getPrivacy():
|
|
|
|
continue
|
|
|
|
for source_ref in event.getSourceRefList():
|
|
|
|
sbase = source_ref.getBase()
|
|
|
|
if sbase != None and not slist.has_key(sbase.getId()):
|
|
|
|
slist[sbase.getId()] = 1
|
|
|
|
|
|
|
|
for name in person.getAlternateNames() + [person.getPrimaryName()]:
|
|
|
|
if private and name.getPrivacy():
|
|
|
|
continue
|
|
|
|
for source_ref in name.getSourceRefList():
|
|
|
|
sbase = source_ref.getBase()
|
|
|
|
if sbase != None and not slist.has_key(sbase.getId()):
|
|
|
|
slist[sbase.getId()] = 1
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def addr_append(text,data):
|
|
|
|
if data:
|
|
|
|
return "%s, %s" % (text,data)
|
|
|
|
else:
|
|
|
|
return text
|
2003-01-08 10:28:00 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def sortById(first,second):
|
|
|
|
fid = first.getId()
|
|
|
|
sid = second.getId()
|
|
|
|
|
|
|
|
if fid == sid:
|
|
|
|
return 0
|
|
|
|
elif fid < sid:
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return 1
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-12-29 11:14:35 +05:30
|
|
|
def make_date(subdate):
|
2002-10-20 19:55:16 +05:30
|
|
|
retval = ""
|
|
|
|
day = subdate.getDay()
|
|
|
|
mon = subdate.getMonth()
|
|
|
|
year = subdate.getYear()
|
|
|
|
mode = subdate.getModeVal()
|
|
|
|
day_valid = subdate.getDayValid()
|
|
|
|
mon_valid = subdate.getMonthValid()
|
|
|
|
year_valid = subdate.getYearValid()
|
|
|
|
|
2003-01-10 10:51:32 +05:30
|
|
|
if _calmap.has_key(subdate.calendar.NAME):
|
|
|
|
(mmap,prefix) = _calmap[subdate.calendar.NAME]
|
2002-12-29 11:14:35 +05:30
|
|
|
else:
|
|
|
|
mmap = _month
|
|
|
|
prefix = ""
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
if not day_valid:
|
|
|
|
try:
|
|
|
|
if not mon_valid:
|
2002-12-30 06:12:47 +05:30
|
|
|
retval = '%d' % year
|
2002-10-20 19:55:16 +05:30
|
|
|
elif not year_valid:
|
2002-12-29 11:14:35 +05:30
|
|
|
retval = '(%s)' % mmap[mon]
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2002-12-30 06:12:47 +05:30
|
|
|
retval = "%s %d" % (mmap[mon],year)
|
2002-10-20 19:55:16 +05:30
|
|
|
except IndexError:
|
|
|
|
print "Month index error - %d" % mon
|
2002-12-30 06:12:47 +05:30
|
|
|
retval = '%d' % year
|
2002-10-20 19:55:16 +05:30
|
|
|
elif not mon_valid:
|
2002-12-30 06:12:47 +05:30
|
|
|
retval = '%d' % year
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
try:
|
|
|
|
month = mmap[mon]
|
|
|
|
if not year_valid:
|
2002-12-29 11:14:35 +05:30
|
|
|
retval = "(%d %s)" % (day,month)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
retval = "%d %s %d" % (day,month,year)
|
|
|
|
except IndexError:
|
|
|
|
print "Month index error - %d" % mon
|
|
|
|
retval = str(year)
|
2002-12-29 11:14:35 +05:30
|
|
|
|
|
|
|
if prefix:
|
|
|
|
retval = "%s %s" % (prefix, retval)
|
|
|
|
|
|
|
|
if _caldef.has_key(mode):
|
|
|
|
retval = "%s %s" % (_caldef[mode],retval)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
return retval
|
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
def fmtline(text,limit,level):
|
|
|
|
new_text = []
|
|
|
|
while len(text) > limit:
|
|
|
|
new_text.append(text[0:limit-1])
|
|
|
|
text = text[limit:]
|
|
|
|
if len(text) > 0:
|
|
|
|
new_text.append(text)
|
|
|
|
app = "\n%d CONC " % (level+1)
|
|
|
|
return string.join(new_text,app)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def gedcom_date(date):
|
|
|
|
if date.range == 1:
|
|
|
|
s1 = ged_subdate(date.get_start_date())
|
|
|
|
s2 = ged_subdate(date.get_stop_date())
|
|
|
|
return "BET %s AND %s" % (s1,s2)
|
|
|
|
elif date.range == -1:
|
|
|
|
return "(%s)" % date.text
|
|
|
|
else:
|
|
|
|
return ged_subdate(date.start)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def ged_subdate(date):
|
|
|
|
|
|
|
|
if not date.getValid():
|
|
|
|
return ""
|
|
|
|
elif not date.getDayValid():
|
|
|
|
try:
|
|
|
|
if not date.getMonthValid():
|
|
|
|
retval = str(date.year)
|
|
|
|
elif not date.getYearValid():
|
|
|
|
retval = "(%s)" % Date.SingleDate.emname[date.month]
|
|
|
|
else:
|
|
|
|
retval = "%s %d" % (Date.SingleDate.emname[date.month],date.year)
|
|
|
|
except IndexError:
|
|
|
|
print "Month index error - %d" % date.month
|
|
|
|
retval = str(date.year)
|
|
|
|
elif not date.getMonthValid():
|
|
|
|
retval = str(date.year)
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
month = Date.SingleDate.emname[date.month]
|
|
|
|
if not date.getYearValid():
|
|
|
|
retval = "(%d %s)" % (date.day,month)
|
|
|
|
else:
|
|
|
|
retval = "%d %s %d" % (date.day,month,date.year)
|
|
|
|
except IndexError:
|
|
|
|
print "Month index error - %d" % date.month
|
|
|
|
retval = str(date.year)
|
|
|
|
|
|
|
|
if date.mode == Date.SingleDate.about:
|
|
|
|
retval = "ABT %s" % retval
|
|
|
|
|
|
|
|
if date.mode == Date.SingleDate.before:
|
|
|
|
retval = "BEF %s" % retval
|
|
|
|
elif date.mode == Date.SingleDate.after:
|
|
|
|
retval = "AFT %s" % retval
|
|
|
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def writeData(database,person):
|
|
|
|
try:
|
|
|
|
GedcomWriter(database,person)
|
|
|
|
except:
|
|
|
|
import DisplayTrace
|
|
|
|
DisplayTrace.DisplayTrace()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class GedcomWriter:
|
|
|
|
"""Writes a GEDCOM file from the passed database"""
|
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
def __init__(self,db,person,cl=0,name=""):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.db = db
|
|
|
|
self.person = person
|
|
|
|
self.restrict = 1
|
|
|
|
self.private = 1
|
2003-01-19 11:55:20 +05:30
|
|
|
self.cnvtxt = ansel_utf8.utf8_to_ansel
|
2002-10-20 19:55:16 +05:30
|
|
|
self.plist = {}
|
|
|
|
self.slist = {}
|
|
|
|
self.flist = {}
|
2003-01-15 10:55:50 +05:30
|
|
|
self.adopt = GedcomInfo.ADOPT_EVENT
|
2002-10-20 19:55:16 +05:30
|
|
|
self.fidval = 0
|
|
|
|
self.fidmap = {}
|
|
|
|
self.pidval = 0
|
|
|
|
self.pidmap = {}
|
|
|
|
self.sidval = 0
|
|
|
|
self.sidmap = {}
|
2003-05-21 02:01:16 +05:30
|
|
|
self.cl = cl
|
|
|
|
self.name = name
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
if self.cl:
|
|
|
|
self.cl_setup()
|
|
|
|
else:
|
|
|
|
glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
|
|
|
|
|
|
|
|
self.topDialog = gtk.glade.XML(glade_file,"gedcomExport")
|
|
|
|
self.topDialog.signal_autoconnect({
|
|
|
|
"destroy_passed_object" : Utils.destroy_passed_object,
|
|
|
|
"gnu_free" : self.gnu_free,
|
|
|
|
"standard_copyright" : self.standard_copyright,
|
|
|
|
"no_copyright" : self.no_copyright,
|
|
|
|
"on_ok_clicked" : self.on_ok_clicked
|
|
|
|
})
|
|
|
|
|
|
|
|
Utils.set_titles(self.topDialog.get_widget('gedcomExport'),
|
|
|
|
self.topDialog.get_widget('title'),
|
|
|
|
_('GEDCOM export'))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
filter_obj = self.topDialog.get_widget("filter")
|
|
|
|
self.copy = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
all = GenericFilter.GenericFilter()
|
|
|
|
all.set_name(_("Entire Database"))
|
|
|
|
all.add_rule(GenericFilter.Everyone([]))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
des = GenericFilter.GenericFilter()
|
|
|
|
des.set_name(_("Descendants of %s") % person.getPrimaryName().getName())
|
|
|
|
des.add_rule(GenericFilter.IsDescendantOf([person.getId()]))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
ans = GenericFilter.GenericFilter()
|
|
|
|
ans.set_name(_("Ancestors of %s") % person.getPrimaryName().getName())
|
|
|
|
ans.add_rule(GenericFilter.IsAncestorOf([person.getId()]))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
com = GenericFilter.GenericFilter()
|
|
|
|
com.set_name(_("People with common ancestor with %s") %
|
|
|
|
person.getPrimaryName().getName())
|
|
|
|
com.add_rule(GenericFilter.HasCommonAncestorWith([person.getId()]))
|
2003-01-08 10:28:00 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
self.filter_menu = GenericFilter.build_filter_menu([all,des,ans,com])
|
|
|
|
filter_obj.set_menu(self.filter_menu)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
gedmap = GedcomInfo.GedcomInfoDB()
|
2003-01-08 10:28:00 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
target_obj = self.topDialog.get_widget("target")
|
|
|
|
myMenu = gtk.Menu()
|
|
|
|
for name in gedmap.get_name_list():
|
|
|
|
menuitem = gtk.MenuItem(name)
|
|
|
|
myMenu.append(menuitem)
|
|
|
|
data = gedmap.get_description(name)
|
|
|
|
menuitem.set_data("data",data)
|
|
|
|
menuitem.show()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
target_obj.set_menu(myMenu)
|
|
|
|
self.target_menu = myMenu
|
2002-11-12 09:42:18 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
pathname = "%s.ged" % os.path.dirname(db.getSavePath())
|
2002-11-12 09:42:18 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
filetgt = self.topDialog.get_widget('fileentry1')
|
|
|
|
filetgt.set_filename(pathname)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
self.topDialog.get_widget("gedcomExport").show()
|
|
|
|
|
2003-02-12 09:55:27 +05:30
|
|
|
def gnu_free(self,obj):
|
|
|
|
self.copy = 1
|
|
|
|
|
|
|
|
def standard_copyright(self,obj):
|
|
|
|
self.copy = 0
|
|
|
|
|
|
|
|
def no_copyright(self,obj):
|
|
|
|
self.copy = 2
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def on_ok_clicked(self,obj):
|
|
|
|
|
|
|
|
self.restrict = self.topDialog.get_widget("restrict").get_active()
|
|
|
|
self.private = self.topDialog.get_widget("private").get_active()
|
|
|
|
|
|
|
|
cfilter = self.filter_menu.get_active().get_data("filter")
|
|
|
|
act_tgt = self.target_menu.get_active()
|
|
|
|
|
|
|
|
self.target_ged = act_tgt.get_data("data")
|
|
|
|
|
|
|
|
self.dest = self.target_ged.get_dest()
|
|
|
|
self.adopt = self.target_ged.get_adopt()
|
|
|
|
self.conc = self.target_ged.get_conc()
|
|
|
|
self.altname = self.target_ged.get_alt_name()
|
|
|
|
self.cal = self.target_ged.get_alt_calendar()
|
|
|
|
self.obje = self.target_ged.get_obje()
|
|
|
|
self.resi = self.target_ged.get_resi()
|
2002-12-04 10:28:07 +05:30
|
|
|
self.prefix = self.target_ged.get_prefix()
|
2003-01-03 08:49:50 +05:30
|
|
|
self.source_refs = self.target_ged.get_source_refs()
|
2002-12-04 10:28:07 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.topDialog.get_widget("ansel").get_active():
|
2003-01-19 11:55:20 +05:30
|
|
|
self.cnvtxt = ansel_utf8.utf8_to_ansel
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2003-01-19 11:55:20 +05:30
|
|
|
self.cnvtxt = keep_utf8
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
name = self.topDialog.get_widget("filename").get_text()
|
|
|
|
|
|
|
|
if cfilter == None:
|
|
|
|
for p in self.db.getPersonKeys():
|
|
|
|
self.plist[p] = 1
|
|
|
|
else:
|
2003-01-08 10:28:00 +05:30
|
|
|
for p in cfilter.apply(self.db, self.db.getPersonMap().values()):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.plist[p.getId()] = 1
|
2003-01-08 10:28:00 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.flist = {}
|
|
|
|
self.slist = {}
|
|
|
|
for key in self.plist.keys():
|
|
|
|
p = self.db.getPerson(key)
|
|
|
|
add_persons_sources(p,self.slist,self.private)
|
|
|
|
for family in p.getFamilyList():
|
|
|
|
add_familys_sources(family,self.slist,self.private)
|
|
|
|
self.flist[family.getId()] = 1
|
|
|
|
|
|
|
|
Utils.destroy_passed_object(obj)
|
|
|
|
|
|
|
|
glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
|
|
|
|
|
|
|
|
self.exprogress = gtk.glade.XML(glade_file,"exportprogress")
|
|
|
|
self.exprogress.signal_autoconnect({
|
|
|
|
"on_close_clicked" : Utils.destroy_passed_object
|
|
|
|
})
|
|
|
|
|
2003-03-21 09:55:55 +05:30
|
|
|
Utils.set_titles(self.exprogress.get_widget('exportprogress'),
|
|
|
|
self.exprogress.get_widget('title'),
|
2003-03-17 10:51:40 +05:30
|
|
|
_('GEDCOM export'))
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.fbar = self.exprogress.get_widget("fbar")
|
|
|
|
self.pbar = self.exprogress.get_widget("pbar")
|
|
|
|
self.sbar = self.exprogress.get_widget("sbar")
|
|
|
|
self.progress = self.exprogress.get_widget('exportprogress')
|
|
|
|
|
|
|
|
closebtn = self.exprogress.get_widget("close")
|
|
|
|
closebtn.connect("clicked",Utils.destroy_passed_object)
|
|
|
|
closebtn.set_sensitive(0)
|
|
|
|
|
|
|
|
self.export_data(name)
|
|
|
|
closebtn.set_sensitive(1)
|
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
def cl_setup(self):
|
|
|
|
self.restrict = 0
|
|
|
|
self.private = 0
|
|
|
|
self.copy = 0
|
|
|
|
|
|
|
|
for p in self.db.getPersonKeys():
|
|
|
|
self.plist[p] = 1
|
|
|
|
|
|
|
|
gedmap = GedcomInfo.GedcomInfoDB()
|
|
|
|
self.target_ged = gedmap.standard
|
|
|
|
|
|
|
|
self.dest = self.target_ged.get_dest()
|
|
|
|
self.adopt = self.target_ged.get_adopt()
|
|
|
|
self.conc = self.target_ged.get_conc()
|
|
|
|
self.altname = self.target_ged.get_alt_name()
|
|
|
|
self.cal = self.target_ged.get_alt_calendar()
|
|
|
|
self.obje = self.target_ged.get_obje()
|
|
|
|
self.resi = self.target_ged.get_resi()
|
|
|
|
self.prefix = self.target_ged.get_prefix()
|
|
|
|
self.source_refs = self.target_ged.get_source_refs()
|
|
|
|
|
|
|
|
self.cnvtxt = keep_utf8
|
|
|
|
|
|
|
|
self.flist = {}
|
|
|
|
self.slist = {}
|
|
|
|
|
|
|
|
for key in self.plist.keys():
|
|
|
|
p = self.db.getPerson(key)
|
|
|
|
add_persons_sources(p,self.slist,self.private)
|
|
|
|
for family in p.getFamilyList():
|
|
|
|
add_familys_sources(family,self.slist,self.private)
|
|
|
|
self.flist[family.getId()] = 1
|
|
|
|
|
|
|
|
self.export_data(self.name)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def export_data(self,filename):
|
|
|
|
try:
|
|
|
|
self.g = open(filename,"w")
|
|
|
|
except IOError,msg:
|
2003-03-21 09:55:55 +05:30
|
|
|
msg2 = _("Could not create %s") % filename
|
|
|
|
ErrorDialog(msg2,str(msg))
|
2002-10-20 19:55:16 +05:30
|
|
|
self.progress.destroy()
|
|
|
|
return
|
|
|
|
except:
|
2003-03-21 09:55:55 +05:30
|
|
|
ErrorDialog(_("Could not create %s") % filename)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.progress.destroy()
|
|
|
|
return
|
|
|
|
|
|
|
|
date = string.split(time.ctime(time.time()))
|
|
|
|
|
|
|
|
self.g.write("0 HEAD\n")
|
|
|
|
self.g.write("1 SOUR GRAMPS\n")
|
2002-12-30 06:12:47 +05:30
|
|
|
self.g.write("2 VERS %s\n" % const.version)
|
|
|
|
self.g.write("2 NAME GRAMPS\n")
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.dest:
|
|
|
|
self.g.write("1 DEST %s\n" % self.dest)
|
|
|
|
self.g.write("1 DATE %s %s %s\n" % (date[2],string.upper(date[1]),date[4]))
|
2003-01-19 11:55:20 +05:30
|
|
|
if self.cnvtxt == ansel_utf8.utf8_to_ansel:
|
2003-02-12 09:55:27 +05:30
|
|
|
self.g.write("1 CHAR ANSEL\n")
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2003-02-12 09:55:27 +05:30
|
|
|
self.g.write("1 CHAR UTF-8\n")
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 SUBM @SUBM@\n")
|
|
|
|
self.g.write("1 FILE %s\n" % filename)
|
2003-02-12 09:55:27 +05:30
|
|
|
self.write_copy()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 GEDC\n")
|
|
|
|
self.g.write("2 VERS 5.5\n")
|
|
|
|
self.g.write('2 FORM LINEAGE-LINKED\n')
|
2003-02-12 09:55:27 +05:30
|
|
|
self.gnu_fdl()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("0 @SUBM@ SUBM\n")
|
|
|
|
owner = self.db.getResearcher()
|
2002-12-30 06:12:47 +05:30
|
|
|
if owner.getName():
|
|
|
|
self.g.write("1 NAME %s\n" % self.cnvtxt(owner.getName()))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.g.write('1 NAME Not Provided\n')
|
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
if owner.getAddress():
|
2002-10-20 19:55:16 +05:30
|
|
|
cnt = 0
|
2002-12-30 06:12:47 +05:30
|
|
|
self.g.write("1 ADDR %s\n" % self.cnvtxt(owner.getAddress()))
|
|
|
|
if owner.getCity():
|
|
|
|
self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getCity()))
|
2002-10-20 19:55:16 +05:30
|
|
|
cnt = 1
|
2002-12-30 06:12:47 +05:30
|
|
|
if owner.getState():
|
|
|
|
self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getState()))
|
2002-10-20 19:55:16 +05:30
|
|
|
cnt = 1
|
2002-12-30 06:12:47 +05:30
|
|
|
if owner.getPostalCode():
|
|
|
|
self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getPostalCode()))
|
2002-10-20 19:55:16 +05:30
|
|
|
cnt = 1
|
2002-12-30 06:12:47 +05:30
|
|
|
if owner.getCountry():
|
|
|
|
self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getCountry()))
|
2002-10-20 19:55:16 +05:30
|
|
|
cnt = 1
|
2002-12-30 06:12:47 +05:30
|
|
|
if owner.getPhone():
|
|
|
|
self.g.write("2 PHON %s\n" % self.cnvtxt(owner.getPhone()))
|
2002-10-20 19:55:16 +05:30
|
|
|
cnt = 1
|
|
|
|
if cnt == 0:
|
|
|
|
self.g.write('2 CONT Not Provided\n')
|
|
|
|
else:
|
|
|
|
self.g.write('1 ADDR Not Provided\n')
|
|
|
|
self.g.write('2 CONT Not Provided\n')
|
|
|
|
|
|
|
|
pkeys = self.plist.keys()
|
|
|
|
pkeys.sort()
|
|
|
|
nump = float(len(self.plist))
|
|
|
|
index = 0.0
|
|
|
|
for key in pkeys:
|
|
|
|
self.write_person(self.db.getPerson(key))
|
|
|
|
index = index + 1
|
2003-05-21 02:01:16 +05:30
|
|
|
if index%100 == 0 and not self.cl:
|
2002-12-30 06:12:47 +05:30
|
|
|
self.pbar.set_fraction(index/nump)
|
2002-10-20 19:55:16 +05:30
|
|
|
while(gtk.events_pending()):
|
|
|
|
gtk.mainiteration()
|
2003-05-21 02:01:16 +05:30
|
|
|
if not self.cl:
|
|
|
|
self.pbar.set_fraction(1.0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.write_families()
|
2003-01-03 08:49:50 +05:30
|
|
|
if self.source_refs:
|
|
|
|
self.write_sources()
|
|
|
|
else:
|
2003-05-21 02:01:16 +05:30
|
|
|
if not self.cl:
|
|
|
|
self.sbar.set_fraction(1.0)
|
2003-01-08 10:28:00 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("0 TRLR\n")
|
|
|
|
self.g.close()
|
|
|
|
|
2003-02-12 09:55:27 +05:30
|
|
|
def write_copy(self):
|
|
|
|
import time
|
|
|
|
|
|
|
|
t = time.localtime(time.time())
|
|
|
|
y = t[0]
|
|
|
|
|
|
|
|
if self.copy == 0:
|
|
|
|
o = self.db.getResearcher().getName()
|
|
|
|
self.g.write('1 COPR Copyright (c) %d %s.\n' % (y,o))
|
|
|
|
elif self.copy == 1:
|
|
|
|
o = self.db.getResearcher().getName()
|
|
|
|
self.g.write('1 COPR Copyright (c) %d %s. See additional copyright NOTE below.\n' % (y,o))
|
|
|
|
|
|
|
|
def gnu_fdl(self):
|
|
|
|
import time
|
|
|
|
|
|
|
|
if self.copy != 1:
|
|
|
|
return
|
|
|
|
|
|
|
|
t = time.localtime(time.time())
|
|
|
|
y = t[0]
|
|
|
|
o = self.db.getResearcher().getName()
|
|
|
|
|
|
|
|
self.g.write('1 NOTE Copyright (c) %d %s.\n' % (y,o))
|
|
|
|
try:
|
|
|
|
f = open(const.fdl,"r")
|
|
|
|
for line in f.readlines():
|
|
|
|
self.g.write('2 CONT %s' % line)
|
|
|
|
f.close()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def write_families(self):
|
|
|
|
nump = float(len(self.flist))
|
|
|
|
index = 0.0
|
|
|
|
for key in self.flist.keys():
|
|
|
|
family = self.db.getFamily(key)
|
|
|
|
father_alive = mother_alive = 0
|
|
|
|
self.g.write("0 @%s@ FAM\n" % self.fid(family.getId()))
|
|
|
|
self.prefn(family)
|
|
|
|
person = family.getFather()
|
|
|
|
if person != None and self.plist.has_key(person.getId()):
|
|
|
|
self.g.write("1 HUSB @%s@\n" % self.pid(person.getId()))
|
|
|
|
father_alive = person.probablyAlive()
|
|
|
|
|
|
|
|
person = family.getMother()
|
|
|
|
if person != None and self.plist.has_key(person.getId()):
|
|
|
|
self.g.write("1 WIFE @%s@\n" % self.pid(person.getId()))
|
|
|
|
mother_alive = person.probablyAlive()
|
|
|
|
|
|
|
|
if not self.restrict or ( not father_alive and not mother_alive ):
|
|
|
|
self.write_ord("SLGS",family.getLdsSeal(),1,const.lds_ssealing)
|
|
|
|
|
|
|
|
for event in family.getEventList():
|
|
|
|
if self.private and event.getPrivacy():
|
|
|
|
continue
|
|
|
|
name = event.getName()
|
|
|
|
val = ""
|
|
|
|
if const.familyConstantEvents.has_key(name):
|
|
|
|
val = const.familyConstantEvents[name]
|
|
|
|
if val == "":
|
|
|
|
val = self.target_ged.gramps2tag(name)
|
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
if val:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 %s %s\n" % (self.cnvtxt(val),
|
|
|
|
self.cnvtxt(event.getDescription())))
|
|
|
|
else:
|
|
|
|
self.g.write("1 EVEN %s\n" % self.cnvtxt(event.getDescription()))
|
|
|
|
self.g.write("2 TYPE %s\n" % self.cnvtxt(name))
|
|
|
|
|
|
|
|
self.dump_event_stats(event)
|
|
|
|
|
|
|
|
for person in family.getChildList():
|
|
|
|
if not self.plist.has_key(person.getId()):
|
|
|
|
continue
|
|
|
|
self.g.write("1 CHIL @%s@\n" % self.pid(person.getId()))
|
2003-01-15 10:55:50 +05:30
|
|
|
if self.adopt == GedcomInfo.ADOPT_FTW:
|
2002-10-20 19:55:16 +05:30
|
|
|
if person.getMainParents() == family:
|
|
|
|
self.g.write('2 _FREL Natural\n')
|
|
|
|
self.g.write('2 _MREL Natural\n')
|
|
|
|
else:
|
|
|
|
for f in person.getParentList():
|
|
|
|
if f[0] == family:
|
|
|
|
self.g.write('2 _FREL %s\n' % f[2])
|
|
|
|
self.g.write('2 _MREL %s\n' % f[1])
|
|
|
|
break
|
2003-01-15 10:55:50 +05:30
|
|
|
if self.adopt == GedcomInfo.ADOPT_LEGACY:
|
2002-10-20 19:55:16 +05:30
|
|
|
for f in person.getAltParentList():
|
|
|
|
if f[0] == family:
|
|
|
|
self.g.write('2 _STAT %s\n' % f[2])
|
|
|
|
break
|
|
|
|
|
|
|
|
index = index + 1
|
2003-05-21 02:01:16 +05:30
|
|
|
if index % 100 == 0 and not self.cl:
|
2002-12-30 06:12:47 +05:30
|
|
|
self.fbar.set_fraction(index/nump)
|
2002-10-20 19:55:16 +05:30
|
|
|
while(gtk.events_pending()):
|
|
|
|
gtk.mainiteration()
|
2003-05-21 02:01:16 +05:30
|
|
|
if not self.cl:
|
|
|
|
self.fbar.set_fraction(1.0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def write_sources(self):
|
|
|
|
nump = float(len(self.slist))
|
|
|
|
index = 0.0
|
|
|
|
for key in self.slist.keys():
|
|
|
|
source = self.db.getSource(key)
|
|
|
|
self.g.write("0 @%s@ SOUR\n" % self.sid(source.getId()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if source.getTitle():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 TITL %s\n" % fmtline(self.cnvtxt(source.getTitle()),248,1))
|
2002-12-30 06:12:47 +05:30
|
|
|
if source.getAuthor():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 AUTH %s\n" % self.cnvtxt(source.getAuthor()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if source.getPubInfo():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 PUBL %s\n" % self.cnvtxt(source.getPubInfo()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if source.getTitle():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 ABBR %s\n" % self.cnvtxt(source.getTitle()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if source.getCallNumber():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 CALN %s\n" % self.cnvtxt(source.getCallNumber()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if source.getNote():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_long_text("NOTE",1,self.cnvtxt(source.getNote()))
|
|
|
|
index = index + 1
|
2003-05-21 02:01:16 +05:30
|
|
|
if index % 100 == 0 and not self.cl:
|
2002-12-30 06:12:47 +05:30
|
|
|
self.sbar.set_fraction(index/nump)
|
2002-10-20 19:55:16 +05:30
|
|
|
while(gtk.events_pending()):
|
|
|
|
gtk.mainiteration()
|
2003-05-21 02:01:16 +05:30
|
|
|
if not self.cl:
|
|
|
|
self.sbar.set_fraction(1.0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def write_person(self,person):
|
|
|
|
self.g.write("0 @%s@ INDI\n" % self.pid(person.getId()))
|
|
|
|
self.prefn(person)
|
|
|
|
self.write_person_name(person.getPrimaryName(),person.getNickName())
|
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
if self.altname == GedcomInfo.ALT_NAME_STD:
|
2002-10-20 19:55:16 +05:30
|
|
|
for name in person.getAlternateNames():
|
|
|
|
self.write_person_name(name,"")
|
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
if person.getGender() == RelLib.Person.male:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 SEX M\n")
|
2003-01-15 10:55:50 +05:30
|
|
|
elif person.getGender() == RelLib.Person.female:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 SEX F\n")
|
|
|
|
|
|
|
|
if not self.restrict or not person.probablyAlive():
|
|
|
|
|
|
|
|
birth = person.getBirth()
|
|
|
|
if not (self.private and birth.getPrivacy()):
|
2002-12-30 06:12:47 +05:30
|
|
|
if not birth.getDateObj().isEmpty() or birth.getPlaceName():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 BIRT\n")
|
|
|
|
self.dump_event_stats(birth)
|
|
|
|
|
|
|
|
death = person.getDeath()
|
|
|
|
if not (self.private and death.getPrivacy()):
|
2002-12-30 06:12:47 +05:30
|
|
|
if not death.getDateObj().isEmpty() or death.getPlaceName():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 DEAT\n")
|
|
|
|
self.dump_event_stats(death)
|
|
|
|
|
|
|
|
uid = person.getPafUid()
|
2002-12-30 06:12:47 +05:30
|
|
|
if uid:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 _UID %s\n" % uid)
|
|
|
|
|
|
|
|
ad = 0
|
|
|
|
|
|
|
|
self.write_ord("BAPL",person.getLdsBaptism(),1,const.lds_baptism)
|
|
|
|
self.write_ord("ENDL",person.getLdsEndowment(),1,const.lds_baptism)
|
|
|
|
self.write_ord("SLGC",person.getLdsSeal(),1,const.lds_csealing)
|
|
|
|
|
|
|
|
for event in person.getEventList():
|
|
|
|
if self.private and event.getPrivacy():
|
|
|
|
continue
|
|
|
|
name = event.getName()
|
|
|
|
val = ""
|
|
|
|
if const.personalConstantEvents.has_key(name):
|
|
|
|
val = const.personalConstantEvents[name]
|
|
|
|
if val == "":
|
|
|
|
val = self.target_ged.gramps2tag(name)
|
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
if self.adopt == GedcomInfo.ADOPT_EVENT and val == "ADOP":
|
2002-10-20 19:55:16 +05:30
|
|
|
ad = 1
|
|
|
|
self.g.write('1 ADOP\n')
|
|
|
|
fam = None
|
|
|
|
for f in person.getParentList():
|
|
|
|
mrel = string.lower(f[1])
|
|
|
|
frel = string.lower(f[2])
|
2002-10-28 19:06:39 +05:30
|
|
|
if mrel=="adopted" or frel=="adopted":
|
2002-10-20 19:55:16 +05:30
|
|
|
fam = f[0]
|
|
|
|
break
|
|
|
|
if fam:
|
|
|
|
self.g.write('2 FAMC @%s@\n' % self.fid(fam.getId()))
|
|
|
|
if mrel == frel:
|
|
|
|
self.g.write('3 ADOP BOTH\n')
|
|
|
|
elif mrel == "adopted":
|
|
|
|
self.g.write('3 ADOP WIFE\n')
|
|
|
|
else:
|
|
|
|
self.g.write('3 ADOP HUSB\n')
|
2002-12-30 06:12:47 +05:30
|
|
|
elif val :
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 %s %s\n" % (self.cnvtxt(val),\
|
|
|
|
self.cnvtxt(event.getDescription())))
|
|
|
|
else:
|
|
|
|
self.g.write("1 EVEN %s\n" % self.cnvtxt(event.getDescription()))
|
|
|
|
self.g.write("2 TYPE %s\n" % self.cnvtxt(event.getName()))
|
|
|
|
|
|
|
|
self.dump_event_stats(event)
|
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
if self.adopt == GedcomInfo.ADOPT_EVENT and ad == 0 and len(person.getParentList()) != 0:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write('1 ADOP\n')
|
|
|
|
fam = None
|
|
|
|
for f in person.getParentList():
|
|
|
|
mrel = string.lower(f[1])
|
|
|
|
frel = string.lower(f[2])
|
2002-10-28 19:06:39 +05:30
|
|
|
if mrel=="adopted" or frel=="adopted":
|
2002-10-20 19:55:16 +05:30
|
|
|
fam = f[0]
|
|
|
|
break
|
|
|
|
if fam:
|
|
|
|
self.g.write('2 FAMC @%s@\n' % self.fid(fam.getId()))
|
|
|
|
if mrel == frel:
|
|
|
|
self.g.write('3 ADOP BOTH\n')
|
|
|
|
elif mrel == "adopted":
|
|
|
|
self.g.write('3 ADOP WIFE\n')
|
|
|
|
else:
|
|
|
|
self.g.write('3 ADOP HUSB\n')
|
|
|
|
|
|
|
|
for attr in person.getAttributeList():
|
|
|
|
if self.private and attr.getPrivacy():
|
|
|
|
continue
|
|
|
|
name = attr.getType()
|
|
|
|
if const.personalConstantAttributes.has_key(name):
|
|
|
|
val = const.personalConstantAttributes[name]
|
|
|
|
else:
|
|
|
|
val = ""
|
2002-12-30 06:12:47 +05:30
|
|
|
if val :
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("1 %s\n" % val)
|
|
|
|
else:
|
|
|
|
self.g.write("1 EVEN\n")
|
|
|
|
self.g.write("2 TYPE %s\n" % self.cnvtxt(name))
|
2003-01-02 10:01:52 +05:30
|
|
|
self.g.write("2 PLAC %s\n" % string.replace(self.cnvtxt(attr.getValue()),'\r',' '))
|
2002-12-30 06:12:47 +05:30
|
|
|
if attr.getNote():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_long_text("NOTE",2,self.cnvtxt(attr.getNote()))
|
|
|
|
for srcref in attr.getSourceRefList():
|
|
|
|
self.write_source_ref(2,srcref)
|
|
|
|
|
|
|
|
for addr in person.getAddressList():
|
|
|
|
if self.private and addr.getPrivacy():
|
|
|
|
continue
|
|
|
|
self.g.write("1 RESI\n")
|
|
|
|
self.print_date("2 DATE",addr.getDateObj())
|
|
|
|
if self.resi == 0:
|
2003-01-26 10:41:35 +05:30
|
|
|
self.write_long_text("ADDR",2,self.cnvtxt(addr.getStreet()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if addr.getCity():
|
2003-01-26 10:41:35 +05:30
|
|
|
self.g.write("3 CITY %s\n" % self.cnvtxt(addr.getCity()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if addr.getState():
|
2003-01-26 10:41:35 +05:30
|
|
|
self.g.write("3 STAE %s\n" % self.cnvtxt(addr.getState()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if addr.getPostal():
|
2003-01-26 10:41:35 +05:30
|
|
|
self.g.write("3 POST %s\n" % self.cnvtxt(addr.getPostal()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if addr.getCountry():
|
2003-01-26 10:41:35 +05:30
|
|
|
self.g.write("3 CTRY %s\n" % self.cnvtxt(addr.getCountry()))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
text = addr.getStreet()
|
|
|
|
text = addr_append(text,addr.getCity())
|
|
|
|
text = addr_append(text,addr.getState())
|
|
|
|
text = addr_append(text,addr.getPostal())
|
|
|
|
text = addr_append(text,addr.getCountry())
|
|
|
|
if text:
|
2003-01-10 10:51:32 +05:30
|
|
|
self.g.write("2 PLAC %s\n" % string.replace(self.cnvtxt(text),'\r',' '))
|
2002-12-30 06:12:47 +05:30
|
|
|
if addr.getNote():
|
2003-05-21 03:28:07 +05:30
|
|
|
self.write_long_text("NOTE",2,self.cnvtxt(addr.getNote()))
|
2002-10-20 19:55:16 +05:30
|
|
|
for srcref in addr.getSourceRefList():
|
2003-05-21 03:28:07 +05:30
|
|
|
self.write_source_ref(2,srcref)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
for family in person.getParentList():
|
|
|
|
if self.flist.has_key(family[0].getId()):
|
|
|
|
self.g.write("1 FAMC @%s@\n" % self.fid(family[0].getId()))
|
2003-01-15 10:55:50 +05:30
|
|
|
if self.adopt == GedcomInfo.ADOPT_PEDI:
|
2002-10-20 19:55:16 +05:30
|
|
|
if string.lower(family[1]) == "adopted":
|
|
|
|
self.g.write("2 PEDI Adopted\n")
|
|
|
|
|
|
|
|
for family in person.getFamilyList():
|
|
|
|
if family != None and self.flist.has_key(family.getId()):
|
|
|
|
self.g.write("1 FAMS @%s@\n" % self.fid(family.getId()))
|
|
|
|
|
|
|
|
if self.obje:
|
|
|
|
for url in person.getUrlList():
|
|
|
|
self.g.write('1 OBJE\n')
|
|
|
|
self.g.write('2 FORM URL\n')
|
2002-12-30 06:12:47 +05:30
|
|
|
if url.get_description():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write('2 TITL %s\n' % url.get_description())
|
2002-12-30 06:12:47 +05:30
|
|
|
if url.get_path():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write('2 FILE %s\n' % url.get_path())
|
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
if person.getNote():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_long_text("NOTE",1,self.cnvtxt(person.getNote()))
|
|
|
|
|
|
|
|
def write_long_text(self,tag,level,note):
|
2003-01-15 10:55:50 +05:30
|
|
|
if self.conc == GedcomInfo.CONC_OK:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_conc_ok(tag,level,note)
|
|
|
|
else:
|
|
|
|
self.write_conc_broken(tag,level,note)
|
|
|
|
|
|
|
|
def write_conc_ok(self,tag,level,note):
|
|
|
|
prefix = "%d %s" % (level,tag)
|
|
|
|
textlines = string.split(note,'\n')
|
|
|
|
if len(note) == 0:
|
|
|
|
self.g.write("%s\n" % prefix)
|
|
|
|
else:
|
|
|
|
for line in textlines:
|
|
|
|
ll = len(line)
|
|
|
|
while ll > 0:
|
|
|
|
brkpt = 70
|
|
|
|
if ll > brkpt:
|
|
|
|
while (ll > brkpt and line[brkpt] in string.whitespace):
|
|
|
|
brkpt = brkpt+1
|
|
|
|
if ll == brkpt:
|
|
|
|
self.g.write("%s %s\n" % (prefix,line))
|
|
|
|
line = ''
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.g.write("%s %s\n" % (prefix,line[0:brkpt+1]))
|
|
|
|
line = line[brkpt+1:]
|
|
|
|
else:
|
|
|
|
self.g.write("%s %s\n" % (prefix,line))
|
|
|
|
line = ""
|
|
|
|
if len(line) > 0:
|
|
|
|
prefix = "%d CONC" % (level+1)
|
|
|
|
else:
|
|
|
|
prefix = "%d CONT" % (level+1)
|
|
|
|
ll = len(line)
|
|
|
|
|
|
|
|
def write_conc_broken(self,tag,level,note):
|
|
|
|
prefix = "%d %s" % (level,tag)
|
|
|
|
textlines = string.split(note,'\n')
|
|
|
|
if len(note) == 0:
|
|
|
|
self.g.write("%s\n" % prefix)
|
|
|
|
else:
|
|
|
|
for line in textlines:
|
|
|
|
ll = len(line)
|
|
|
|
while ll > 0:
|
|
|
|
brkpt = 70
|
|
|
|
if ll > brkpt:
|
|
|
|
while (ll > brkpt and line[brkpt] not in string.whitespace):
|
|
|
|
brkpt = brkpt+1
|
|
|
|
if ll == brkpt:
|
|
|
|
self.g.write("%s %s\n" % (prefix,line))
|
|
|
|
line = ''
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.g.write("%s %s\n" % (prefix,line[0:brkpt+1]))
|
|
|
|
line = line[brkpt+1:]
|
|
|
|
else:
|
|
|
|
self.g.write("%s %s\n" % (prefix,line))
|
|
|
|
line = ""
|
|
|
|
if len(line) > 0:
|
|
|
|
prefix = "%d CONC" % (level+1)
|
|
|
|
else:
|
|
|
|
prefix = "%d CONT" % (level+1)
|
|
|
|
ll = len(line)
|
|
|
|
|
|
|
|
def dump_event_stats(self,event):
|
|
|
|
dateobj = event.getDateObj()
|
|
|
|
self.print_date("2 DATE",dateobj)
|
2002-12-30 06:12:47 +05:30
|
|
|
if event.getPlaceName():
|
2003-01-02 10:01:52 +05:30
|
|
|
self.g.write("2 PLAC %s\n" % string.replace(self.cnvtxt(event.getPlaceName()),'\r',' '))
|
2002-12-30 06:12:47 +05:30
|
|
|
if event.getCause():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("2 CAUS %s\n" % self.cnvtxt(event.getCause()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if event.getNote():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_long_text("NOTE",2,self.cnvtxt(event.getNote()))
|
|
|
|
for srcref in event.getSourceRefList():
|
|
|
|
self.write_source_ref(2,srcref)
|
|
|
|
|
|
|
|
def write_ord(self,name,ord,index,statlist):
|
|
|
|
if ord == None:
|
|
|
|
return
|
|
|
|
self.g.write('%d %s\n' % (index,name))
|
|
|
|
self.print_date("%d DATE" % (index + 1), ord.getDateObj())
|
|
|
|
if ord.getFamily():
|
|
|
|
self.g.write('%d FAMC @%s@\n' % (index+1,self.fid(ord.getFamily().getId())))
|
2002-12-30 06:12:47 +05:30
|
|
|
if ord.getTemple():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write('%d TEMP %s\n' % (index+1,ord.getTemple()))
|
2002-12-30 06:12:47 +05:30
|
|
|
if ord.getPlaceName():
|
2003-01-02 10:01:52 +05:30
|
|
|
self.g.write("2 PLAC %s\n" % string.replace(self.cnvtxt(ord.getPlaceName()),'\r',' '))
|
2002-10-20 19:55:16 +05:30
|
|
|
if ord.getStatus() != 0:
|
|
|
|
self.g.write("2 STAT %s\n" % self.cnvtxt(statlist[ord.getStatus()]))
|
2002-12-30 06:12:47 +05:30
|
|
|
if ord.getNote():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_long_text("NOTE",index+1,self.cnvtxt(ord.getNote()))
|
|
|
|
for srcref in ord.getSourceRefList():
|
|
|
|
self.write_source_ref(index+1,srcref)
|
|
|
|
|
|
|
|
def print_date(self,prefix,date):
|
|
|
|
start = date.get_start_date()
|
|
|
|
if date.isEmpty():
|
|
|
|
val = date.getText()
|
2002-12-30 06:12:47 +05:30
|
|
|
if val:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("%s %s\n" % (prefix,self.cnvtxt(val)))
|
2002-12-29 11:14:35 +05:30
|
|
|
else:
|
2002-10-20 19:55:16 +05:30
|
|
|
if date.isRange():
|
2002-12-29 11:14:35 +05:30
|
|
|
val = "FROM %s TO %s" % (make_date(start),
|
|
|
|
make_date(date.get_stop_date()))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2002-12-30 06:12:47 +05:30
|
|
|
val = make_date(start)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("%s %s\n" % (prefix,val))
|
|
|
|
|
|
|
|
def write_person_name(self,name,nick):
|
|
|
|
firstName = self.cnvtxt(name.getFirstName())
|
|
|
|
surName = self.cnvtxt(name.getSurname())
|
2002-12-04 10:28:07 +05:30
|
|
|
surPref = self.cnvtxt(name.getSurnamePrefix())
|
2002-10-20 19:55:16 +05:30
|
|
|
suffix = self.cnvtxt(name.getSuffix())
|
|
|
|
title = self.cnvtxt(name.getTitle())
|
|
|
|
if suffix == "":
|
2002-12-30 06:12:47 +05:30
|
|
|
if not surPref:
|
2002-12-04 10:28:07 +05:30
|
|
|
self.g.write("1 NAME %s /%s/\n" % (firstName,surName))
|
|
|
|
else:
|
|
|
|
self.g.write("1 NAME %s /%s %s/\n" % (firstName,surPref,surName))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2002-12-30 06:12:47 +05:30
|
|
|
if not surPref:
|
2002-12-04 10:28:07 +05:30
|
|
|
self.g.write("1 NAME %s /%s %s/, %s\n" % (firstName,surPref,surName,suffix))
|
|
|
|
else:
|
|
|
|
self.g.write("1 NAME %s /%s/, %s\n" % (firstName,surName,suffix))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
if name.getFirstName():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("2 GIVN %s\n" % firstName)
|
2002-12-04 10:28:07 +05:30
|
|
|
if self.prefix:
|
|
|
|
if surPref:
|
|
|
|
self.g.write('2 SPFX %s\n' % surPref)
|
2002-12-30 06:12:47 +05:30
|
|
|
if surName:
|
2002-12-04 10:28:07 +05:30
|
|
|
self.g.write("2 SURN %s\n" % surName)
|
|
|
|
else:
|
|
|
|
if surPref:
|
|
|
|
self.g.write("2 SURN %s %s\n" % (surPref,surName))
|
2002-12-14 10:37:09 +05:30
|
|
|
elif surName:
|
2002-12-04 10:28:07 +05:30
|
|
|
self.g.write("2 SURN %s\n" % surName)
|
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
if name.getSuffix():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("2 NSFX %s\n" % suffix)
|
2002-12-30 06:12:47 +05:30
|
|
|
if name.getTitle():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write("2 NPFX %s\n" % title)
|
2002-12-30 06:12:47 +05:30
|
|
|
if nick:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.g.write('2 NICK %s\n' % nick)
|
2002-12-30 06:12:47 +05:30
|
|
|
if name.getNote():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.write_long_text("NOTE",2,self.cnvtxt(name.getNote()))
|
|
|
|
for srcref in name.getSourceRefList():
|
|
|
|
self.write_source_ref(2,srcref)
|
|
|
|
|
|
|
|
def write_source_ref(self,level,ref):
|
|
|
|
if ref.getBase() == None:
|
|
|
|
return
|
2003-01-03 08:49:50 +05:30
|
|
|
|
|
|
|
if self.source_refs:
|
|
|
|
self.g.write("%d SOUR @%s@\n" %
|
|
|
|
(level,self.sid(ref.getBase().getId())))
|
|
|
|
if ref.getPage() != "":
|
|
|
|
self.g.write("%d PAGE %s\n" % (level+1,ref.getPage()))
|
|
|
|
|
|
|
|
ref_text = ref.getText()
|
|
|
|
if ref_text != "" or not ref.getDate().isEmpty():
|
|
|
|
self.g.write('%d DATA\n' % (level+1))
|
|
|
|
if ref_text != "":
|
2003-01-26 10:41:35 +05:30
|
|
|
self.write_long_text("TEXT",level+2,self.cnvtxt(ref_text))
|
2003-01-03 08:49:50 +05:30
|
|
|
pfx = "%d DATE" % (level+2)
|
|
|
|
self.print_date(pfx,ref.getDate())
|
|
|
|
else:
|
|
|
|
# We put title, page, and date on the SOUR line.
|
2003-01-08 10:28:00 +05:30
|
|
|
# Not using CONC and CONT because GeneWeb does not support these.
|
2003-01-03 08:49:50 +05:30
|
|
|
# TEXT and NOTE will be ignored by GeneWeb, but we can't
|
2003-01-08 10:28:00 +05:30
|
|
|
# output paragaphs in SOUR without CONT.
|
2003-01-03 08:49:50 +05:30
|
|
|
sbase = ref.getBase()
|
|
|
|
if sbase and sbase.getTitle():
|
|
|
|
txt = sbase.getTitle() + ". "
|
|
|
|
else:
|
|
|
|
txt = ""
|
|
|
|
if ref.getPage():
|
|
|
|
txt = txt + ref.getPage() + ". "
|
|
|
|
self.g.write("%d SOUR %s" % (level,self.cnvtxt(txt)))
|
|
|
|
if not ref.getDate().isEmpty():
|
|
|
|
self.print_date("", ref.getDate())
|
|
|
|
else:
|
|
|
|
self.g.write("\n")
|
|
|
|
if ref.getText():
|
2003-01-26 10:41:35 +05:30
|
|
|
self.write_long_text("TEXT",level+1,self.cnvtxt(ref_text))
|
2003-01-03 08:49:50 +05:30
|
|
|
|
2002-12-30 06:12:47 +05:30
|
|
|
if ref.getComments():
|
2003-01-26 10:41:35 +05:30
|
|
|
self.write_long_text("NOTE",level+1,self.cnvtxt(ref.getComments()))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def fid(self,id):
|
|
|
|
return id
|
|
|
|
|
|
|
|
def prefn(self,person):
|
2002-12-30 06:12:47 +05:30
|
|
|
match = _get_int.search(person.getId())
|
2002-10-20 19:55:16 +05:30
|
|
|
if match:
|
|
|
|
self.g.write('1 REFN %d\n' % int(match.groups()[0]))
|
|
|
|
|
|
|
|
def frefn(self,family):
|
2002-12-30 06:12:47 +05:30
|
|
|
match = _get_int.search(family.getId())
|
2002-10-20 19:55:16 +05:30
|
|
|
if match:
|
|
|
|
self.g.write('1 REFN %d\n' % int(match.groups()[0]))
|
|
|
|
|
|
|
|
def pid(self,id):
|
|
|
|
return id
|
|
|
|
|
|
|
|
def sid(self,id):
|
|
|
|
if self.sidmap.has_key(id):
|
|
|
|
return self.sidmap[id]
|
|
|
|
else:
|
|
|
|
val = "S%05d" % self.sidval
|
|
|
|
self.sidval = self.sidval + 1
|
|
|
|
self.sidmap[id] = val
|
|
|
|
return val
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from Plugins import register_export
|
|
|
|
|
|
|
|
register_export(writeData,_("Export to GEDCOM"))
|
|
|
|
|
|
|
|
|
|
|
|
|