2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
|
|
|
from RelLib import *
|
|
|
|
from GrampsParser import *
|
|
|
|
import intl
|
2001-05-18 04:38:27 +05:30
|
|
|
_ = intl.gettext
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
import string
|
|
|
|
import time
|
|
|
|
import gzip
|
|
|
|
import os
|
|
|
|
from gnome.ui import *
|
|
|
|
|
|
|
|
import xml.sax
|
|
|
|
import xml.sax.saxutils
|
|
|
|
|
2001-05-18 04:38:27 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Try to abstract SAX1 from SAX2
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
try:
|
|
|
|
import xml.sax.saxexts
|
|
|
|
sax = 1
|
|
|
|
except:
|
|
|
|
from codecs import *
|
|
|
|
sax = 2
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Initialization function for the module. Called to start the reading
|
|
|
|
# of data.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def importData(database, filename, callback):
|
|
|
|
|
|
|
|
basefile = os.path.dirname(filename)
|
|
|
|
database.smap = {}
|
|
|
|
database.pmap = {}
|
|
|
|
database.fmap = {}
|
|
|
|
|
2001-05-18 04:38:27 +05:30
|
|
|
if sax == 1:
|
|
|
|
parser = xml.sax.saxexts.make_parser()
|
|
|
|
parser.setDocumentHandler(GrampsParser(database,callback,basefile,1))
|
|
|
|
parser.setErrorHandler(xml.sax.saxutils.ErrorRaiser())
|
|
|
|
xml_file = gzip.open(filename,"rb")
|
|
|
|
parser.parseFile(xml_file)
|
|
|
|
else:
|
|
|
|
parser = xml.sax.make_parser()
|
|
|
|
parser.setContentHandler(GrampsParser(database,callback,basefile,1))
|
|
|
|
xml_file = EncodedFile(gzip.open(filename,"rb"),'utf-8','latin-1')
|
|
|
|
parser.parse(xml_file)
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
xml_file.close()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Initialization function for the module. Called to start the reading
|
|
|
|
# of data.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def loadData(database, filename, callback):
|
|
|
|
|
|
|
|
basefile = os.path.dirname(filename)
|
|
|
|
database.smap = {}
|
|
|
|
database.pmap = {}
|
|
|
|
database.fmap = {}
|
|
|
|
|
|
|
|
filename = os.path.normpath(filename)
|
|
|
|
|
2001-05-18 04:38:27 +05:30
|
|
|
if sax == 1:
|
|
|
|
parser = xml.sax.saxexts.make_parser()
|
|
|
|
parser.setDocumentHandler(GrampsParser(database,callback,basefile,0))
|
|
|
|
parser.setErrorHandler(xml.sax.saxutils.ErrorRaiser())
|
|
|
|
else:
|
|
|
|
parser = xml.sax.make_parser()
|
|
|
|
parser.setContentHandler(GrampsParser(database,callback,basefile,0))
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
try:
|
2001-05-18 04:38:27 +05:30
|
|
|
if sax == 1:
|
|
|
|
xml_file = gzip.open(filename,"rb")
|
|
|
|
else:
|
|
|
|
xml_file = EncodedFile(gzip.open(filename,"rb"),'utf-8','latin-1')
|
2001-05-13 07:26:57 +05:30
|
|
|
except IOError,msg:
|
2001-05-23 04:00:13 +05:30
|
|
|
GnomeErrorDialog(_("%s could not be opened\n") % filename + str(msg))
|
2001-05-13 07:26:57 +05:30
|
|
|
return 0
|
|
|
|
except:
|
2001-05-23 04:00:13 +05:30
|
|
|
GnomeErrorDialog(_("%s could not be opened\n") % filename)
|
2001-05-13 07:26:57 +05:30
|
|
|
return 0
|
|
|
|
|
|
|
|
try:
|
2001-05-18 04:38:27 +05:30
|
|
|
if sax == 1:
|
|
|
|
parser.parseFile(xml_file)
|
|
|
|
else:
|
|
|
|
parser.parse(xml_file)
|
2001-05-13 07:26:57 +05:30
|
|
|
except xml.sax.SAXParseException:
|
2001-05-23 04:00:13 +05:30
|
|
|
GnomeErrorDialog(_("%s is a corrupt file") % filename)
|
2001-05-13 07:26:57 +05:30
|
|
|
return 0
|
|
|
|
except IOError,msg:
|
2001-05-23 04:00:13 +05:30
|
|
|
GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg))
|
2001-05-13 07:26:57 +05:30
|
|
|
return 0
|
|
|
|
except:
|
2001-05-23 04:00:13 +05:30
|
|
|
GnomeErrorDialog(_("Error reading %s") % filename)
|
2001-05-13 07:26:57 +05:30
|
|
|
return 0
|
2001-05-18 04:38:27 +05:30
|
|
|
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
xml_file.close()
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
2001-05-18 04:38:27 +05:30
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import profile
|
|
|
|
|
|
|
|
def lcb(val):
|
|
|
|
pass
|
|
|
|
|
|
|
|
db = RelDataBase()
|
|
|
|
file = sys.argv[1]
|
|
|
|
|
|
|
|
t1 = time.time()
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2001-05-18 04:38:27 +05:30
|
|
|
loadData(db,file,lcb)
|
|
|
|
t2 = time.time()
|
|
|
|
print t2 - t1
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|