Skip to content
Snippets Groups Projects
start 6.12 KiB
Newer Older
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
# 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)
# 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's avatar
Vincent Hatakeyama committed
#
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
# Version 23.0.1
source $here/odoo_scripts_common

echo "$INFO Starting odoo ($ODOO_TYPE) for development"

#
# Do some magic to find the odoo command to run
#

# First test if odoo command exists
case $ODOO_TYPE in
    odoo7 | odoo8)
        odoo_addons_path=${ODOO_ADDONS_PATH:-/opt/odoo/sources/odoo}
echo "$DEBUG Trying odoo command $odoo_command"
if [ -x "$(command -v $odoo_command)" ];
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
then
    odoo_bin=$odoo_command
    echo "$DEBUG Odoo command found ($odoo_bin)"
    echo "$DEBUG No odoo command found"
    echo "$DEBUG Trying import in python"
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
    if [ "$ODOO_TYPE" = "odoo7" ] || [ "$ODOO_TYPE" = "odoo8" ];
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
    then
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
        print_statement="import os;import openerp;print os.path.abspath(openerp.__file__)"
    else
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
        print_statement="import os;import odoo;print os.path.abspath(odoo.__file__)"
    fi
    # module_path will be .../<directory>/openerp/__init__.pyc
    module_path=$(python -B -c "$print_statement" 2> /dev/null)
    odoo_bin=$odoo_command
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
    if test -z "$module_path";
    then
        echo "$DEBUG No odoo found by using module path"
        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" ];
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
        then
            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"
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
            else
                echo "$FATAL No odoo found"
                echo "$INFO Maybe you forgot to activate your environment?"
                exit 1
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
            fi
        else
            echo "$DEBUG Odoo found by using virtuenvwrapper"
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
        fi
        echo "$DEBUG Odoo found by using module path ($module_path)"
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
    fi
    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
#
# Try to handle argument to this program to give them back to odoo without duplicating them
#
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed

args=$*
echo "$DEBUG Try to find if any db host is specified"
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
then
    db_host=""
else
    db_host="--db_host=localhost"
fi
echo "$DEBUG Try to find if any odoo configuration is specified"
if echo "$args" | grep -q -e '\( \|^\)-c' -e '\( \|^\)--config';
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
then
    echo "$DEBUG Configuration is specified, no extra argument added"
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
    config=""
    addons_path=""
else
    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's avatar
Vincent Hatakeyama committed
    then
        echo "$DEBUG addons-path is specified, no extra argument added"
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
        addons_path=""
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
    else
        if [ -n "${ODOO_ADDONS_PATH+set}" ];
            if [ -n "${ODOO_ADDONS_PATH}" ];
            then
                pathes=$ODOO_ADDONS_PATH
            fi
        else
            echo "$DEBUG Reading modules from setup.cfg"
            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(','))))")
            echo "$DEBUG --addons-path=$pathes"
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
    fi
fi
# use load-language from setup.cfg if none already provided
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)
        load_language="--load-language=$load_language"
    echo "$DEBUG load-language=$load_language"
# 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
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)"