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

ansible/parsing: PEP8 compliancy (#24701)

- Make PEP8 compliant
This commit is contained in:
Dag Wieers 2017-05-18 19:41:00 +02:00 committed by John R Barker
parent 5babe2daea
commit 6f6bdf7914
12 changed files with 58 additions and 71 deletions

View file

@ -237,15 +237,17 @@ class DataLoader:
b_main = b'main%s' % (suffix)
b_tasked = b'tasks/%s' % (b_main)
if b_path.endswith(b'tasks') and os.path.exists(os.path.join(b_path, b_main)) \
or os.path.exists(os.path.join(b_upath, b_tasked)) \
or os.path.exists(os.path.join(os.path.dirname(b_path), b_tasked)):
if (
b_path.endswith(b'tasks') and
os.path.exists(os.path.join(b_path, b_main)) or
os.path.exists(os.path.join(b_upath, b_tasked)) or
os.path.exists(os.path.join(os.path.dirname(b_path), b_tasked))
):
isit = True
break
return isit
def path_dwim_relative(self, path, dirname, source, is_role=False):
'''
find one file in either a role or playbook dir with or without

View file

@ -19,12 +19,11 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.errors import AnsibleParserError, AnsibleError
from ansible.module_utils.six import iteritems, string_types
from ansible.module_utils._text import to_text
from ansible.plugins import module_loader
from ansible.parsing.splitter import parse_kv, split_args
from ansible.plugins import module_loader
from ansible.template import Templar
@ -96,7 +95,6 @@ class ModuleArgsParser:
assert isinstance(task_ds, dict)
self._task_ds = task_ds
def _split_module_string(self, module_string):
'''
when module names are expressed like:
@ -111,7 +109,6 @@ class ModuleArgsParser:
else:
return (tokens[0], "")
def _handle_shell_weirdness(self, action, args):
'''
given an action name and an args dictionary, return the
@ -259,7 +256,6 @@ class ModuleArgsParser:
delegate_to = self._task_ds.get('delegate_to', None)
args = dict()
# This is the standard YAML form for command-type modules. We grab
# the args and pass them in as additional arguments, which can/will
# be overwritten via dict updates from the other arg sources below
@ -272,7 +268,6 @@ class ModuleArgsParser:
thing = self._task_ds['action']
action, args = self._normalize_parameters(thing, action=action, additional_args=additional_args)
# local_action
if 'local_action' in self._task_ds:
# local_action is similar but also implies a delegate_to
@ -294,7 +289,6 @@ class ModuleArgsParser:
thing = value
action, args = self._normalize_parameters(thing, action=action, additional_args=additional_args)
# if we didn't see any module in the task at all, it's not a task really
if action is None:
if 'ping' not in module_loader:

View file

@ -23,6 +23,7 @@ __metaclass__ = type
def is_quoted(data):
return len(data) > 1 and data[0] == data[-1] and data[0] in ('"', "'") and data[-2] != '\\'
def unquote(data):
''' removes first and last quotes from a string, if the string starts and ends with the same quotes '''
if is_quoted(data):

View file

@ -19,8 +19,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import re
import codecs
import re
from ansible.errors import AnsibleParserError
from ansible.module_utils._text import to_text
@ -177,7 +177,7 @@ def split_args(args):
# now we loop over each split chunk, coalescing tokens if the white space
# split occurred within quotes or a jinja2 block of some kind
for itemidx,item in enumerate(items):
for (itemidx, item) in enumerate(items):
# we split on spaces and newlines separately, so that we
# can tell which character we split on for reassembly
@ -185,7 +185,7 @@ def split_args(args):
tokens = item.strip().split(' ')
line_continuation = False
for idx,token in enumerate(tokens):
for (idx, token) in enumerate(tokens):
# if we hit a line continuation character, but
# we're not inside quotes, ignore it and continue

View file

@ -18,4 +18,3 @@
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

View file

@ -166,6 +166,7 @@ patterns = {
}
def parse_address(address, allow_ranges=False):
"""
Takes a string and returns a (host, port) tuple. If the host is None, then

View file

@ -24,6 +24,7 @@ try:
except ImportError:
import simplejson as json
def jsonify(result, format=False):
''' format JSON output (uncompressed or uncompressed) '''
@ -38,4 +39,3 @@ def jsonify(result, format=False):
return json.dumps(result, sort_keys=True, indent=indent, ensure_ascii=False)
except UnicodeDecodeError:
return json.dumps(result, sort_keys=True, indent=indent)

View file

@ -712,7 +712,8 @@ class VaultAES256:
hash_function = SHA256
# make two keys and one iv
pbkdf2_prf = lambda p, s: HMAC.new(p, s, hash_function).digest()
def pbkdf2_prf(p, s):
return HMAC.new(p, s, hash_function).digest()
b_derivedkey = PBKDF2(b_password, b_salt, dkLen=(2 * keylength) + ivlength,
count=10000, prf=pbkdf2_prf)

View file

@ -18,4 +18,3 @@
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

View file

@ -24,10 +24,10 @@ from yaml.nodes import MappingNode
from ansible.module_utils._text import to_bytes
from ansible.parsing.vault import VaultLib
from ansible.parsing.yaml.objects import AnsibleMapping, AnsibleSequence, AnsibleUnicode
from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
from ansible.parsing.yaml.objects import AnsibleMapping, AnsibleSequence, AnsibleUnicode, AnsibleVaultEncryptedUnicode
from ansible.utils.unsafe_proxy import wrap_var
try:
from __main__ import display
except ImportError:
@ -99,8 +99,7 @@ class AnsibleConstructor(SafeConstructor):
ciphertext_data = to_bytes(value)
if self._b_vault_password is None:
raise ConstructorError(None, None,
"found vault but no vault password provided", node.start_mark)
raise ConstructorError(None, None, "found vault but no vault password provided", node.start_mark)
# could pass in a key id here to choose the vault to associate with
vault = self._vaults['default']
@ -159,4 +158,5 @@ AnsibleConstructor.add_constructor(
AnsibleConstructor.add_constructor(
u'!vault',
AnsibleConstructor.construct_vault_encrypted_unicode)
AnsibleConstructor.add_constructor(u'!vault-encrypted', AnsibleConstructor.construct_vault_encrypted_unicode)

View file

@ -22,8 +22,7 @@ __metaclass__ = type
import yaml
from ansible.module_utils.six import PY3
from ansible.parsing.yaml.objects import AnsibleUnicode, AnsibleSequence, AnsibleMapping
from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
from ansible.parsing.yaml.objects import AnsibleUnicode, AnsibleSequence, AnsibleMapping, AnsibleVaultEncryptedUnicode
from ansible.utils.unsafe_proxy import AnsibleUnsafeText
from ansible.vars.hostvars import HostVars
@ -35,9 +34,11 @@ class AnsibleDumper(yaml.SafeDumper):
'''
pass
def represent_hostvars(self, data):
return self.represent_dict(dict(data))
# Note: only want to represent the encrypted data
def represent_vault_encrypted_unicode(self, data):
return self.represent_scalar(u'!vault', data._ciphertext.decode(), style='|')

View file

@ -682,17 +682,6 @@ lib/ansible/modules/utilities/logic/async_wrapper.py
lib/ansible/modules/utilities/logic/wait_for.py
lib/ansible/modules/web_infrastructure/ejabberd_user.py
lib/ansible/modules/web_infrastructure/jboss.py
lib/ansible/parsing/dataloader.py
lib/ansible/parsing/mod_args.py
lib/ansible/parsing/quoting.py
lib/ansible/parsing/splitter.py
lib/ansible/parsing/utils/__init__.py
lib/ansible/parsing/utils/addresses.py
lib/ansible/parsing/utils/jsonify.py
lib/ansible/parsing/vault/__init__.py
lib/ansible/parsing/yaml/__init__.py
lib/ansible/parsing/yaml/constructor.py
lib/ansible/parsing/yaml/dumper.py
lib/ansible/playbook/__init__.py
lib/ansible/playbook/attribute.py
lib/ansible/playbook/base.py