Skip to content

Commit ecd6de3

Browse files
committed
better align script with best and local practices
1 parent 9e1156d commit ecd6de3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

bin/load_data.sh

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#
33
# Load Django application data
44
#
5+
#### SETUP ####################################################################
6+
57
set -o errexit
68
set -o errtrace
79
set -o nounset
@@ -12,6 +14,8 @@ trap '_es=${?};
1214
printf " exited with a status of ${_es}\n";
1315
exit ${_es}' ERR
1416

17+
DATA_FILE='../cc-legal-tools-data/config/app_data.yaml'
18+
DIR_REPO="$(cd -P -- "${0%/*}/.." && pwd -P)"
1519
# https://en.wikipedia.org/wiki/ANSI_escape_code
1620
E0="$(printf "\e[0m")" # reset
1721
E30="$(printf "\e[30m")" # black foreground
@@ -20,7 +24,6 @@ E107="$(printf "\e[107m")" # bright white background
2024

2125
#### FUNCTIONS ################################################################
2226

23-
2427
check_docker() {
2528
local _msg
2629
if ! docker compose exec app true 2>/dev/null; then
@@ -30,29 +33,27 @@ check_docker() {
3033
fi
3134
}
3235

33-
3436
error_exit() {
3537
# Echo error message and exit with error
3638
echo -e "${E31}ERROR:${E0} ${*}" 1>&2
3739
exit 1
3840
}
3941

40-
4142
print_header() {
4243
# Print 80 character wide black on white heading with time
4344
printf "${E30}${E107}# %-70s$(date '+%T') ${E0}\n" "${@}"
4445
}
4546

46-
4747
#### MAIN #####################################################################
4848

49+
cd "${DIR_REPO}"
50+
4951
check_docker
5052

51-
print_header 'Load data (LegalCode and Tool models)'
52-
data_file='../cc-legal-tools-data/config/app_data.yaml'
53-
du -h "${data_file}"
53+
print_header 'Django loaddata - Import LegalCode and Tool model data'
54+
du -h "${DATA_FILE}"
5455
docker compose exec app ./manage.py loaddata \
5556
--app legal_tools \
5657
--verbosity 3 \
57-
"${data_file}"
58+
"${DATA_FILE}"
5859
echo

0 commit comments

Comments
 (0)