--- a/sbsv2/raptor/python/filter_list.py Thu May 13 13:53:03 2010 +0100
+++ b/sbsv2/raptor/python/filter_list.py Thu May 13 14:14:32 2010 +0100
@@ -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,7 +98,6 @@
# Find all the filter plugins
self.pbox = pbox
possiblefilters = self.pbox.classesof(filter_interface.Filter)
-
filterdict = {}
for p in possiblefilters:
name = p.__name__.lower()
@@ -89,14 +105,22 @@
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:
- found = False
+ for (f, params) in filterCalls:
+ # if the filter exists and is a valid filter use it
if f.lower() in filterdict:
- self.filters.append(filterdict[f.lower()]())
+ 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 != []: