@@ -3,8 +3,9 @@ set -euo pipefail
33
44# Usage function
55usage () {
6- echo " Usage: ./industry/run_industry.sh -i <industry-name> [-d] [-t] [-r | -h]"
7- echo " -i <industry-name> (re)Install this industry"
6+ echo " Usage: ./industry/run_industry.sh -n <industry-name> [-i] [-d] [-t] [-r | -h]"
7+ echo " -n <industry-name> Name of the industry to run"
8+ echo " -i Import this industry"
89 echo " -d Enable demo data when installing"
910 echo " -t Run tests for the installed industry"
1011 echo " -r Reset the database before running but keeps the industry dependencies installed"
@@ -21,9 +22,10 @@ HARD_RESET=false
2122DEMO=False
2223
2324# Parse arguments
24- while getopts " :i:dtrh " opt; do
25+ while getopts " :n:idtrh " opt; do
2526 case $opt in
26- i) INDUSTRY_NAME=" $OPTARG " ; INSTALL=true ;;
27+ n) INDUSTRY_NAME=" $OPTARG " ;;
28+ i) INSTALL=true ;;
2729 d) DEMO=True ;;
2830 t) TEST=true ;;
2931 r) RESET=true ;;
@@ -43,19 +45,31 @@ PYTHON_BIN="python3"
4345ODOO_BIN=" odoo/odoo-bin"
4446ADDONS_PATH=" industry/tests,enterprise,odoo/addons,odoo/odoo/addons,design-themes"
4547TEST_TAGS=" /test_generic,/test_$INDUSTRY_NAME "
46- DUMP_PATH=../dump " / $INDUSTRY_NAME "
48+ DEP_DB= " dep- $INDUSTRY_NAME "
4749
48- # create dump if it doesn't exist
49- if [[ ! -f " $DUMP_PATH " ]]; then
50+ # check module exists
51+ if [ ! -d " industry/$INDUSTRY_NAME " ]; then
52+ echo " Module '$INDUSTRY_NAME ' does not exist."
53+ exit 1
54+ fi
55+
56+ # check manifest exists
57+ if [ ! -f " industry/$INDUSTRY_NAME /__manifest__.py" ]; then
58+ echo " Manifest file not found."
59+ exit 1
60+ fi
61+
62+ # try to init the db to check if it exists
63+ if $PYTHON_BIN $ODOO_BIN db init $DEP_DB > /dev/null 2>&1 ; then
5064 HARD_RESET=true
5165fi
5266
67+ # reset the dependency db
5368if $HARD_RESET ; then
54- echo " Resetting database '$INDUSTRY_NAME '..."
55- mkdir -p " $( dirname " $DUMP_PATH " ) "
69+ echo " Resetting database '$DEP_DB '..."
70+ $PYTHON_BIN $ODOO_BIN db init $DEP_DB --force
5671 echo " Initializing dependencies..."
57- $PYTHON_BIN $ODOO_BIN db init $INDUSTRY_NAME --force
58- $PYTHON_BIN $ODOO_BIN --addons-path=" $ADDONS_PATH " module install base_import_module -d $INDUSTRY_NAME
72+ $PYTHON_BIN $ODOO_BIN --addons-path=" $ADDONS_PATH " module install base_import_module -d $DEP_DB
5973 TMP_DEP_PY=$( mktemp)
6074 cat << EOF > "$TMP_DEP_PY "
6175import sys
@@ -66,20 +80,19 @@ print("")
6680env.cr.commit()
6781exit()
6882EOF
69- cat $TMP_DEP_PY | $PYTHON_BIN $ODOO_BIN shell --addons-path=" $ADDONS_PATH " -d $INDUSTRY_NAME
83+ cat $TMP_DEP_PY | $PYTHON_BIN $ODOO_BIN shell --addons-path=" $ADDONS_PATH " -d $DEP_DB
7084 rm -f " $TMP_DEP_PY "
71- $PYTHON_BIN $ODOO_BIN db dump $INDUSTRY_NAME $DUMP_PATH
7285fi
7386
7487# reload db when reset
7588if $RESET || $HARD_RESET ; then
76- $PYTHON_BIN $ODOO_BIN db load $INDUSTRY_NAME $DUMP_PATH --force
89+ echo " Copying database '$DEP_DB ' into '$INDUSTRY_NAME '..."
90+ $PYTHON_BIN $ODOO_BIN db duplicate $DEP_DB $INDUSTRY_NAME --force
7791fi
7892
7993# install industry module
8094if $INSTALL ; then
8195 echo " Initializing industry module..."
82-
8396 TMP_INSTALL_PY=$( mktemp)
8497 cat << EOF > "$TMP_INSTALL_PY "
8598import sys
0 commit comments