Filter speed ups, and hook for filter plugins
svn: r15800
This commit is contained in:
parent
ac7210d0ba
commit
5583ab113e
@ -55,50 +55,35 @@ class MatchesFilterBase(Rule):
|
||||
category = _('General filters')
|
||||
|
||||
def prepare(self, db):
|
||||
#if Filters.SystemFilters:
|
||||
#for filt in Filters.SystemFilters.get_filters(self.namespace):
|
||||
#if filt.get_name() == self.list[0]:
|
||||
#for rule in filt.flist:
|
||||
#rule.prepare(db)
|
||||
if Filters.CustomFilters:
|
||||
for filt in Filters.CustomFilters.get_filters(self.namespace):
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.prepare(db)
|
||||
filters = Filters.CustomFilters.get_filters_dict(self.namespace)
|
||||
if self.list[0] in filters:
|
||||
filt = filters[self.list[0]]
|
||||
for rule in filt.flist:
|
||||
rule.prepare(db)
|
||||
|
||||
def reset(self):
|
||||
#if Filters.SystemFilters:
|
||||
#for filt in Filters.SystemFilters.get_filters(self.namespace):
|
||||
#if filt.get_name() == self.list[0]:
|
||||
#for rule in filt.flist:
|
||||
#rule.reset()
|
||||
if Filters.CustomFilters:
|
||||
for filt in Filters.CustomFilters.get_filters(self.namespace):
|
||||
if filt.get_name() == self.list[0]:
|
||||
for rule in filt.flist:
|
||||
rule.reset()
|
||||
filters = Filters.CustomFilters.get_filters_dict(self.namespace)
|
||||
if self.list[0] in filters:
|
||||
filt = filters[self.list[0]]
|
||||
for rule in filt.flist:
|
||||
rule.reset()
|
||||
|
||||
def apply(self, db, obj):
|
||||
#if Filters.SystemFilters:
|
||||
#for filt in Filters.SystemFilters.get_filters(self.namespace):
|
||||
#if filt.get_name() == self.list[0]:
|
||||
#return filt.check(db, obj.handle)
|
||||
if Filters.CustomFilters:
|
||||
for filt in Filters.CustomFilters.get_filters(self.namespace):
|
||||
if filt.get_name() == self.list[0]:
|
||||
return filt.check(db, obj.handle)
|
||||
filters = Filters.CustomFilters.get_filters_dict(self.namespace)
|
||||
if self.list[0] in filters:
|
||||
filt = filters[self.list[0]]
|
||||
return filt.check(db, obj.handle)
|
||||
return False
|
||||
|
||||
def find_filter(self):
|
||||
"""
|
||||
Return the selected filter or None.
|
||||
"""
|
||||
#if Filters.SystemFilters:
|
||||
#for filt in Filters.SystemFilters.get_filters(self.namespace):
|
||||
#if filt.get_name() == self.list[0]:
|
||||
#return filt
|
||||
if Filters.CustomFilters:
|
||||
for filt in Filters.CustomFilters.get_filters(self.namespace):
|
||||
if filt.get_name() == self.list[0]:
|
||||
return filt
|
||||
filters = Filters.CustomFilters.get_filters_dict(self.namespace)
|
||||
if self.list[0] in filters:
|
||||
return filters[self.list[0]]
|
||||
return None
|
||||
|
@ -51,6 +51,17 @@ class FilterList(object):
|
||||
def __init__(self, file):
|
||||
self.filter_namespaces = {}
|
||||
self.file = os.path.expanduser(file)
|
||||
self._cached = None
|
||||
|
||||
def get_filters_dict(self, namespace='generic'):
|
||||
"""
|
||||
This runs every for every item to be matched!
|
||||
"""
|
||||
if self._cached is None:
|
||||
filters = self.get_filters(namespace)
|
||||
self._cached = dict([(filt.name, filt) for filt in filters])
|
||||
else:
|
||||
return self._cached
|
||||
|
||||
def get_filters(self, namespace='generic'):
|
||||
"""
|
||||
@ -60,18 +71,19 @@ class FilterList(object):
|
||||
filters = self.filter_namespaces[namespace]
|
||||
else:
|
||||
filters = []
|
||||
# plugins = PLUGMAN.process_plugin_data('Filters')
|
||||
# plugin_filters = []
|
||||
# if plugins:
|
||||
# try:
|
||||
# plugin_filters = [plug for plug in [plug(namespace)
|
||||
# if callable(plug)
|
||||
# else plug
|
||||
# for plug in plugins]
|
||||
# if plug is not None]
|
||||
# except:
|
||||
# import traceback
|
||||
# traceback.print_exc()
|
||||
plugins = PLUGMAN.process_plugin_data('Filters')
|
||||
if plugins:
|
||||
plugin_filters = []
|
||||
try:
|
||||
plugin_filters = [plug for plug in [plug(namespace)
|
||||
if callable(plug)
|
||||
else plug
|
||||
for plug in plugins]
|
||||
if plug is not None]
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
filters += plugin_filters
|
||||
return filters
|
||||
|
||||
def add(self, namespace, filt):
|
||||
|
Loading…
Reference in New Issue
Block a user