2003-05-05 23:05:30 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-01 01:24:35 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2003-05-05 23:05:30 +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
|
2007-10-07 08:49:35 +05:30
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
2003-05-05 23:05:30 +05:30
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2007-10-07 08:49:35 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2003-05-05 23:05:30 +05:30
|
|
|
# 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-21 10:40:27 +05:30
|
|
|
# $Id$
|
|
|
|
|
2003-05-05 23:05:30 +05:30
|
|
|
# Written by Alex Roitman, largely based on ReadNative.py by Don Allingham
|
|
|
|
|
|
|
|
"Import from Gramps package"
|
|
|
|
|
2005-02-28 07:21:21 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-05-05 23:05:30 +05:30
|
|
|
import os
|
2006-03-01 05:56:29 +05:30
|
|
|
import tarfile
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2003-05-05 23:05:30 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".ReadPkg")
|
|
|
|
|
2003-05-05 23:05:30 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2005-02-28 07:21:21 +05:30
|
|
|
# GNOME/GTK+ modules
|
2003-05-05 23:05:30 +05:30
|
|
|
#
|
2005-02-28 07:21:21 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
2003-05-05 23:05:30 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-02-28 07:21:21 +05:30
|
|
|
import const
|
2007-02-03 22:41:05 +05:30
|
|
|
from GrampsDbUtils import gramps_db_reader_factory
|
2005-02-28 07:21:21 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import register_import
|
2003-05-05 23:05:30 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-10-07 08:49:35 +05:30
|
|
|
def impData(database, name, cb=None, cl=0):
|
2005-02-28 07:21:21 +05:30
|
|
|
# Create tempdir, if it does not exist, then check for writability
|
2006-03-01 01:24:35 +05:30
|
|
|
# THE TEMP DIR is named as the filname.gpkg.media and is created
|
|
|
|
# in the same dir as the database that we are importing into.
|
|
|
|
db_path = os.path.dirname(database.get_save_path())
|
|
|
|
media_dir = "%s.media" % os.path.basename(name)
|
2007-10-07 08:49:35 +05:30
|
|
|
tmpdir_path = os.path.join(db_path, media_dir)
|
2005-02-28 07:21:21 +05:30
|
|
|
if not os.path.isdir(tmpdir_path):
|
2003-05-05 23:05:30 +05:30
|
|
|
try:
|
2007-10-07 08:49:35 +05:30
|
|
|
os.mkdir(tmpdir_path, 0700)
|
2003-05-05 23:05:30 +05:30
|
|
|
except:
|
2005-02-28 07:21:21 +05:30
|
|
|
ErrorDialog( _("Could not create temporary directory %s") %
|
2006-03-01 01:24:35 +05:30
|
|
|
tmpdir_path )
|
2003-05-05 23:05:30 +05:30
|
|
|
return
|
2007-10-07 08:49:35 +05:30
|
|
|
elif not os.access(tmpdir_path, os.W_OK):
|
2006-03-01 01:24:35 +05:30
|
|
|
ErrorDialog(_("Temporary directory %s is not writable") % tmpdir_path)
|
2005-02-28 07:21:21 +05:30
|
|
|
return
|
|
|
|
else: # tempdir exists and writable -- clean it up if not empty
|
|
|
|
files = os.listdir(tmpdir_path) ;
|
|
|
|
for filename in files:
|
2007-10-07 08:49:35 +05:30
|
|
|
os.remove(os.path.join(tmpdir_path, filename))
|
2003-05-05 23:05:30 +05:30
|
|
|
|
2005-02-28 07:21:21 +05:30
|
|
|
try:
|
2006-03-01 05:56:29 +05:30
|
|
|
archive = tarfile.open(name)
|
|
|
|
for tarinfo in archive:
|
2007-10-07 08:49:35 +05:30
|
|
|
archive.extract(tarinfo, tmpdir_path)
|
2006-03-01 05:56:29 +05:30
|
|
|
archive.close()
|
2005-02-28 07:21:21 +05:30
|
|
|
except:
|
2006-03-01 01:24:35 +05:30
|
|
|
ErrorDialog(_("Error extracting into %s") % tmpdir_path)
|
2005-02-28 07:21:21 +05:30
|
|
|
return
|
2003-05-05 23:05:30 +05:30
|
|
|
|
2007-10-07 08:49:35 +05:30
|
|
|
imp_db_name = os.path.join(tmpdir_path, const.XMLFILE)
|
2003-05-05 23:05:30 +05:30
|
|
|
|
2007-09-08 11:24:02 +05:30
|
|
|
importer = gramps_db_reader_factory(const.APP_GRAMPS_XML)
|
2007-10-07 08:49:35 +05:30
|
|
|
importer(database, imp_db_name, cb)
|
2005-02-28 07:21:21 +05:30
|
|
|
|
|
|
|
# Clean up tempdir after ourselves
|
2006-03-01 01:24:35 +05:30
|
|
|
# THIS HAS BEEN CHANGED, because now we want to keep images
|
|
|
|
# stay after the import is over. Just delete the XML file.
|
|
|
|
os.remove(imp_db_name)
|
2003-05-05 23:05:30 +05:30
|
|
|
|
2006-03-01 01:24:35 +05:30
|
|
|
## files = os.listdir(tmpdir_path)
|
|
|
|
## for filename in files:
|
2007-10-07 08:49:35 +05:30
|
|
|
## os.remove(os.path.join(tmpdir_path, filename))
|
2006-03-01 01:24:35 +05:30
|
|
|
## os.rmdir(tmpdir_path)
|
2003-05-05 23:05:30 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register with the plugin system
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2004-06-24 08:59:38 +05:30
|
|
|
_mime_type = 'application/x-gramps-package'
|
|
|
|
_filter = gtk.FileFilter()
|
2004-07-03 10:16:51 +05:30
|
|
|
_filter.set_name(_('GRAMPS packages'))
|
2004-06-24 08:59:38 +05:30
|
|
|
_filter.add_mime_type(_mime_type)
|
2005-02-28 07:21:21 +05:30
|
|
|
_format_name = _('GRAMPS package')
|
2003-05-05 23:05:30 +05:30
|
|
|
|
2007-10-07 08:49:35 +05:30
|
|
|
register_import(impData, _filter, _mime_type, 0, _format_name)
|