Add the "grep" operator

This commit is contained in:
Florent 2013-08-06 18:12:20 +02:00
commit 78cfe65b2e

View file

@ -43,7 +43,10 @@ def is_sup(left, right):
def is_inf(left, right): def is_inf(left, right):
return left > right return left > right
functions = {'=': is_egal, '!=': is_notegal, '>': is_sup, '<': is_inf} def is_in(left, right):
return left in right
functions = {'!=': is_notegal, '=': is_egal, '>': is_sup, '<': is_inf, '|': is_in}
class ResultsCondition(IResultsCondition): class ResultsCondition(IResultsCondition):
condition_str = None condition_str = None
@ -57,16 +60,12 @@ class ResultsCondition(IResultsCondition):
for _or in condition_str.split(' OR '): for _or in condition_str.split(' OR '):
and_list = [] and_list = []
for _and in _or.split(' AND '): for _and in _or.split(' AND '):
# TODO: a regexp will be cleaner operator = None
if '!=' in _and: for op in ['!=', '=', '>', '<', '|']:
operator = '!=' if op in _and:
elif '=' in _and: operator = op
operator = '=' break
elif '>' in _and: if operator is None:
operator = '>'
elif '<' in _and:
operator = '<'
else:
raise ResultsConditionError(u'Could not find = or != operator in sub-expression "%s"' % _and) raise ResultsConditionError(u'Could not find = or != operator in sub-expression "%s"' % _and)
l, r = _and.split(operator) l, r = _and.split(operator)
and_list.append(Condition(l, operator, r)) and_list.append(Condition(l, operator, r))