moved files

This commit is contained in:
CaCO3
2023-02-04 00:53:04 +01:00
parent b90fe4cc98
commit cb78ef07f6
75 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
"""
Grab all parameter files and concat them into a single file.
The header structure gets moved down 1 level
"""
import os
import shutil
import glob
parameterDocsFolder = "parameter-pages"
parameterOverviewFile = "../docs/Parameters.md"
parameterOverviewTemplateFile = "./templates/overview.md"
def appendParameterFile(folder, file):
print(folder, file)
with open(file, 'r') as parameterFileHandle:
parameterDoc = parameterFileHandle.read()
parameterDoc = parameterDoc.replace("# ", "### ") # Move all headings 2 level down
# Add parameter doc to overview page
with open(parameterOverviewFile, 'a') as overviewFileHandle:
overviewFileHandle.write(parameterDoc + "\n---\n\n")
# Create templated overview markdown file
if os.path.exists(parameterOverviewFile):
os.remove(parameterOverviewFile)
shutil.copy(parameterOverviewTemplateFile, parameterOverviewFile)
"""
Append all parameter pages in a sorted manner
"""
folders = sorted( filter( os.path.isdir, glob.glob(parameterDocsFolder + '/*') ) )
for folder in folders:
folder = folder.split("/")[-1]
# print(folder)
# Add section
with open(parameterOverviewFile, 'a') as overviewFileHandle:
overviewFileHandle.write("\n## [%s]\n\n" % folder)
files = sorted(filter(os.path.isfile, glob.glob(parameterDocsFolder + "/" + folder + '/*')))
for file in files:
# print(" %s" % file)
appendParameterFile(folder, file)

View File

@@ -0,0 +1,68 @@
"""
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-pages"
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)