tools/build_docs.sh
9b973670
 #!/usr/bin/env bash
 
b3fdb1c9
 # **build_docs.sh** - Build the docs for DevStack
9b973670
 #
dc97cb71
 # - Install shocco if not found on ``PATH`` and ``INSTALL_SHOCCO`` is set
 # - Clone ``MASTER_REPO`` branch ``MASTER_BRANCH``
0cbddea5
 # - Re-creates ``doc/build/html`` directory from existing repo + new generated script docs
9b973670
 
 # Usage:
b3fdb1c9
 ## build_docs.sh [-o <out-dir>]
54b97323
 ## -o <out-dir>     Write the static HTML output to <out-dir>
 ##                  (Note that <out-dir> will be deleted and re-created to ensure it is clean)
9b973670
 
 # Defaults
 # --------
 
0cbddea5
 HTML_BUILD=doc/build/html
54b97323
 
dc97cb71
 # Keep track of the DevStack directory
c04ddbe8
 TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
 
9b973670
 # Uses this shocco branch: https://github.com/dtroyer/shocco/tree/rst_support
 SHOCCO=${SHOCCO:-shocco}
 if ! which shocco; then
c04ddbe8
     if [[ ! -x $TOP_DIR/shocco/shocco ]]; then
9b973670
         if [[ -z "$INSTALL_SHOCCO" ]]; then
             echo "shocco not found in \$PATH, please set environment variable SHOCCO"
             exit 1
         fi
         echo "Installing local copy of shocco"
c04ddbe8
         if ! which pygmentize; then
             sudo pip install Pygments
         fi
         if ! which rst2html.py; then
             sudo pip install docutils
         fi
9b973670
         git clone -b rst_support https://github.com/dtroyer/shocco shocco
         cd shocco
         ./configure
54b97323
         make || exit
9b973670
         cd ..
     fi
c04ddbe8
     SHOCCO=$TOP_DIR/shocco/shocco
9b973670
 fi
 
 # Process command-line args
b3fdb1c9
 while getopts o: c; do
9b973670
     case $c in
54b97323
         o)  HTML_BUILD=$OPTARG
9b973670
             ;;
     esac
 done
 shift `expr $OPTIND - 1`
 
54b97323
 
9b973670
 # Processing
 # ----------
 
b3fdb1c9
 # Ensure build dir exists
54b97323
 mkdir -p $HTML_BUILD
9b973670
 
54b97323
 # Get fully qualified dirs
 FQ_HTML_BUILD=$(cd $HTML_BUILD && pwd)
 
926c99d0
 # Insert automated bits
 GLOG=$(mktemp gitlogXXXX)
b3fdb1c9
 echo "<ul>" >$GLOG
926c99d0
 git log \
     --pretty=format:'            <li>%s - <em>Commit <a href="https://review.openstack.org/#q,%h,n,z">%h</a> %cd</em></li>' \
     --date=short \
b3fdb1c9
     --since '6 months ago' | grep -v Merge >>$GLOG
 echo "</ul>" >>$GLOG
 sed -i~ -e $"/^.*%GIT_LOG%.*$/r $GLOG" -e $"/^.*%GIT_LOG%.*$/s/^.*%GIT_LOG%.*$//" $FQ_HTML_BUILD/changes.html
926c99d0
 rm -f $GLOG
 
9b973670
 # Build list of scripts to process
 FILES=""
6d50d95c
 for f in $(find . \( -name .git -o -name .tox \) -prune -o \( -type f -name \*.sh -not -path \*shocco/\* -print \)); do
9b973670
     echo $f
     FILES+="$f "
54b97323
     mkdir -p $FQ_HTML_BUILD/`dirname $f`;
     $SHOCCO $f > $FQ_HTML_BUILD/$f.html
9b973670
 done
bf2ad701
 for f in $(find functions functions-common inc lib pkg samples -type f -name \*); do
9b973670
     echo $f
     FILES+="$f "
54b97323
     mkdir -p $FQ_HTML_BUILD/`dirname $f`;
     $SHOCCO $f > $FQ_HTML_BUILD/$f.html
9b973670
 done
0cbddea5
 echo "$FILES" >doc/files
9b973670
 
 # Clean up or report the temp workspace
 if [[ -n REPO && -n $PUSH_REPO ]]; then
54b97323
     echo rm -rf $TMP_ROOT
9b973670
 else
     if [[ -z "$TMP_ROOT" ]]; then
         TMP_ROOT="$(pwd)"
     fi
54b97323
     echo "Built docs in $HTML_BUILD"
9b973670
 fi