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
This commit is contained in:
Vassilii Khachaturov 2013-10-20 16:54:48 +00:00
parent 59457923fa
commit bf6901e6ed
3 changed files with 18 additions and 20 deletions

View File

@ -431,7 +431,7 @@
<ref name="primary-object"/>
<optional><ref name="date-content"/></optional>
<optional><element name="page"><text/></element></optional>
<optional><element name="confidence"><text/></element></optional>
<element name="confidence"><text/></element>
<zeroOrMore><element name="noteref">
<ref name="noteref-content"/>
</element></zeroOrMore>

View File

@ -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

View File

@ -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)