From bf6901e6edbdf7741558ae712e66803265f25fbd Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Sun, 20 Oct 2013 16:54:48 +0000 Subject: [PATCH] 7125/7102: port my fix from gramps40 Don't bump 1.6.0 XML version, because Gramps 4.1 -- the first version to use it -- hasn't been released yet svn: r23356 --- data/grampsxml.rng | 2 +- gramps/plugins/importer/importxml.py | 32 +++++++++++++--------------- gramps/plugins/lib/libgrampsxml.py | 4 ++-- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/data/grampsxml.rng b/data/grampsxml.rng index 07e9e034d..a0a278644 100644 --- a/data/grampsxml.rng +++ b/data/grampsxml.rng @@ -431,7 +431,7 @@ - + diff --git a/gramps/plugins/importer/importxml.py b/gramps/plugins/importer/importxml.py index cfc496b76..e4174f775 100644 --- a/gramps/plugins/importer/importxml.py +++ b/gramps/plugins/importer/importxml.py @@ -74,6 +74,7 @@ from gramps.version import VERSION from gramps.gen.config import config #import gramps.plugins.lib.libgrampsxml from gramps.plugins.lib import libgrampsxml +from gramps.gen.plug.utils import version_str_to_tup #------------------------------------------------------------------------- # @@ -487,7 +488,7 @@ class GrampsParser(UpdateCallback): UpdateCallback.__init__(self, user.callback) self.user = user self.__gramps_version = 'unknown' - self.__xml_version = '1.0.0' + self.__xml_version = (1, 0, 0) self.stext_list = [] self.scomments_list = [] self.note_list = [] @@ -988,17 +989,17 @@ class GrampsParser(UpdateCallback): if 'xmlns' in attrs: xmlns = attrs.get('xmlns').split('/') if len(xmlns)>= 2 and not xmlns[2] == 'gramps-project.org': - self.__xml_version = '0.0.0' + self.__xml_version = (0, 0, 0) else: try: - self.__xml_version = xmlns[4] + self.__xml_version = version_str_to_tup(xmlns[4], 3) except: #leave version at 1.0.0 although it could be 0.0.0 ?? pass else: #1.0 or before xml, no dtd schema yet on # http://www.gramps-project.org/xml/ - self.__xml_version = '0.0.0' + self.__xml_version = (0, 0, 0) def start_created(self, attrs): """ @@ -1019,18 +1020,13 @@ class GrampsParser(UpdateCallback): """ Check the version of Gramps and XML. """ + xmlversion_str = '.'.join(str(i) for i in self.__xml_version) if self.__gramps_version == 'unknown': msg = _("The .gramps file you are importing does not contain information about " "the version of Gramps with, which it was produced.\n\n" "The file will not be imported.") raise GrampsImportError(_('Import file misses Gramps version'), msg) - if not re.match("\d+\.\d+\.\d+", self.__xml_version): - msg = _("The .gramps file you are importing does not contain a " - "valid xml-namespace number.\n\n" - "The file will not be imported.") - raise GrampsImportError(_('Import file contains unacceptable XML ' - 'namespace version'), msg) - if self.__xml_version > libgrampsxml.GRAMPS_XML_VERSION: + if self.__xml_version > libgrampsxml.GRAMPS_XML_VERSION_TUPLE: msg = _("The .gramps file you are importing was made by " "version %(newer)s of " "Gramps, while you are running an older version %(older)s. " @@ -1038,7 +1034,7 @@ class GrampsParser(UpdateCallback): "latest version of Gramps and try again." ) % { 'newer' : self.__gramps_version, 'older' : VERSION } raise GrampsImportError('', msg) - if self.__xml_version < '1.0.0': + if self.__xml_version < (1, 0, 0): msg = _("The .gramps file you are importing was made by version " "%(oldgramps)s of Gramps, while you are running a more " "recent version %(newgramps)s.\n\n" @@ -1049,10 +1045,10 @@ class GrampsParser(UpdateCallback): "\n for more info." ) % {'oldgramps': self.__gramps_version, 'newgramps': VERSION, - 'xmlversion': self.__xml_version, + 'xmlversion': xmlversion_str, } raise GrampsImportError(_('The file will not be imported'), msg) - elif self.__xml_version < '1.1.0': + elif self.__xml_version < (1, 1, 0): msg = _("The .gramps file you are importing was made by version " "%(oldgramps)s of Gramps, while you are running a much " "more recent version %(newgramps)s.\n\n" @@ -1064,7 +1060,7 @@ class GrampsParser(UpdateCallback): "\nfor more info." ) % {'oldgramps': self.__gramps_version, 'newgramps': VERSION, - 'xmlversion': self.__xml_version, + 'xmlversion': xmlversion_str, } self.user.warn(_('Old xml file'), msg) @@ -1660,7 +1656,7 @@ class GrampsParser(UpdateCallback): self.name = Name() name_type = attrs.get('type', "Birth Name") # Mapping "Other Name" from gramps 2.0.x to Unknown - if (self.__xml_version == '1.0.0') and (name_type == 'Other Name'): + if (self.__xml_version == (1, 0, 0)) and (name_type == 'Other Name'): self.name.set_type(NameType.UNKNOWN) else: self.name.type.set_from_xml_str(name_type) @@ -2036,7 +2032,9 @@ class GrampsParser(UpdateCallback): self.citation) self.citation.private = bool(attrs.get("priv")) self.citation.change = int(attrs.get('change', self.change)) - self.citation.confidence = self.conf # default + self.citation.confidence = ( + self.conf if self.__xml_version >= (1, 5, 1) + else 0 ) # See bug# 7125 self.info.add('new-object', CITATION_KEY, self.citation) return self.citation diff --git a/gramps/plugins/lib/libgrampsxml.py b/gramps/plugins/lib/libgrampsxml.py index ba3f26d09..a226c25b1 100644 --- a/gramps/plugins/lib/libgrampsxml.py +++ b/gramps/plugins/lib/libgrampsxml.py @@ -35,5 +35,5 @@ # Public Constants # #------------------------------------------------------------------------ -GRAMPS_XML_VERSION = "1.6.0" # version for Gramps 4.1 - +GRAMPS_XML_VERSION_TUPLE = (1,6,0) # version for Gramps 4.1 +GRAMPS_XML_VERSION = '.'.join(str(i) for i in GRAMPS_XML_VERSION_TUPLE)