Skip to content

Commit 0421ee3

Browse files
[IMP] utils: industry run script improvements.
- swapped db dump logic for dp duplicate for increased preformance. - set [-i] to be optional and added -n for db name input closes #1194 Signed-off-by: Vallaeys Valentin (vava) <[email protected]>
1 parent defe5a9 commit 0421ee3

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

run_industry.sh

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ set -euo pipefail
33

44
# Usage function
55
usage() {
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
2122
DEMO=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"
4345
ODOO_BIN="odoo/odoo-bin"
4446
ADDONS_PATH="industry/tests,enterprise,odoo/addons,odoo/odoo/addons,design-themes"
4547
TEST_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
5165
fi
5266

67+
# reset the dependency db
5368
if $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"
6175
import sys
@@ -66,20 +80,19 @@ print("")
6680
env.cr.commit()
6781
exit()
6882
EOF
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
7285
fi
7386

7487
# reload db when reset
7588
if $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
7791
fi
7892

7993
# install industry module
8094
if $INSTALL; then
8195
echo "Initializing industry module..."
82-
8396
TMP_INSTALL_PY=$(mktemp)
8497
cat <<EOF > "$TMP_INSTALL_PY"
8598
import sys

0 commit comments

Comments
 (0)