Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set theory v2 #7534

Merged
merged 3 commits into from Aug 5, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 29 additions & 5 deletions lib/ansible/runner/filter_plugins/core.py
Expand Up @@ -23,6 +23,7 @@
import pipes
import glob
import re
import collections
import operator as py_operator
from ansible import errors
from ansible.utils import md5s
Expand Down Expand Up @@ -140,19 +141,42 @@ def regex_replace(value='', pattern='', replacement='', ignorecase=False):
return _re.sub(replacement, value)

def unique(a):
return set(a)
if isinstance(a,collections.Hashable):
c = set(a)
else:
c = []
for x in a:
if x not in c:
c.append(x)
return c

def intersect(a, b):
return set(a).intersection(b)
if isinstance(a,collections.Hashable) and isinstance(b,collections.Hashable):
c = set(a) & set(b)
else:
c = unique(filter(lambda x: x in b, a))
return c

def difference(a, b):
return set(a).difference(b)
if isinstance(a,collections.Hashable) and isinstance(b,collections.Hashable):
c = set(a) - set(b)
else:
c = unique(filter(lambda x: x not in b, a))
return c

def symmetric_difference(a, b):
return set(a).symmetric_difference(b)
if isinstance(a,collections.Hashable) and isinstance(b,collections.Hashable):
c = set(a) ^ set(b)
else:
c = unique(filter(lambda x: x not in intersect(a,b), union(a,b)))
return c

def union(a, b):
return set(a).union(b)
if isinstance(a,collections.Hashable) and isinstance(b,collections.Hashable):
c = set(a) | set(b)
else:
c = unique(a + b)
return c

def version_compare(value, version, operator='eq', strict=False):
''' Perform a version comparison on a value '''
Expand Down