Skip to content
Snippets Groups Projects
create_documentation 2.74 KiB
Newer Older
#!/bin/zsh
# vim: set shiftwidth=4 softtabstop=4:
#
# This script generates documentation in all submodules.

# It needs:
# - openerp to be installed
# 

# Version 2.7

here=$(dirname $0)
project_home=$(cd $here && cd .. && echo $PWD)
project_name=$(basename $project_home)
python=python

format=html
out_dir=${project_home}/_build/$format

# color stuff
autoload colors && colors
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
    eval $COLOR='$fg_no_bold[${(L)COLOR}]'
    eval BOLD_$COLOR='$fg_bold[${(L)COLOR}]'
done
eval RESET='$reset_color'

pushd $project_home

for doc_dir in doc docs; do
    if [ -e ".git" ]; then
	branch="$(git rev-parse --abbrev-ref HEAD)"
    elif [ -e ".hg" ]; then
	branch="$(hg id -b)"
    else
	echo "${RED}WARN${RESET} - Branch name not found"
	branch="unknown"
    fi
    if [[ -d "$doc_dir" ]] ; then
	pushd $doc_dir
	for language in "en" ; do
	    make -e SPHINXOPTS=-Dlanguage=${language} $format
	    # TODO read value from Makefile
	    builddir=_build
	    dest_dir=$out_dir/$project_name/$language/$branch
	    if [[ $? -eq 0 ]] ; then
		echo "${YELLOW}INFO ${RESET} - Documentation generation done for $doc_dir (superproject), copy to $dest_dir"
		mkdir -p $dest_dir
		cp -r $builddir/$format/. $dest_dir
	    else
		echo "${RED}ERROR${RESET} - Documentation generation failed for $doc_dir (superproject)"
	    fi
	done
	popd
    fi
done

for dir in $($python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print(' '.join(c.get('odoo_scripts', 'addon_dirs', '').split()))") ; do
    pushd $dir
    for module in * ; do
	if [[ -d "$module" ]] ; then
	    pushd $module
	    for doc_dir in doc docs ; do
		if [[ -d $doc_dir && -e $doc_dir/Makefile ]]; then
		    echo ${YELLOW}INFO ${RESET} - Makefile found in $dir/$module/$doc_dir
		    if [ -e ".git" ]; then
			branch="$(git rev-parse --abbrev-ref HEAD)"
		    elif [ -e ".hg" ]; then
			branch="$(hg id -b)"
		    else
			branch="default"
		    fi
		    pushd $doc_dir
		    # TODO read value from Makefile
		    for language in "en" ; do
    			make -e SPHINXOPTS=-Dlanguage=${language} $format
			# TODO read value from Makefile
			builddir=_build
			dest_dir=$out_dir/$module/$language/$branch
			if [[ $? -eq 0 ]] ; then
			    echo ${YELLOW}INFO ${RESET} - Documentation generation done for $dir/$module/$doc_dir, copy to $dest_dir
			    mkdir -p $dest_dir
			    cp -r $builddir/$format/. $dest_dir
			else
			    echo ${RED}ERROR${RESET} - Documentation generation failed for $dir/$module/$doc_dir
			fi
		    done
		    popd
		fi
	    done
	    if [[ -z "$has_doc" ]] ; then
		echo ${RED}ERROR${RESET} - Missing documentation for $dir/$module
	    fi