Newer
Older
#!/bin/sh
# vim: set shiftwidth=4 softtabstop=4:
#
# This script start odoo for development
#
# You can set ODOO_DATA_DIR and ODOO_DB_HOST if you want to avoid using the default value ($HOME/var/tmp and localhost)

Vincent Hatakeyama
committed
# ODOO_TYPE can be set instead of putting it in setup.cfg

Vincent Hatakeyama
committed
here=$(dirname "$0")
project_home=$(cd "$here" && cd .. && echo "$PWD")
if [ -x "$(command -v python3)" ];
then
python="python3"
else
python="python2"
fi
ODOO_TYPE=${ODOO_TYPE:-$($python -B -c "from six.moves import configparser ; c = configparser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print(c.get('odoo_scripts', 'odoo_type') if c.has_option('odoo_scripts', 'odoo_type') else 'odoo8')")}

Vincent Hatakeyama
committed
echo "INFO - Starting odoo ($ODOO_TYPE) for development"

Vincent Hatakeyama
committed
#
# Do some magic to find the odoo command to run
#
# First test if odoo command exists
case $ODOO_TYPE in
odoo7 | odoo8)
odoo_command=openerp-server
odoo_addons_path=${ODOO_ADDONS_PATH:-/opt/odoo/sources/odoo}
;;
odoo_command=odoo
;;
esac
echo "DEBUG - Trying odoo command $odoo_command"
if [ -x "$(command -v $odoo_command)" ];
odoo_bin=$odoo_command
echo "DEBUG - Command found"

Vincent Hatakeyama
committed
else
echo "DEBUG - No odoo command found"
echo "DEBUG - Trying import in python"
if [ "$ODOO_TYPE" = "odoo7" ] || [ "$ODOO_TYPE" = "odoo8" ];
print_statement="import os;import openerp;print os.path.abspath(openerp.__file__)"
else
print_statement="import os;import odoo;print os.path.abspath(odoo.__file__)"

Vincent Hatakeyama
committed
fi
# module_path will be .../<directory>/openerp/__init__.pyc
module_path=$(python -B -c "$print_statement" 2> /dev/null)
echo "DEBUG - No odoo found by using module path"

Vincent Hatakeyama
committed
virtualenv_name=$(basename "$(readlink -f "$(dirname start)")")
echo "DEBUG - Trying $virtualenv_name virtualenvwrapper"
# assume you use virtualenvwrapper, and try the same env name as the project
venv_python=$WORKON_HOME/$virtualenv_name/bin/python
if [ -e "$venv_python" ];
module_path=$($venv_python -B -c "$print_statement" 2> /dev/null)
fi
if test -z "$module_path";
then
echo "DEBUG - No odoo found by using virtuenvwrapper"
echo "DEBUG - Trying in /opt/odoo/sources/odoo"
if test -e "/opt/odoo/sources/odoo/$odoo_bin";
then
echo "DEBUG - Found in /opt/odoo/sources/odoo"
odoo_bin=/opt/odoo/sources/odoo/$odoo_bin
module_path="/opt/odoo/sources/odoo/odoo/__init__.py"
else
echo "FATAL - No odoo found"
echo "INFO - Maybe you forgot to activate your environment?"
exit 1
fi
else
echo "DEBUG - Odoo found by using virtuenvwrapper"
fi

Vincent Hatakeyama
committed
else
echo "DEBUG - Odoo found by using module path ($module_path)"

Vincent Hatakeyama
committed

Vincent Hatakeyama
committed
odoo=$(dirname "$(dirname $module_path)")

Vincent Hatakeyama
committed
if expr "$odoo" : ^.*\.egg$ || [ "$ODOO_TYPE" = "odoo10" ] ;
then
odoo_addons_path=${ODOO_ADDONS_PATH:-/opt/odoo/sources/odoo}
else
odoo_addons_path=${ODOO_ADDONS_PATH:-$odoo}
fi

Vincent Hatakeyama
committed
#
# Try to handle argument to this program to give them back to odoo without duplicating them
#

Vincent Hatakeyama
committed
if echo "$args" | grep -q -e '\( \|^\)--db_host';
then
db_host=""
else
db_host="--db_host=localhost"
fi

Vincent Hatakeyama
committed
if echo "$args" | grep -q -e '\( \|^\)-c' -e '\( \|^\)--config';
if [ -e "${project_home}/conf/drone/odoo.conf" ];
then
config="-c ${project_home}/conf/drone/odoo.conf"
elif [ -e "${project_home}/conf/dev/odoo.conf" ];
then
config="-c ${project_home}/conf/dev/odoo.conf"
fi

Vincent Hatakeyama
committed
if echo "$args" | grep -q -e '\( \|^\)--addons-path';
if [ -n "${ODOO_ADDONS_PATH+set}" ];

Vincent Hatakeyama
committed
then
if [ -n "${ODOO_ADDONS_PATH}" ];
then
pathes=$ODOO_ADDONS_PATH
fi
else
if [ "$ODOO_TYPE" = "odoo7" ] || [ "$ODOO_TYPE" = "odoo8" ];
then
pathes=$($python -B -c "from six.moves import configparser ; import os ; c = configparser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print(','.join(['$odoo_addons_path/addons']+['${project_home}/'+line for line in set(os.path.dirname(path) for path in c.get('odoo_scripts', 'modules').split())]))")
else
pathes=$($python -B -c "from six.moves import configparser ; import os ; c = configparser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print(','.join(['${project_home}/'+line for line in set(os.path.dirname(path) for path in c.get('odoo_scripts', 'modules').split())]))")
fi

Vincent Hatakeyama
committed
fi
if [ -n "$pathes" ];
then
addons_path="--addons-path=$pathes"
fi

Vincent Hatakeyama
committed
# use load-language from setup.cfg if none already provided

Vincent Hatakeyama
committed
if echo "$args" | grep -q -e '\( \|^\)-c' -e '\( \|^\)--load-language';

Vincent Hatakeyama
committed
echo "INFO - load-language flag detected, no reading from setup.cfg"

Vincent Hatakeyama
committed
load_language=$($python -B -c "from six.moves import configparser ; c = configparser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print(c.get('odoo_scripts', 'load-language') if c.has_option('odoo_scripts', 'load-language') else '')")
if [ -n "$load_language" ];
then
load_language="--load-language $load_language"
fi

Vincent Hatakeyama
committed
#

Vincent Hatakeyama
committed
# Start Odoo

Vincent Hatakeyama
committed
#

Vincent Hatakeyama
committed
echo "INFO - Odoo Version: $($odoo_bin --version)"

Vincent Hatakeyama
committed
echo "DEBUG - command line is: ${PRE_ODOO_BIN}$(command -v $odoo_bin) $config $db_host $addons_path $args $load_language"
# shellcheck disable=SC2046,SC2086
${PRE_ODOO_BIN}$(command -v $odoo_bin) $config $db_host $addons_path $args $load_language