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
|
|
|
|
#
|
|
|
|
|
2001-08-31 09:10:23 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2001-11-02 23:16:33 +05:30
|
|
|
# Standard Python Modules
|
2001-08-31 09:10:23 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-05-13 07:26:57 +05:30
|
|
|
import string
|
|
|
|
import os
|
|
|
|
|
2001-11-02 23:16:33 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gnome/GTK
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from gnome.ui import GnomeErrorDialog
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from RelLib import *
|
|
|
|
from GrampsParser import GrampsParser, GrampsImportParser
|
|
|
|
from intl import gettext
|
|
|
|
_ = gettext
|
2001-08-31 09:10:23 +05:30
|
|
|
|
2001-11-02 23:16:33 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Try to detect the presence of gzip
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-09-23 19:58:15 +05:30
|
|
|
try:
|
|
|
|
import gzip
|
|
|
|
gzip_ok = 1
|
|
|
|
except:
|
|
|
|
gzip_ok = 0
|
|
|
|
|
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-11-14 05:04:29 +05:30
|
|
|
parser = GrampsImportParser(database,callback,basefile)
|
2001-07-30 04:57:42 +05:30
|
|
|
|
2001-09-23 19:58:15 +05:30
|
|
|
if gzip_ok:
|
|
|
|
use_gzip = 1
|
|
|
|
try:
|
|
|
|
f = gzip.open(filename,"r")
|
|
|
|
f.read(1)
|
|
|
|
f.close()
|
|
|
|
except IOError,msg:
|
|
|
|
use_gzip = 0
|
|
|
|
else:
|
2001-07-30 04:57:42 +05:30
|
|
|
use_gzip = 0
|
|
|
|
|
2001-06-17 00:33:54 +05:30
|
|
|
try:
|
2001-07-30 04:57:42 +05:30
|
|
|
if use_gzip:
|
|
|
|
xml_file = gzip.open(filename,"rb")
|
|
|
|
else:
|
|
|
|
xml_file = open(filename,"r")
|
2001-06-17 00:33:54 +05:30
|
|
|
except IOError,msg:
|
|
|
|
GnomeErrorDialog(_("%s could not be opened\n") % filename + str(msg))
|
|
|
|
return 0
|
|
|
|
except:
|
|
|
|
GnomeErrorDialog(_("%s could not be opened\n") % filename)
|
|
|
|
return 0
|
2001-05-18 04:38:27 +05:30
|
|
|
|
2001-06-17 00:33:54 +05:30
|
|
|
try:
|
2001-06-28 20:54:51 +05:30
|
|
|
parser.parse(xml_file)
|
2001-06-17 00:33:54 +05:30
|
|
|
except IOError,msg:
|
|
|
|
GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg))
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
return 0
|
|
|
|
except:
|
|
|
|
GnomeErrorDialog(_("Error reading %s") % filename)
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
return 0
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
xml_file.close()
|
2002-03-16 22:56:58 +05:30
|
|
|
return 1
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Initialization function for the module. Called to start the reading
|
|
|
|
# of data.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-08-24 03:43:56 +05:30
|
|
|
def loadData(database, filename, callback=None):
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
basefile = os.path.dirname(filename)
|
|
|
|
database.smap = {}
|
|
|
|
database.pmap = {}
|
|
|
|
database.fmap = {}
|
|
|
|
|
|
|
|
filename = os.path.normpath(filename)
|
|
|
|
|
2001-11-14 05:04:29 +05:30
|
|
|
parser = GrampsParser(database,callback,basefile)
|
2001-05-18 04:38:27 +05:30
|
|
|
|
2001-09-23 19:58:15 +05:30
|
|
|
if gzip_ok:
|
|
|
|
use_gzip = 1
|
|
|
|
try:
|
|
|
|
f = gzip.open(filename,"r")
|
|
|
|
f.read(1)
|
|
|
|
f.close()
|
|
|
|
except IOError,msg:
|
|
|
|
use_gzip = 0
|
|
|
|
else:
|
2001-07-30 04:57:42 +05:30
|
|
|
use_gzip = 0
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
try:
|
2001-07-30 04:57:42 +05:30
|
|
|
if use_gzip:
|
|
|
|
xml_file = gzip.open(filename,"rb")
|
|
|
|
else:
|
|
|
|
xml_file = open(filename,"r")
|
2001-05-13 07:26:57 +05:30
|
|
|
except IOError,msg:
|
2001-08-24 03:43:56 +05:30
|
|
|
filemsg = _("%s could not be opened\n") % filename
|
|
|
|
GnomeErrorDialog(filemsg + 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
|
2001-10-09 23:26:26 +05:30
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
try:
|
2001-06-28 20:54:51 +05:30
|
|
|
parser.parse(xml_file)
|
2001-05-13 07:26:57 +05:30
|
|
|
except IOError,msg:
|
2001-09-01 22:43:15 +05:30
|
|
|
errmsg = "%s\n%s" % (_("Error reading %s") % filename,str(msg))
|
2001-08-24 03:43:56 +05:30
|
|
|
GnomeErrorDialog(errmsg)
|
2001-05-24 03:48:12 +05:30
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
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-24 03:48:12 +05:30
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
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-08-24 03:43:56 +05:30
|
|
|
|
2001-10-04 09:52:41 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Initialization function for the module. Called to start the reading
|
|
|
|
# of data.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def loadRevision(database, file, filename, revision, callback=None):
|
|
|
|
|
|
|
|
basefile = os.path.dirname(filename)
|
|
|
|
database.smap = {}
|
|
|
|
database.pmap = {}
|
|
|
|
database.fmap = {}
|
|
|
|
|
2001-11-14 05:04:29 +05:30
|
|
|
parser = GrampsParser(database,callback,basefile)
|
2001-10-04 09:52:41 +05:30
|
|
|
|
|
|
|
filename = _("%s (revision %s)") % (filename,revision)
|
|
|
|
|
|
|
|
try:
|
|
|
|
parser.parse(file)
|
|
|
|
except IOError,msg:
|
|
|
|
errmsg = "%s\n%s" % (_("Error reading %s") % filename, str(msg))
|
|
|
|
GnomeErrorDialog(errmsg)
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
return 0
|
|
|
|
except:
|
|
|
|
GnomeErrorDialog(_("Error reading %s") % filename)
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
return 0
|
|
|
|
|
|
|
|
file.close()
|
|
|
|
return 1
|
|
|
|
|
2001-08-24 03:43:56 +05:30
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import profile
|
2001-11-02 12:25:19 +05:30
|
|
|
import sys
|
2001-11-02 23:16:33 +05:30
|
|
|
import time
|
2001-08-24 03:43:56 +05:30
|
|
|
|
2002-02-21 20:43:48 +05:30
|
|
|
database = GrampsDB()
|
2001-08-24 03:43:56 +05:30
|
|
|
t1 = time.time()
|
2001-10-19 05:43:23 +05:30
|
|
|
if len(sys.argv) > 2:
|
|
|
|
profile.run('loadData(database, sys.argv[1])')
|
|
|
|
else:
|
|
|
|
loadData(database,sys.argv[1])
|
2001-08-24 03:43:56 +05:30
|
|
|
t2 = time.time()
|
|
|
|
print t2-t1
|