forked from networktocode/netutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
development_scripts.py
executable file
·242 lines (230 loc) · 8.44 KB
/
development_scripts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
"""Developer script to generate markdown tables."""
from jinja2 import Environment, BaseLoader, select_autoescape
from netutils.utils import _JINJA2_FUNCTION_MAPPINGS
from netutils import lib_mapper
from netutils.config.compliance import parser_map
LIB_MAPPER_TEMPLATE = """| {{ header_src }} | | {{ header_dst }} |
| ---------- | -- | ------ |
{%- for key, val in _dict|dictsort %}
| {{ key }} | → | {{ val }} |
{%- endfor %}
"""
PARSER_MAPPER_TEMPLATE = """| OS Name | Parser Class |
| ---------- | ------ |
{%- for key, val in _dict|dictsort %}
| {{ key }} | netutils.config.parser.{{ val.__name__ }} |
{%- endfor %}
"""
JINJA_MAPPER_TEMPLATE = """| Filter name | Function |
| ---------- | ------ |
{%- for key, val in _dict|dictsort(false, 'value') %}
| {{ key }} | netutils.{{ val }} |
{%- endfor %}
"""
TEMPLATE = {
"LIB_MAPPER_TEMPLATE": LIB_MAPPER_TEMPLATE,
"PARSER_MAPPER_TEMPLATE": PARSER_MAPPER_TEMPLATE,
"JINJA_MAPPER_TEMPLATE": JINJA_MAPPER_TEMPLATE,
}
MAPPER = {
"LIB_MAPPER_TEMPLATE": {
"aerleon": {
"header_src": "AERLEON",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.AERLEON_LIB_MAPPER,
"_file": "docs/user/lib_mapper/aerleon.md",
},
"aerleon_reverse": {
"header_src": "NORMALIZED",
"header_dst": "AERLEON",
"_dict": lib_mapper.AERLEON_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/aerleon_reverse.md",
},
"ansible": {
"header_src": "ANSIBLE",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.ANSIBLE_LIB_MAPPER,
"_file": "docs/user/lib_mapper/ansible.md",
},
"ansible_reverse": {
"header_src": "NORMALIZED",
"header_dst": "ANSIBLE",
"_dict": lib_mapper.ANSIBLE_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/ansible_reverse.md",
},
"capirca": {
"header_src": "CAPIRCA",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.CAPIRCA_LIB_MAPPER,
"_file": "docs/user/lib_mapper/capirca.md",
},
"capirca_reverse": {
"header_src": "NORMALIZED",
"header_dst": "CAPIRCA",
"_dict": lib_mapper.CAPIRCA_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/capirca_reverse.md",
},
"dna_center": {
"header_src": "DNA_CENTER",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.DNA_CENTER_LIB_MAPPER,
"_file": "docs/user/lib_mapper/dna_center.md",
},
"dna_center_reverse": {
"header_src": "NORMALIZED",
"header_dst": "DNA_CENTER",
"_dict": lib_mapper.DNA_CENTER_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/dna_center_reverse.md",
},
"forwardnetworks": {
"header_src": "FORWARDNETWORKS",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.FORWARDNETWORKS_LIB_MAPPER,
"_file": "docs/user/lib_mapper/forwardnetworks.md",
},
"forwardnetworks_reverse": {
"header_src": "NORMALIZED",
"header_dst": "FORWARDNETWORKS",
"_dict": lib_mapper.FORWARDNETWORKS_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/forwardnetworks_reverse.md",
},
"hierconfig": {
"header_src": "HIERCONFIG",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.HIERCONFIG_LIB_MAPPER,
"_file": "docs/user/lib_mapper/hierconfig.md",
},
"hierconfig_reverse": {
"header_src": "NORMALIZED",
"header_dst": "HIERCONFIG",
"_dict": lib_mapper.HIERCONFIG_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/hierconfig_reverse.md",
},
"napalm": {
"header_src": "NAPALM",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.NAPALM_LIB_MAPPER,
"_file": "docs/user/lib_mapper/napalm.md",
},
"napalm_reverse": {
"header_src": "NORMALIZED",
"header_dst": "NAPALM",
"_dict": lib_mapper.NAPALM_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/napalm_reverse.md",
},
"netmiko": {
"header_src": "NETMIKO",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.NETMIKO_LIB_MAPPER,
"_file": "docs/user/lib_mapper/netmiko.md",
},
"netmiko_reverse": {
"header_src": "NORMALIZED",
"header_dst": "NETMIKO",
"_dict": lib_mapper.NETMIKO_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/netmiko_reverse.md",
},
"netutilsparser": {
"header_src": "NETUTILSPARSER",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.NETUTILSPARSER_LIB_MAPPER,
"_file": "docs/user/lib_mapper/netutilsparser.md",
},
"netutilsparser_reverse": {
"header_src": "NORMALIZED",
"header_dst": "NETUTILSPARSER",
"_dict": lib_mapper.NETUTILSPARSER_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/netutilsparser_reverse.md",
},
"nist": {
"header_src": "NIST",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.NIST_LIB_MAPPER,
"_file": "docs/user/lib_mapper/nist.md",
},
"nist_reverse": {
"header_src": "NORMALIZED",
"header_dst": "NIST",
"_dict": lib_mapper.NIST_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/nist_reverse.md",
},
"ntctemplates": {
"header_src": "NTCTEMPLATES",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.NTCTEMPLATES_LIB_MAPPER,
"_file": "docs/user/lib_mapper/ntctemplates.md",
},
"ntctemplates_reverse": {
"header_src": "NORMALIZED",
"header_dst": "NTCTEMPLATES",
"_dict": lib_mapper.NTCTEMPLATES_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/ntctemplates_reverse.md",
},
"pyats": {
"header_src": "PYATS",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.PYATS_LIB_MAPPER,
"_file": "docs/user/lib_mapper/pyats.md",
},
"pyats_reverse": {
"header_src": "NORMALIZED",
"header_dst": "PYATS",
"_dict": lib_mapper.PYATS_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/pyats_reverse.md",
},
"pyntc": {
"header_src": "PYNTC",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.PYNTC_LIB_MAPPER,
"_file": "docs/user/lib_mapper/pyntc.md",
},
"pyntc_reverse": {
"header_src": "NORMALIZED",
"header_dst": "PYNTC",
"_dict": lib_mapper.PYNTC_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/pyntc_reverse.md",
},
"scrapli": {
"header_src": "SCRAPLI",
"header_dst": "NORMALIZED",
"_dict": lib_mapper.SCRAPLI_LIB_MAPPER,
"_file": "docs/user/lib_mapper/scrapli.md",
},
"scrapli_reverse": {
"header_src": "NORMALIZED",
"header_dst": "SCRAPLI",
"_dict": lib_mapper.SCRAPLI_LIB_MAPPER_REVERSE,
"_file": "docs/user/lib_mapper/scrapli_reverse.md",
},
},
"PARSER_MAPPER_TEMPLATE": {
"default": {
"_dict": parser_map,
"_file": "docs/dev/include_parser_list.md",
},
},
"JINJA_MAPPER_TEMPLATE": {
"default": {
"_dict": _JINJA2_FUNCTION_MAPPINGS,
"_file": "docs/user/include_jinja_list.md",
},
},
}
def main(test=False):
"""Generate or test generation of standard files."""
env = Environment(loader=BaseLoader, autoescape=select_autoescape())
for template_name, value in MAPPER.items():
for data in value.values():
_file = data["_file"]
output = env.from_string(TEMPLATE[template_name]).render(**data)
if test:
with open(_file, encoding="utf8") as file:
actual = file.read()
if output != actual:
return False
else:
with open(_file, "w", encoding="utf8") as file:
file.write(output)
return True
if __name__ == "__main__":
main()