Skip to content
Snippets Groups Projects
Commit bda015a9 authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

DOC: WIP: update cookbook generation

parent 7574eab8
Branches
Tags
No related merge requests found
......@@ -2,11 +2,20 @@
set(OUT_OF_SOURCE_BUILD FALSE)
if(NOT PROJECT_NAME)
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.0)
project(OTBCookBook)
set(OUT_OF_SOURCE_BUILD TRUE)
option(BUILD_TESTING "Build the testing tree." ON)
endif()
if(BUILD_TESTING)
enable_testing()
include(CTest)
endif()
string(TIMESTAMP OTB_COPYRIGHT_YEAR "%Y")
set(OTB_COPYRIGHT_TEXT "${OTB_COPYRIGHT_YEAR}, OTB Team")
#find OTB
find_package(OTB REQUIRED)
......@@ -27,125 +36,96 @@ message(STATUS "OTB_PYTHONPATH = '${OTB_PYTHONPATH}'")
message(STATUS "OTB_APPLICATION_PATH = '${OTB_APPLICATION_PATH}'")
message(STATUS "OTB_INSTALL_PREFIX = '${OTB_INSTALL_PREFIX}'")
#find Python
find_package(PythonInterp REQUIRED)
find_program(SH_INTERP sh)
if(NOT SH_INTERP)
message(FATAL_ERROR "'sh' program not found")
if(NOT OTB_PYTHONPATH)
message(FATAL_ERROR "OTB_PYTHONPATH empty")
endif()
find_program(SPHINX_BUILD sphinx-build)
if(NOT OTB_APPLICATION_PATH)
message(FATAL_ERROR "OTB_APPLICATION_PATH empty")
endif()
if(NOT SPHINX_BUILD)
message(FATAL_ERROR "The 'sphinx-build' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the 'sphinx-build' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org")
if(NOT OTB_INSTALL_PREFIX)
message(FATAL_ERROR "OTB_INSTALL_PREFIX empty")
endif()
string(TIMESTAMP OTB_COPYRIGHT_YEAR "%Y")
set(OTB_COPYRIGHT_TEXT "${OTB_COPYRIGHT_YEAR}, OTB Team")
#find Python
find_package(PythonInterp REQUIRED)
set(RST_GENERATED_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/rst)
find_program(SH_INTERP sh)
mark_as_advanced(SH_INTERP)
set(RST_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/_build")
set(RST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/rst)
find_program(LATEX_COMMAND NAMES latex)
mark_as_advanced(LATEX_COMMAND)
#make some directories
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_GENERATED_SOURCE_DIR}/Applications)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_GENERATED_SOURCE_DIR}/recipes)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_GENERATED_SOURCE_DIR}/Art)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_GENERATED_SOURCE_DIR}/Art/MonteverdiImages)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_GENERATED_SOURCE_DIR}/Art/ClassifImages)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_GENERATED_SOURCE_DIR}/Art/QtImages)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_GENERATED_SOURCE_DIR}/_static)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_GENERATED_SOURCE_DIR}/_templates)
find_program(TAR_COMMAND NAMES tar)
mark_as_advanced(TAR_COMMAND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/RunApplicationsRstGenerator.sh.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/RunApplicationsRstGenerator.sh
@ONLY)
find_program(SPHINX_BUILD NAMES sphinx-build)
mark_as_advanced(SPHINX_BUILD)
file(GLOB images ${CMAKE_CURRENT_SOURCE_DIR}/Art/*.*)
foreach(image ${images})
get_filename_component(out_file ${image} NAME)
configure_file(${image} ${RST_GENERATED_SOURCE_DIR}/Art/${out_file} COPYONLY)
endforeach()
find_program(PDFLATEX_COMMAND NAMES pdflatex )
mark_as_advanced(PDFLATEX_COMMAND)
file(GLOB mvd_images ${CMAKE_CURRENT_SOURCE_DIR}/Art/MonteverdiImages/*.*)
foreach(mvd_image ${mvd_images})
get_filename_component(out_file ${mvd_image} NAME)
configure_file(${mvd_image} ${RST_GENERATED_SOURCE_DIR}/Art/MonteverdiImages/${out_file} COPYONLY)
foreach(cmd LATEX_COMMAND TAR_COMMAND PDFLATEX_COMMAND SPHINX_BUILD SH_INTERP)
if(NOT ${cmd})
message(FATAL_ERROR "${cmd} not set. Cannot continue")
endif()
endforeach()
file(GLOB classif_images ${CMAKE_CURRENT_SOURCE_DIR}/Art/ClassifImages/*.*)
foreach(classif_image ${classif_images})
get_filename_component(out_file ${classif_image} NAME)
configure_file(${classif_image} ${RST_GENERATED_SOURCE_DIR}/Art/ClassifImages/${out_file} COPYONLY)
endforeach()
set(RST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rst)
file(GLOB qt_images ${CMAKE_CURRENT_SOURCE_DIR}/Art/QtImages/*.png)
foreach(qt_image ${qt_images})
get_filename_component(out_file ${qt_image} NAME)
configure_file(${qt_image} ${RST_GENERATED_SOURCE_DIR}/Art/QtImages/${out_file} COPYONLY)
endforeach()
set(RST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/rst)
set(LATEX_DIR ${CMAKE_CURRENT_BINARY_DIR}/latex)
set(HTML_DIR ${CMAKE_CURRENT_BINARY_DIR}/html)
file(GLOB sar_images ${CMAKE_CURRENT_SOURCE_DIR}/Art/SARImages/*.png)
foreach(sar_image ${sar_images})
get_filename_component(out_file ${sar_image} NAME)
configure_file(${sar_image} ${RST_GENERATED_SOURCE_DIR}/Art/SARImages/${out_file} COPYONLY)
endforeach()
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${RST_BINARY_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_BINARY_DIR})
file(GLOB rst_sources1 ${RST_SOURCES}/*.rst)
foreach(rst_file ${rst_sources1})
get_filename_component(out_file ${rst_file} NAME)
configure_file(${rst_file} ${RST_GENERATED_SOURCE_DIR}/${out_file} COPYONLY)
endforeach()
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${HTML_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${HTML_DIR})
file(GLOB rst_sources2 ${RST_SOURCES}/recipes/*.rst)
foreach(rst_file ${rst_sources2})
get_filename_component(out_file ${rst_file} NAME)
configure_file(${rst_file} ${RST_GENERATED_SOURCE_DIR}/recipes/${out_file} COPYONLY)
endforeach()
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${LATEX_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${LATEX_DIR})
file(GLOB rst_sources3 ${RST_SOURCES}/Applications/*.rst)
foreach(rst_file ${rst_sources3})
get_filename_component(out_file ${rst_file} NAME)
configure_file(${rst_file} ${RST_GENERATED_SOURCE_DIR}/Applications/${out_file} COPYONLY)
endforeach()
execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/RunApplicationsRstGenerator.sh)
file(GLOB rst_sources4 ${RST_SOURCES}/*.txt)
foreach(rst_file ${rst_sources4})
get_filename_component(out_file ${rst_file} NAME)
configure_file(${rst_file} ${RST_GENERATED_SOURCE_DIR}/${out_file} COPYONLY)
endforeach()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/RunApplicationsRstGenerator.sh.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/RunApplicationsRstGenerator.sh
@ONLY)
configure_file(${RST_SOURCES}/conf.py.in ${RST_GENERATED_SOURCE_DIR}/conf.py @ONLY)
configure_file(${RST_SOURCES}/Makefile.in ${RST_GENERATED_SOURCE_DIR}/Makefile @ONLY)
file(COPY ${RST_SOURCE_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
find_program(LATEX_COMMAND NAMES latex)
mark_as_advanced(LATEX_COMMAND)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Art DESTINATION ${RST_BINARY_DIR})
find_program(TAR_COMMAND NAMES tar)
mark_as_advanced(TAR_COMMAND)
set(SPHINX_CONF_DIR ${CMAKE_CURRENT_BINARY_DIR})
find_program(PDFLATEX_COMMAND NAMES pdflatex )
mark_as_advanced(PDFLATEX_COMMAND)
configure_file(${RST_SOURCE_DIR}/conf.py.in ${SPHINX_CONF_DIR}/conf.py @ONLY)
foreach(cmd LATEX_COMMAND TAR_COMMAND PDFLATEX_COMMAND)
if(NOT ${cmd})
message(FATAL_ERROR "${cmd} not set. Cannot continue")
endif()
endforeach()
#configure_file(${RST_SOURCE_DIR}/Makefile.in ${RST_GENERATED_SOURCE_DIR}/Makefile.sphinx @ONLY)
# Internal variables.
# PAPEROPT_a4 = -D latex_paper_size=a4
# PAPEROPT_letter = -D latex_paper_size=letter
# ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# # the i18n builder cannot share the environment and doctrees with the others
# I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
add_custom_target(generate_otbapps_rst
ALL
COMMAND ${SH_INTERP} ${CMAKE_CURRENT_BINARY_DIR}/RunApplicationsRstGenerator.sh
WORKING_DIRECTORY ${RST_GENERATED_SOURCE_DIR}
WORKING_DIRECTORY ${RST_BINARY_DIR}
COMMENT "Auto-generating Application Reference Documentation in RST"
)
add_custom_target(CookBookHTMLFromRST
add_custom_target(CookBookHTML
ALL
COMMAND ${CMAKE_MAKE_PROGRAM} html
WORKING_DIRECTORY ${RST_GENERATED_SOURCE_DIR}
COMMAND ${SPHINX_BUILD}
-b html
${RST_BINARY_DIR}
${HTML_DIR}
-W
-v
-c ${SPHINX_CONF_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS generate_otbapps_rst
COMMENT "Building RST documentation in html")
......@@ -155,14 +135,26 @@ add_custom_target(CookBookArchive
--transform "s/^html/CookBook-${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR}/"
-czf ${CMAKE_BINARY_DIR}/CookBook-${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR}-html.tar.gz html
WORKING_DIRECTORY ${RST_BUILD_DIR}
DEPENDS CookBookHTMLFromRST
DEPENDS CookBookHTML
COMMENT "Creating archive for html CookBook")
add_custom_target(CookBookPDFFromRST
ALL
COMMAND ${CMAKE_MAKE_PROGRAM} latexpdf
WORKING_DIRECTORY ${RST_GENERATED_SOURCE_DIR}
DEPENDS generate_otbapps_rst
COMMENT "Building RST documentation in pdf")
add_custom_target(CookBookTexFromRST
ALL
COMMAND ${SPHINX_BUILD}
-b latex
${RST_BINARY_DIR}
${LATEX_DIR}
-W
-v
-c ${SPHINX_CONF_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS generate_otbapps_rst
COMMENT "Generating Tex files from rst"
VERBATIM)
add_custom_target(CookBookPDF
ALL
COMMAND ${CMAKE_MAKE_PROGRAM} all-pdf
WORKING_DIRECTORY ${LATEX_DIR}
DEPENDS CookBookTexFromRST
COMMENT "Building RST documentation in pdf")
......@@ -430,7 +430,11 @@ def RstHeading(text, delimiter):
def ApplicationToRst(appname):
output = ""
app = otbApplication.Registry.CreateApplication(appname)
app = None
try:
app = otbApplication.Registry.CreateApplication(appname)
except e:
print e
# TODO: remove this when bug 440 is fixed
app.Init()
output += RstHeading(app.GetDocName(), '^')
......@@ -496,56 +500,79 @@ def RstPageHeading(text):
def GenerateRstForApplications():
out = ""
blackList = ["TestApplication", "Example"]
blackList = ["TestApplication", "Example", "ApplicationExample"]
appIndexFile = open('Applications.rst', 'w')
appNames = [app for app in otbApplication.Registry.GetAvailableApplications() if app not in blackList]
if not appNames:
print 'No OTB applications available. Please check ITK_AUTOLOAD_PATH env variable'
sys.exit(1)
sectionTags = ["Image Manipulation","Vector Data Manipulation", "Calibration","Geometry", "Image Filtering","Feature Extraction","Stereo","Learning","Segmentation"]
allApps = None
try:
allApps = otbApplication.Registry.GetAvailableApplications( )
except e:
print 'error in otbApplication.Registry.GetAvailableApplications()'
sys.exit(1)
# appNames = [app for app in otbApplication.Registry.GetAvailableApplications() if app not in blackList]
if not allApps:
print 'No OTB applications available. Please check OTB_APPLICATION_PATH env variable'
sys.exit(1)
sectionTags = ["Image Manipulation",
"Vector Data Manipulation",
"Calibration","Geometry", "Image Filtering","Feature Extraction",
"Stereo","Learning","Segmentation", "Miscellaneous"]
appIndexFile.write(RstPageHeading("Applications"))
for tag in sectionTags:
directory= "Applications/" + tag
if not os.path.exists(directory):
os.makedirs(directory)
tag_ = tag.replace(' ', '_')
appIndexFile.write('\tApplications/' + tag_ + '.rst' + linesep)
#directory= "Applications/" + tag
# if not os.path.exists(directory):
# os.makedirs(directory)
appIndexFile.write('\tApplications/' + tag.replace(' ', '_') + '.rst' + linesep)
#chapterIndexFile = open('Applications/' + tag + '.rst', 'w')
#chapterIndexFile.write(RstPageHeading(tag))
#print linesep + RstHeading(tag, '=')
appsRemoved = []
for appName in appNames:
apptags = GetApplicationTags(appName)
if apptags.count(tag) > 0:
print "Generating " + appName + ".rst"
#chapterIndexFile.write("\t" + tag + '/' + appName + linesep)
appFile = open('Applications/app_' + appName + '.rst', 'w')
out = ApplicationToRst(appName)
appFile.write(out)
appFile.close()
appsRemoved.append(appName)
for appName in appsRemoved:
appNames.remove(appName)
#chapterIndexFile.close()
misctag = "Miscellaneous" #should this be Utilities
if not os.path.exists("Applications/" + misctag):
os.makedirs("Applications/" + misctag)
appIndexFile.write('\tApplications/' + misctag + linesep)
# misctag = "Miscellaneous" #should this be Utilities
# if not os.path.exists("Applications/" + misctag):
# os.makedirs("Applications/" + misctag)
# appIndexFile.write('\tApplications/' + misctag + linesep)
appIndexFile.close()
#miscChapterIndexFile = open("Applications/" + misctag + '.rst', 'w')
#miscChapterIndexFile.write(RstPageHeading(misctag))
#appsRemoved = []
appNames = [app for app in allApps if app not in blackList]
print "All apps: %s" % (appNames,)
for appName in appNames:
apptags = GetApplicationTags(appName)
# if apptags.count(tag) > 0:
print "Generating " + appName + ".rst"
appFile = open("Applications/app_" + appName + ".rst", 'w')
#chapterIndexFile.write("\t" + tag + '/' + appName + linesep)
appFile = open('Applications/app_' + appName + '.rst', 'w')
out = ApplicationToRst(appName)
appFile.write(out)
appFile.close()
#miscChapterIndexFile.write('\t' + misctag + '/' + appName + linesep)
out = ""
#appsRemoved.append(appName)
# for appName in appsRemoved:
# appNames.remove(appName)
#chapterIndexFile.close()
#miscChapterIndexFile = open("Applications/" + misctag + '.rst', 'w')
#miscChapterIndexFile.write(RstPageHeading(misctag))
# for appName in appNames:
# print "Generating " + appName + ".rst"
# appFile = open("Applications/app_" + appName + ".rst", 'w')
# out = ApplicationToRst(appName)
# appFile.write(out)
# appFile.close()
# #miscChapterIndexFile.write('\t' + misctag + '/' + appName + linesep)
# out = ""
return out
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment