1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

ansible/vars/: PEP8 compliancy (#24685)

- Make PEP8 compliant
This commit is contained in:
Dag Wieers 2017-05-16 19:51:27 +02:00 committed by John R Barker
parent 9178e176b5
commit 4f29662a9e
4 changed files with 24 additions and 25 deletions

View file

@ -71,7 +71,7 @@ def preprocess_vars(a):
if a is None:
return None
elif not isinstance(a, list):
data = [ a ]
data = [a]
else:
data = a
@ -81,6 +81,7 @@ def preprocess_vars(a):
return data
def strip_internal_keys(dirty):
'''
All keys stating with _ansible_ are internal, so create a copy of the 'dirty' dict
@ -119,15 +120,15 @@ class VariableManager:
def __getstate__(self):
data = dict(
fact_cache = self._fact_cache,
np_fact_cache = self._nonpersistent_fact_cache,
vars_cache = self._vars_cache,
extra_vars = self._extra_vars,
host_vars_files = self._host_vars_files,
group_vars_files = self._group_vars_files,
omit_token = self._omit_token,
options_vars = self._options_vars,
#inventory = self._inventory,
fact_cache=self._fact_cache,
np_fact_cache=self._nonpersistent_fact_cache,
vars_cache=self._vars_cache,
extra_vars=self._extra_vars,
host_vars_files=self._host_vars_files,
group_vars_files=self._group_vars_files,
omit_token=self._omit_token,
options_vars=self._options_vars,
# inventory=self._inventory,
)
return data
@ -192,7 +193,7 @@ class VariableManager:
if a is None:
return None
elif not isinstance(a, list):
data = [ a ]
data = [a]
else:
data = a
@ -307,7 +308,7 @@ class VariableManager:
# the with_first_found mechanism.
vars_file_list = vars_file_item
if not isinstance(vars_file_list, list):
vars_file_list = [ vars_file_list ]
vars_file_list = [vars_file_list]
# now we iterate through the (potential) files, and break out
# as soon as we read one from the list. If none are found, we
@ -389,7 +390,7 @@ class VariableManager:
if task and task.delegate_to is not None and include_delegate_to:
all_vars['ansible_delegated_vars'] = self._get_delegated_vars(loader, play, task, all_vars)
#VARIABLE_CACHE[cache_entry] = all_vars
# VARIABLE_CACHE[cache_entry] = all_vars
if task or play:
all_vars['vars'] = all_vars.copy()
@ -439,7 +440,7 @@ class VariableManager:
variables['ansible_play_hosts'] = [x for x in variables['ansible_play_hosts_all'] if x not in play._removed_hosts]
variables['ansible_play_batch'] = [x.name for x in self._inventory.get_hosts() if x.name not in play._removed_hosts]
#DEPRECATED: play_hosts should be deprecated in favor of ansible_play_batch,
# DEPRECATED: play_hosts should be deprecated in favor of ansible_play_batch,
# however this would take work in the templating engine, so for now we'll add both
variables['play_hosts'] = variables['ansible_play_batch']
@ -628,7 +629,6 @@ class VariableManager:
return data
def add_group_vars_file(self, path, loader):
'''
Loads and caches a host_vars file in the _host_vars_files dict,

View file

@ -40,6 +40,7 @@ except ImportError:
__all__ = ['HostVars']
# Note -- this is a Mapping, not a MutableMapping
class HostVars(collections.Mapping):
''' A special view of vars_cache that adds values from the inventory when needed. '''

View file

@ -30,6 +30,7 @@ except ImportError:
from ansible.utils.display import Display
display = Display()
def get_reserved_names(include_private=True):
''' this function returns the list of reserved names associated with play objects'''
@ -37,8 +38,8 @@ def get_reserved_names(include_private=True):
private = set()
result = set()
#FIXME: find a way to 'not hardcode', possibly need role deps/includes
class_list = [ Play, Role, Block, Task ]
# FIXME: find a way to 'not hardcode', possibly need role deps/includes
class_list = [Play, Role, Block, Task]
for aclass in class_list:
aobj = aclass()
@ -55,7 +56,7 @@ def get_reserved_names(include_private=True):
public.add('local_action')
# loop implies with_
#FIXME: remove after with_ is not only deprecated but removed
# FIXME: remove after with_ is not only deprecated but removed
if 'loop' in private or 'loop' in public:
public.add('with_')
@ -66,6 +67,7 @@ def get_reserved_names(include_private=True):
return result
def warn_if_reserved(myvars):
''' this function warns if any variable passed conflicts with internally reserved names '''
reserved = get_reserved_names()
@ -74,4 +76,3 @@ def warn_if_reserved(myvars):
continue # we add this one internally
if varname in reserved:
display.warning('Found variable using reserved name: %s' % varname)

View file

@ -873,9 +873,6 @@ lib/ansible/utils/listify.py
lib/ansible/utils/path.py
lib/ansible/utils/ssh_functions.py
lib/ansible/utils/vars.py
lib/ansible/vars/__init__.py
lib/ansible/vars/hostvars.py
lib/ansible/vars/reserved.py
setup.py
test/integration/cleanup_azure.py
test/integration/cleanup_ec2.py