-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgo
executable file
·243 lines (204 loc) · 5.84 KB
/
go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env bash
set -e
function main {
case "$1" in
"prep" )
if [ "$2" = "--back" ]; then
prepbackend
elif [ "$2" = "--front" ]; then
prepfrontend
else
prepbackend
prepfrontend
fi;;
"build" )
build;;
"resetdb" )
if [ "$2" = "--test" ]; then
killtestdbconnections
resetdb test
elif [ "$2" = "--prod" ]; then
killdbconnections
resetdb prod
else
killdbconnections
resetdb
fi;;
"pushcontacts2rapidpro" )
if [ "$2" = "--prod" ]; then
pushcontacts2rapidpro prod
elif [ "$2" = "--stag" ]; then
pushcontacts2rapidpro stag
else
pushcontacts2rapidpro dev
fi;;
"startcelery" )
if [ "$2" = "--prod" ]; then
startcelery prod
else
startcelery dev
fi;;
"seed" )
seed;;
"bt" )
testbackend;;
"ut" )
testjsunit;;
"ft" )
if [ "$2" = "--headless" ]; then
testfunctional --headless
elif [ "$2" = "--nomigrations" ]; then
testfunctional --nomigrations
else
testfunctional
fi;;
"fft" )
testfunctional --multi;;
"at" )
testbackend
testjsunit
testfunctional;;
"rs" )
runserver;;
"prepush" )
testbackend
testjsunit;;
"performance" )
performance $2;;
"setupmap" )
setupmap $2 $3;;
esac
}
function build {
cd eums/client
grunt build
cd -
}
function prepbackend {
if [ ! -d ~/.virtualenvs/eums ]; then
virtualenv ~/.virtualenvs/eums
fi
source ~/.virtualenvs/eums/bin/activate
pip install -r requirements.txt
killtestdbconnections
echo "drop database eums_test; create database eums_test;" | psql -h localhost -U postgres
echo "******* make migrations ********"
python manage.py makemigrations && python manage.py migrate
}
function prepfrontend {
cd eums/client
sudo npm install -g grunt-cli
npm install
sudo npm install -g bower
echo n | bower install
cd -
}
function resetdb {
if [ "$1" = "test" ]; then
echo "+++ Resetting test database eums_test..."
echo "drop database eums_test; create database eums_test;" | psql -h localhost -U postgres
python manage.py migrate --settings=eums.test_settings
python manage.py setup_permissions --settings=eums.test_settings
python manage.py shell_plus --settings=eums.test_settings < eums/fixtures/load_flows_and_questions.py
python manage.py loaddata eums/client/test/functional/fixtures/user.json --settings=eums.test_settings
else
echo "+++ Resetting database eums..."
echo "drop database eums; create database eums;" | psql -h localhost -U postgres
python manage.py migrate
python manage.py setup_permissions
python manage.py shell_plus < eums/fixtures/cleanup_questions.py
python manage.py shell_plus < eums/fixtures/load_flows_and_questions.py
python manage.py shell_plus < eums/fixtures/init_basic_data.py
python manage.py shell_plus < eums/fixtures/cleanup_runqueues.py
if [ "$1" = "prod" ]; then
echo "+++ Reset production database..."
python manage.py runscript eums.fixtures.create_superuser_password --script-args="username=admin,password=${ADMIN_PASSWORD}"
else
python manage.py loaddata eums/client/test/functional/fixtures/user.json
fi
fi
}
function pushcontacts2rapidpro {
if [ "$1" = "prod" ]; then
python manage.py shell_plus < eums/rapid_pro/sync_eums_contacts.py --setting=eums.settings_production
elif [ "$1" = "stag" ];then
python manage.py shell_plus < eums/rapid_pro/sync_eums_contacts.py --setting=eums.settings_staging
else
python manage.py shell_plus < eums/rapid_pro/sync_eums_contacts.py --setting=eums.settings_dev
fi
}
function testbackend {
source ~/.virtualenvs/eums/bin/activate
pip install -r requirements.txt
python manage.py test -v 2 --noinput
}
function testjsunit {
cd eums/client
grunt unit
cd -
}
function performance {
cd eums/client
if [ "$1" ]; then
echo "Measuring load time for EUMS at $1..."
grunt performance --baseUrl=$1
else
echo "Measuring load time for EUMS at http://localhost"
grunt performance --baseUrl=http://localhost
fi
cd scripts
ant
}
function testfunctional {
killtestdbconnections
if [ $(lsof -t -i :9000) ]; then kill -9 $(lsof -t -i :9000); fi
cd eums/client
source ~/.virtualenvs/eums/bin/activate
if [ "$1" = "--headless" ]; then
grunt prep-test-env
python ../../manage.py runserver 9000 --settings=eums.settings_test &> /dev/null &
grunt functional-headless
elif [ "$1" = "--nomigrations" ]; then
grunt functional-nomigrations
elif [ "$1" = "--multi" ]; then
grunt functional --multi
else
grunt functional
fi
grunt build
cd -
}
function killdbconnections {
echo "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'eums' AND pid <> pg_backend_pid();" | psql -U postgres &> /dev/null
}
function killtestdbconnections {
echo "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'eums_test' AND pid <> pg_backend_pid();" | psql -U postgres &> /dev/null
}
function runserver {
cd eums/client
npm install
bower install
grunt build
cd -
pip install -r requirements.txt
./manage.py migrate
./manage.py setup_permissions
./manage.py runserver --settings=eums.settings_dev
}
function seed {
python manage.py loaddata eums/fixtures/sample-data.json
}
function setupmap {
cd ./scripts/setupmap
. ./setupmap.sh
}
function startcelery {
if [ "$1" = "prod" ]; then
export DJANGO_SETTINGS_MODULE="eums.settings_production"
else
export DJANGO_SETTINGS_MODULE="eums.settings_dev"
fi
celery worker -A eums -B --loglevel=INFO
}
main $@
exit 0