doc: fixing documentation structure
[csit.git] / resources / libraries / bash / function / docs.sh
index ec5cbef..cb3f36d 100644 (file)
@@ -47,56 +47,70 @@ function generate_docs () {
 
     pushd "${TOOLS_DIR}"/doc_gen || die "Pushd failed!"
 
-    WORKING_DIR="tmp"
     BUILD_DIR="_build"
 
+    # Remove the old build:
+    rm -rf ${BUILD_DIR} || true
+    rm -rf /tmp/tmp-csit* || true
+
+    export WORKING_DIR=$(mktemp -d /tmp/tmp-csitXXX) || die "export failed"
+
     # Create working directories
-    mkdir "${BUILD_DIR}"
-    mkdir --parents "${WORKING_DIR}"/resources/libraries/python/
-    mkdir --parents "${WORKING_DIR}"/resources/libraries/robot/
-    mkdir --parents "${WORKING_DIR}"/tests/
+    mkdir -p "${BUILD_DIR}" || die "Mkdir failed!"
+    mkdir -p "${WORKING_DIR}"/resources/libraries/python/ || die "Mkdir failed!"
+    mkdir -p "${WORKING_DIR}"/resources/libraries/robot/ || die "Mkdir failed!"
+    mkdir -p "${WORKING_DIR}"/tests/ || die "Mkdir failed!"
 
     # Copy the Sphinx source files:
-    cp -r src/* ${WORKING_DIR}/
+    cp -r src/* ${WORKING_DIR}/ || die "Copy the Sphinx source files failed!"
 
     # Copy the source files to be processed:
-    from_dir="../../../resources/libraries/python/"
+    from_dir="${RESOURCES_DIR}/libraries/python/"
     to_dir="${WORKING_DIR}/resources/libraries/python/"
-    command="rsync -a --include '*/'"
-    ${command} --include '*.py' --exclude '*' "${from_dir}" "${to_dir}"
-    cp ../../../resources/__init__.py ${WORKING_DIR}/resources/
-    cp ../../../resources/libraries/__init__.py ${WORKING_DIR}/resources/libraries/
-    from_dir="../../../resources/libraries/robot/"
+    dirs="${from_dir} ${to_dir}"
+    rsync -ar --include='*/' --include='*.py' --exclude='*' ${dirs} || {
+        die "rSync failed!"
+    }
+
+    from_dir="${RESOURCES_DIR}/libraries/robot/"
     to_dir="${WORKING_DIR}/resources/libraries/robot/"
-    ${command} --include '*.robot' --exclude '*' "${from_dir}" "${to_dir}"
-    from_dir="../../../tests/"
+    dirs="${from_dir} ${to_dir}"
+    rsync -ar --include='*/' --include '*.robot' --exclude '*' ${dirs} || {
+        die "rSync failed!"
+    }
+    touch ${to_dir}/index.robot || {
+        die "Touch index.robot file failed!"
+    }
+
+    from_dir="${CSIT_DIR}/tests/"
     to_dir="${WORKING_DIR}/tests/"
-    ${command} --include '*.robot' --exclude '*' "${from_dir}" "${to_dir}"
+    dirs="${from_dir} ${to_dir}"
+    rsync -ar --include='*/' --include '*.robot' --exclude '*' ${dirs} || {
+        die "rSync failed!"
+    }
+
+    # to remove GPL licence section
+    find "${WORKING_DIR}/tests/" -type f -exec sed -i '/\*\*\*/,$!d' {} \;
 
-    python3 gen_rst.py
-    # Remove all rst files from ./${WORKING_DIR}/env directory - we do not need
-    # them
-    find ./${WORKING_DIR}/env -type f -name '*.rst' | xargs rm -f
+    find ${WORKING_DIR}/ -type d -exec echo {} \; -exec touch {}/__init__.py \;
+
+    python3 gen_rst.py || die "Generate .rst files failed!"
 
     # Generate the documentation:
-    DATE=$(date -u '+%d-%b-%Y')
+    DATE=$(date -u '+%d-%b-%Y') || die "Get date failed!"
 
     all_options=("-v")
     all_options+=("-c" "${WORKING_DIR}")
     all_options+=("-a")
     all_options+=("-b" "html")
     all_options+=("-E")
-    all_options+=("-D" "release=$1")
-    all_options+=("-D" "version='$1 documentation - $DATE'")
+    all_options+=("-D" "version="${GERRIT_BRANCH:-master}"")
     all_options+=("${WORKING_DIR}" "${BUILD_DIR}/")
 
     set +e
     sphinx-build "${all_options[@]}"
     DOCS_EXIT_STATUS="$?"
     set -e
-
-    find . -type d -name 'env' | xargs rm -rf
-
 }
 
 function generate_report () {