2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-02-02 20:23:31 +05:30
|
|
|
# Copyright (C) 2000-2006 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
|
|
|
|
#
|
|
|
|
|
2004-06-28 18:50:33 +05:30
|
|
|
# $Id$
|
2003-10-23 21:03:57 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"Import from GEDCOM"
|
|
|
|
|
|
|
|
import os
|
2007-02-14 05:30:31 +05:30
|
|
|
import gtk
|
2006-01-25 10:37:10 +05:30
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
import Errors
|
2007-02-21 05:28:39 +05:30
|
|
|
from _GedcomParse import GedcomParser, StageOne
|
2007-02-14 05:30:31 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
|
|
|
from bsddb import db
|
2006-01-23 06:57:46 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-01-22 07:36:46 +05:30
|
|
|
def importData(database, filename, callback=None, use_trans=False):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-09-24 10:07:59 +05:30
|
|
|
try:
|
2007-02-14 05:30:31 +05:30
|
|
|
ifile = open(filename, "r")
|
2006-09-24 10:07:59 +05:30
|
|
|
except IOError:
|
|
|
|
return
|
2004-09-25 03:35:46 +05:30
|
|
|
|
|
|
|
ansel = False
|
|
|
|
gramps = False
|
2005-01-16 09:30:35 +05:30
|
|
|
for index in range(50):
|
2007-02-14 05:30:31 +05:30
|
|
|
line = ifile.readline().split()
|
2004-10-11 02:46:44 +05:30
|
|
|
if len(line) == 0:
|
|
|
|
break
|
2006-02-16 10:36:40 +05:30
|
|
|
if len(line) > 2 and line[1][0:4] == 'CHAR' and line[2] == "ANSEL":
|
2004-09-25 03:35:46 +05:30
|
|
|
ansel = True
|
2006-02-16 10:36:40 +05:30
|
|
|
if len(line) > 2 and line[1][0:4] == 'SOUR' and line[2] == "GRAMPS":
|
2004-09-25 03:35:46 +05:30
|
|
|
gramps = True
|
2007-02-14 05:30:31 +05:30
|
|
|
ifile.close()
|
2004-09-25 03:35:46 +05:30
|
|
|
|
|
|
|
if not gramps and ansel:
|
2006-01-13 08:05:11 +05:30
|
|
|
glade_file = "%s/gedcomimport.glade" % os.path.dirname(__file__)
|
2007-02-14 05:30:31 +05:30
|
|
|
top = gtk.glade.XML(glade_file, 'encoding','gramps')
|
2004-09-25 03:35:46 +05:30
|
|
|
code = top.get_widget('codeset')
|
|
|
|
code.set_active(0)
|
|
|
|
dialog = top.get_widget('encoding')
|
|
|
|
dialog.run()
|
2007-02-14 05:30:31 +05:30
|
|
|
code_set = code.get_active()
|
2004-09-25 03:35:46 +05:30
|
|
|
dialog.destroy()
|
|
|
|
else:
|
2007-02-14 05:30:31 +05:30
|
|
|
code_set = None
|
|
|
|
import2(database, filename, callback, code_set, use_trans)
|
2004-09-25 03:35:46 +05:30
|
|
|
|
2007-02-14 05:30:31 +05:30
|
|
|
def import2(database, filename, callback, code_set, use_trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
# add some checking here
|
|
|
|
try:
|
2007-02-14 05:30:31 +05:30
|
|
|
ifile = open(filename,"rU")
|
2007-02-20 04:20:09 +05:30
|
|
|
np = StageOne(ifile)
|
|
|
|
np.parse()
|
|
|
|
print np.get_encoding()
|
|
|
|
ifile.seek(0)
|
2007-02-21 05:28:39 +05:30
|
|
|
gedparse = GedcomParser(database, ifile, filename, callback, np)
|
2007-02-14 05:30:31 +05:30
|
|
|
except IOError, msg:
|
|
|
|
ErrorDialog(_("%s could not be opened\n") % filename, str(msg))
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
2007-02-23 11:33:02 +05:30
|
|
|
except Errors.GedcomError, msg:
|
|
|
|
ErrorDialog(_("Invalid GEDCOM file"),
|
|
|
|
_("%s could not be imported") % filename + "\n" + str(msg))
|
|
|
|
return
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-02-21 05:28:39 +05:30
|
|
|
|
2004-10-19 08:49:25 +05:30
|
|
|
if database.get_number_of_people() == 0:
|
|
|
|
use_trans = False
|
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
try:
|
2007-02-14 05:30:31 +05:30
|
|
|
read_only = database.readonly
|
2006-12-16 09:17:03 +05:30
|
|
|
database.readonly = False
|
2007-02-14 05:30:31 +05:30
|
|
|
close = gedparse.parse_gedcom_file(use_trans)
|
|
|
|
database.readonly = read_only
|
|
|
|
ifile.close()
|
|
|
|
except IOError, msg:
|
|
|
|
msg = _("%s could not be opened\n") % filename
|
|
|
|
ErrorDialog(msg, str(msg))
|
2003-01-15 10:55:50 +05:30
|
|
|
return
|
2005-12-06 12:08:09 +05:30
|
|
|
except db.DBSecondaryBadError, msg:
|
|
|
|
WarningDialog(_('Database corruption detected'),
|
|
|
|
_('A problem was detected with the database. Please '
|
|
|
|
'run the Check and Repair Database tool to fix the '
|
|
|
|
'problem.'))
|
|
|
|
return
|
2006-11-11 10:32:26 +05:30
|
|
|
except Errors.GedcomError, msg:
|
|
|
|
ErrorDialog(_('Error reading GEDCOM file'), str(msg))
|
|
|
|
return
|
2006-03-05 10:01:24 +05:30
|
|
|
|
2007-02-14 05:30:31 +05:30
|
|
|
def import_from_string(database, text, callback, code_set, use_trans):
|
|
|
|
# add some checking here
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2007-02-14 05:30:31 +05:30
|
|
|
from cStringIO import StringIO
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-02-14 05:30:31 +05:30
|
|
|
ifile = StringIO(text)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-02-14 05:30:31 +05:30
|
|
|
try:
|
|
|
|
np = NoteParser(ifile, False, code_set)
|
|
|
|
ifile.seek(0)
|
|
|
|
gedparse = GedcomParser(database, ifile, "inline-string", callback,
|
|
|
|
code_set, np.get_map(), np.get_lines(),
|
|
|
|
np.get_persons())
|
|
|
|
except IOError, msg:
|
|
|
|
ErrorDialog(_("%s could not be opened\n") % "inline-string", str(msg))
|
2004-06-27 08:40:06 +05:30
|
|
|
return
|
2006-06-06 00:19:31 +05:30
|
|
|
|
2007-02-14 05:30:31 +05:30
|
|
|
if database.get_number_of_people() == 0:
|
|
|
|
use_trans = False
|
2007-01-12 10:46:29 +05:30
|
|
|
|
2007-02-14 05:30:31 +05:30
|
|
|
try:
|
|
|
|
read_only = database.readonly
|
|
|
|
database.readonly = False
|
|
|
|
gedparse.parse_gedcom_file(use_trans)
|
|
|
|
database.readonly = read_only
|
|
|
|
ifile.close()
|
|
|
|
except IOError, msg:
|
|
|
|
msg = _("%s could not be opened\n") % 'inline-string'
|
|
|
|
ErrorDialog(msg, str(msg))
|
|
|
|
return
|
|
|
|
except db.DBSecondaryBadError, msg:
|
|
|
|
WarningDialog(_('Database corruption detected'),
|
|
|
|
_('A problem was detected with the database. Please '
|
|
|
|
'run the Check and Repair Database tool to fix the '
|
|
|
|
'problem.'))
|
|
|
|
return
|
|
|
|
except Errors.GedcomError, msg:
|
|
|
|
ErrorDialog(_('Error reading GEDCOM file'), str(msg))
|
2006-02-19 10:15:54 +05:30
|
|
|
return
|
2006-01-27 10:31:48 +05:30
|
|
|
|