Something went wrong on our end
-
Vincent Hatakeyama authored
shell script do not assume they are called from a directory in the project home, but called from the project home while the scripts themeselves might be somewhere else Other scripts already assumes that so it should not have much impact, it allows more possibility for the location of the scriptsVincent Hatakeyama authored shell script do not assume they are called from a directory in the project home, but called from the project home while the scripts themeselves might be somewhere else Other scripts already assumes that so it should not have much impact, it allows more possibility for the location of the scripts
start 5.84 KiB
#!/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)
# ODOO_TYPE can be set instead of putting it in setup.cfg
#
# Version 4.0
here=$(dirname "$0")
# assume we are called from the project home
project_home=$PWD
if [ -x "$(command -v python3)" ];
then
python="python3"
else
python="python2"
fi
# odoo7, odoo8, odoo10, odoo11, odoo13
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')")}
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_command=openerp-server
odoo_addons_path=${ODOO_ADDONS_PATH:-/opt/odoo/sources/odoo}
;;
odoo10 | odoo11 | odoo13)
odoo_command=odoo
;;
esac
echo "DEBUG - Trying odoo command $odoo_command"
if [ -x "$(command -v $odoo_command)" ];
then
odoo_bin=$odoo_command
echo "DEBUG - Command found"
else
echo "DEBUG - No odoo command found"
echo "DEBUG - Trying import in python"
if [ "$ODOO_TYPE" = "odoo7" ] || [ "$ODOO_TYPE" = "odoo8" ];
then
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__)"
fi
# module_path will be .../<directory>/openerp/__init__.pyc
module_path=$(python -B -c "$print_statement" 2> /dev/null)
odoo_bin=$odoo_command
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" ];
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"
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
else
echo "DEBUG - Odoo found by using module path ($module_path)"
fi
odoo=$(dirname "$(dirname $module_path)")
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
fi
#
# Try to handle argument to this program to give them back to odoo without duplicating them
#
args=$*
if echo "$args" | grep -q -e '\( \|^\)--db_host';
then
db_host=""
else
db_host="--db_host=localhost"
fi
if echo "$args" | grep -q -e '\( \|^\)-c' -e '\( \|^\)--config';
then
config=""
addons_path=""
else
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
if echo "$args" | grep -q -e '\( \|^\)--addons-path';
then
addons_path=""
else
if [ -n "${ODOO_ADDONS_PATH+set}" ];
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
fi
if [ -n "$pathes" ];
then
addons_path="--addons-path=$pathes"
fi
fi
fi
# use load-language from setup.cfg if none already provided
if echo "$args" | grep -q -e '\( \|^\)-c' -e '\( \|^\)--load-language';
then
echo "INFO - load-language flag detected, no reading from setup.cfg"
else
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
fi
#
# Start Odoo
#
echo "INFO - Odoo Version: $($odoo_bin --version)"
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