Newer
Older
#!/bin/zsh
# vim: set shiftwidth=4 softtabstop=4:
#
# This script will create a database, install some modules and run tests on it
#
# Arguments:
#
# - db host if any (will use socket if nothing is provided)
# - db user
Houzefa Abbasbhay
committed
# - other arguments are forwarded as is to the setup command.
#
# Required:
#
# - access to pg database
#

Vincent Hatakeyama
committed
# Version 2.14
Houzefa Abbasbhay
committed

Vincent Hatakeyama
committed
project_home=$(cd $here && cd .. && echo $PWD)
dbname=$(basename $project_home)_test

Vincent Hatakeyama
committed
if [[ -e "${project_home}/conf/dev/odoo.conf" ]];
then
dbowner=$(python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/conf/dev/odoo.conf') ; print c.get('options', 'db_user')")
else
dbowner=odoo
fi

Vincent Hatakeyama
committed
modules_to_install=$(python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print ','.join(c.get('odoo_scripts', 'module_list', '').split())")
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# color stuff
autoload colors
if [[ "$terminfo[colors]" -gt 7 ]];
then
colors
fi
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'
# argument handling
if [[ $# -gt 0 ]];
then
echo ${YELLOW}INFO ${RESET} - Using database host $1
PG_HOST=-h$1
ODOO_HOST=--db_host=$1
shift
if [[ $# -gt 0 ]];
then
echo ${YELLOW}INFO ${RESET} - Using database user $1
PG_USER=-U$1
ODOO_USER=--db_user=$1
dbowner=$1
shift
else
PG_USER=""
ODOO_USER=""
fi
else
PG_HOST=""
ODOO_HOST=""
PG_USER=""
ODOO_USER=""
fi

Vincent Hatakeyama
committed
# This should be a parameter if it was simple to parse
INSTALL_ARGUMENTS="--log-level=${INSTALL_LOG_LEVEL:-warn}"
echo "[${YELLOW}INFO${RESET}] Drop any existing database '$dbname'"
dropdb $PG_HOST $PG_USER --if-exists $dbname --no-password
echo "[${YELLOW}INFO${RESET}] Create database '$dbname' with owner $dbowner"
createdb $PG_HOST $PG_USER -O $dbowner $dbname --no-password || { echo ${RED}FATAL${RESET} - Cannot create test database ; exit 1; }
unaccent=$(python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/conf/dev/odoo.conf') ; print c.get('options', 'unaccent', False)")
if [[ "$unaccent" == "True" ]];
then
psql $PG_HOST $PG_USER $dbname -c "CREATE EXTENSION unaccent;"
fi
echo "[${YELLOW}INFO${RESET}] Modules to install: $modules_to_install"
echo "[${YELLOW}INFO${RESET}] Install those modules"
logfile=$(tempfile --suffix=.log)

Vincent Hatakeyama
committed
$here/start $INSTALL_ARGUMENTS -i $modules_to_install -d $dbname --max-cron=0 --stop-after-init $* $ODOO_HOST $ODOO_USER 2>&1 | tee $logfile | sed -e 's/\(.*\) \(INFO\) \(.*\)/\o033[2m\1\o033[22m \o033[32m\o033[7m\2\o033[27m \3\o033[39m/' -e 's/\(.*\) \(DEBUG\) \(.*\)/\o033[2m\1\o033[22m \o033[33m\o033[7m\2\o033[27m \2\o033[39m/' -e 's/\(.*\) \(WARNING\) \(.*\)/\o033[2m\1\o033[22m \o033[33m\o033[7m\2\o033[27m \3\o033[39m/' -e 's/\(.*\) \(ERROR\) \(.*\)/\o033[2m\1\o033[22m \o033[31m\o033[7m\2\o033[27m \3\o033[0m/' -e 's/ FAILED/ \o033[41m\o033[97m\o033[1mFAILED\o033[0m/' -e 's/ FAIL\(.*\)/ \o033[41m\o033[97m\o033[1mFAIL\o033[49m\o033[31m\1\o033[0m/' -e 's/\(.*\) \(CRITICAL\) \(.*\)/\o033[2m\1\o033[22m \o033[33m\o033[7m\2\o033[27m \3\o033[39m/' -e 's/\(.*\) \(TEST\) \(.*\) \(ERROR\)\(.*\)/\o033[2m\1\o033[22m \o033[34m\o033[7m\2\o033[27m \3\o033[0m \o033[41m\o033[97m\o033[1m\4\o033[49m\o033[31m\5\o033[0m/' -e 's/\(.*\) \(TEST\) \(.*\) \(OK\)/\o033[2m\1\o033[22m \o033[34m\o033[7m\2\o033[27m \3\o033[0m \o033[32m\o033[7m\4\o033[27m\o033[39m/' -e 's/\(.*\) \(TEST\) \(.*\)/\o033[2m\1\o033[22m \o033[34m\o033[7m\2\o033[27m \3 \o033[0m/'

Vincent Hatakeyama
committed
if [[ $start_status -ne 0 ]];
then
echo "[${RED}FATAL${RESET}] Cannot install modules (exit ${start_status})"

Vincent Hatakeyama
committed
exit $start_status
fi
failed=$(grep ' CRITICAL\| ERROR' $logfile -c)
rm $logfile
if [[ $failed -gt 0 ]];
then
echo "[${RED}FATAL${RESET}] Cannot install modules (ERROR or CRITICAL found)"
exit 1
fi
echo "[${YELLOW}INFO ${RESET}] Run tests on $dbname"
$here/run_tests $dbname $ODOO_HOST $ODOO_USER $*