Skip to content

Commit 3748cc8

Browse files
author
Bradley A. Thornton
committed
linting fixes
1 parent ad7e127 commit 3748cc8

File tree

23 files changed

+364
-220
lines changed

23 files changed

+364
-220
lines changed

models/myos/interfaces/myos_interfaces.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
GENERATOR_VERSION: '1.0'
33
ANSIBLE_METADATA: |
44
{
5-
'metadata_version': '1.1',
6-
'status': ['preview'],
7-
'supported_by': '<support_group>'
5+
'metadata_version': '1.1',
6+
'status': ['preview'],
7+
'supported_by': '<support_group>'
88
}
99
1010
NETWORK_OS: myos

roles/resource_module/filter_plugins/to_argspec.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Copyright (c) 2019 Ansible Project
2-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
2+
# GNU General Public License v3.0+
3+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
34

45
from __future__ import (absolute_import, division, print_function)
5-
__metaclass__ = type
6+
__metaclass__ = type # pylint: disable=C0103
67

7-
import yaml
88
import pprint
9+
import yaml
910

1011
from ansible.module_utils.six import iteritems
1112
from ansible.module_utils.six import string_types
1213
from ansible.utils.display import Display
1314
from ansible.errors import AnsibleFilterError
1415

1516
OPTIONS_METADATA = ('type', 'elements', 'default', 'choices', 'required')
16-
SUBOPTIONS_METADATA = ('mutually_exclusive', 'required_together', 'required_one_of', 'supports_check_mode', 'required_if')
17+
SUBOPTIONS_METADATA = ('mutually_exclusive', 'required_together',
18+
'required_one_of', 'supports_check_mode', 'required_if')
1719

1820
display = Display()
1921

@@ -27,24 +29,48 @@ def retrieve_metadata(values, out):
2729

2830

2931
def dive(obj, result):
30-
for k, v in iteritems(obj):
32+
for k, val in iteritems(obj):
3133
result[k] = dict()
32-
retrieve_metadata(v, result[k])
33-
suboptions = v.get('suboptions')
34+
retrieve_metadata(val, result[k])
35+
suboptions = val.get('suboptions')
3436
if suboptions:
3537
for item in SUBOPTIONS_METADATA:
36-
if item in v:
37-
result[k][item] = v[item]
38+
if item in val:
39+
result[k][item] = val[item]
3840
result[k]['options'] = dict()
3941
dive(suboptions, result[k]['options'])
4042

43+
def pretty(value, htchar='\t', lfchar='\n', indent=0):
44+
nlch = lfchar + htchar * (indent + 1)
45+
if type(value) is dict:
46+
items = [
47+
nlch + repr(key) + ': ' + pretty(value[key], htchar, lfchar, indent + 1)
48+
for key in value
49+
]
50+
return '{%s}' % (','.join(items) + lfchar + htchar * indent)
51+
elif type(value) is list:
52+
items = [
53+
nlch + pretty(item, htchar, lfchar, indent + 1)
54+
for item in value
55+
]
56+
return '[%s]' % (','.join(items) + lfchar + htchar * indent)
57+
elif type(value) is tuple:
58+
items = [
59+
nlch + pretty(item, htchar, lfchar, indent + 1)
60+
for item in value
61+
]
62+
return '(%s)' % (','.join(items) + lfchar + htchar * indent)
63+
else:
64+
return repr(value)
4165

4266
def to_argspec(spec):
4367
if 'DOCUMENTATION' not in spec:
44-
raise AnsibleFilterError("missing required element 'DOCUMENTATION' in model")
68+
raise AnsibleFilterError("missing required element 'DOCUMENTATION'"
69+
" in model")
4570

4671
if not isinstance(spec['DOCUMENTATION'], string_types):
47-
raise AnsibleFilterError("value of element 'DOCUMENTATION' should be of type string")
72+
raise AnsibleFilterError("value of element 'DOCUMENTATION'"
73+
" should be of type string")
4874
result = {}
4975
doc = yaml.safe_load(spec['DOCUMENTATION'])
5076

roles/resource_module/filter_plugins/to_doc.py

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import os
88
import shutil
9-
import json
109
from subprocess import Popen, PIPE
1110

1211
from copy import deepcopy
@@ -20,17 +19,23 @@
2019

2120
SECTIONS = ('ANSIBLE_METADATA', 'DOCUMENTATION', 'EXAMPLES', 'RETURN')
2221

23-
DOC_SECTION_SANITIZE = ('mutually_exclusive', 'required_together', 'required_one_of', 'supports_check_mode', 'required_if')
22+
DOC_SECTION_SANITIZE = ('mutually_exclusive', 'required_together',
23+
'required_one_of', 'supports_check_mode',
24+
'required_if')
2425

2526
DEFAULT_RETURN = """
2627
before:
2728
description: The configuration prior to the model invocation.
2829
returned: always
29-
sample: The configuration returned will always be in the same format of the parameters above.
30+
sample: >
31+
The configuration returned will always be in the same format
32+
of the parameters above.
3033
after:
3134
description: The resulting configuration model invocation.
3235
returned: when changed
33-
sample: The configuration returned will always be in the same format of the parameters above.
36+
sample: >
37+
The configuration returned will always be in the same format
38+
of the parameters above.
3439
commands:
3540
description: The set of commands pushed to the remote device.
3641
returned: always
@@ -47,8 +52,7 @@ def to_list(val):
4752
return list(val)
4853
elif val is not None:
4954
return [val]
50-
else:
51-
return list()
55+
return list()
5256

5357

5458
def add(line, spaces=0, newline=True):
@@ -59,27 +63,31 @@ def add(line, spaces=0, newline=True):
5963
output.write(line)
6064

6165

62-
def get_ansible_metadata(spec, path):
66+
def get_ansible_metadata(spec, _path):
6367
# write ansible metadata
6468
if 'ANSIBLE_METADATA' not in spec:
65-
raise AnsibleFilterError("missing required element 'ANSIBLE_METADATA' in model")
69+
raise AnsibleFilterError("missing required element 'ANSIBLE_METADATA'"
70+
" in model")
6671

6772
metadata = spec['ANSIBLE_METADATA']
6873
if not isinstance(metadata, string_types):
69-
raise AnsibleFilterError("value of element 'ANSIBLE_METADATA' should be of type string")
74+
raise AnsibleFilterError("value of element 'ANSIBLE_METADATA'"
75+
" should be of type string")
7076

7177
add('ANSIBLE_METADATA = %s' % metadata, newline=True)
72-
#add(metadata)
78+
# add(metadata)
7379

7480

75-
def get_documentation(spec, path):
81+
def get_documentation(spec, _path):
7682
# write documentation
7783
if 'DOCUMENTATION' not in spec:
78-
raise AnsibleFilterError("missing required element 'DOCUMENTATION' in model")
84+
raise AnsibleFilterError("missing required element 'DOCUMENTATION'"
85+
" in model")
7986

8087
doc = spec['DOCUMENTATION']
8188
if not isinstance(doc, string_types):
82-
raise AnsibleFilterError("value of element 'DOCUMENTATION' should be of type string")
89+
raise AnsibleFilterError("value of element 'DOCUMENTATION' should be"
90+
" of type string")
8391

8492
add('DOCUMENTATION = """')
8593
add('---')
@@ -90,22 +98,26 @@ def get_documentation(spec, path):
9098
def get_examples(spec, path):
9199
# write examples
92100
if 'EXAMPLES' not in spec:
93-
raise AnsibleFilterError("missing required element 'EXAMPLES' in model")
101+
raise AnsibleFilterError("missing required element 'EXAMPLES'"
102+
" in model")
94103

95104
add('EXAMPLES = """')
96105
dir_name = os.path.dirname(path)
97106
for item in to_list(spec['EXAMPLES']):
98-
with open(os.path.join(dir_name, item)) as fp:
99-
add(fp.read().strip("\n"))
107+
with open(os.path.join(dir_name, item)) as fileh:
108+
add(fileh.read().strip("\n"))
100109
add("\n")
101110
add('"""')
102111

103112

104-
def get_return(spec, path):
113+
def get_return(spec, _path):
105114
# write return
106115
ret = spec.get('RETURN')
107116
add('RETURN = """')
108-
add(ret) if ret else add(DEFAULT_RETURN.strip())
117+
if ret:
118+
add(ret)
119+
else:
120+
add(DEFAULT_RETURN.strip())
109121
add('"""')
110122

111123

@@ -114,28 +126,33 @@ def validate_model(model, contents):
114126
resource_module_dir = unfrackpath(RM_DIR_PATH)
115127
makedirs_safe(resource_module_dir)
116128
module_name = "%s_%s" % (model['NETWORK_OS'], model['RESOURCE'])
117-
module_file_path = os.path.join(RM_DIR_PATH, '%s.%s' % (module_name, 'py'))
118-
module_file_path = os.path.realpath(os.path.expanduser(module_file_path))
119-
with open(module_file_path, 'w+') as fp:
120-
fp.write(contents)
129+
module_file_path = os.path.join(RM_DIR_PATH, '%s.%s' % (module_name,
130+
'py'))
131+
exxpath = os.path.expanduser(module_file_path)
132+
module_file_path = os.path.realpath(exxpath)
133+
with open(module_file_path, 'w+') as fileh:
134+
fileh.write(contents)
121135

122136
display.debug("Module file: %s" % module_file_path)
123137

124138
# validate the model
125-
cmd = ["ansible-doc", "-M", os.path.dirname(module_file_path), module_name]
126-
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
127-
out, err = p.communicate()
139+
cmd = ["ansible-doc", "-M", os.path.dirname(module_file_path),
140+
module_name]
141+
proco = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
142+
out, err = proco.communicate()
128143
if err:
129144
raise AnsibleError("Error while parsing module: %s" % err)
130145
display.debug("Module output:\n%s" % out)
131-
except Exception as e:
132-
raise AnsibleError('Failed to validate the model with error: %s\n%s' % (e, contents))
146+
except Exception as err:
147+
raise AnsibleError('Failed to validate the model with error: %s\n%s'
148+
% (err, contents))
133149
finally:
134-
shutil.rmtree(os.path.realpath(os.path.expanduser(resource_module_dir)), ignore_errors=True)
150+
expuser = os.path.expanduser(resource_module_dir)
151+
shutil.rmtree(os.path.realpath(expuser), ignore_errors=True)
135152

136153

137154
def _sanitize_documentation(doc):
138-
sanitize_doc =[]
155+
sanitize_doc = []
139156
for line in doc.splitlines():
140157
for item in DOC_SECTION_SANITIZE:
141158
if line.strip().startswith(item):

roles/resource_module/templates/module_directory/network_os/network_os_facts.py.j2

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33
# {{ rm['COPYRIGHT'] }}
4-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
# GNU General Public License v3.0+
5+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
56
"""
67
The module file for {{ network_os }}_facts
78
"""
@@ -14,7 +15,7 @@ from {{ import_path }}. \
1415

1516
ANSIBLE_METADATA = {'metadata_version': '{{rm_ansible_metadata['metadata_version']}}',
1617
'status': {{rm_ansible_metadata['status']}},
17-
'supported_by': '{{rm_ansible_metadata['supported_by']}}',}
18+
'supported_by': '{{rm_ansible_metadata['supported_by']}}'}
1819

1920

2021
DOCUMENTATION = """
@@ -82,6 +83,7 @@ RETURN = """
8283
See the respective resource module parameters for the tree.
8384
"""
8485

86+
8587
def main():
8688
"""
8789
Main entry point for module execution
@@ -93,15 +95,17 @@ def main():
9395
warnings = ['default value for `gather_subset` \
9496
will be changed to `min` from `!config` v2.11 onwards']
9597

96-
connection = Connection(module._socket_path) #pylint: disable=W0212
98+
connection = Connection(module._socket_path) # pylint: disable=W0212
9799
gather_subset = module.params['gather_subset']
98100
gather_network_resources = module.params['gather_network_resources']
99-
result = Facts().get_facts(module, connection, gather_subset, gather_network_resources)
101+
result = Facts().get_facts(module, connection, gather_subset,
102+
gather_network_resources)
100103

101104
ansible_facts, additional_warnings = result
102105
warnings.extend(additional_warnings)
103106

104107
module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
105108

109+
106110
if __name__ == '__main__':
107111
main()

roles/resource_module/templates/module_directory/network_os/network_os_resource.py.j2

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33
# {{ rm['COPYRIGHT'] }}
4-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5-
6-
##############################################
7-
################# WARNING ####################
8-
##############################################
9-
###
10-
### This file is auto generated by the resource
11-
### module builder playbook.
12-
###
13-
### Do not edit this file manually.
14-
###
15-
### Changes to this file will be over written
16-
### by the resource module builder.
17-
###
18-
### Changes should be made in the model used to
19-
### generate this file or in the resource module
20-
### builder template.
21-
###
22-
##############################################
23-
##############################################
24-
##############################################
4+
# GNU General Public License v3.0+
5+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6+
7+
#############################################
8+
# WARNING #
9+
#############################################
10+
#
11+
# This file is auto generated by the resource
12+
# module builder playbook.
13+
#
14+
# Do not edit this file manually.
15+
#
16+
# Changes to this file will be over written
17+
# by the resource module builder.
18+
#
19+
# Changes should be made in the model used to
20+
# generate this file or in the resource module
21+
# builder template.
22+
#
23+
#############################################
2524

2625
"""
2726
The module file for {{ network_os }}_{{ resource }}
2827
"""
2928

3029
from __future__ import absolute_import, division, print_function
31-
__metaclass__ = type
30+
__metaclass__ = type # pylint: disable=C0103
3231

3332
{{ rm|to_doc(model) }}
33+
34+
# pylint: disable=C0413
3435
from ansible.module_utils.basic import AnsibleModule
3536
from {{ import_path }}. \
3637
{{ network_os }}.config.{{ resource }}.{{ resource }} import {{ resource|capitalize }}
38+
# pylint: enable=C0413
3739

3840

3941
def main():

roles/resource_module/templates/module_utils/network_os/argspec/facts/facts.py.j2

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33
# {{ rm['COPYRIGHT'] }}
4-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
# GNU General Public License v3.0+
5+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
56
"""
67
The arg spec for the {{ network_os }} facts module.
78
"""
89

9-
class FactsArgs(object): #pylint: disable=R0903
10+
11+
class FactsArgs(object): # pylint: disable=R0903
1012
""" The arg spec for the {{ network_os }} facts module
1113
"""
1214

@@ -20,5 +22,7 @@ class FactsArgs(object): #pylint: disable=R0903
2022

2123
argument_spec = {
2224
'gather_subset': dict(default=['!config'], type='list'),
23-
'gather_network_resources': dict(default=['all'], choices=choices, type='list'),
25+
'gather_network_resources': dict(default=['all'],
26+
choices=choices,
27+
type='list'),
2428
}

0 commit comments

Comments
 (0)