-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage.sh
executable file
·225 lines (186 loc) · 3.58 KB
/
manage.sh
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
#!/bin/bash
VENV_BIN=.venv/bin
TEST_SITE_DOMAIN='offshorecrawler-rss-feed.surge.sh'
TEST_SITE_BUILD_FOLDER='test-site-build'
_p () {
setup_env
python $@
}
# Operations on django
admin () {
setup_env
django-admin $@
}
cel () {
setup_env
celery $@
}
_heroku() {
remote=$1
args=("$@")
args=${args[@]:1}
heroku $args --remote $remote
}
# Usage: _django_heroku <git remote branch> <command args>
_django_heroku () {
remote=$1
args=("$@")
args=${args[@]:1}
heroku run python manage.py "${args}" --remote $remote
}
backup_heroku() {
remote=${1:-heroku}
heroku run python manage.py dumpdata \
--all --natural-primary --natural-foreign \
--exclude=auth \
--exclude=frontend \
--exclude=sessions \
--remote $remote \
-- > backup_heroku.json
}
django_heroku () {
_django_heroku heroku $@
}
django () {
setup_env
./crawler/manage.py $@
}
dj_test() {
django test $@ --settings=crawler.settings.test
}
test(){
dj_test crawler $@
}
shell() {
django shell
}
makemigrations () {
django makemigrations
}
migrate () {
django migrate
}
python_shell() {
setup_env
cd crawler
ipython
cd -
}
# VIRTUALENV FUNCTIONS
install_venv () {
pip3 install --user virtualenv
virtualenv -p python3 .venv
}
setup_env () {
if [ -f .env ]
then
echo ".env file found, sourcing it for environnement variables"
source .env
fi;
source .venv/bin/activate
}
install_python_deps () {
echo Installing python dependencies
pip install -r crawler/requirements.txt
}
update_requirements () {
setup_env
pip freeze > crawler/requirements.txt
}
pip () {
./$VENV_BIN/pip $@
}
remote_bundle () {
cd test-site
bundle $@
cd ..
}
# Operations on jekyll
jekyll () {
remote_bundle exec jekyll $@
}
install_ruby_deps () {
echo Installing ruby dependencies
# If bundle command doesn't exist we install the bundler gem
if ! type bundle > /dev/null; then
gem install bundler
fi
remote_bundle install
}
install () {
install_venv
setup_env
install_python_deps
install_ruby_deps
}
# Run crawler server locally
start_crawler () {
port=${1:-4000}
django runserver $port
}
# Run test site
start_test_site () {
port=${1:-5000}
jekyll serve --port $port
}
start_redis () {
port=${1:-3000}
redis-server --port $port
}
start_celery () {
setup_env
cd crawler
celery -A crawler worker -l debug -B -E
cd -
}
start () {
tmux new-session -d -s config './manage.sh start_crawler'
tmux split-window -v -t config './manage.sh start_redis'
tmux split-window -h -t config './manage.sh start_test_site'
tmux split-window -v -t config './manage.sh start_celery'
tmux -2 attach-session -t config
}
set(){
_h config:set $1=$2
}
get(){
_h config:get $1
}
_h(){
heroku $@ --remote heroku
}
# DEPLOY COMMANDS
# usage: deploy_heroku <remote-branche-name>
deploy_heroku () {
git subtree push --prefix crawler/ $1 master
}
build_test_site() {
jekyll build -d ../$TEST_SITE_BUILD_FOLDER $@
}
push_test_site() {
git add $TEST_SITE_BUILD_FOLDER
git commit -m "Update build"
git subtree push --prefix $TEST_SITE_BUILD_FOLDER pages gh-pages
}
deploy_test_site () {
build_test_site --baseurl "CrawlerToolkit/"
push_test_site
}
deploy () {
deploy_heroku heroku
}
# deploy to crawler-toolkit-staging remote.
deploy_staging () {
deploy_heroku heroku-staging
}
# Search in source files
sif(){
path="${2:-crawler/crawler/}"
grep -rn $path -e $1 --exclude=*.{pyc,swo,swn}
}
if [[ "$(type -t $@)" =~ .*function ]];
then
eval $(printf "%q " "$@")
else
echo "Function $@ not found, please check manage.sh file"
fi