def render_application(appname, allapps): "Render app to rst" # Create the application without logger to avoid the deprecation warning log app = otbApplication.Registry.CreateApplicationWithoutLogger(appname) # TODO: remove this when bug 440 is fixed app.Init() application_documentation_warnings(app) output = template_application.format( label=appname, deprecation_string=render_deprecation_string(app), multiwriting_string=render_multiwriting_string(app), heading=rst_section(app.GetName(), '='), description=app.GetDescription(), longdescription=make_links(app.GetDocLongDescription(), allapps), parameters=render_parameters(app), examples_cli=render_all_examples_cli(app), examples_python=render_all_examples_python(app), limitations=render_limitations(app), see_also=make_links(render_see_also(app), allapps)) return output
def render_limitations(app): "Render app DocLimitations to rst" limitations = app.GetDocLimitations() if limitations is None or len(limitations) == 0 or limitations == "None": return "" else: return rst_section("Limitations", "-") + limitations
def render_see_also(app): "Render app See Also to rst" see_also = app.GetDocSeeAlso() if see_also is None or len(see_also) < 2: return "" else: return rst_section("See also", "-") + "| " + see_also.replace( "\n", "\n| ") # use line blocks for see also
def render_parameters(app): "Render application parameters to rst" output = "" fake_markers = detect_abuse(app) previous_level = 1 for key in app.GetParametersKeys(): type = app.GetParameterType(key) # If reducing level not on a group parameter, render a horizontal line current_level = 1 + key.count(".") if current_level < previous_level and type != ParameterType_Group: output += "\n\n------------\n\n" previous_level = current_level # Choice parameter values can act as groups # Detect that case to add a section title if key in fake_markers: output += rst_section( app.GetParameterName(fake_markers[key]) + " options", "^") if type == ParameterType_Group: output += template_parameter_group.format( name=rst_section(app.GetParameterName(key), "^"), description=app.GetParameterDescription(key)) elif type == ParameterType_Choice: output += render_choice(app, key) else: output += template_parameter.format( name=app.GetParameterName(key), key=key, value=rst_parameter_value(app, key), description=app.GetParameterDescription(key), flags=rst_parameter_flags(app, key), ) return output
def render_example(filename, otb_root): "Render a cxx example to rst" # Read the source code of the cxx example code = open(join(otb_root, filename)).read() # Don't show the license header to make it nicer, # and the cookbook is already under a CC license examples_license_header = open( "templates/examples_license_header.txt").read() code = code.replace(examples_license_header, "") # Extract usages example_usage = "" usage_matches = list( re.finditer(examples_usage_regex, code, flags=re.MULTILINE | re.DOTALL)) examples_usage_template = open("templates/example_usage.rst").read() for match in usage_matches: example_usage += examples_usage_template.format( indent(match.group(1).strip())) # Don't show usage in example source code = re.sub(examples_usage_regex, "", code, flags=re.MULTILINE | re.DOTALL) # Make the link to the source code link_name = os.path.basename(filename) link_href = "https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/raw/develop/" + filename + "?inline=false" # Read the description from the example .rst file if it exists example_rst_file = join(otb_root, filename.replace(".cxx", ".rst")) if os.path.isfile(example_rst_file): rst_description = open(example_rst_file).read() else: rst_description = "" # Render the template name = os.path.basename(filename) template_example = open("templates/example.rst").read() output_rst = template_example.format(label=name, heading=rst_section(name, "="), description=rst_description, usage=example_usage, code=indent(code.strip()), link_name=link_name, link_href=link_href) return output_rst