diff --git a/ChangeLog b/ChangeLog index 94a9ddc33..e36191956 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,14 @@ * man/sv/gramps.1.in: tried to add Swedish man page (sv). but failed. How do I create man/sv in the svn repository? +2008-01-15 Benny Malengier + * src/gen/db/exceptions.py: wrong exception def, bug #1593 + * src/GrampsDbUtils/_WriteXML.py: correctly catch the exception + * src/GrampsDbUtils/_GrampsDbWriteXML.py: remove double def of xml export + * src/GrampsDbUtils/_GrampsDbWRFactories.py: remove write backend factory + * src/ExportAssistant.py: on fail, do not set success = True + * src/GrampsDbUtils/__init__.py: don't export unused stuff + 2008-01-15 Benny Malengier * src/ArgHandler.py: on autoload, do some extra checks first. diff --git a/src/ExportAssistant.py b/src/ExportAssistant.py index 04ab48644..e6ef73488 100644 --- a/src/ExportAssistant.py +++ b/src/ExportAssistant.py @@ -430,13 +430,12 @@ class ExportAssistant(gtk.Assistant, ManagedWindow.ManagedWindow) : # Lock page, show progress bar self.pre_save(page) # save - self.save() + success = self.save() # Unlock page self.post_save() #update the label and title - success = True - if success: + if success is None or success: conclusion_title = _('Your data has been saved') conclusion_text = _( 'The copy of your data has been ' @@ -449,7 +448,7 @@ class ExportAssistant(gtk.Assistant, ManagedWindow.ManagedWindow) : #add test, what is dir conclusion_text += '\n\n' + 'Filename: %s' %self.chooser.get_filename() else: - conclusion_title = _('Saving failed'), + conclusion_title = _('Saving failed') conclusion_text = _( 'There was an error while saving your data. ' 'You may try starting the export again.\n\n' diff --git a/src/GrampsDbUtils/_GrampsDbWRFactories.py b/src/GrampsDbUtils/_GrampsDbWRFactories.py index c87698b24..5efc08a84 100644 --- a/src/GrampsDbUtils/_GrampsDbWRFactories.py +++ b/src/GrampsDbUtils/_GrampsDbWRFactories.py @@ -33,41 +33,18 @@ required e.g.: > > # To get a Gedcom reader > GrampsDb.gramps_db_reader_factory(db_type = const.APP_GEDCOM) - + +As of 3.0 the writer_factory is deprecated. Exporter uses directly the plugin +system for export, no factory needed. """ import const import logging log = logging.getLogger(".GrampDb") - from gen.db import GrampsDbException from PluginUtils import import_list - -def gramps_db_writer_factory(db_type): - """Factory class for obtaining a Gramps database writers. - - - @param db_type: the type of backend required. - @type db_type: one of the app_* constants in const.py - - Raises GrampsDbException if the db_type is not recognised. - """ - - if db_type == const.APP_GRAMPS_XML: - import _WriteXML as WriteXML - md = WriteXML.exportData - elif db_type == const.APP_GEDCOM: - import _WriteGedcom as WriteGedcom - md = WriteGedcom.exportData - else: - raise GrampsDbException("Attempt to create a database " - "writer for unknown format: " - "db_type = %s" % (str(db_type),)) - - return md - def gramps_db_reader_factory(db_type): """Factory class for obtaining a Gramps database importers. @@ -97,7 +74,7 @@ def gramps_db_reader_factory(db_type): if not found: raise GrampsDbException("Attempt to create a database " "reader for unknown format: " - "db_type = %s" % (str(db_type),)) + "db_type = %s" % (str(db_type))) return md diff --git a/src/GrampsDbUtils/_GrampsDbWriteXML.py b/src/GrampsDbUtils/_GrampsDbWriteXML.py index 4ba76fcfc..2920d2e22 100644 --- a/src/GrampsDbUtils/_GrampsDbWriteXML.py +++ b/src/GrampsDbUtils/_GrampsDbWriteXML.py @@ -23,6 +23,8 @@ """ Contains the interface to allow a database to get written using GRAMPS' XML file format. +This module contains all that is needed for xml write, however it does not +provide the export plugin functionality. That is provided in _WriteXML.py """ #------------------------------------------------------------------------- @@ -31,7 +33,6 @@ GRAMPS' XML file format. # #------------------------------------------------------------------------- import time -import shutil import os import codecs from xml.sax.saxutils import escape @@ -61,63 +62,14 @@ from BasicUtils import UpdateCallback from gen.db.exceptions import GrampsDbWriteFailure #from gen.utils.longop import LongOpStatus -import gen.proxy - -#------------------------------------------------------------------------- -# -# Attempt to load the GZIP library. Some version of python do not seem -# to be compiled with this available. -# -#------------------------------------------------------------------------- -try: - import gzip - _gzip_ok = 1 -except: - _gzip_ok = 0 - - _xml_version = "1.2.0" # table for skipping control chars from XML strip_dict = dict.fromkeys(range(9)+range(12,20)) - def escxml(d): return escape(d, { '"' : '"' } ) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def exportData(database, filename, person, option_box, callback, version="unknown"): - if os.path.isfile(filename): - try: - shutil.copyfile(filename, filename + ".bak") - shutil.copystat(filename, filename + ".bak") - except: - pass - - compress = _gzip_ok == 1 - - option_box.parse_options() - - restrict = option_box.restrict - private = option_box.private - - if private: - database = gen.proxy.PrivateProxyDb(database) - - if restrict: - database = gen.proxy.LivingProxyDb( - database, gen.proxy.LivingProxyDb.MODE_RESTRICT) - - if not option_box.cfilter.is_empty(): - database = gen.proxy.FilterProxyDb(database, option_box.cfilter) - - g = GrampsDbXmlWriter(database, 0, compress, version, callback) - return g.write(filename) - #------------------------------------------------------------------------- # # @@ -164,8 +116,8 @@ class GrampsDbXmlWriter(UpdateCallback): base = os.path.dirname(filename) if os.path.isdir(base): if not os.access(base,os.W_OK) or not os.access(base,os.R_OK): - raise GrampsDbWriteFailure,\ - (_('Failure writing %s') % filename, + raise GrampsDbWriteFailure( + _('Failure writing %s') % filename, _("The database cannot be saved because you do " "not have permission to write to the directory. " "Please make sure you have write access to the " @@ -174,9 +126,9 @@ class GrampsDbXmlWriter(UpdateCallback): if os.path.exists(filename): if not os.access(filename,os.W_OK): - raise GrampsDbWriteFailure, \ - (_('Failure writing %s') % filename, - _("The database cannot be saved because you do " + raise GrampsDbWriteFailure( + _('Failure writing %s') % filename, + _("The database cannot be saved because you do " "not have permission to write to the file. " "Please make sure you have write access to the " "file and try again.")) @@ -193,7 +145,8 @@ class GrampsDbXmlWriter(UpdateCallback): g = open(filename,"w") except IOError,msg: print str(msg) - raise GrampsDbWriteFailure((_('Failure writing %s') % filename,str(msg))) + raise GrampsDbWriteFailure((_('Failure writing %s') % filename, + str(msg))) return 0 self.g = codecs.getwriter("utf8")(g) @@ -1151,12 +1104,5 @@ def conf_priv(obj): # # #------------------------------------------------------------------------- -_title = _('GRAMPS _XML database') -_description = _('The GRAMPS XML database is a format used by older ' - 'versions of GRAMPS. It is read-write compatible with ' - 'the present GRAMPS database format.') -_config = None -_filename = 'gramps' -from PluginUtils import register_export -register_export(exportData,_title,_description,_config,_filename) +# Don't export a writer for plugins, that is the task of _WriteXML.py \ No newline at end of file diff --git a/src/GrampsDbUtils/_WriteXML.py b/src/GrampsDbUtils/_WriteXML.py index 819ffb167..f62b66046 100644 --- a/src/GrampsDbUtils/_WriteXML.py +++ b/src/GrampsDbUtils/_WriteXML.py @@ -30,6 +30,8 @@ GRAMPS' XML file format. # load standard python libraries # #------------------------------------------------------------------------- +import shutil +import os from gettext import gettext as _ #------------------------------------------------------------------------- @@ -43,6 +45,19 @@ from QuestionDialog import ErrorDialog import GrampsDbUtils import ExportOptions from gen.db.exceptions import GrampsDbWriteFailure +import gen.proxy + +#------------------------------------------------------------------------- +# +# Attempt to load the GZIP library. Some version of python do not seem +# to be compiled with this available. +# +#------------------------------------------------------------------------- +try: + import gzip + _gzip_ok = 1 +except: + _gzip_ok = 0 #------------------------------------------------------------------------- # @@ -53,8 +68,32 @@ def export_data(database, filename, person, option_box, callback=None): """ Calls the XML writer with the syntax expected by the export plugin """ - return GrampsDbUtils.exportData(database, filename, person, option_box, - callback, const.VERSION) + if os.path.isfile(filename): + try: + shutil.copyfile(filename, filename + ".bak") + shutil.copystat(filename, filename + ".bak") + except: + pass + + compress = _gzip_ok == 1 + + option_box.parse_options() + + restrict = option_box.restrict + private = option_box.private + + if private: + database = gen.proxy.PrivateProxyDb(database) + + if restrict: + database = gen.proxy.LivingProxyDb( + database, gen.proxy.LivingProxyDb.MODE_RESTRICT) + + if not option_box.cfilter.is_empty(): + database = gen.proxy.FilterProxyDb(database, option_box.cfilter) + + g = XmlWriter(database, callback, 0, compress) + return g.write(filename) #------------------------------------------------------------------------- # @@ -74,10 +113,12 @@ class XmlWriter(GrampsDbUtils.GrampsDbXmlWriter): """ Write the database to the specified file. """ + ret = 0 #False try: ret = GrampsDbUtils.GrampsDbXmlWriter.write(self, filename) - except GrampsDbWriteFailure, val: - ErrorDialog(val[0], val[1]) + except GrampsDbWriteFailure, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1, m2) return ret #------------------------------------------------------------------------- diff --git a/src/GrampsDbUtils/__init__.py b/src/GrampsDbUtils/__init__.py index 53a2231e2..7073c615e 100644 --- a/src/GrampsDbUtils/__init__.py +++ b/src/GrampsDbUtils/__init__.py @@ -38,15 +38,13 @@ on using these factories see the _GrampsDbUtilsFactories.py file comments. __version__ = "$Revision$" from _GrampsDbWRFactories import \ - gramps_db_writer_factory, \ gramps_db_reader_factory from _GedcomParse import GedcomParser from _WriteGedcom import GedcomWriter -from _GrampsDbWriteXML import GrampsDbXmlWriter, \ - exportData, quick_write +from _GrampsDbWriteXML import GrampsDbXmlWriter from _WriteXML import XmlWriter import _Backup as Backup diff --git a/src/gen/db/exceptions.py b/src/gen/db/exceptions.py index a2f8b35da..dac19d73b 100644 --- a/src/gen/db/exceptions.py +++ b/src/gen/db/exceptions.py @@ -26,21 +26,26 @@ class GrampsDbException(Exception): def __init__(self, value): + Exception.__init__(self) self.value = value def __str__(self): - return repr(self.value) + return self.value class GrampsDbWriteFailure(Exception): """ Error used to indicate that a write to a database has failed. """ - - def __int__(self, value): + def __init__(self, value, value2=""): + Exception.__init__(self) self.value = value + self.value2 = value2 def __str__(self): - return repr(self.value) + return self.value + + def messages(self): + return self.value, self.value2 class FileVersionError(Exception): """