5012: Move custom rule configuration file into the version directory and provide upgrade from previous version

svn: r18115
This commit is contained in:
Nick Hall 2011-09-06 14:43:03 +00:00
parent ec1018973d
commit b5ff4c9aea
2 changed files with 17 additions and 1 deletions

View File

@ -108,6 +108,8 @@ class FilterParser(handler.ContentHandler):
def endElement(self, tag):
if tag == "rule" and self.r is not None:
if len(self.r.labels) != len(self.a):
self.__upgrade()
if len(self.r.labels) < len(self.a):
print _("WARNING: Too many arguments in filter '%s'!\n"\
"Trying to load with subset of arguments.") %\
@ -134,6 +136,20 @@ class FilterParser(handler.ContentHandler):
def characters(self, data):
pass
def __upgrade(self):
"""
Upgrade argument lists to latest version.
"""
# HasPlace rule has extra locality field in v3.3
if self.r == Rules.Place.HasPlace and len(self.a) == 8:
self.a = self.a[0:2] + [u''] + self.a[4:8] + [self.a[3]] + \
[self.a[2]]
# HasNameOf rule has new fields for surnames in v3.3
if self.r == Rules.Person.HasNameOf and len(self.a) == 7:
self.a = self.a[0:2] + [self.a[3]] + [self.a[2]] + [self.a[6]] + \
[u''] + [self.a[4]] + [u'', u''] + [self.a[5]] + \
[u'', u'0']
#-------------------------------------------------------------------------
#
# Name to class mappings

View File

@ -145,7 +145,7 @@ IMAGE_DIR = os.path.join(ROOT_DIR, "images")
VERSION_DIR = os.path.join(
HOME_DIR, "gramps%s%s" % (VERSION_TUPLE[0], VERSION_TUPLE[1]))
CUSTOM_FILTERS = os.path.join(HOME_DIR, "custom_filters.xml")
CUSTOM_FILTERS = os.path.join(VERSION_DIR, "custom_filters.xml")
REPORT_OPTIONS = os.path.join(HOME_DIR, "report_options.xml")
TOOL_OPTIONS = os.path.join(HOME_DIR, "tool_options.xml")