Skip to content
Snippets Groups Projects
Commit ad2e69b5 authored by Victor Poughon's avatar Victor Poughon
Browse files

DOC: add automatic internal links in app description

parent 4ea627a8
No related branches found
No related tags found
2 merge requests!621Release 7.0 (master),!316Christmas CookBook
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
import os import os
import sys import sys
import argparse import argparse
import re
import otbApplication import otbApplication
from otbApplication import ParameterType_Bool, ParameterType_Int, ParameterType_Radius, ParameterType_RAM, ParameterType_Float, ParameterType_String, ParameterType_StringList, ParameterType_InputFilename, ParameterType_OutputFilename, ParameterType_InputImage, ParameterType_ComplexInputImage, ParameterType_OutputImage, ParameterType_ComplexOutputImage, ParameterType_InputVectorData, ParameterType_OutputVectorData, ParameterType_Directory, ParameterType_Choice, ParameterType_InputImageList, ParameterType_InputVectorDataList, ParameterType_InputFilenameList, ParameterType_InputProcessXML, ParameterType_OutputProcessXML, ParameterType_ListView, ParameterType_Group from otbApplication import ParameterType_Bool, ParameterType_Int, ParameterType_Radius, ParameterType_RAM, ParameterType_Float, ParameterType_String, ParameterType_StringList, ParameterType_InputFilename, ParameterType_OutputFilename, ParameterType_InputImage, ParameterType_ComplexInputImage, ParameterType_OutputImage, ParameterType_ComplexOutputImage, ParameterType_InputVectorData, ParameterType_OutputVectorData, ParameterType_Directory, ParameterType_Choice, ParameterType_InputImageList, ParameterType_InputVectorDataList, ParameterType_InputFilenameList, ParameterType_InputProcessXML, ParameterType_OutputProcessXML, ParameterType_ListView, ParameterType_Group
...@@ -355,7 +356,19 @@ def render_see_also(app): ...@@ -355,7 +356,19 @@ def render_see_also(app):
else: else:
return rst_section("See also", "-") + see_also return rst_section("See also", "-") + see_also
def render_application(appname): def multireplace(string, replacements):
"multiple string replace (from https://stackoverflow.com/a/6117124/5815110)"
substrs = sorted(replacements, key=len, reverse=True)
regexp = re.compile('|'.join(map(re.escape, substrs)))
return regexp.sub(lambda match: replacements[match.group(0)], string)
def make_links(text, allapps):
"Replace name of applications by internal rst links"
rep = {appname: ":ref:`{}`".format("app-" + appname) for appname in allapps}
return multireplace(text, rep)
def render_application(appname, allapps):
"Render app to rst" "Render app to rst"
app = otbApplication.Registry.CreateApplication(appname) app = otbApplication.Registry.CreateApplication(appname)
...@@ -368,9 +381,10 @@ def render_application(appname): ...@@ -368,9 +381,10 @@ def render_application(appname):
parameters = rst_parameters(app) parameters = rst_parameters(app)
output = template_application.format( output = template_application.format(
label="app-" + appname,
heading=rst_section(app.GetName(), '='), heading=rst_section(app.GetName(), '='),
description=app.GetDescription(), description=app.GetDescription(),
longdescription=app.GetDocLongDescription(), longdescription=make_links(app.GetDocLongDescription(), allapps),
parameters=parameters, parameters=parameters,
examples_cli=render_all_examples_cli(app), examples_cli=render_all_examples_cli(app),
examples_python=render_all_examples_python(app), examples_python=render_all_examples_python(app),
...@@ -434,7 +448,7 @@ def GenerateRstForApplications(rst_dir): ...@@ -434,7 +448,7 @@ def GenerateRstForApplications(rst_dir):
# Write application rst # Write application rst
#print("Generating " + appName + ".rst" + " on tag " + tag) #print("Generating " + appName + ".rst" + " on tag " + tag)
with open(rst_dir + '/Applications/app_' + appName + '.rst', 'w') as appFile: with open(rst_dir + '/Applications/app_' + appName + '.rst', 'w') as appFile:
appFile.write(render_application(appName)) appFile.write(render_application(appName, appNames))
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(usage="Export application(s) to rst file") parser = argparse.ArgumentParser(usage="Export application(s) to rst file")
......
.. _{label}:
{heading} {heading}
{description} {description}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment