From 0b59dad73b9c5c26f1c1b1f803cf96b07983e135 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Wed, 4 Feb 2009 21:37:15 +0000 Subject: [PATCH] #2490 : Migration : register new arg values on custom_filter.xml svn: r11857 --- src/Filters/Rules/_HasNoteBase.py | 8 ++++++++ src/Filters/Rules/_Rule.py | 5 +++-- src/Filters/_FilterParser.py | 22 ++++++++++++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Filters/Rules/_HasNoteBase.py b/src/Filters/Rules/_HasNoteBase.py index 45cb14ed3..418df1360 100755 --- a/src/Filters/Rules/_HasNoteBase.py +++ b/src/Filters/Rules/_HasNoteBase.py @@ -46,6 +46,14 @@ class HasNoteBase(Rule): description = _("Matches objects that have a certain number of notes") category = _('General filters') + def __init__(self, arg): + # Upgrade from pre 3.1 HasNote filter, use defaults that correspond + # Previous filter had 0 arguments + if len(arg) == 0: + Rule.__init__(self, ["0", 'greater than']) + else: + Rule.__init__(self, arg) + def prepare(self, db): # things we want to do just once, not for every handle if self.list[1] == _('lesser than'): diff --git a/src/Filters/Rules/_Rule.py b/src/Filters/Rules/_Rule.py index 5fb86275c..f8307d9ea 100644 --- a/src/Filters/Rules/_Rule.py +++ b/src/Filters/Rules/_Rule.py @@ -55,8 +55,9 @@ class Rule: def set_list(self, arg): assert isinstance(arg, list) or arg is None, "Argument is not a list" assert len(arg) == len(self.labels), \ - "Number of arguments does not match number of labels.\n"\ - "list: %s\nlabels: %s" % (arg,self.labels) + "ERROR: Number of arguments does not match number of labels.\n"\ + " list: %s\n"\ + " labels: %s" % (arg,self.labels) self.list = arg def values(self): diff --git a/src/Filters/_FilterParser.py b/src/Filters/_FilterParser.py index d70636464..8bd9959d6 100644 --- a/src/Filters/_FilterParser.py +++ b/src/Filters/_FilterParser.py @@ -108,16 +108,26 @@ 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): - print "WARNING: Invalid number of arguments in filter '%s'!" %\ - self.f.get_name() + print _("WARNING: To many arguments in filter '%s'!\n"\ + "Trying to load with subset of arguments.") %\ + self.f.get_name() nargs = len(self.r.labels) rule = self.r(self.a[0:nargs]) self.f.add_rule(rule) - elif len(self.r.labels) > len(self.a): - print "ERROR: Invalid number of arguments in filter '%s'!" % \ - self.f.get_name() else: - rule = self.r(self.a) + if len(self.r.labels) > len(self.a): + print _("WARNING: To few arguments in filter '%s'!\n" \ + " Trying to load anyway in the hope this "\ + "will be upgraded.") %\ + self.f.get_name() + try: + rule = self.r(self.a) + except AssertionError, msg: + print msg + print _("ERROR: filter %s could not be correctly loaded. " + "Edit the filter!") % self.f.get_name() + return + self.f.add_rule(rule) def characters(self, data):