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)

Vincent Hatakeyama
committed
project_name_from_home=$(basename $project_home)
project_name=${DRONE_REPO_NAME:-project_name_from_home}
languages=(${LANGUAGES:-en})
format=html
out_dir=${project_home}/_build/$format
error=0
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

Vincent Hatakeyama
committed
# determine branch name
if [ -n "$DRONE_BRANCH" ]; then
branch="$DRONE_BRANCH"

Vincent Hatakeyama
committed
elif [ -e ".git" ]; then
branch="$(git rev-parse --abbrev-ref HEAD)"

Vincent Hatakeyama
committed
elif [ -e ".hg" ]; then
branch="$(hg id -b)"

Vincent Hatakeyama
committed
else
echo "${RED}WARN${RESET} - Branch name not found"
branch="unknown"

Vincent Hatakeyama
committed
fi
echo "${YELLOW}INFO ${RESET} - Branch name: $branch"

Vincent Hatakeyama
committed
for doc_dir in doc docs; do
if [[ -d "$doc_dir" ]] ; then
pushd $doc_dir
for language in $languages ; do
make -e SPHINXOPTS=-Dlanguage=${language} $format
if [[ $? -eq 0 ]] ; then
# TODO read value from Makefile
builddir=_build
dest_dir=$out_dir/$project_name/$language/$branch
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)"
((error++))

Vincent Hatakeyama
committed
if type "python3" > /dev/null;
then

Vincent Hatakeyama
committed
odoo_modules="$(python3 -B -c "import configparser ; c = configparser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print (c.has_option('odoo_scripts', 'modules') and ' '.join(c.get('odoo_scripts', 'modules').split()) or '')")"

Vincent Hatakeyama
committed
else

Vincent Hatakeyama
committed
odoo_modules="$(python2 -B -c "import ConfigParser ; c = ConfigParser.SafeConfigParser() ; c.read('${project_home}/setup.cfg') ; print (c.has_option('odoo_scripts', 'modules') and ' '.join(c.get('odoo_scripts', 'modules').split()) or '')")"

Vincent Hatakeyama
committed
fi
for module_path in $(eval echo $odoo_modules) ;

Vincent Hatakeyama
committed
do
if [[ -d "$module_path" ]] ; then
pushd $module_path
module=$(basename $module_path)

Vincent Hatakeyama
committed
has_doc=""
if [ -e ".git" ]; then
branch="$(git rev-parse --abbrev-ref HEAD)"
elif [ -e ".hg" ]; then
branch="$(hg identify --branch)"
else
echo "${RED}WARN${RESET} - Branch name not found"
branch="default"
fi

Vincent Hatakeyama
committed
for doc_dir in doc docs ; do
if [[ -d $doc_dir && -e $doc_dir/Makefile ]]; then
echo "${YELLOW}INFO ${RESET} - Branch name: $branch"

Vincent Hatakeyama
committed
has_doc=True
echo ${YELLOW}INFO ${RESET} - Makefile found in $dir/$module_path/$doc_dir

Vincent Hatakeyama
committed
# TODO read value from Makefile
for language in $languages ; do

Vincent Hatakeyama
committed
make -e SPHINXOPTS=-Dlanguage=${language} $format
if [[ $? -eq 0 ]] ; then
# TODO read value from Makefile
builddir=_build
dest_dir=$out_dir/$module/$language/$branch
echo ${YELLOW}INFO ${RESET} - Documentation generation done for $dir/$module_path/$doc_dir, copy to $dest_dir

Vincent Hatakeyama
committed
mkdir -p $dest_dir
cp -r $builddir/$format/. $dest_dir
else
echo ${RED}ERROR${RESET} - Documentation generation failed for $dir/$module_path/$doc_dir
((error++))

Vincent Hatakeyama
committed
fi
done
popd

Vincent Hatakeyama
committed
done
if [[ -z "$has_doc" ]] ; then
echo ${RED}ERROR${RESET} - Missing documentation for $dir/$module_path

Vincent Hatakeyama
committed
popd
fi
exit $error