--- a/sbsv2/raptor/python/filter_list.py Tue May 18 19:36:14 2010 +0100
+++ b/sbsv2/raptor/python/filter_list.py Fri Jun 04 13:09:28 2010 +0100
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+# Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
# All rights reserved.
# This component and the accompanying materials are made available
# under the terms of the License "Eclipse Public License v1.0"
@@ -19,6 +19,7 @@
import os
import sys
import raptor
+import re
import filter_interface
import pluginbox
import traceback
@@ -64,8 +65,24 @@
"""Nothing to do for stdout"""
return True
-
-
+def SplitList(listString):
+ """turn a CLI filter string into a list of (class, param) pairs.
+
+ for example, "foo[a,b],bar[c,d]"
+
+ becomes [ ("foo", ["a","b"]) , ("bar", ["c","d"]) ]
+ """
+ matches = re.findall("(\w+)(\[([^\[\]]*)\])?,?", listString)
+
+ pairs = []
+ for m in matches:
+ classname = m[0]
+ if len(m[2]) > 0:
+ pairs.append( (classname, m[2].split(",")) )
+ else:
+ pairs.append( (classname, []) )
+ return pairs
+
class FilterList(filter_interface.Filter):
def __init__(self):
@@ -81,14 +98,31 @@
# Find all the filter plugins
self.pbox = pbox
possiblefilters = self.pbox.classesof(filter_interface.Filter)
+ filterdict = {}
+ for p in possiblefilters:
+ name = p.__name__.lower()
+ if name in filterdict:
+ raise ValueError("filters found in SBS_HOME/python/plugins which have duplicate name: %s " % p.__name__)
+ else:
+ filterdict[name] = p
+
+ # turn "filternames" into a list of (classname, parameters) pairs
+ filterCalls = SplitList(filternames)
+
+ # look for each filter class in the box
unfound = []
self.filters = []
- for f in filternames:
- unfound.append(f) # unfound unless we find it
- for pl in possiblefilters:
- if pl.__name__.upper() == f.upper():
- self.filters.append(pl())
- unfound = unfound[:-1]
+ for (f, params) in filterCalls:
+ # if the filter exists and is a valid filter use it
+ if f.lower() in filterdict:
+ if params:
+ self.filters.append(filterdict[f.lower()](params))
+ else:
+ self.filters.append(filterdict[f.lower()]())
+ else:
+ # record missing filters
+ unfound.append(f)
+
if unfound != []:
raise ValueError("requested filters not found: %s \
\nAvailable filters are: %s" % (str(unfound), self.format_output_list(possiblefilters)))