X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Fdocs-build.sh;h=56793f0e3f708e9b9583e33fd1f0bb3c7fe6d4e3;hb=refs%2Fchanges%2F59%2F4659%2F2;hp=5ac8b2be67f64f9a12a640ea53d0e902207056ae;hpb=65bcd191470b2f338f05db0d760ddd601fd0fb07;p=releng.git diff --git a/utils/docs-build.sh b/utils/docs-build.sh index 5ac8b2be6..56793f0e3 100755 --- a/utils/docs-build.sh +++ b/utils/docs-build.sh @@ -60,12 +60,11 @@ function check_rst_doc() { function add_html_notes() { _src="$1" - _dir="$2" - if grep -q -e ' _sha1_' "$_src"/*.rst ; then + if grep -e ' _sha1_' "$_src"/*.rst ; then # TODO: remove this, once old templates were removed from all repos. echo - echo "Warn: '_sha1_' was found in $_dir , use the latest document template." + echo "Warn: '_sha1_' was found, use the latest document template." echo " See https://wiki.opnfv.org/documentation/tools ." echo sed -i "s/ _sha1_/ $git_sha1/g" "$_src"/*.rst @@ -73,6 +72,13 @@ function add_html_notes() { sed -i -e "\$a\\\n.. only:: html\n$html_notes" "$_src"/*.rst } +function prepare_src_files() { + mkdir -p "$BUILD_DIR" + [[ -e "$BUILD_DIR/src" ]] && rm -rf "$BUILD_DIR/src" + cp -r "$SRC_DIR" "$BUILD_DIR/src" + add_html_notes "$BUILD_DIR/src" +} + function add_config() { _conf="$1" _param="$2" @@ -84,6 +90,35 @@ function add_config() { fi } +function is_top_dir() { + [[ "$1" == "$SRC_DIR" ]] +} + +function generate_name_for_top_dir() { + for suffix in '' '.top' '.all' '.master' '_' '__' '___' + do + _name="$(basename $SRC_DIR)$suffix" + [[ -e "$SRC_DIR/$_name" ]] && continue + echo "$_name" + return + done + + echo "Error: cannot find name for top directory [$SRC_DIR]" + exit 1 +} + +function generate_name() { + _dir=$1 + + if is_top_dir "$_dir" ; then + _name=$(generate_name_for_top_dir $SRC_DIR) + else + _name="${_dir#$SRC_DIR/}" + fi + # Replace '/' by '_' + echo "${_name////_}" +} + check_rst_doc $SRC_DIR @@ -92,10 +127,12 @@ if [[ ! -d "$RELENG_DIR" ]] ; then exit 1 fi +prepare_src_files + find $SRC_DIR -name $INDEX_RST -printf '%h\n' | while read dir do - name="${dir##*/}" - src="$BUILD_DIR/src/$name" + name=$(generate_name $dir) + src="$BUILD_DIR/src${dir#$SRC_DIR}" build="$BUILD_DIR/$name" output="$OUTPUT_DIR/$name" conf="$src/conf.py" @@ -106,12 +143,6 @@ do echo "#################${dir//?/#}" echo - mkdir -p "$BUILD_DIR/src" - [[ -e "$src" ]] && rm -rf "$src" - cp -r "$dir" "$src" - - add_html_notes "$src" "$dir" - [[ ! -f "$conf" ]] && cp "$default_conf" "$conf" title=$(cd $src; python -c "$get_title_script") latex_conf="[('index', '$name.tex', \"$title\", 'OPNFV', 'manual'),]" @@ -143,4 +174,9 @@ do [[ -n "$GERRIT_COMMENT" ]] && echo "$msg" >> "$GERRIT_COMMENT" } + if is_top_dir "$dir" ; then + mv "$output"/* "$OUTPUT_DIR"/ + rm -rf "$output" + fi + done