Adapt dashboard to a second vPing scenario
[releng.git] / utils / docs-build.sh
index e5e6025..b397094 100755 (executable)
@@ -137,7 +137,11 @@ prepare_src_files
 find $DOCS_DIR -name $INDEX_RST -printf '%h\n' | while read dir
 do
     name=$(generate_name $dir)
-    src="$SRC_DIR/${dir#$DOCS_DIR/}"
+    if is_top_dir "$dir" ; then
+        src="$SRC_DIR"
+    else
+        src="$SRC_DIR/${dir#$DOCS_DIR/}"
+    fi
     build="$BUILD_DIR/$name"
     output="$OUTPUT_DIR/$name"
     conf="$src/conf.py"
@@ -179,8 +183,37 @@ do
         [[ -n "$GERRIT_COMMENT" ]] && echo "$msg" >> "$GERRIT_COMMENT"
     }
 
+    # TODO: failures in ODT creation should be handled error and
+    #       cause 'exit 1' before OPNFV B release.
+    tex=$(find $build -name '*.tex' | head -1)
+    odt="${tex%.tex}.odt"
+    if [[ -e $tex ]] && which pandoc > /dev/null ; then
+        (
+            cd $(dirname $tex)
+            pandoc $(basename $tex) -o $(basename $odt)
+        ) && {
+            mv $odt $output/
+        }|| {
+            msg="Error: ODT creation for $dir has failed."
+            echo
+            echo "$msg"
+            echo
+        }
+    else
+        echo "Warn: tex file and/or 'pandoc' are not found, skip ODT creation."
+    fi
+
     if is_top_dir "$dir" ; then
-        mv "$output"/* "$OUTPUT_DIR"/
+        # NOTE: Having top level document (docs/index.rst) is not recommended.
+        #       It may cause conflicts with other docs (mostly with HTML
+        #       folders for contents in top level docs and other document
+        #       folders). But, let's try merge of those contents into the top
+        #       docs directory.
+        (
+            cd $output
+            find . -type d -print | xargs -I d mkdir -p ../d
+            find . -type f -print | xargs -I f mv -b f ../f
+        )
         rm -rf "$output"
     fi