Files
AI-on-the-edge-device-docs/generate-param-docs/generate-param-doc-pages.py
CaCO3 db2a3482df Auto gen parameter doc (#14)
* added script to generate parameter documentation

* extended readme

* added templated parameter pages

* Update build-docs.yaml

* .

* .

---------

Co-authored-by: CaCO3 <caco@ruinelli.ch>
2023-02-04 00:39:20 +01:00

69 lines
2.2 KiB
Python

"""
For each parameter which can be found in the config file,
create a markdown file with a templated contentf it does not exist yet.
The files are grouped in sub folders representing the config sections.
"""
import os
import configparser
import urllib.request
configFileUrl = "https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/rolling/sd-card/config/config.ini"
parameterDocsFolder = "parameter-docs"
parameterTemplateFile = "./templates/parameter.md"
# Fetch default config file from URL
with urllib.request.urlopen(configFileUrl) as response:
content = response.read().decode("utf-8")
lines = str(content).split("\n")
for l in range(len(lines)):
lines[l] = lines[l].strip() + "\n"
if lines[l][0] == ";":
lines[l] = lines[l][1:] # Remove comment
content = "".join(lines)
config = configparser.ConfigParser(allow_no_value=True)
config.optionxform = str # Make it case-insensitive
config.read_string(content)
#shutil.rmtree(parameterDocsFolder)
if not os.path.exists(parameterDocsFolder):
os.mkdir(parameterDocsFolder)
with open(parameterTemplateFile, 'r') as parameterTemplateFileHandle:
parameterTemplate = parameterTemplateFileHandle.read()
for section in config:
if section != "DEFAULT":
#print(section)
subFolder = parameterDocsFolder + "/" + section
if not os.path.exists(subFolder):
os.mkdir(subFolder)
for parameter in config[section]:
if not " " in parameter: # Ignore parameters with whitespaces in them (special format, not part of editable config)
value = config[section][parameter]
#print(" %s = %s" % (parameter, value))
"""
For each config line, create a markdown file
"""
parameterDocFile = subFolder + '/' + parameter + ".md"
if not os.path.exists(parameterDocFile): # File does not exist yet, generate template
with open(parameterDocFile, 'w') as paramFileHandle:
content = parameterTemplate
content = content.replace("$NAME", parameter)
content = content.replace("$DEFAULT", value)
paramFileHandle.write(content)