From 185c16260479b74f5a553c08f4fa449d7895964e Mon Sep 17 00:00:00 2001
From: Abdussalam SALEH MGHIR <salehma@visu04.sis.cnes.fr>
Date: Thu, 7 Oct 2021 08:13:54 +0000
Subject: [PATCH] ENH : Update creation of the wiki

---
 .gitignore                        |  1 +
 doc_cookbook/README.md            |  8 ++++++-
 doc_cookbook/script_doc_sphinx.sh | 37 +++++++++++++++++++++----------
 3 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore
index bbcab77..9c9c0ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@
 *.pyc
 .\#*
 \#*\#
+/doc_cookbook/rst_tmp/*
diff --git a/doc_cookbook/README.md b/doc_cookbook/README.md
index 82bb6b4..0d5dca1 100644
--- a/doc_cookbook/README.md
+++ b/doc_cookbook/README.md
@@ -22,10 +22,16 @@ cd <diapotb_root_path>/doc_cookbook
 ```
 <diapotb_root_path> : root path of the repository diapotb 
 
+- The temporary repertory used to store all the source files is created:
+```shell
+mkdir -p rst_tmp
+cp -R rst/* rst_tmp
+```
+
 - Then, the rst files are generated:
 
 ```shell
-python otbGenerateWrappersRstDoc.py rst
+python otbGenerateWrappersRstDoc.py rst_tmp
 ```
 
 3. The new wiki is generated:
diff --git a/doc_cookbook/script_doc_sphinx.sh b/doc_cookbook/script_doc_sphinx.sh
index 7e32e8f..0f82778 100755
--- a/doc_cookbook/script_doc_sphinx.sh
+++ b/doc_cookbook/script_doc_sphinx.sh
@@ -1,28 +1,41 @@
+#!/bin/bash
 # Output Path where the wiki for the diapotb will be generated
 wiki_output_path=$1
+#check number of arguments
+if [[ $# -ne 1 ]]
+then
+    echo "Illegal number of parameters" >&2
+    exit 2
+fi
+
+# Path directory of the current script
+path_dir=$(dirname $0)
 # Creation if non existant of the repository used to generate the wiki
-mkdir -p rst_tmp
+mkdir -p $path_dir/rst_tmp
 # Copy of the C++ source files and the static files to the temporary repository from which will be generated the wiki
-cp -R rst/* rst_tmp
+cp -R $path_dir/rst/* $path_dir/rst_tmp
 # Generate the source files for the python scripts of the processing chains 
-sphinx-apidoc -f -o ./rst_API_Python/ ../python_src/
+sphinx-apidoc -f -o $path_dir/rst_API_Python/ $path_dir/../python_src/
 # Copy of the interesting source files to rst_tmp
 # Deletion of some lines uninteresting inside utils.rst
-line_submodule_utils_start=$(grep -wn 'Submodules' ./rst_API_Python/utils.rst | cut -d: -f1)
+line_submodule_utils_start=$(grep -wn 'Submodules' $path_dir/rst_API_Python/utils.rst | cut -d: -f1)
 line_submodule_utils_end=$(($line_submodule_utils_start + 1))
-line_modcont_utils_start=$(grep -wn 'Module contents' ./rst_API_Python/utils.rst | cut -d: -f1)
+line_modcont_utils_start=$(grep -wn 'Module contents' $path_dir/rst_API_Python/utils.rst | cut -d: -f1)
 line_modcont_utils_end=$(($line_modcont_utils_start + 6))
 # Copy of the modified utils.rst to rst_tmp
-sed "${line_submodule_utils_start},${line_submodule_utils_end}d;${line_modcont_utils_start},${line_modcont_utils_end}d" rst_API_Python/utils.rst > rst_tmp/PythonAPI/utils.rst
+sed "${line_submodule_utils_start},${line_submodule_utils_end}d;${line_modcont_utils_start},${line_modcont_utils_end}d" $path_dir/rst_API_Python/utils.rst > $path_dir/rst_tmp/PythonAPI/utils.rst
 
 # Deletion of some lines uninteresting inside processings.rst
-line_submodule_processing_start=$(grep -wn 'Submodules' ./rst_API_Python/processings.rst | cut -d: -f1)
+line_submodule_processing_start=$(grep -wn 'Submodules' $path_dir/rst_API_Python/processings.rst | cut -d: -f1)
 line_submodule_processing_end=$(($line_submodule_processing_start + 1))
-line_modcont_processing_start=$(grep -wn 'Module contents' ./rst_API_Python/processings.rst | cut -d: -f1)
+line_modcont_processing_start=$(grep -wn 'Module contents' $path_dir/rst_API_Python/processings.rst | cut -d: -f1)
 line_modcont_processing_end=$(($line_modcont_processing_start + 6))
 # Copy of the modified processings.rst to rst_tmp
-sed "${line_submodule_processing_start},${line_submodule_processing_end}d;${line_modcont_processing_start},${line_modcont_processing_end}d" rst_API_Python/processings.rst > rst_tmp/PythonAPI/processings.rst
+sed "${line_submodule_processing_start},${line_submodule_processing_end}d;${line_modcont_processing_start},${line_modcont_processing_end}d" $path_dir/rst_API_Python/processings.rst > $path_dir/rst_tmp/PythonAPI/processings.rst
 # Generate the wiki repository from the source repository
-sphinx-build -M markdown ./rst_tmp/ $wiki_output_path/diapotb_wiki/ -c .
-#sphinx-build -b html ./rst_tmp/ $wiki_output_path/diapotb_wiki_html/ -c .
-rm -r rst_tmp
+sphinx-build -M markdown $path_dir/rst_tmp/ $wiki_output_path/diapotb_wiki/ -c $path_dir
+#sphinx-build -b html $path_dir/rst_tmp/ $wiki_output_path/diapotb_wiki_html/ -c $path_dir
+if [[ -d "${path_dir}/rst_tmp" ]]
+then
+    rm -r $path_dir/rst_tmp
+fi
-- 
GitLab