Commit ad2e69b5 authored by Victor Poughon's avatar Victor Poughon

DOC: add automatic internal links in app description

parent 4ea627a8
......@@ -22,6 +22,7 @@
import os
import sys
import argparse
import re
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
......@@ -355,7 +356,19 @@ def render_see_also(app):
else:
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"
app = otbApplication.Registry.CreateApplication(appname)
......@@ -368,9 +381,10 @@ def render_application(appname):
parameters = rst_parameters(app)
output = template_application.format(
label="app-" + appname,
heading=rst_section(app.GetName(), '='),
description=app.GetDescription(),
longdescription=app.GetDocLongDescription(),
longdescription=make_links(app.GetDocLongDescription(), allapps),
parameters=parameters,
examples_cli=render_all_examples_cli(app),
examples_python=render_all_examples_python(app),
......@@ -434,7 +448,7 @@ def GenerateRstForApplications(rst_dir):
# Write application rst
#print("Generating " + appName + ".rst" + " on tag " + tag)
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__":
parser = argparse.ArgumentParser(usage="Export application(s) to rst file")
......
Markdown is supported
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