From 82f1e25c268d3b166e34409c97e56f9620bedef9 Mon Sep 17 00:00:00 2001 From: "Dennis.Glaeser" <dennis.glaeser@iws.uni-stuttgart.de> Date: Mon, 30 Mar 2020 12:02:51 +0200 Subject: [PATCH] [docgen] use .json format for .doc_config --- examples/1ptracer/.doc_config | 18 +++++--- examples/2pinfiltration/.doc_config | 14 +++--- examples/freeflowchannel/.doc_config | 12 +++-- examples/generate_example_docs.py | 54 ++++++++++++----------- examples/shallowwaterfriction/.doc_config | 14 +++--- 5 files changed, 65 insertions(+), 47 deletions(-) diff --git a/examples/1ptracer/.doc_config b/examples/1ptracer/.doc_config index fd0ffdb7e1..028f23fcd6 100644 --- a/examples/1ptracer/.doc_config +++ b/examples/1ptracer/.doc_config @@ -1,7 +1,11 @@ -doc/intro.md -spatialparams_1p.hh -problem_1p.hh -spatialparams_tracer.hh -problem_tracer.hh -main.cc -doc/results.md +{ + "README.md" : [ + "doc/intro.md", + "spatialparams_1p.hh", + "problem_1p.hh", + "spatialparams_tracer.hh", + "problem_tracer.hh", + "main.cc", + "doc/results.md" + ] +} diff --git a/examples/2pinfiltration/.doc_config b/examples/2pinfiltration/.doc_config index fd1032cf16..bd7eeb8e44 100644 --- a/examples/2pinfiltration/.doc_config +++ b/examples/2pinfiltration/.doc_config @@ -1,5 +1,9 @@ -doc/intro.md -spatialparams.hh -problem.hh -main.cc -doc/results.md +{ + "README.md" : [ + "doc/intro.md", + "spatialparams.hh", + "problem.hh", + "main.cc", + "doc/results.md" + ] +} diff --git a/examples/freeflowchannel/.doc_config b/examples/freeflowchannel/.doc_config index cf97091424..09ab5781d7 100644 --- a/examples/freeflowchannel/.doc_config +++ b/examples/freeflowchannel/.doc_config @@ -1,4 +1,8 @@ -doc/intro.md -problem.hh -main.cc -doc/results.md +{ + "README.md" : [ + "doc/intro.md", + "problem.hh", + "main.cc", + "doc/results.md" + ] +} diff --git a/examples/generate_example_docs.py b/examples/generate_example_docs.py index 908f9b360c..c20f706be3 100755 --- a/examples/generate_example_docs.py +++ b/examples/generate_example_docs.py @@ -1,43 +1,45 @@ #!/usr/bin/env python3 import os +import json import argparse from convert_code_to_doc import * -def convertToMarkdownAndMerge(dir, includeList): - with open(os.path.join(dir, "README.md"), "w") as readme: - for include, description in includeList: - fileExtension = os.path.splitext(include)[1] - if fileExtension == ".md": - with open(os.path.join(dir, include), "r") as markdown: - readme.write(markdown.read()) - elif fileExtension == ".hh" or fileExtension == ".cc": - title = description + " (`{}`)\n\n\n" if description else "The file `{}`\n\n\n" - title = title.format(os.path.split(include)[1]) - readme.write("\n\n## " + title) - with open(os.path.join(dir, include), "r") as cppCode: - readme.write(transformCode(cppCode.read(), cppRules()) + "\n") - else: - raise IOError("Unsupported or unknown file extension *{}".format(fileExtension)) +def convertToMarkdownAndMerge(dir, config): + + for target, sources in config.items(): + + targetExtension = os.path.splitext(target)[1] + if not targetExtension == ".md": + raise IOError("Markdown files expected as targets! Given target: {}".format(target)) + + targetPath = os.path.join(dir, target) + os.makedirs(os.path.dirname(targetPath), exist_ok=True) + + with open(targetPath, "w") as targetFile: + for source in sources: + fileExtension = os.path.splitext(source)[1] + if fileExtension == ".md": + with open(os.path.join(dir, source), "r") as markdown: + targetFile.write(markdown.read()) + elif fileExtension == ".hh" or fileExtension == ".cc": + with open(os.path.join(dir, source), "r") as cppCode: + targetFile.write("\n\n" + transformCode(cppCode.read(), cppRules()) + "\n") + else: + raise IOError("Unsupported or unknown file extension *{}".format(fileExtension)) def generateReadme(dir): - includeList = None + config = None # look for .doc_config, if not found we pass try: configname = os.path.join(dir, ".doc_config") - with open(configname, 'r') as config: - def readline(line): - line = line.split(' ', 1) - if len(line) == 1: - return [line[0], ""] - else: - return [line[0], line[1]] - includeList = [readline(line) for line in config.read().splitlines()] + with open(configname, 'r') as configFile: + config = json.load(configFile) except FileNotFoundError: pass - if includeList is not None: - convertToMarkdownAndMerge(dir, includeList) + if config is not None: + convertToMarkdownAndMerge(dir, config) if __name__ == '__main__': parser = argparse.ArgumentParser() diff --git a/examples/shallowwaterfriction/.doc_config b/examples/shallowwaterfriction/.doc_config index fd1032cf16..bd7eeb8e44 100644 --- a/examples/shallowwaterfriction/.doc_config +++ b/examples/shallowwaterfriction/.doc_config @@ -1,5 +1,9 @@ -doc/intro.md -spatialparams.hh -problem.hh -main.cc -doc/results.md +{ + "README.md" : [ + "doc/intro.md", + "spatialparams.hh", + "problem.hh", + "main.cc", + "doc/results.md" + ] +} -- GitLab