2003-05-14 09:53:30 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-01-15 14:46:45 +05:30
|
|
|
# Copyright (C) 2000-2008 Donald N. Allingham
|
2003-05-14 09:53: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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2007-09-12 20:32:03 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2003-05-14 09:53: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
|
|
|
|
#
|
|
|
|
|
2003-12-02 08:05:49 +05:30
|
|
|
# $Id$
|
|
|
|
|
2008-01-17 03:12:05 +05:30
|
|
|
"Export to CD (nautilus)."
|
2003-05-14 09:53:30 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2007-01-22 09:26:23 +05:30
|
|
|
import sys
|
2008-01-15 14:46:45 +05:30
|
|
|
#from cStringIO import StringIO
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".WriteCD")
|
|
|
|
|
2003-05-14 09:53:30 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
2006-06-05 04:53:10 +05:30
|
|
|
import Errors
|
|
|
|
|
|
|
|
try:
|
|
|
|
import gnome
|
|
|
|
except ImportError:
|
|
|
|
raise Errors.UnavailableError(
|
|
|
|
_("Cannot be loaded because python bindings "
|
|
|
|
"for GNOME are not installed"))
|
2005-01-27 08:48:21 +05:30
|
|
|
|
|
|
|
try:
|
|
|
|
from gnomevfs import URI, create, OPEN_WRITE, make_directory, FileExistsError
|
|
|
|
except:
|
|
|
|
from gnome.vfs import URI, create, OPEN_WRITE, make_directory, FileExistsError
|
2003-05-14 09:53:30 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-02-03 22:41:05 +05:30
|
|
|
from GrampsDbUtils import XmlWriter
|
2008-01-15 14:46:45 +05:30
|
|
|
#import Mime
|
|
|
|
#import const
|
2003-05-15 04:52:35 +05:30
|
|
|
import QuestionDialog
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import register_export
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2003-07-16 00:47:17 +05:30
|
|
|
_title_string = _("Export to CD")
|
|
|
|
|
2003-05-14 09:53:30 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# writeData
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-09-12 20:32:03 +05:30
|
|
|
def writeData(database, filename, person, option_box=None, callback=None):
|
|
|
|
writer = PackageWriter(database, filename, callback)
|
2008-01-15 14:46:45 +05:30
|
|
|
return writer.export()
|
2003-05-14 09:53:30 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PackageWriter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PackageWriter:
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def __init__(self, database, filename="", cl=0, callback=None):
|
2003-05-14 09:53:30 +05:30
|
|
|
self.db = database
|
2003-05-21 02:01:16 +05:30
|
|
|
self.cl = cl
|
2005-02-20 04:03:24 +05:30
|
|
|
self.filename = filename
|
2006-05-10 03:30:07 +05:30
|
|
|
self.callback = callback
|
2005-02-20 04:03:24 +05:30
|
|
|
|
|
|
|
def export(self):
|
2003-05-21 02:01:16 +05:30
|
|
|
if self.cl:
|
2008-01-15 14:46:45 +05:30
|
|
|
return self.cl_run()
|
2003-05-21 02:01:16 +05:30
|
|
|
else:
|
2008-01-15 14:46:45 +05:30
|
|
|
return self.gui_run()
|
2003-05-15 00:51:18 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
def cl_run(self):
|
2005-02-20 04:03:24 +05:30
|
|
|
base = os.path.basename(self.filename)
|
2003-05-21 02:01:16 +05:30
|
|
|
|
|
|
|
try:
|
2005-01-27 08:48:21 +05:30
|
|
|
uri = URI('burn:///%s' % base)
|
2007-09-12 20:32:03 +05:30
|
|
|
make_directory(uri, OPEN_WRITE)
|
2005-01-27 08:48:21 +05:30
|
|
|
except FileExistsError, msg:
|
2007-09-12 20:32:03 +05:30
|
|
|
QuestionDialog.ErrorDialog(_("CD export preparation failed"),
|
2004-04-09 09:35:48 +05:30
|
|
|
"1 %s " % str(msg))
|
2008-01-15 14:46:45 +05:30
|
|
|
return False
|
2004-04-09 09:35:48 +05:30
|
|
|
except:
|
2005-12-06 12:08:09 +05:30
|
|
|
uri_name = "burn:///" + base
|
2007-09-12 20:32:03 +05:30
|
|
|
QuestionDialog.ErrorDialog("CD export preparation failed",
|
2005-12-06 12:08:09 +05:30
|
|
|
'Could not create %s' % uri_name)
|
2008-01-15 14:46:45 +05:30
|
|
|
return False
|
2003-05-21 02:01:16 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
for obj_id in self.db.get_media_object_handles():
|
2004-08-07 10:46:57 +05:30
|
|
|
obj = self.db.get_object_from_handle(obj_id)
|
2004-02-14 11:10:30 +05:30
|
|
|
oldfile = obj.get_path()
|
2003-05-21 02:01:16 +05:30
|
|
|
root = os.path.basename(oldfile)
|
|
|
|
if os.path.isfile(oldfile):
|
2007-09-12 20:32:03 +05:30
|
|
|
self.copy_file(oldfile, 'burn:///%s/%s' % (base, root))
|
2003-05-21 23:36:41 +05:30
|
|
|
else:
|
2007-09-12 20:32:03 +05:30
|
|
|
print "Warning: media file %s was not found, " % root, \
|
2003-05-21 23:36:41 +05:30
|
|
|
"so it was ignored."
|
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
# Write XML now
|
2007-09-12 20:32:03 +05:30
|
|
|
g = create('burn:///%s/data.gramps' % base, OPEN_WRITE )
|
|
|
|
gfile = XmlWriter(self.db, None, 2)
|
2003-05-21 02:01:16 +05:30
|
|
|
gfile.write_handle(g)
|
|
|
|
g.close()
|
2008-01-15 14:46:45 +05:30
|
|
|
return True
|
2003-05-21 02:01:16 +05:30
|
|
|
|
2005-02-20 04:03:24 +05:30
|
|
|
def gui_run(self):
|
2004-01-18 07:29:30 +05:30
|
|
|
missmedia_action = 0
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2005-02-20 04:03:24 +05:30
|
|
|
base = os.path.basename(self.filename)
|
2003-05-15 00:51:18 +05:30
|
|
|
|
2003-05-15 04:52:35 +05:30
|
|
|
try:
|
2005-01-27 08:48:21 +05:30
|
|
|
uri = URI('burn:///%s' % base)
|
2007-09-12 20:32:03 +05:30
|
|
|
make_directory(uri, OPEN_WRITE)
|
2005-01-27 08:48:21 +05:30
|
|
|
except FileExistsError:
|
2007-09-12 20:32:03 +05:30
|
|
|
QuestionDialog.ErrorDialog(_("CD export preparation failed"),
|
2004-04-09 09:35:48 +05:30
|
|
|
"File already exists")
|
2008-01-15 14:46:45 +05:30
|
|
|
return False
|
2004-04-09 09:35:48 +05:30
|
|
|
except:
|
2005-12-06 12:08:09 +05:30
|
|
|
uri_name = "burn:///" + base
|
2007-09-12 20:32:03 +05:30
|
|
|
QuestionDialog.ErrorDialog(_("CD export preparation failed"),
|
2005-12-06 12:08:09 +05:30
|
|
|
_('Could not create %s') % uri_name)
|
2008-01-15 14:46:45 +05:30
|
|
|
return False
|
2003-05-15 04:52:35 +05:30
|
|
|
|
|
|
|
try:
|
2005-01-27 08:48:21 +05:30
|
|
|
uri = URI('burn:///%s/.thumb' % base)
|
2007-09-12 20:32:03 +05:30
|
|
|
make_directory(uri, OPEN_WRITE)
|
2005-01-27 08:48:21 +05:30
|
|
|
except FileExistsError, msg:
|
2007-09-12 20:32:03 +05:30
|
|
|
QuestionDialog.ErrorDialog("CD export preparation failed",
|
2004-04-09 09:35:48 +05:30
|
|
|
"4 %s " % str(msg))
|
2008-01-15 14:46:45 +05:30
|
|
|
return False
|
2004-04-09 09:35:48 +05:30
|
|
|
except:
|
2005-12-06 12:08:09 +05:30
|
|
|
uri_name = "burn:///" + base + "/.thumb"
|
2007-09-12 20:32:03 +05:30
|
|
|
QuestionDialog.ErrorDialog(_("CD export preparation failed"),
|
2005-12-06 12:08:09 +05:30
|
|
|
_('Could not create %s') % uri_name)
|
2008-01-15 14:46:45 +05:30
|
|
|
return False
|
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() == self.object_handle:
|
2003-05-15 00:51:18 +05:30
|
|
|
nl.remove(o)
|
2004-02-21 11:41:59 +05:30
|
|
|
p.set_media_list(nl)
|
2007-09-12 20:32:03 +05:30
|
|
|
self.db.commit_family(p, None)
|
2004-04-09 09:35:48 +05:30
|
|
|
|
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() == self.object_handle:
|
2003-05-15 00:51:18 +05:30
|
|
|
nl.remove(o)
|
2004-02-21 11:41:59 +05:30
|
|
|
p.set_media_list(nl)
|
2007-09-12 20:32:03 +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() == self.object_handle:
|
2003-05-15 00:51:18 +05:30
|
|
|
nl.remove(o)
|
2004-02-21 11:41:59 +05:30
|
|
|
p.set_media_list(nl)
|
2007-09-12 20:32:03 +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() == self.object_handle:
|
2003-05-15 00:51:18 +05:30
|
|
|
nl.remove(o)
|
2004-02-21 11:41:59 +05:30
|
|
|
p.set_media_list(nl)
|
2007-09-12 20:32:03 +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:32:05 +05:30
|
|
|
nl = p.get_media_list()
|
|
|
|
for o in nl:
|
2004-07-28 07:59:07 +05:30
|
|
|
if o.get_reference_handle() == self.object_handle:
|
2004-06-23 02:32:05 +05:30
|
|
|
nl.remove(o)
|
|
|
|
p.set_media_list(nl)
|
2007-09-12 20:32:03 +05:30
|
|
|
self.db.commit_event(p, None)
|
|
|
|
self.db.remove_object(self.object_handle, 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):
|
2007-09-12 20:32:03 +05:30
|
|
|
newfile = unicode(fs_top.get_filename(),
|
2007-01-22 09:26:23 +05:30
|
|
|
sys.getfilesystemencoding())
|
2003-05-15 00:51:18 +05:30
|
|
|
if os.path.isfile(newfile):
|
2007-09-12 20:32:03 +05:30
|
|
|
self.copy_file(newfile, 'burn:///%s/%s' % (base, obase))
|
2005-02-20 04:03:24 +05:30
|
|
|
|
2003-05-15 00:51:18 +05:30
|
|
|
fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file"))
|
|
|
|
fs_top.hide_fileop_buttons()
|
2007-09-12 20:32:03 +05:30
|
|
|
fs_top.ok_button.connect('clicked', fs_ok_clicked)
|
|
|
|
fs_top.cancel_button.connect('clicked', fs_close_window)
|
2003-05-15 00:51:18 +05:30
|
|
|
fs_top.run()
|
2003-06-10 05:30:05 +05:30
|
|
|
fs_top.destroy()
|
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)
|
2003-05-15 04:52:35 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
for obj_id in self.db.get_media_object_handles():
|
2004-08-07 10:46:57 +05:30
|
|
|
obj = self.db.get_object_from_handle(obj_id)
|
2004-02-14 11:10:30 +05:30
|
|
|
oldfile = obj.get_path()
|
2003-05-15 04:52:35 +05:30
|
|
|
root = os.path.basename(oldfile)
|
2003-05-15 00:51:18 +05:30
|
|
|
if os.path.isfile(oldfile):
|
2007-09-12 20:32:03 +05:30
|
|
|
self.copy_file(oldfile, 'burn:///%s/%s' % (base, root))
|
2003-05-15 00:51:18 +05:30
|
|
|
else:
|
|
|
|
# File is lost => ask what to do
|
2004-07-28 07:59:07 +05:30
|
|
|
self.object_handle = obj.get_handle()
|
2004-01-18 07:29:30 +05:30
|
|
|
if missmedia_action == 0:
|
2007-09-12 20:32:03 +05:30
|
|
|
mmd = QuestionDialog.MissingMediaDialog(_("Media object could not be found"),
|
2005-02-20 04:03:24 +05:30
|
|
|
_("%(file_name)s is referenced in the database, but no longer exists. "
|
2004-01-18 07:29:30 +05:30
|
|
|
"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."
|
2007-09-12 20:32:03 +05:30
|
|
|
) % { 'file_name' : oldfile },
|
2004-01-18 07:29:30 +05:30
|
|
|
remove_clicked, leave_clicked, select_clicked)
|
2004-01-19 23:10:39 +05:30
|
|
|
missmedia_action = mmd.default_action
|
|
|
|
elif missmedia_action == 1:
|
|
|
|
remove_clicked()
|
|
|
|
elif missmedia_action == 2:
|
|
|
|
leave_clicked()
|
|
|
|
elif missmedia_action == 3:
|
|
|
|
select_clicked()
|
2003-05-15 00:51:18 +05:30
|
|
|
|
|
|
|
# Write XML now
|
2007-02-02 22:44:12 +05:30
|
|
|
uri = 'burn:///%s/data.gramps' % base
|
|
|
|
uri = uri.encode('utf8')
|
2007-09-12 20:32:03 +05:30
|
|
|
g = create(uri, OPEN_WRITE)
|
|
|
|
gfile = XmlWriter(self.db, self.callback, 2)
|
2003-05-14 09:53:30 +05:30
|
|
|
gfile.write_handle(g)
|
|
|
|
g.close()
|
2003-11-02 04:50:15 +05:30
|
|
|
os.system("nautilus --no-desktop burn:///")
|
2008-01-15 14:46:45 +05:30
|
|
|
return True
|
2005-02-20 04:03:24 +05:30
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def copy_file(self, src, dest):
|
|
|
|
original = open(src, "r")
|
2005-02-20 04:03:24 +05:30
|
|
|
destobj = URI(dest)
|
2007-09-12 20:32:03 +05:30
|
|
|
target = create(destobj, OPEN_WRITE)
|
2005-02-20 04:03:24 +05:30
|
|
|
done = 0
|
|
|
|
while 1:
|
|
|
|
buf = original.read(2048)
|
|
|
|
if buf == '':
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
target.write(buf)
|
|
|
|
target.close()
|
|
|
|
original.close()
|
|
|
|
|
2003-05-14 09:53:30 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register the plugin
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-01-17 03:12:05 +05:30
|
|
|
_title = _('_Export to CD (portable XML)')
|
2005-02-20 04:03:24 +05:30
|
|
|
_description = _('Exporting to CD copies all your data and media '
|
|
|
|
'object files to the CD Creator. You may later burn the CD '
|
|
|
|
'with this data, and that copy will be completely portable '
|
|
|
|
'across different machines and binary architectures.')
|
|
|
|
_config = None
|
|
|
|
_filename = 'burn'
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
register_export(writeData, _title, _description, _config, _filename)
|