0003796: Make export available when no GUI available. Patch from jmodule (Jakim Friant).

svn: r15294
This commit is contained in:
Brian Matherly
2010-05-01 04:12:42 +00:00
parent 356f23ac98
commit df32be43de
137 changed files with 29439 additions and 9737 deletions

View File

@@ -4,6 +4,7 @@
# Copyright (C) 2007-2008 Douglas S. Blank
# Copyright (C) 2004-2007 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant
#
# 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
@@ -50,7 +51,6 @@ LOG = logging.getLogger(".ExportCSV")
import gen.lib
from Filters import GenericFilter, Rules, build_filter_model
import Utils
from QuestionDialog import ErrorDialog
import gen.proxy
import DateHandler
from glade import Glade
@@ -60,8 +60,8 @@ from glade import Glade
# The function that does the exporting
#
#-------------------------------------------------------------------------
def exportData(database, filename, option_box=None, callback=None):
gw = CSVWriter(database, filename, option_box, callback)
def exportData(database, filename, msg_callback, option_box=None, callback=None):
gw = CSVWriter(database, filename, msg_callback, option_box, callback)
return gw.export_data()
#-------------------------------------------------------------------------
@@ -219,11 +219,12 @@ class CSVWriterOptionBox(object):
#
#-------------------------------------------------------------------------
class CSVWriter(object):
def __init__(self, database, filename, option_box=None, callback=None):
def __init__(self, database, filename, msg_callback, option_box=None, callback=None):
self.db = database
self.option_box = option_box
self.filename = filename
self.callback = callback
self.msg_callback = msg_callback
if callable(self.callback): # callback is really callable
self.update = self.update_real
else:
@@ -293,10 +294,10 @@ class CSVWriter(object):
self.g = UnicodeWriter(self.fp)
except IOError,msg:
msg2 = _("Could not create %s") % self.filename
ErrorDialog(msg2,str(msg))
self.msg_callback(msg2,str(msg))
return False
except:
ErrorDialog(_("Could not create %s") % self.filename)
self.msg_callback(_("Could not create %s") % self.filename)
return False
######################### initialize progress bar
self.count = 0

View File

@@ -3,6 +3,7 @@
#
# Copyright (C) 2003-2006, 2008 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant
#
# 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
@@ -47,7 +48,6 @@ log = logging.getLogger(".WriteFtree")
import Utils
from Filters import GenericFilter, Rules, build_filter_model
import Errors
from QuestionDialog import ErrorDialog
from glade import Glade
#-------------------------------------------------------------------------
@@ -55,8 +55,8 @@ from glade import Glade
# writeData
#
#-------------------------------------------------------------------------
def writeData(database, filename, option_box=None, callback=None):
writer = FtreeWriter(database, filename, option_box, callback)
def writeData(database, filename, msg_callback, option_box=None, callback=None):
writer = FtreeWriter(database, msg_callback, filename, option_box, callback)
return writer.export_data()
class FtreeWriterOptionBox(object):
@@ -123,12 +123,13 @@ class FtreeWriterOptionBox(object):
#-------------------------------------------------------------------------
class FtreeWriter(object):
def __init__(self, database, filename="", option_box=None,
def __init__(self, database, msg_callback, filename="", option_box=None,
callback = None):
self.db = database
self.option_box = option_box
self.filename = filename
self.callback = callback
self.msg_callback = msg_callback
if callable(self.callback): # callback is really callable
self.update = self.update_real
else:
@@ -154,7 +155,7 @@ class FtreeWriter(object):
except Errors.FilterError, msg:
(m1, m2) = msg.messages()
ErrorDialog(m1, m2)
self.msg_callback(m1, m2)
return
def update_empty(self):

View File

@@ -5,6 +5,7 @@
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2008-2009 Gary Burton
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
# Copyright (C) 2010 Jakim Friant
#
# 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
@@ -46,7 +47,6 @@ from ExportOptions import WriterOptionBox
from gen.updatecallback import UpdateCallback
from Utils import media_path_full, get_unicode_path
import gen.proxy
from QuestionDialog import ErrorDialog
from PlaceUtils import conv_lat_lon
#-------------------------------------------------------------------------
@@ -1398,7 +1398,7 @@ class GedcomWriter(UpdateCallback):
#
#
#-------------------------------------------------------------------------
def export_data(database, filename, option_box=None, callback=None):
def export_data(database, filename, msg_callback, option_box=None, callback=None):
"""
External interface used to register with the plugin system.
"""
@@ -1408,7 +1408,7 @@ def export_data(database, filename, option_box=None, callback=None):
ret = ged_write.write_gedcom_file(filename)
except IOError, msg:
msg2 = _("Could not create %s") % filename
ErrorDialog(msg2, str(msg))
msg_callback(msg2, str(msg))
except Errors.DatabaseError, msg:
ErrorDialog(_("Export failed"), str(msg))
msg_callback(_("Export failed"), str(msg))
return ret

View File

@@ -5,6 +5,7 @@
# Copyright (C) 2004-2006, 2008 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2009 Gary Burton
# Copyright (C) 2010 Jakim Friant
#
# 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
@@ -49,7 +50,6 @@ import gen.lib
from Filters import GenericFilter, Rules, build_filter_model
#import const
import Utils
from QuestionDialog import ErrorDialog
from glade import Glade
import config
@@ -139,12 +139,13 @@ class GeneWebWriterOptionBox(object):
self.images_path = ""
class GeneWebWriter(object):
def __init__(self, database, filename="", option_box=None,
def __init__(self, database, msg_callback, filename="", option_box=None,
callback=None):
self.db = database
self.option_box = option_box
self.filename = filename
self.callback = callback
self.msg_callback = msg_callback
if callable(self.callback): # callback is really callable
self.update = self.update_real
else:
@@ -215,14 +216,14 @@ class GeneWebWriter(object):
self.g = open(self.filename, "w")
except IOError,msg:
msg2 = _("Could not create %s") % self.filename
ErrorDialog(msg2, str(msg))
self.msg_callback(msg2, str(msg))
return False
except:
ErrorDialog(_("Could not create %s") % self.filename)
self.msg_callback(_("Could not create %s") % self.filename)
return False
if len(self.flist) < 1:
ErrorDialog(_("No families matched by selected filter"))
self.msg_callback(_("No families matched by selected filter"))
return False
self.count = 0
@@ -609,6 +610,6 @@ class GeneWebWriter(object):
#
#
#-------------------------------------------------------------------------
def exportData(database, filename, option_box=None, callback=None):
gw = GeneWebWriter(database, filename, option_box, callback)
def exportData(database, filename, msg_callback, option_box=None, callback=None):
gw = GeneWebWriter(database, msg_callback, filename, option_box, callback)
return gw.export_data()

View File

@@ -5,6 +5,7 @@
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2008 Gary Burton
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
# Copyright (C) 2010 Jakim Friant
#
# 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
@@ -69,7 +70,7 @@ import constfunc
# writeData
#
#-------------------------------------------------------------------------
def writeData(database, filename, option_box=None, callback=None):
def writeData(database, filename, msg_callback, option_box=None, callback=None):
# Rename file, if it exists already, with <filename>.bak
# as it it for normal XML export.
@@ -105,7 +106,7 @@ def writeData(database, filename, option_box=None, callback=None):
if option_box.unlinked:
database = gen.proxy.ReferencedProxyDb(database)
writer = PackageWriter(database, filename, callback)
writer = PackageWriter(database, filename, msg_callback, callback)
return writer.export()
#-------------------------------------------------------------------------
@@ -115,9 +116,10 @@ def writeData(database, filename, option_box=None, callback=None):
#-------------------------------------------------------------------------
class PackageWriter(object):
def __init__(self, database, filename, callback=None):
def __init__(self, database, filename, msg_callback, callback=None):
self.db = database
self.callback = callback
self.msg_callback = msg_callback
self.filename = filename
def export(self):
@@ -228,7 +230,7 @@ class PackageWriter(object):
# Write XML now
g = StringIO()
gfile = XmlWriter(self.db, self.callback, 2)
gfile = XmlWriter(self.db, msg_callback, self.callback, 2)
gfile.write_handle(g)
tarinfo = tarfile.TarInfo('data.gramps')
tarinfo.size = len(g.getvalue())

View File

@@ -4,6 +4,7 @@
# Copyright (C) 2004 Martin Hawlisch
# Copyright (C) 2005-2006, 2008 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant
#
# 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
@@ -50,7 +51,6 @@ from Filters import GenericFilter, Rules, build_filter_model
import Utils
from gen.lib import Date, EventType
import Errors
from QuestionDialog import ErrorDialog
from glade import Glade
#-------------------------------------------------------------------------
@@ -116,13 +116,14 @@ class CalendarWriterOptionBox(object):
self.cfilter = self.filter_menu[self.filters.get_active()][1]
class CalendarWriter(object):
def __init__(self, database, cl=0, filename="", option_box=None,
def __init__(self, database, msg_callback, cl=0, filename="", option_box=None,
callback=None):
self.db = database
self.option_box = option_box
self.cl = cl
self.filename = filename
self.callback = callback
self.msg_callback = msg_callback
if callable(self.callback): # callback is really callable
self.update = self.update_real
else:
@@ -153,7 +154,7 @@ class CalendarWriter(object):
self.db, self.db.iter_person_handles()))
except Errors.FilterError, msg:
(m1, m2) = msg.messages()
ErrorDialog(m1, m2)
self.msg_callback(m1, m2)
return
self.flist = {}
@@ -194,10 +195,10 @@ class CalendarWriter(object):
self.g = open(filename,"w")
except IOError,msg:
msg2 = _("Could not create %s") % filename
ErrorDialog(msg2, str(msg))
self.msg_callback(msg2, str(msg))
return False
except:
ErrorDialog(_("Could not create %s") % filename)
self.msg_callback(_("Could not create %s") % filename)
return False
self.writeln("BEGIN:VCALENDAR")

View File

@@ -4,6 +4,7 @@
# Copyright (C) 2004 Martin Hawlisch
# Copyright (C) 2005-2008 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant
#
# 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
@@ -48,7 +49,6 @@ log = logging.getLogger(".ExportVCard")
from Filters import GenericFilter, Rules, build_filter_model
from gen.lib import Date
import Errors
from QuestionDialog import ErrorDialog
from glade import Glade
#-------------------------------------------------------------------------
@@ -115,13 +115,14 @@ class CardWriterOptionBox(object):
self.cfilter = self.filter_menu[self.filters.get_active()][1]
class CardWriter(object):
def __init__(self, database, cl=0, filename="", option_box=None,
def __init__(self, database, msg_callback, cl=0, filename="", option_box=None,
callback=None):
self.db = database
self.option_box = option_box
self.cl = cl
self.filename = filename
self.callback = callback
self.msg_callback = msg_callback
if callable(self.callback): # callback is really callable
self.update = self.update_real
else:
@@ -144,7 +145,7 @@ class CardWriter(object):
self.plist[p] = 1
except Errors.FilterError, msg:
(m1, m2) = msg.messages()
ErrorDialog(m1, m2)
self.msg_callback(m1, m2)
return
def update_empty(self):
@@ -171,10 +172,10 @@ class CardWriter(object):
self.g = open(filename,"w")
except IOError,msg:
msg2 = _("Could not create %s") % filename
ErrorDialog(msg2, str(msg))
self.msg_callback(msg2, str(msg))
return False
except:
ErrorDialog(_("Could not create %s") % filename)
self.msg_callback(_("Could not create %s") % filename)
return False
self.count = 0

View File

@@ -6,6 +6,7 @@
# Copyright (C) 2008 Gary Burton
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
# Copyright (C) 2009 Douglas S. Blank
# Copyright (C) 2010 Jakim Friant
#
# 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
@@ -60,7 +61,7 @@ from gen.updatecallback import UpdateCallback
from gen.db.exceptions import DbWriteFailure
import const
import constfunc
from QuestionDialog import ErrorDialog
#from QuestionDialog import ErrorDialog
from ExportOptions import WriterOptionBox
import gen.proxy
import libgrampsxml
@@ -93,7 +94,7 @@ class GrampsXmlWriter(UpdateCallback):
Writes a database to the XML file.
"""
def __init__(self, db, strip_photos=0, compress=1, version="unknown",
def __init__(self, db, strip_photos=0, compress=1, version="unknown",
callback=None):
"""
Initialize, but does not write, an XML file.
@@ -1147,7 +1148,7 @@ def conf_priv(obj):
# export_data
#
#-------------------------------------------------------------------------
def export_data(database, filename, option_box=None, callback=None):
def export_data(database, filename, msg_callback, option_box=None, callback=None):
"""
Call the XML writer with the syntax expected by the export plugin.
"""
@@ -1184,7 +1185,7 @@ def export_data(database, filename, option_box=None, callback=None):
if option_box.unlinked:
database = gen.proxy.ReferencedProxyDb(database)
g = XmlWriter(database, callback, 0, compress)
g = XmlWriter(database, msg_callback, callback, 0, compress)
return g.write(filename)
#-------------------------------------------------------------------------
@@ -1197,9 +1198,10 @@ class XmlWriter(GrampsXmlWriter):
Writes a database to the XML file.
"""
def __init__(self, dbase, callback, strip_photos, compress=1):
def __init__(self, dbase, msg_callback, callback, strip_photos, compress=1):
GrampsXmlWriter.__init__(
self, dbase, strip_photos, compress, const.VERSION, callback)
self.msg_callback = msg_callback
def write(self, filename):
"""
@@ -1210,5 +1212,5 @@ class XmlWriter(GrampsXmlWriter):
ret = GrampsXmlWriter.write(self, filename)
except DbWriteFailure, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1, m2)
self.msg_callback(m1, m2)
return ret