Newer
Older
# 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 (see odoo_scripts_common)
# odoo_scripts_start_logfile can be set to indicate where to store Odoo tests out. stdout and stderr are both redirected.

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
;;
echo "$DEBUG Trying odoo command $odoo_command"
if [ -x "$(command -v $odoo_command)" ];

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"
echo "$FATAL No odoo found"
echo "$INFO Maybe you forgot to activate your environment?"
exit 1
echo "$DEBUG Odoo found by using virtuenvwrapper"

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
#
echo "$DEBUG Try to find if any db host is specified"

Vincent Hatakeyama
committed
if echo "$args" | grep -q -e '\( \|^\)--db_host';
then
db_host=""
else
db_host="--db_host=localhost"
fi
echo "$DEBUG Try to find if any odoo configuration is specified"

Vincent Hatakeyama
committed
if echo "$args" | grep -q -e '\( \|^\)-c' -e '\( \|^\)--config';
echo "$DEBUG Configuration is specified, no extra argument added"
if [ -e "${project_home}/conf/drone/odoo.conf" ];
then
echo "$DEBUG Use ${project_home}/conf/drone/odoo.conf as configuration file"
config="--config=${project_home}/conf/drone/odoo.conf"
elif [ -e "${project_home}/conf/dev/odoo.conf" ];
echo "$DEBUG Use ${project_home}/conf/dev/odoo.conf as configuration file"
config="--config=${project_home}/conf/dev/odoo.conf"
echo "$DEBUG Try to find if any addons path is provided"

Vincent Hatakeyama
committed
if echo "$args" | grep -q -e '\( \|^\)--addons-path';
echo "$DEBUG addons-path is specified, no extra argument added"
if [ -n "${ODOO_ADDONS_PATH+set}" ];

Vincent Hatakeyama
committed
then
if [ -n "${ODOO_ADDONS_PATH}" ];
then
pathes=$ODOO_ADDONS_PATH
fi
else
modules_to_use=$(read_odoo_scripts_expandable_configuration_key modules)
if [ "$ODOO_TYPE" = "odoo7" ] || [ "$ODOO_TYPE" = "odoo8" ];
then
pathes=$($python -B -c "import os;print(','.join(['$odoo_addons_path/addons']+list(set(os.path.dirname(path) for path in '${modules_to_use}'.split(',')))))")
pathes=$($python -B -c "import os;print(','.join(set(os.path.dirname(path) for path in '${modules_to_use}'.split(','))))")

Vincent Hatakeyama
committed
fi
if [ -n "$pathes" ];
then

Vincent Hatakeyama
committed
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';
echo "$INFO load-language flag detected, no reading from setup.cfg"
echo "$DEBUG Reading load-language from configuration"
load_language=$(read_odoo_scripts_configuration_key load-language)

Vincent Hatakeyama
committed
if [ -n "$load_language" ];
then
load_language="--load-language=$load_language"

Vincent Hatakeyama
committed
fi
# set odoo_scripts_start_logfile if empty
if [[ -z "$odoo_scripts_start_logfile" ]];
then
odoo_scripts_start_logfile=$(mktemp --suffix=.log)
function clean_logfile() {
rm $odoo_scripts_start_logfile
}
trap clean_logfile INT TERM
fi

Vincent Hatakeyama
committed
#

Vincent Hatakeyama
committed
# Start Odoo

Vincent Hatakeyama
committed
#
echo "$INFO Odoo Version: $($odoo_bin --version)"
echo "$DEBUG command line is: ${PRE_ODOO_BIN}$(which $odoo_bin) $config $db_host $addons_path $args $load_language"
exec zsh -c "(${PRE_ODOO_BIN}$(which $odoo_bin) $config $db_host $addons_path $args $load_language 2>&1) > >(tee $odoo_scripts_start_logfile)"