Skip to content

Commit

Permalink
No need to support tuples of tuples.
Browse files Browse the repository at this point in the history
  • Loading branch information
truthbk committed Dec 9, 2015
1 parent 64a68c5 commit fee440c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions checks/libs/wmi/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ def _get_connection(self):

return connection

"""
Builds filter from a filter list.
- filters: expects a list of dicts, typically:
- [{'Property': value},...] or
- [{'Property': (comparison_op, value)},...]
NOTE: If we just provide a value we defailt to '=' comparison operator.
Otherwise, specify the operator in a tuple as above: (comp_op, value)
The filters also support lists/tuples as property 'values' to filter.
When such a list is provided, we OR filter for all such property values:
- [{'Property': [value1, value2, value3]},...] or
- [{'Property': [(cmp_op, value1), (cmp_op, value2)]},...] or
Normally the filter is expected to be exclusive, such that all filter conditions
should be met - therefore we AND all filters. If you'd like to OR, then set
inclusive to True.
"""
@staticmethod
def _format_filter(filters, inclusive):
"""
Expand All @@ -271,7 +289,7 @@ def build_where_clause(fltr, inclusive):
oper = '='

if len(fltr) == 0:
if isinstance(value, list) or isinstance(value, tuple):
if isinstance(value, list):
internal_filter = map(lambda x: {prop: (oper, x)}, value)
return "( {clause} )".format(clause=build_where_clause(internal_filter, True))
else:
Expand All @@ -281,7 +299,7 @@ def build_where_clause(fltr, inclusive):
constant=value
)

if isinstance(value, list) or isinstance(value, tuple):
if isinstance(value, list):
internal_filter = map(lambda x: {prop: (oper, x)}, value)
if inclusive:
return "( {clause} ) OR {more}".format(
Expand Down

0 comments on commit fee440c

Please sign in to comment.