2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-01-15 14:46:45 +05:30
|
|
|
# Copyright (C) 2000-2008 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2008-07-21 00:03:04 +05:30
|
|
|
# Copyright (C) 2008 Gary Burton
|
2008-09-04 17:16:43 +05:30
|
|
|
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
|
2010-05-01 09:42:42 +05:30
|
|
|
# Copyright (C) 2010 Jakim Friant
|
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
|
2009-11-03 23:03:35 +05:30
|
|
|
import shutil
|
2002-10-20 19:55:16 +05:30
|
|
|
import os
|
2007-01-22 09:26:23 +05:30
|
|
|
import sys
|
2006-03-01 05:56:29 +05:30
|
|
|
import tarfile
|
2002-10-20 19:55:16 +05:30
|
|
|
from cStringIO import StringIO
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext 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
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-12-05 12:05:21 +05:30
|
|
|
from ExportOptions import WriterOptionBox
|
2009-10-24 19:23:20 +05:30
|
|
|
import gen.proxy
|
2008-11-04 09:42:51 +05:30
|
|
|
from ExportXml import XmlWriter
|
2008-03-04 23:02:38 +05:30
|
|
|
import Utils
|
2010-02-08 22:54:43 +05:30
|
|
|
import constfunc
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# writeData
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-05-01 09:42:42 +05:30
|
|
|
def writeData(database, filename, msg_callback, option_box=None, callback=None):
|
2009-11-03 23:03:35 +05:30
|
|
|
|
|
|
|
# Rename file, if it exists already, with <filename>.bak
|
|
|
|
# as it it for normal XML export.
|
|
|
|
|
|
|
|
if os.path.isfile(filename):
|
|
|
|
try:
|
|
|
|
shutil.copyfile(filename, filename + ".bak")
|
|
|
|
shutil.copystat(filename, filename + ".bak")
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2008-11-04 09:42:51 +05:30
|
|
|
if option_box:
|
|
|
|
option_box.parse_options()
|
2010-05-30 09:37:50 +05:30
|
|
|
database = option_box.get_filtered_database(database)
|
2008-07-21 00:03:04 +05:30
|
|
|
|
2010-05-01 09:42:42 +05:30
|
|
|
writer = PackageWriter(database, filename, msg_callback, callback)
|
2008-01-15 14:46:45 +05:30
|
|
|
return writer.export()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PackageWriter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class PackageWriter(object):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2010-05-01 09:42:42 +05:30
|
|
|
def __init__(self, database, filename, msg_callback, callback=None):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.db = database
|
2006-03-01 11:46:36 +05:30
|
|
|
self.callback = callback
|
2010-05-01 09:42:42 +05:30
|
|
|
self.msg_callback = msg_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):
|
2008-01-15 14:46:45 +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
|
2009-07-08 21:41:20 +05:30
|
|
|
for p_id in self.db.iter_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)
|
2009-07-04 01:53:41 +05:30
|
|
|
for key in self.db.iter_person_handles():
|
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):
|
2010-10-09 18:03:47 +05:30
|
|
|
name = Utils.get_unicode_path_from_file_chooser(fs_top.get_filename())
|
2003-05-15 00:51:18 +05:30
|
|
|
if os.path.isfile(name):
|
2006-03-01 10:34:22 +05:30
|
|
|
archive.add(name)
|
2009-05-15 23:42:10 +05:30
|
|
|
|
|
|
|
fs_top = gtk.FileChooserDialog("%s - GRAMPS" % _("Select file"),
|
|
|
|
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_OK, gtk.RESPONSE_OK)
|
|
|
|
)
|
|
|
|
response = fs_top.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
fs_ok_clicked(fs_top)
|
|
|
|
elif response == gtk.RESPONSE_CANCEL:
|
|
|
|
fs_close_window(fs_top)
|
2003-05-15 00:51:18 +05:30
|
|
|
|
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)
|
2009-02-24 10:11:23 +05:30
|
|
|
filename = Utils.media_path_full(self.db, mobject.get_path())
|
2008-03-22 03:58:28 +05:30
|
|
|
archname = str(mobject.get_path())
|
2006-03-01 10:34:22 +05:30
|
|
|
if os.path.isfile(filename):
|
2008-03-22 03:58:28 +05:30
|
|
|
archive.add(filename, archname)
|
2007-01-27 11:00:15 +05:30
|
|
|
# else:
|
|
|
|
# # File is lost => ask what to do
|
|
|
|
# if missmedia_action == 0:
|
|
|
|
# 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 },
|
|
|
|
# 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()
|
2010-05-08 17:15:41 +05:30
|
|
|
gfile = XmlWriter(self.db, self.msg_callback, 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()
|
2010-02-08 22:54:43 +05:30
|
|
|
if not constfunc.win():
|
2006-09-02 07:17:08 +05:30
|
|
|
tarinfo.uid = os.getuid()
|
|
|
|
tarinfo.gid = os.getgid()
|
2006-03-01 05:56:29 +05:30
|
|
|
g.seek(0)
|
2008-01-15 14:46:45 +05:30
|
|
|
archive.addfile(tarinfo, g)
|
2006-03-01 05:56:29 +05:30
|
|
|
archive.close()
|
2002-10-20 19:55:16 +05:30
|
|
|
g.close()
|
|
|
|
|
2008-01-15 14:46:45 +05:30
|
|
|
return True
|