2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-02-19 06:19:49 +05:30
|
|
|
# Copyright (C) 2000-2005 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
|
|
|
|
#
|
|
|
|
|
2005-02-19 06:19:49 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
import const
|
|
|
|
|
|
|
|
ADOPT_NONE = 0
|
|
|
|
ADOPT_EVENT = 1
|
|
|
|
ADOPT_FTW = 2
|
|
|
|
ADOPT_LEGACY = 3
|
|
|
|
ADOPT_PEDI = 4
|
|
|
|
ADOPT_STD = 5
|
|
|
|
CONC_OK = 0
|
|
|
|
CONC_BROKEN = 1
|
|
|
|
ALT_NAME_NONE = 0
|
|
|
|
ALT_NAME_STD = 1
|
|
|
|
ALT_NAME_ALIAS = 2
|
|
|
|
ALT_NAME_AKA = 3
|
|
|
|
ALT_NAME_EVENT_AKA = 4
|
|
|
|
ALT_NAME_UALIAS = 5
|
|
|
|
CALENDAR_NO = 0
|
|
|
|
CALENDAR_YES = 1
|
|
|
|
OBJE_NO = 0
|
|
|
|
OBJE_YES = 1
|
2002-12-04 10:28:07 +05:30
|
|
|
PREFIX_NO = 0
|
|
|
|
PREFIX_YES = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
RESIDENCE_ADDR = 0
|
|
|
|
RESIDENCE_PLAC = 1
|
2003-01-03 08:49:50 +05:30
|
|
|
SOURCE_REFS_NO = 0
|
|
|
|
SOURCE_REFS_YES = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# XML parser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-02-19 06:19:49 +05:30
|
|
|
from xml.parsers.expat import ParserCreate
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
class GedcomDescription:
|
|
|
|
def __init__(self,name):
|
|
|
|
self.name = name
|
|
|
|
self.dest = ""
|
|
|
|
self.adopt = ADOPT_STD
|
|
|
|
self.conc = CONC_OK
|
|
|
|
self.altname = ALT_NAME_STD
|
|
|
|
self.cal = CALENDAR_YES
|
|
|
|
self.obje = OBJE_YES
|
|
|
|
self.resi = RESIDENCE_ADDR
|
2003-01-03 08:49:50 +05:30
|
|
|
self.source_refs = SOURCE_REFS_YES
|
2002-10-20 19:55:16 +05:30
|
|
|
self.gramps2tag_map = {}
|
|
|
|
self.tag2gramps_map = {}
|
2002-12-04 10:28:07 +05:30
|
|
|
self.prefix = PREFIX_YES
|
2003-06-28 23:05:00 +05:30
|
|
|
self.endl = "\n"
|
2002-12-04 10:28:07 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def set_dest(self,val):
|
|
|
|
self.dest = val
|
|
|
|
|
|
|
|
def get_dest(self):
|
|
|
|
return self.dest
|
|
|
|
|
2003-06-28 23:05:00 +05:30
|
|
|
def set_endl(self,val):
|
|
|
|
self.endl = val.replace('\\r','\r').replace('\\n','\n')
|
|
|
|
|
|
|
|
def get_endl(self):
|
|
|
|
return self.endl
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def set_adopt(self,val):
|
|
|
|
self.adopt = val
|
|
|
|
|
|
|
|
def get_adopt(self):
|
|
|
|
return self.adopt
|
|
|
|
|
2002-12-04 10:28:07 +05:30
|
|
|
def set_prefix(self,val):
|
|
|
|
self.prefix=val
|
|
|
|
|
|
|
|
def get_prefix(self):
|
|
|
|
return self.prefix
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def set_conc(self,val):
|
|
|
|
self.conc = val
|
|
|
|
|
|
|
|
def get_conc(self):
|
|
|
|
return self.conc
|
|
|
|
|
|
|
|
def set_alt_name(self,val):
|
|
|
|
self.altname = val
|
|
|
|
|
|
|
|
def get_alt_name(self):
|
|
|
|
return self.altname
|
|
|
|
|
|
|
|
def set_alt_calendar(self,val):
|
|
|
|
self.cal = val
|
|
|
|
|
|
|
|
def get_alt_calendar(self):
|
|
|
|
return self.cal
|
|
|
|
|
|
|
|
def set_obje(self,val):
|
|
|
|
self.obje = val
|
|
|
|
|
|
|
|
def get_obje(self):
|
|
|
|
return self.obje
|
|
|
|
|
|
|
|
def set_resi(self,val):
|
|
|
|
self.resi = val
|
|
|
|
|
|
|
|
def get_resi(self):
|
|
|
|
return self.resi
|
|
|
|
|
2003-01-03 08:49:50 +05:30
|
|
|
def set_source_refs(self,val):
|
|
|
|
self.source_refs = val
|
|
|
|
|
|
|
|
def get_source_refs(self):
|
|
|
|
return self.source_refs
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def add_tag_value(self,tag,value):
|
|
|
|
self.gramps2tag_map[value] = tag
|
|
|
|
self.tag2gramps_map[tag] = value
|
|
|
|
|
|
|
|
def gramps2tag(self,key):
|
|
|
|
if self.gramps2tag_map.has_key(key):
|
|
|
|
return self.gramps2tag_map[key]
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def tag2gramps(self,key):
|
|
|
|
if self.tag2gramps_map.has_key(key):
|
|
|
|
return self.tag2gramps_map[key]
|
|
|
|
return key
|
|
|
|
|
|
|
|
class GedcomInfoDB:
|
|
|
|
def __init__(self):
|
|
|
|
self.map = {}
|
|
|
|
|
|
|
|
self.standard = GedcomDescription("GEDCOM 5.5 standard")
|
|
|
|
self.standard.set_dest("GEDCOM 5.5")
|
2003-01-08 10:28:00 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
try:
|
2006-03-03 05:47:58 +05:30
|
|
|
filepath = os.path.join(const.data_dir,"gedcom.xml")
|
2004-05-14 04:15:51 +05:30
|
|
|
f = open(filepath.encode('iso8859-1'),"r")
|
2002-10-20 19:55:16 +05:30
|
|
|
except:
|
|
|
|
return
|
2003-01-08 10:28:00 +05:30
|
|
|
|
|
|
|
parser = GedInfoParser(self)
|
|
|
|
parser.parse(f)
|
|
|
|
f.close()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def add_description(self,name,obj):
|
|
|
|
self.map[name] = obj
|
|
|
|
|
|
|
|
def get_description(self,name):
|
|
|
|
if self.map.has_key(name):
|
|
|
|
return self.map[name]
|
|
|
|
return self.standard
|
|
|
|
|
|
|
|
def get_from_source_tag(self,name):
|
|
|
|
for k in self.map.keys():
|
|
|
|
val = self.map[k]
|
|
|
|
if val.get_dest() == name:
|
|
|
|
return val
|
|
|
|
return self.standard
|
|
|
|
|
|
|
|
def get_name_list(self):
|
|
|
|
mylist = self.map.keys()
|
|
|
|
mylist.sort()
|
|
|
|
return ["GEDCOM 5.5 standard"] + mylist
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class GedInfoParser:
|
|
|
|
def __init__(self,parent):
|
|
|
|
self.parent = parent
|
|
|
|
self.current = None
|
|
|
|
|
|
|
|
def parse(self,file):
|
2005-02-19 06:19:49 +05:30
|
|
|
p = ParserCreate()
|
2002-10-20 19:55:16 +05:30
|
|
|
p.StartElementHandler = self.startElement
|
|
|
|
p.ParseFile(file)
|
|
|
|
|
|
|
|
def startElement(self,tag,attrs):
|
|
|
|
if tag == "target":
|
2002-11-19 09:45:02 +05:30
|
|
|
name = attrs['name']
|
2002-10-20 19:55:16 +05:30
|
|
|
self.current = GedcomDescription(name)
|
|
|
|
self.parent.add_description(name,self.current)
|
|
|
|
elif tag == "dest":
|
2002-11-19 09:45:02 +05:30
|
|
|
self.current.set_dest(attrs['val'])
|
2003-06-28 23:05:00 +05:30
|
|
|
elif tag == "endl":
|
|
|
|
self.current.set_endl(attrs['val'])
|
2002-10-20 19:55:16 +05:30
|
|
|
elif tag == "adopt":
|
2003-01-08 10:28:00 +05:30
|
|
|
val = attrs['val']
|
2002-10-20 19:55:16 +05:30
|
|
|
if val == 'none':
|
|
|
|
self.current.set_adopt(ADOPT_NONE)
|
|
|
|
elif val == 'event':
|
|
|
|
self.current.set_adopt(ADOPT_EVENT)
|
|
|
|
elif val == 'ftw':
|
|
|
|
self.current.set_adopt(ADOPT_FTW)
|
|
|
|
elif val == 'legacy':
|
|
|
|
self.current.set_adopt(ADOPT_LEGACY)
|
|
|
|
elif val == 'pedigree':
|
|
|
|
self.current.set_adopt(ADOPT_PEDI)
|
|
|
|
elif tag == "conc":
|
2002-11-19 09:45:02 +05:30
|
|
|
if attrs['val'] == 'broken':
|
2002-10-20 19:55:16 +05:30
|
|
|
self.current.set_conc(CONC_BROKEN)
|
|
|
|
elif tag == "alternate_names":
|
2003-01-08 10:28:00 +05:30
|
|
|
val = attrs['val']
|
2002-10-20 19:55:16 +05:30
|
|
|
if val == 'none':
|
|
|
|
self.current.set_alt_name(ALT_NAME_NONE)
|
|
|
|
elif val == 'event_aka':
|
|
|
|
self.current.set_alt_name(ALT_NAME_EVENT_AKA)
|
|
|
|
elif val == 'alias':
|
|
|
|
self.current.set_alt_name(ALT_NAME_ALIAS)
|
|
|
|
elif val == 'aka':
|
|
|
|
self.current.set_alt_name(ALT_NAME_AKA)
|
|
|
|
elif val == '_alias':
|
|
|
|
self.current.set_alt_name(ALT_NAME_UALIAS)
|
|
|
|
elif tag == "calendars":
|
2002-11-19 09:45:02 +05:30
|
|
|
if attrs['val'] == 'no':
|
2002-10-20 19:55:16 +05:30
|
|
|
self.current.set_alt_calendar(CALENDAR_NO)
|
|
|
|
elif tag == "event":
|
2002-11-19 09:45:02 +05:30
|
|
|
self.current.add_tag_value(attrs['tag'],attrs['value'])
|
2002-10-20 19:55:16 +05:30
|
|
|
elif tag == "object_support":
|
2002-11-19 09:45:02 +05:30
|
|
|
if attrs['val'] == 'no':
|
2002-10-20 19:55:16 +05:30
|
|
|
self.current.set_obje(OBJE_NO)
|
2002-12-04 10:28:07 +05:30
|
|
|
elif tag == "prefix":
|
|
|
|
if attrs['val'] == 'no':
|
|
|
|
self.current.set_obje(PREFIX_NO)
|
2002-10-20 19:55:16 +05:30
|
|
|
elif tag == "residence":
|
2002-11-19 09:45:02 +05:30
|
|
|
if attrs['val'] == 'place':
|
2002-10-20 19:55:16 +05:30
|
|
|
self.current.set_resi(RESIDENCE_PLAC)
|
2003-01-03 08:49:50 +05:30
|
|
|
elif tag == "source_refs":
|
2003-01-08 10:28:00 +05:30
|
|
|
if attrs['val'] == 'no':
|
2003-01-03 08:49:50 +05:30
|
|
|
self.current.set_source_refs(SOURCE_REFS_NO)
|