gramps/src/GrampsDbUtils/_ReadGedcom.py

148 lines
4.6 KiB
Python
Raw Normal View History

2002-10-20 19:55:16 +05:30
#
# Gramps - a GTK+/GNOME based genealogy program
#
# 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$
2002-10-20 19:55:16 +05:30
"Import from GEDCOM"
import os
import gtk
import Errors
from _GedcomParse import GedcomParser, StageOne
from QuestionDialog import ErrorDialog
from bsddb import db
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def importData(database, filename, callback=None, use_trans=False):
2002-10-20 19:55:16 +05:30
2006-09-23 Don Allingham <don@gramps-project.org> * src/images/sources.svg: new icon * src/images/reports.svg: new icon * src/images/tools.svg: new icon * src/images/events.svg: new icon * src/images/place.svg: new icon * src/images/tools.svg: new icon * src/ViewManager.py: use new icons * src/gramps_main.py: register new icons 2006-09-22 Don Allingham <don@gramps-project.org> * src/GrampsDb/_GrampsGEDDB.py: support for disabling transactions * src/GrampsDb/_GrampsXMLDB.py: support for disabling transactions * src/GrampsDb/_GrampsBSDDB.py: support for disabling transactions * src/GrampsDb/_GrampsDbBase.py: support for disabling transactions * src/GrampsDb/_ReadGedcom.py: check for IO Eror * src/ViewManager.py: display message if a portability problem is detected * src/QuestionDialog.py: Add Warning dialog that can be disabled * src/DbLoader.py: Detect missing database problem * src/ArgHandler.py: support for disabling transactions * src/GrampsCfg.py: new config keys for transactions * src/Config/_GrampsConfigKeys.py: new config keys for transactions 2006-09-17 Don Allingham <don@gramps-project.org> * src/ViewManager.py: handle missing database on autoload (#447) * src/ArgHandler.py: handle missing database on autoload (#447) * src/DbLoader.py: handle missing database on autoload (#447) * src/Makefile.am: remove uninstalled packages from makefile * src/GrampsDb/_ReadXML.py: place vs. address changes * src/GrampsDb/_WriteXML.py: place vs. address changes * src/GrampsDb/_EditPlace.py: place vs. address changes * src/Editors/_EditPlace.py: place vs. address changes * src/Editors/_EditLocation.py: place vs. address changes * src/RelLib/_Address.py: place vs. address changes * src/RelLib/_LocationBase.py: place vs. address changes * src/RelLib/_Location.py: place vs. address changes * src/DisplayTabs/_LocationModel.py: place vs. address changes * src/DisplayTabs/_LocationEmbedList.py: place vs. address changes * src/glade/gramps.glade: place vs. address changes svn: r7325
2006-09-24 10:07:59 +05:30
try:
ifile = open(filename, "r")
2006-09-23 Don Allingham <don@gramps-project.org> * src/images/sources.svg: new icon * src/images/reports.svg: new icon * src/images/tools.svg: new icon * src/images/events.svg: new icon * src/images/place.svg: new icon * src/images/tools.svg: new icon * src/ViewManager.py: use new icons * src/gramps_main.py: register new icons 2006-09-22 Don Allingham <don@gramps-project.org> * src/GrampsDb/_GrampsGEDDB.py: support for disabling transactions * src/GrampsDb/_GrampsXMLDB.py: support for disabling transactions * src/GrampsDb/_GrampsBSDDB.py: support for disabling transactions * src/GrampsDb/_GrampsDbBase.py: support for disabling transactions * src/GrampsDb/_ReadGedcom.py: check for IO Eror * src/ViewManager.py: display message if a portability problem is detected * src/QuestionDialog.py: Add Warning dialog that can be disabled * src/DbLoader.py: Detect missing database problem * src/ArgHandler.py: support for disabling transactions * src/GrampsCfg.py: new config keys for transactions * src/Config/_GrampsConfigKeys.py: new config keys for transactions 2006-09-17 Don Allingham <don@gramps-project.org> * src/ViewManager.py: handle missing database on autoload (#447) * src/ArgHandler.py: handle missing database on autoload (#447) * src/DbLoader.py: handle missing database on autoload (#447) * src/Makefile.am: remove uninstalled packages from makefile * src/GrampsDb/_ReadXML.py: place vs. address changes * src/GrampsDb/_WriteXML.py: place vs. address changes * src/GrampsDb/_EditPlace.py: place vs. address changes * src/Editors/_EditPlace.py: place vs. address changes * src/Editors/_EditLocation.py: place vs. address changes * src/RelLib/_Address.py: place vs. address changes * src/RelLib/_LocationBase.py: place vs. address changes * src/RelLib/_Location.py: place vs. address changes * src/DisplayTabs/_LocationModel.py: place vs. address changes * src/DisplayTabs/_LocationEmbedList.py: place vs. address changes * src/glade/gramps.glade: place vs. address changes svn: r7325
2006-09-24 10:07:59 +05:30
except IOError:
return
ansel = False
gramps = False
for index in range(50):
line = ifile.readline().split()
if len(line) == 0:
break
if len(line) > 2 and line[1][0:4] == 'CHAR' and line[2] == "ANSEL":
ansel = True
if len(line) > 2 and line[1][0:4] == 'SOUR' and line[2] == "GRAMPS":
gramps = True
ifile.close()
if not gramps and ansel:
2006-01-13 08:05:11 +05:30
glade_file = "%s/gedcomimport.glade" % os.path.dirname(__file__)
top = gtk.glade.XML(glade_file, 'encoding','gramps')
code = top.get_widget('codeset')
code.set_active(0)
dialog = top.get_widget('encoding')
dialog.run()
code_set = code.get_active()
dialog.destroy()
else:
code_set = None
import2(database, filename, callback, code_set, use_trans)
def import2(database, filename, callback, code_set, use_trans):
2002-10-20 19:55:16 +05:30
# add some checking here
try:
ifile = open(filename,"rU")
2007-02-20 04:20:09 +05:30
np = StageOne(ifile)
np.parse()
print np.get_encoding()
ifile.seek(0)
gedparse = GedcomParser(database, ifile, filename, callback, np)
except IOError, msg:
ErrorDialog(_("%s could not be opened\n") % filename, str(msg))
2002-10-20 19:55:16 +05:30
return
if database.get_number_of_people() == 0:
use_trans = False
try:
read_only = database.readonly
database.readonly = False
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))
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
except Errors.GedcomError, msg:
ErrorDialog(_('Error reading GEDCOM file'), str(msg))
return
2006-03-05 10:01:24 +05:30
def import_from_string(database, text, callback, code_set, use_trans):
# add some checking here
from cStringIO import StringIO
2002-10-20 19:55:16 +05:30
ifile = StringIO(text)
2002-10-20 19:55:16 +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))
return
if database.get_number_of_people() == 0:
use_trans = False
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))
return