2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-01 05:56:29 +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
|
|
|
|
#
|
|
|
|
|
2003-12-02 08:05:49 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"Export to GRAMPS package"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import time
|
|
|
|
import os
|
2006-03-01 05:56:29 +05:30
|
|
|
import tarfile
|
2002-10-20 19:55:16 +05:30
|
|
|
from cStringIO import StringIO
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".WritePkg")
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-10 03:30:07 +05:30
|
|
|
from GrampsDb import XmlWriter
|
2002-10-20 19:55:16 +05:30
|
|
|
import Utils
|
2003-05-15 00:51:18 +05:30
|
|
|
from QuestionDialog import MissingMediaDialog
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import register_export
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# writeData
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-02-20 00:35:48 +05:30
|
|
|
def writeData(database,filename,person,callback=None):
|
|
|
|
ret = 0
|
2006-03-05 10:01:24 +05:30
|
|
|
writer = PackageWriter(database,filename,callback)
|
|
|
|
ret = writer.export()
|
2005-02-20 00:35:48 +05:30
|
|
|
return ret
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PackageWriter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PackageWriter:
|
|
|
|
|
2006-03-01 11:46:36 +05:30
|
|
|
def __init__(self,database,filename,callback):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.db = database
|
2006-03-01 11:46:36 +05:30
|
|
|
self.callback = callback
|
2005-02-20 00:35:48 +05:30
|
|
|
self.filename = filename
|
2004-06-12 10:09:45 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
def export(self):
|
2004-01-18 07:29:30 +05:30
|
|
|
missmedia_action = 0
|
2003-05-15 00:51:18 +05:30
|
|
|
#--------------------------------------------------------------
|
|
|
|
def remove_clicked():
|
|
|
|
# File is lost => remove all references and the object itself
|
2004-08-13 10:04:07 +05:30
|
|
|
for p_id in self.db.get_family_handles():
|
2004-08-20 03:05:16 +05:30
|
|
|
p = self.db.get_family_from_handle(p_id)
|
2004-02-21 11:41:59 +05:30
|
|
|
nl = p.get_media_list()
|
2003-05-15 00:51:18 +05:30
|
|
|
for o in nl:
|
2004-07-28 07:59:07 +05:30
|
|
|
if o.get_reference_handle() == m_id:
|
2003-05-15 00:51:18 +05:30
|
|
|
nl.remove(o)
|
2004-02-21 11:41:59 +05:30
|
|
|
p.set_media_list(nl)
|
2004-06-23 02:19:22 +05:30
|
|
|
self.db.commit_family(p,None)
|
2004-08-13 10:04:07 +05:30
|
|
|
for key in self.db.get_person_handles(sort_handles=False):
|
2004-08-07 10:46:57 +05:30
|
|
|
p = self.db.get_person_from_handle(key)
|
2004-02-21 11:41:59 +05:30
|
|
|
nl = p.get_media_list()
|
2003-05-15 00:51:18 +05:30
|
|
|
for o in nl:
|
2004-07-28 07:59:07 +05:30
|
|
|
if o.get_reference_handle() == m_id:
|
2003-05-15 00:51:18 +05:30
|
|
|
nl.remove(o)
|
2004-02-21 11:41:59 +05:30
|
|
|
p.set_media_list(nl)
|
2004-06-23 02:19:22 +05:30
|
|
|
self.db.commit_person(p,None)
|
2004-08-13 10:04:07 +05:30
|
|
|
for key in self.db.get_source_handles():
|
2004-08-07 10:46:57 +05:30
|
|
|
p = self.db.get_source_from_handle(key)
|
2004-02-21 11:41:59 +05:30
|
|
|
nl = p.get_media_list()
|
2003-05-15 00:51:18 +05:30
|
|
|
for o in nl:
|
2004-07-28 07:59:07 +05:30
|
|
|
if o.get_reference_handle() == m_id:
|
2003-05-15 00:51:18 +05:30
|
|
|
nl.remove(o)
|
2004-02-21 11:41:59 +05:30
|
|
|
p.set_media_list(nl)
|
2004-06-23 02:19:22 +05:30
|
|
|
self.db.commit_source(p,None)
|
2004-08-13 10:04:07 +05:30
|
|
|
for key in self.db.get_place_handles():
|
2004-08-07 10:46:57 +05:30
|
|
|
p = self.db.get_place_from_handle(key)
|
2004-02-21 11:41:59 +05:30
|
|
|
nl = p.get_media_list()
|
2003-05-15 00:51:18 +05:30
|
|
|
for o in nl:
|
2004-07-28 07:59:07 +05:30
|
|
|
if o.get_reference_handle() == m_id:
|
2003-05-15 00:51:18 +05:30
|
|
|
nl.remove(o)
|
2004-02-21 11:41:59 +05:30
|
|
|
p.set_media_list(nl)
|
2004-06-23 02:19:22 +05:30
|
|
|
self.db.commit_place(p,None)
|
2004-08-13 10:04:07 +05:30
|
|
|
for key in self.db.get_event_handles():
|
* src/AddSpouse.py, src/ChooseParents.py, src/EditPerson.py,
src/EditPlace.py, src/EditSource.py, src/EventEdit.py,
src/FamilyView.py, src/GenericFilter.py,
src/Marriage.py, src/PedView.py, src/PeopleModel.py,
src/PlaceView.py, src/RelLib.py, src/SelectChild.py,
src/Sort.py, src/SourceView.py, src/SubstKeywords.py,
src/WriteGedcom.py, src/WriteXML.py, src/plugins/AncestorReport.py,
src/plugins/Ancestors.py, src/plugins/ChangeTypes.py,
src/plugins/DescendReport.py, src/plugins/DetDescendantReport.py,
src/plugins/EventCmp.py, src/plugins/FamilyGroup.py,
src/plugins/FanChart.py, src/plugins/FtmStyleAncestors.py,
src/plugins/FtmStyleDescendants.py, src/plugins/GraphViz.py,
src/plugins/IndivComplete.py, src/plugins/IndivSummary.py,
src/plugins/Merge.py, src/plugins/RelCalc.py, src/plugins/RelGraph.py,
src/plugins/Summary.py, src/plugins/TimeLine.py, src/plugins/Verify.py,
src/plugins/WebPage.py, src/plugins/WriteCD.py,
src/plugins/WritePkg.py, src/plugins/DetAncestralReport.py:
Use get_event_from_handle (not find_ ).
svn: r3462
2004-08-22 00:26:01 +05:30
|
|
|
p = self.db.get_event_from_handle(key)
|
2004-06-23 02:19:22 +05:30
|
|
|
nl = p.get_media_list()
|
|
|
|
for o in nl:
|
2004-07-28 07:59:07 +05:30
|
|
|
if o.get_reference_handle() == m_id:
|
2004-06-23 02:19:22 +05:30
|
|
|
nl.remove(o)
|
|
|
|
p.set_media_list(nl)
|
|
|
|
self.db.commit_event(p,None)
|
|
|
|
self.db.remove_object(m_id,None)
|
2003-05-15 00:51:18 +05:30
|
|
|
|
|
|
|
def leave_clicked():
|
|
|
|
# File is lost => do nothing, leave as is
|
|
|
|
pass
|
|
|
|
|
|
|
|
def select_clicked():
|
|
|
|
# File is lost => select a file to replace the lost one
|
|
|
|
def fs_close_window(obj):
|
2003-06-10 05:30:05 +05:30
|
|
|
pass
|
2003-05-15 00:51:18 +05:30
|
|
|
|
|
|
|
def fs_ok_clicked(obj):
|
|
|
|
name = fs_top.get_filename()
|
|
|
|
if os.path.isfile(name):
|
2006-03-01 10:34:22 +05:30
|
|
|
archive.add(name)
|
2003-05-15 00:51:18 +05:30
|
|
|
|
|
|
|
fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file"))
|
|
|
|
fs_top.hide_fileop_buttons()
|
|
|
|
fs_top.ok_button.connect('clicked',fs_ok_clicked)
|
|
|
|
fs_top.cancel_button.connect('clicked',fs_close_window)
|
|
|
|
fs_top.run()
|
2003-06-10 05:30:05 +05:30
|
|
|
fs_top.destroy()
|
2003-05-15 00:51:18 +05:30
|
|
|
#---------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-03-01 05:56:29 +05:30
|
|
|
archive = tarfile.open(self.filename,'w:gz')
|
2003-05-15 00:51:18 +05:30
|
|
|
|
|
|
|
# Write media files first, since the database may be modified
|
|
|
|
# during the process (i.e. when removing object)
|
2004-08-13 10:04:07 +05:30
|
|
|
for m_id in self.db.get_media_object_handles():
|
2004-08-07 10:46:57 +05:30
|
|
|
mobject = self.db.get_object_from_handle(m_id)
|
2006-03-01 10:34:22 +05:30
|
|
|
filename = mobject.get_path()
|
|
|
|
if os.path.isfile(filename):
|
|
|
|
archive.add(filename)
|
2003-05-15 00:51:18 +05:30
|
|
|
else:
|
|
|
|
# File is lost => ask what to do
|
2004-01-18 07:29:30 +05:30
|
|
|
if missmedia_action == 0:
|
2006-03-01 10:34:22 +05:30
|
|
|
mmd = MissingMediaDialog(
|
|
|
|
_("Media object could not be found"),
|
|
|
|
_("%(file_name)s is referenced in the database, "
|
|
|
|
"but no longer exists. The file may have been "
|
|
|
|
"deleted or moved to a different location. "
|
|
|
|
"You may choose to either remove the reference "
|
|
|
|
"from the database, keep the reference to the "
|
|
|
|
"missing file, or select a new file."
|
|
|
|
) % { 'file_name' : filename },
|
2004-01-18 07:29:30 +05:30
|
|
|
remove_clicked, leave_clicked, select_clicked)
|
|
|
|
missmedia_action = mmd.default_action
|
|
|
|
elif missmedia_action == 1:
|
|
|
|
remove_clicked()
|
|
|
|
elif missmedia_action == 2:
|
|
|
|
leave_clicked()
|
|
|
|
elif missmedia_action == 3:
|
|
|
|
select_clicked()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-15 00:51:18 +05:30
|
|
|
# Write XML now
|
|
|
|
g = StringIO()
|
2006-03-01 11:46:36 +05:30
|
|
|
gfile = XmlWriter(self.db,self.callback,2)
|
2006-03-01 10:34:22 +05:30
|
|
|
gfile.write_handle(g)
|
2006-03-01 05:56:29 +05:30
|
|
|
tarinfo = tarfile.TarInfo('data.gramps')
|
|
|
|
tarinfo.size = len(g.getvalue())
|
|
|
|
tarinfo.mtime = time.time()
|
|
|
|
tarinfo.uid = os.getuid()
|
|
|
|
tarinfo.gid = os.getgid()
|
|
|
|
g.seek(0)
|
|
|
|
archive.addfile(tarinfo,g)
|
|
|
|
archive.close()
|
2002-10-20 19:55:16 +05:30
|
|
|
g.close()
|
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
return 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register the plugin
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-02-20 04:03:24 +05:30
|
|
|
_title = _('GRAM_PS package (portable XML)')
|
2005-02-20 00:35:48 +05:30
|
|
|
_description = _('GRAMPS package is an archived XML database together with the media object files.')
|
|
|
|
_config = None
|
|
|
|
_filename = 'gpkg'
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
register_export(writeData,_title,_description,_config,_filename)
|