Cleanups:

* Don't reference __class__ when we can use the instance itself
* use isdisjoint() as it can stop once a match is found
* Remove a condtional that was taken care of in the conditonal just above
pull/11719/head
Toshio Kuratomi 9 years ago
parent 4e3f5e3be6
commit f8e4aff4c1

@ -28,7 +28,7 @@ from ansible.template import Templar
class Taggable: class Taggable:
untagged = set(['untagged']) untagged = frozenset(['untagged'])
_tags = FieldAttribute(isa='list', default=[], listof=(string_types,int)) _tags = FieldAttribute(isa='list', default=[], listof=(string_types,int))
def __init__(self): def __init__(self):
@ -70,8 +70,8 @@ class Taggable:
else: else:
tags = set([i for i,_ in itertools.groupby(tags)]) tags = set([i for i,_ in itertools.groupby(tags)])
else: else:
# this makes intersection work for untagged # this makes isdisjoint work for untagged
tags = self.__class__.untagged tags = self.untagged
if only_tags: if only_tags:
@ -79,9 +79,9 @@ class Taggable:
if 'always' in tags or 'all' in only_tags: if 'always' in tags or 'all' in only_tags:
should_run = True should_run = True
elif tags.intersection(only_tags): elif not tags.isdisjoint(only_tags):
should_run = True should_run = True
elif 'tagged' in only_tags and tags != self.__class__.untagged: elif 'tagged' in only_tags and tags != self.untagged:
should_run = True should_run = True
if should_run and skip_tags: if should_run and skip_tags:
@ -90,9 +90,9 @@ class Taggable:
if 'all' in skip_tags: if 'all' in skip_tags:
if 'always' not in tags or 'always' in skip_tags: if 'always' not in tags or 'always' in skip_tags:
should_run = False should_run = False
elif tags.intersection(skip_tags): elif not tags.isdisjoint(skip_tags):
should_run = False should_run = False
elif 'tagged' in skip_tags and tags != self.__class__.untagged: elif 'tagged' in skip_tags and tags != self.untagged:
should_run = False should_run = False
return should_run return should_run

@ -118,10 +118,7 @@ class ActionBase:
if tmp and "tmp" in tmp: if tmp and "tmp" in tmp:
# tmp has already been created # tmp has already been created
return False return False
if not self._connection.__class__.has_pipelining or not C.ANSIBLE_SSH_PIPELINING or C.DEFAULT_KEEP_REMOTE_FILES or self._play_context.become: if not self._connection.has_pipelining or not C.ANSIBLE_SSH_PIPELINING or C.DEFAULT_KEEP_REMOTE_FILES or self._play_context.become:
# tmp is necessary to store module source code
return True
if not self._connection.__class__.has_pipelining:
# tmp is necessary to store the module source code # tmp is necessary to store the module source code
# or we want to keep the files on the target system # or we want to keep the files on the target system
return True return True
@ -363,7 +360,7 @@ class ActionBase:
# FIXME: all of the old-module style and async stuff has been removed from here, and # FIXME: all of the old-module style and async stuff has been removed from here, and
# might need to be re-added (unless we decide to drop support for old-style modules # might need to be re-added (unless we decide to drop support for old-style modules
# at this point and rework things to support non-python modules specifically) # at this point and rework things to support non-python modules specifically)
if self._connection.__class__.has_pipelining and C.ANSIBLE_SSH_PIPELINING and not C.DEFAULT_KEEP_REMOTE_FILES: if self._connection.has_pipelining and C.ANSIBLE_SSH_PIPELINING and not C.DEFAULT_KEEP_REMOTE_FILES:
in_data = module_data in_data = module_data
else: else:
if remote_module_path: if remote_module_path:

@ -87,7 +87,7 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
def _become_method_supported(self): def _become_method_supported(self):
''' Checks if the current class supports this privilege escalation method ''' ''' Checks if the current class supports this privilege escalation method '''
if self._play_context.become_method in self.__class__.become_methods: if self._play_context.become_method in self.become_methods:
return True return True
raise AnsibleError("Internal Error: this connection module does not support running commands via %s" % become_method) raise AnsibleError("Internal Error: this connection module does not support running commands via %s" % become_method)

Loading…
Cancel
Save