2003-07-31 17:28:08 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-01-15 14:46:45 +05:30
|
|
|
# Copyright (C) 2003-2006, 2008 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2010-05-01 09:42:42 +05:30
|
|
|
# Copyright (C) 2010 Jakim Friant
|
2003-07-31 17:28:08 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2003-12-07 04:35:52 +05:30
|
|
|
# $Id$
|
|
|
|
|
2003-07-31 17:28:08 +05:30
|
|
|
"Export to Web Family Tree"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".WriteFtree")
|
|
|
|
|
2003-07-31 17:28:08 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Utils
|
2009-04-17 00:59:40 +05:30
|
|
|
from Filters import GenericFilter, Rules, build_filter_model
|
2010-05-30 09:37:50 +05:30
|
|
|
from ExportOptions import WriterOptionBox
|
2003-08-02 07:52:34 +05:30
|
|
|
import Errors
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2009-04-17 00:59:40 +05:30
|
|
|
|
2003-07-31 17:28:08 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# writeData
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-05-01 09:42:42 +05:30
|
|
|
def writeData(database, filename, msg_callback, option_box=None, callback=None):
|
2010-05-30 09:37:50 +05:30
|
|
|
writer = FtreeWriter(database, filename, msg_callback, option_box, callback)
|
2008-01-15 14:46:45 +05:30
|
|
|
return writer.export_data()
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# FtreeWriter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class FtreeWriter(object):
|
2003-12-07 04:35:52 +05:30
|
|
|
|
2010-05-30 09:37:50 +05:30
|
|
|
def __init__(self, database, filename, msg_callback, option_box=None,
|
2008-01-15 14:46:45 +05:30
|
|
|
callback = None):
|
2005-02-20 00:35:48 +05:30
|
|
|
self.db = database
|
|
|
|
self.filename = filename
|
2010-05-01 09:42:42 +05:30
|
|
|
self.msg_callback = msg_callback
|
2010-05-30 09:37:50 +05:30
|
|
|
self.option_box = option_box
|
|
|
|
self.callback = callback
|
2008-07-14 21:17:15 +05:30
|
|
|
if callable(self.callback): # callback is really callable
|
2006-05-10 01:15:18 +05:30
|
|
|
self.update = self.update_real
|
|
|
|
else:
|
|
|
|
self.update = self.update_empty
|
2005-02-20 00:35:48 +05:30
|
|
|
|
2010-05-30 09:37:50 +05:30
|
|
|
if option_box:
|
2005-02-20 00:35:48 +05:30
|
|
|
self.option_box.parse_options()
|
2010-05-30 09:37:50 +05:30
|
|
|
self.db = option_box.get_filtered_database(self.db)
|
2005-02-20 00:35:48 +05:30
|
|
|
|
2010-05-30 09:37:50 +05:30
|
|
|
self.plist = [x for x in self.db.iter_person_handles()]
|
2005-02-20 00:35:48 +05:30
|
|
|
|
2006-05-10 01:15:18 +05:30
|
|
|
def update_empty(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def update_real(self):
|
|
|
|
self.count += 1
|
|
|
|
newval = int(100*self.count/self.total)
|
|
|
|
if newval != self.oldval:
|
|
|
|
self.callback(newval)
|
|
|
|
self.oldval = newval
|
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
def export_data(self):
|
2003-07-31 17:28:08 +05:30
|
|
|
name_map = {}
|
|
|
|
id_map = {}
|
|
|
|
id_name = {}
|
2006-05-10 01:15:18 +05:30
|
|
|
self.count = 0
|
|
|
|
self.oldval = 0
|
|
|
|
self.total = 2*len(self.plist)
|
|
|
|
|
2003-08-02 07:52:34 +05:30
|
|
|
for key in self.plist:
|
2006-05-10 01:15:18 +05:30
|
|
|
self.update()
|
2004-08-07 10:46:57 +05:30
|
|
|
pn = self.db.get_person_from_handle(key).get_primary_name()
|
2004-02-14 11:10:30 +05:30
|
|
|
sn = pn.get_surname()
|
|
|
|
items = pn.get_first_name().split()
|
2009-04-17 00:59:40 +05:30
|
|
|
n = ("%s %s" % (items[0], sn)) if items else sn
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
count = -1
|
2008-07-17 23:40:32 +05:30
|
|
|
if n in name_map:
|
2003-07-31 17:28:08 +05:30
|
|
|
count = 0
|
|
|
|
while 1:
|
2008-01-15 14:46:45 +05:30
|
|
|
nn = "%s%d" % (n, count)
|
2008-07-17 23:40:32 +05:30
|
|
|
if nn not in name_map:
|
2003-07-31 17:28:08 +05:30
|
|
|
break;
|
2003-09-25 04:19:51 +05:30
|
|
|
count += 1
|
2003-07-31 17:28:08 +05:30
|
|
|
name_map[nn] = key
|
|
|
|
id_map[key] = nn
|
|
|
|
else:
|
|
|
|
name_map[n] = key
|
|
|
|
id_map[key] = n
|
2008-01-15 14:46:45 +05:30
|
|
|
id_name[key] = get_name(pn, count)
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
f = open(self.filename,"w")
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2003-08-02 07:52:34 +05:30
|
|
|
for key in self.plist:
|
2006-05-10 01:15:18 +05:30
|
|
|
self.update()
|
2004-08-07 10:46:57 +05:30
|
|
|
p = self.db.get_person_from_handle(key)
|
2003-07-31 17:28:08 +05:30
|
|
|
name = id_name[key]
|
2009-04-17 00:59:40 +05:30
|
|
|
father = mother = email = web = ""
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
family_handle = p.get_main_parents_family_handle()
|
|
|
|
if family_handle:
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2009-04-17 00:59:40 +05:30
|
|
|
if family.get_father_handle() and \
|
|
|
|
family.get_father_handle() in id_map:
|
2005-02-20 00:35:48 +05:30
|
|
|
father = id_map[family.get_father_handle()]
|
2009-04-17 00:59:40 +05:30
|
|
|
if family.get_mother_handle() and \
|
|
|
|
family.get_mother_handle() in id_map:
|
2005-02-20 00:35:48 +05:30
|
|
|
mother = id_map[family.get_mother_handle()]
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
#
|
|
|
|
# Calculate Date
|
|
|
|
#
|
2006-05-10 01:15:18 +05:30
|
|
|
birth_ref = p.get_birth_ref()
|
|
|
|
death_ref = p.get_death_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth_event = self.db.get_event_from_handle(birth_ref.ref)
|
2005-02-20 00:35:48 +05:30
|
|
|
birth = birth_event.get_date_object()
|
|
|
|
else:
|
|
|
|
birth = None
|
2006-05-10 01:15:18 +05:30
|
|
|
if death_ref:
|
|
|
|
death_event = self.db.get_event_from_handle(death_ref.ref)
|
2005-02-20 00:35:48 +05:30
|
|
|
death = death_event.get_date_object()
|
|
|
|
else:
|
|
|
|
death = None
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2010-05-30 09:37:50 +05:30
|
|
|
#if self.restrict:
|
|
|
|
# alive = Utils.probably_alive(p, self.db)
|
|
|
|
#else:
|
|
|
|
# alive = 0
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2010-05-30 09:37:50 +05:30
|
|
|
if birth:
|
|
|
|
if death:
|
2008-01-15 14:46:45 +05:30
|
|
|
dates = "%s-%s" % (fdate(birth), fdate(death))
|
2003-07-31 17:28:08 +05:30
|
|
|
else:
|
|
|
|
dates = fdate(birth)
|
|
|
|
else:
|
2010-05-30 09:37:50 +05:30
|
|
|
if death:
|
2003-07-31 17:28:08 +05:30
|
|
|
dates = fdate(death)
|
|
|
|
else:
|
|
|
|
dates = ""
|
|
|
|
|
2008-01-15 14:46:45 +05:30
|
|
|
f.write('%s;%s;%s;%s;%s;%s\n' % (name, father, mother, email, web,
|
|
|
|
dates))
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
f.close()
|
2008-01-15 14:46:45 +05:30
|
|
|
return True
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
def fdate(val):
|
2005-02-20 00:35:48 +05:30
|
|
|
if val.get_year_valid():
|
|
|
|
if val.get_month_valid():
|
|
|
|
if val.get_day_valid():
|
2008-01-15 14:46:45 +05:30
|
|
|
return "%d/%d/%d" % (val.get_day(), val.get_month(),
|
|
|
|
val.get_year())
|
2003-07-31 17:28:08 +05:30
|
|
|
else:
|
2008-01-15 14:46:45 +05:30
|
|
|
return "%d/%d" % (val.get_month(), val.get_year())
|
2003-07-31 17:28:08 +05:30
|
|
|
else:
|
2005-02-20 00:35:48 +05:30
|
|
|
return "%d" % val.get_year()
|
2003-07-31 17:28:08 +05:30
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
2008-01-15 14:46:45 +05:30
|
|
|
def get_name(name, count):
|
2003-07-31 17:28:08 +05:30
|
|
|
"""returns a name string built from the components of the Name
|
|
|
|
instance, in the form of Firstname Surname"""
|
2009-04-17 19:02:41 +05:30
|
|
|
|
2009-04-17 20:28:25 +05:30
|
|
|
return (name.first_name + ' ' +
|
2009-04-17 19:02:41 +05:30
|
|
|
(name.prefix + ' ' if name.prefix else '') +
|
|
|
|
name.surname +
|
|
|
|
(str(count) if count != -1 else '') +
|
|
|
|
(', ' +name.suffix if name.suffix else '')
|
|
|
|
)
|