forked from nautobot/nornir-nautobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_troubleshooting_docs.py
More file actions
executable file
·36 lines (27 loc) · 1.34 KB
/
Copy pathget_troubleshooting_docs.py
File metadata and controls
executable file
·36 lines (27 loc) · 1.34 KB
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
"""Generate troubleshooting documentation for each error code."""
import os
from jinja2 import Environment, FileSystemLoader
from nornir_nautobot.constants import ERROR_CODES
def generate_files_from_template(template_file):
"""
Generates files from a Jinja2 template in the same directory as the script.
Args:
template_file (str): Name of the Jinja2 template file.
output_dir (str): Path to the directory where the output files will be saved.
data (dict): Data to be passed to the template.
num_files (int, optional): Number of files to generate. Defaults to 1.
"""
data = {}
template_dir = os.path.dirname(os.path.abspath(__file__))
env = Environment(loader=FileSystemLoader(template_dir), autoescape=True)
template = env.get_template(template_file)
for error_code, error in ERROR_CODES.items():
data["error_code"] = error_code
data["error"] = error
output_filename = f"{error_code}.md" # Customize the filename as needed
output_filepath = os.path.join(template_dir, "docs", "user", "troubleshooting", output_filename)
output_content = template.render(data)
with open(output_filepath, "w", encoding="utf-8") as doc_file:
doc_file.write(output_content)
if __name__ == "__main__":
generate_files_from_template("error_code_template.j2")