Commit cf60e1d3 authored by Timo Koch's avatar Timo Koch
Browse files

[examples] Add Python script generating the example docs

parent bad64107
#!/usr/bin/env python3
import os
import argparse
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--directory", help="The folder to look for examples", default=".")
parser.add_argument("-m", "--markdowngenerator", help="The markdown generator script taking a list of files", default="../bin/doc/")
args = vars(parser.parse_args())
def convertToMarkdownAndMerge(dir, includeList):
script = os.path.join(os.path.abspath(args["markdowngenerator"]))
with open(os.path.join(dir, ""), "w") as readme:
for include in includeList:
if os.path.splitext(include)[1] == ".md":
with open(include, "r") as markdown:
readme.write("\n\n## The file `{}`\n\n".format(os.path.split(include)[1]))
markdown = subprocess.check_output(["bash", script, include], encoding="utf-8")
readme.write(markdown + "\n")
def generateReadme(dir):
includeList = None
configname = os.path.join(dir, ".doc_config")
with open(configname, 'r') as config:
includeList = [os.path.join(dir, include) for include in]
except FileNotFoundError:
print("Error: The example directory {} does not contain a .doc_config file! Could not generate!".format(dir))
if includeList is not None:
convertToMarkdownAndMerge(dir, includeList)
for path in os.listdir(args["directory"]):
abspath = os.path.join(os.path.abspath(args["directory"]), path)
if os.path.isdir(abspath):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment