2003-05-14 09:53:30 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2004-01-18 07:29:30 +05:30
|
|
|
# Copyright (C) 2000-2004 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.
|
|
|
|
#
|
|
|
|
# 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$
|
|
|
|
|
2003-05-15 00:51:18 +05:30
|
|
|
"Export to CD (nautilus)"
|
2003-05-14 09:53:30 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
from cStringIO import StringIO
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
2003-12-02 08:05:49 +05:30
|
|
|
import gnome
|
2003-05-14 09:53:30 +05:30
|
|
|
import gnome.vfs
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import WriteXML
|
|
|
|
import Utils
|
2003-05-15 00:51:18 +05:30
|
|
|
import const
|
2003-05-15 04:52:35 +05:30
|
|
|
import QuestionDialog
|
|
|
|
import ImgManip
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
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
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def writeData(database,person):
|
|
|
|
try:
|
|
|
|
PackageWriter(database)
|
|
|
|
except:
|
|
|
|
import DisplayTrace
|
|
|
|
DisplayTrace.DisplayTrace()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PackageWriter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PackageWriter:
|
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
def __init__(self,database,cl=0,name=""):
|
2003-05-14 09:53:30 +05:30
|
|
|
self.db = database
|
2003-05-21 02:01:16 +05:30
|
|
|
self.cl = cl
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
if self.cl:
|
|
|
|
self.cl_run()
|
|
|
|
else:
|
|
|
|
base = os.path.dirname(__file__)
|
|
|
|
glade_file = "%s/%s" % (base,"cdexport.glade")
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
dic = {
|
|
|
|
"destroy_passed_object" : Utils.destroy_passed_object,
|
2003-12-02 08:05:49 +05:30
|
|
|
"on_ok_clicked" : self.on_ok_clicked,
|
|
|
|
"on_help_clicked" : self.on_help_clicked
|
2003-05-21 02:01:16 +05:30
|
|
|
}
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2003-08-17 07:44:33 +05:30
|
|
|
self.top = gtk.glade.XML(glade_file,"packageExport","gramps")
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
Utils.set_titles(self.top.get_widget('packageExport'),
|
2003-07-16 00:47:17 +05:30
|
|
|
self.top.get_widget('title'),_title_string)
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
self.top.signal_autoconnect(dic)
|
|
|
|
self.top.get_widget("packageExport").show()
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2003-05-15 04:52:35 +05:30
|
|
|
def copy_file(self,src,dest):
|
|
|
|
original = open(src,"r")
|
|
|
|
destobj = gnome.vfs.URI(dest)
|
|
|
|
target = gnome.vfs.create(destobj,gnome.vfs.OPEN_WRITE)
|
|
|
|
done = 0
|
|
|
|
while 1:
|
|
|
|
buf = original.read(2048)
|
|
|
|
if buf == '':
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
target.write(buf)
|
|
|
|
target.close()
|
|
|
|
original.close()
|
2003-05-15 00:51:18 +05:30
|
|
|
|
2003-05-15 04:52:35 +05:30
|
|
|
def make_thumbnail(self,dbname,root,path):
|
|
|
|
img = ImgManip.ImgManip(path)
|
|
|
|
data = img.jpg_scale_data(const.thumbScale,const.thumbScale)
|
|
|
|
|
|
|
|
uri = gnome.vfs.URI('burn:///%s/.thumb/%s.jpg' % (dbname,root))
|
|
|
|
th = gnome.vfs.create(uri,gnome.vfs.OPEN_WRITE)
|
|
|
|
th.write(data)
|
|
|
|
th.close()
|
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
def cl_run(self):
|
|
|
|
base = os.path.basename(self.name)
|
|
|
|
|
|
|
|
try:
|
|
|
|
uri = gnome.vfs.URI('burn:///%s' % base)
|
|
|
|
gnome.vfs.make_directory(uri,gnome.vfs.OPEN_WRITE)
|
2004-04-09 09:35:48 +05:30
|
|
|
except gnome.vfs.FileExistsError, msg:
|
|
|
|
QuestionDialog.ErrorDialog(_("CD export preparation failed"),
|
|
|
|
"1 %s " % str(msg))
|
|
|
|
return
|
|
|
|
except:
|
|
|
|
QuestionDialog.ErrorDialog("CD export preparation failed",
|
|
|
|
'Could not create burn:///%s' % base)
|
|
|
|
return
|
2003-05-21 02:01:16 +05:30
|
|
|
|
|
|
|
try:
|
|
|
|
uri = gnome.vfs.URI('burn:///%s/.thumb' % base)
|
|
|
|
gnome.vfs.make_directory(uri,gnome.vfs.OPEN_WRITE)
|
2004-04-09 09:35:48 +05:30
|
|
|
except gnome.vfs.FileExistsError, msg:
|
|
|
|
QuestionDialog.ErrorDialog("CD export preparation failed",
|
|
|
|
"2 %s " % str(msg))
|
|
|
|
return
|
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):
|
|
|
|
self.copy_file(oldfile,'burn:///%s/%s' % (base,root))
|
2004-02-14 11:10:30 +05:30
|
|
|
if obj.get_mime_type()[0:5] == "image":
|
|
|
|
self.make_thumbnail(base,root,obj.get_path())
|
2003-05-21 23:36:41 +05:30
|
|
|
else:
|
|
|
|
print "Warning: media file %s was not found," % root,\
|
|
|
|
"so it was ignored."
|
|
|
|
|
2003-05-21 02:01:16 +05:30
|
|
|
# Write XML now
|
|
|
|
g = gnome.vfs.create('burn:///%s/data.gramps' % base,gnome.vfs.OPEN_WRITE )
|
|
|
|
gfile = WriteXML.XmlWriter(self.db,None,1)
|
|
|
|
gfile.write_handle(g)
|
|
|
|
g.close()
|
|
|
|
|
2003-12-02 08:05:49 +05:30
|
|
|
def on_help_clicked(self,obj):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
|
|
|
gnome.help_display('gramps-manual','export-data')
|
|
|
|
|
2003-05-14 09:53:30 +05:30
|
|
|
def on_ok_clicked(self,obj):
|
|
|
|
Utils.destroy_passed_object(obj)
|
2004-01-18 07:29:30 +05:30
|
|
|
missmedia_action = 0
|
2003-05-14 09:53:30 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
base = os.path.basename(self.db.get_save_path())
|
2003-05-15 00:51:18 +05:30
|
|
|
|
2003-05-15 04:52:35 +05:30
|
|
|
try:
|
|
|
|
uri = gnome.vfs.URI('burn:///%s' % base)
|
|
|
|
gnome.vfs.make_directory(uri,gnome.vfs.OPEN_WRITE)
|
2004-04-09 09:35:48 +05:30
|
|
|
except gnome.vfs.FileExistsError:
|
|
|
|
QuestionDialog.ErrorDialog(_("CD export preparation failed"),
|
|
|
|
"File already exists")
|
|
|
|
return
|
|
|
|
except:
|
|
|
|
QuestionDialog.ErrorDialog(_("CD export preparation failed"),
|
|
|
|
_('Could not create burn:///%s') % base)
|
|
|
|
return
|
2003-05-15 04:52:35 +05:30
|
|
|
|
|
|
|
try:
|
|
|
|
uri = gnome.vfs.URI('burn:///%s/.thumb' % base)
|
|
|
|
gnome.vfs.make_directory(uri,gnome.vfs.OPEN_WRITE)
|
2004-04-09 09:35:48 +05:30
|
|
|
except gnome.vfs.FileExistsError, msg:
|
|
|
|
QuestionDialog.ErrorDialog("CD export preparation failed",
|
|
|
|
"4 %s " % str(msg))
|
|
|
|
return
|
|
|
|
except:
|
|
|
|
QuestionDialog.ErrorDialog(_("CD export preparation failed"),
|
|
|
|
_('Could not create burn:///%s/.thumb') % base)
|
|
|
|
return
|
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-07-28 07:59:07 +05:30
|
|
|
p = self.db.find_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)
|
2004-06-23 02:32:05 +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)
|
2004-06-23 02:32:05 +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)
|
2004-06-23 02:32:05 +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)
|
2004-06-23 02:32:05 +05:30
|
|
|
self.db.commit_place(p,None)
|
2004-08-13 10:04:07 +05:30
|
|
|
for key in self.db.get_event_handles():
|
2004-07-28 07:59:07 +05:30
|
|
|
p = self.db.find_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)
|
|
|
|
self.db.commit_event(p,None)
|
2004-07-28 07:59:07 +05:30
|
|
|
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):
|
|
|
|
newfile = fs_top.get_filename()
|
|
|
|
if os.path.isfile(newfile):
|
2003-05-15 04:52:35 +05:30
|
|
|
self.copy_file(newfile,'burn:///%s/%s' % (base,obase))
|
2003-05-15 00:51:18 +05:30
|
|
|
ntype = Utils.get_mime_type(newfile)
|
|
|
|
if ntype[0:5] == "image":
|
2003-05-15 04:52:35 +05:30
|
|
|
self.make_thumbnail(base,obase,newfile)
|
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
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
# 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):
|
2003-05-15 04:52:35 +05:30
|
|
|
self.copy_file(oldfile,'burn:///%s/%s' % (base,root))
|
2004-02-14 11:10:30 +05:30
|
|
|
if obj.get_mime_type()[0:5] == "image":
|
|
|
|
self.make_thumbnail(base,root,obj.get_path())
|
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:
|
|
|
|
mmd = QuestionDialog.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' : oldfile },
|
|
|
|
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
|
2003-05-14 09:53:30 +05:30
|
|
|
g = gnome.vfs.create('burn:///%s/data.gramps' % base,gnome.vfs.OPEN_WRITE )
|
|
|
|
gfile = WriteXML.XmlWriter(self.db,None,1)
|
|
|
|
gfile.write_handle(g)
|
|
|
|
g.close()
|
2003-11-02 04:50:15 +05:30
|
|
|
os.system("nautilus --no-desktop burn:///")
|
2003-05-14 09:53:30 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register the plugin
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from Plugins import register_export
|
|
|
|
|
2003-07-16 02:59:38 +05:30
|
|
|
register_export(writeData,_title_string)
|