forked from RaD/dishop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
418 lines (373 loc) · 15.3 KB
/
build.xml
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<project name="commentwin" default="help">
<property environment="sysenv"/>
<property file="project.user.properties"/>
<property file="project.properties"/>
<property name="build_to" value="${ant_build_dir}/${project_name}"/>
<import file="${basedir}/antfarm/macros.xml"/>
<import file="${basedir}/antfarm/db_mysql.xml"/>
<import file="${basedir}/property_processor.xml"/>
<record name="${project_name}.antlog.txt" action="start"/>
<condition property="windows">
<os family="windows"/>
</condition>
<condition property="unix">
<or>
<os family="unix"/>
<os family="linux"/>
</or>
</condition>
<target name="help">
<echo message="List available commands:"/>
<echo message=" init - initializes environment, downloads dependencies;"/>
<echo message=" update - update environment, downloads dependencies;"/>
<echo message=" configure - prepares configuration files;"/>
<echo message=" deploy - deployment the project;"/>
<echo message=" clean - removes trash and autogenerated files;"/>
<echo message=" dropenv - removes virtual environment."/>
<echo message=" --- "/>
<echo message=" db_init - initialize database;"/>
<echo message=" db_drop - drop database;"/>
<echo message=" db_imp -DF=file - drop database;"/>
<echo message=" db_exp -DF=file - drop database;"/>
<echo message=" --- "/>
<echo message=" testenv - initialize test environment;"/>
<echo message=" testrun - run test;"/>
<echo message=" testdrop - drop test environment;"/>
<echo message=" --- "/>
<echo message=" epydoc - generate project documentation;"/>
</target>
<target name="db_init" depends="configure">
<if>
<equals arg1="${db_engine}" arg2="mysql"/>
<then>
<mysql_run_sql_as_root path="${basedir}/conf" file="db_mysql_create.sql"/>
</then>
<else>
<echo message="Not implemented yet!"/>
</else>
</if>
</target>
<target name="db_drop" depends="configure">
<if>
<equals arg1="${db_engine}" arg2="mysql"/>
<then>
<mysql_run_sql_as_root path="${basedir}/conf" file="db_mysql_drop.sql"/>
</then>
<else>
<echo message="Not implemented yet!"/>
</else>
</if>
</target>
<target name="init">
<condition property="no_virtual_environment">
<not>
<available file="${basedir}/env/bin/activate" type="file"/>
</not>
</condition>
<if> <!-- ant-contrib -->
<isset property="no_virtual_environment"/>
<then>
<sequential>
<echo message="Initialize virtual environment for this project."/>
<exec executable="virtualenv" failonerror="true">
<arg line="${basedir}/env"/>
</exec>
<echo message="Install PIP into the virtual environment."/>
<if>
<equals arg1="${antfarm_quiet}" arg2="True"/>
<then>
<exec executable="${basedir}/env/bin/easy_install" failonerror="true">
<arg line="-q pip"/>
</exec>
</then>
<else>
<exec executable="${basedir}/env/bin/easy_install" failonerror="true">
<arg line="pip"/>
</exec>
</else>
</if>
<echo message="Source the virtual environment."/>
<property name="sysenv.PATH" value="${basedir}/env/lib/python${python_version}/site-packages:%{sysenv.PATH}"/>
<property name="sysenv.PYTHON_EGG_CACHE" value="${basedir}/env/.python-eggs:%{sysenv.PYTHON_EGG_CACHE}"/>
<echo message="Install dependencies into the virtual environment. Please wait..."/>
<if>
<equals arg1="${antfarm_quiet}" arg2="True"/>
<then>
<exec executable="${basedir}/env/bin/pip" failonerror="true">
<arg line="install -q -E ${basedir}/env -r ./deps.txt"/>
</exec>
</then>
<else>
<exec executable="${basedir}/env/bin/pip" failonerror="true">
<arg line="install -E ${basedir}/env -r ./deps.txt"/>
</exec>
</else>
</if>
<echo message="Source environment with: . ${basedir}/env/bin/activate"/>
<echo message="Use deactivate to disable virtual environment."/>
</sequential>
</then>
</if>
</target>
<target name="update">
<condition property="no_pip">
<not>
<available file="${basedir}/env/bin/pip" type="file"/>
</not>
</condition>
<if> <!-- ant-contrib -->
<isset property="no_pip"/>
<then>
<fail message="Please, initialize virtual environment first."/>
</then>
<else>
<sequential>
<echo message="Source the virtual environment."/>
<property name="sysenv.PATH" value="${basedir}/env/lib/python${python_version}/site-packages:%{sysenv.PATH}"/>
<property name="sysenv.PYTHON_EGG_CACHE" value="${basedir}/env/.python-eggs:%{sysenv.PYTHON_EGG_CACHE}"/>
<echo message="Update dependencies in the virtual environment. Please wait..."/>
<if>
<equals arg1="${antfarm_quiet}" arg2="True"/>
<then>
<exec executable="${basedir}/env/bin/pip" failonerror="true">
<arg line="install -q -E ${basedir}/env -r ./deps.txt"/>
</exec>
</then>
<else>
<exec executable="${basedir}/env/bin/pip" failonerror="true">
<arg line="install -E ${basedir}/env -r ./deps.txt"/>
</exec>
</else>
</if>
<echo message="Source environment with: . ${basedir}/env/bin/activate"/>
<echo message="Use deactivate to disable virtual environment."/>
</sequential>
</else>
</if>
</target>
<target name="configure">
<condition property="not_user_configuration">
<not>
<available file="${basedir}/project.user.properties" type="file"/>
</not>
</condition>
<if> <!-- ant-contrib -->
<isset property="not_user_configuration"/>
<then>
<copy file="${basedir}/tpls/project_user.template"
tofile="${basedir}/project.user.properties"
overwrite="false" encoding="utf-8"/>
<fail message="Please, edit your project.user.properties before any actions!"/>
</then>
</if>
<make_prop_file filename="${basedir}/${cumulative_config}"/>
<mkdir dir="${basedir}/conf/"/>
<parse_template src="${basedir}/tpls/logrotate.template"
dst="${basedir}/conf/django.logrotate"
params="${basedir}/${cumulative_config}"/>
<parse_template src="${basedir}/tpls/dump_sh.template"
dst="${basedir}/conf/dump.sh"
params="${basedir}/${cumulative_config}"/>
<parse_template src="${basedir}/tpls/search.template"
dst="${basedir}/conf/search.sh"
params="${basedir}/${cumulative_config}"/>
<parse_template src="${basedir}/tpls/httpd_vhosts.template"
dst="${basedir}/conf/httpd-vhosts.conf"
params="${basedir}/${cumulative_config}"/>
<parse_template src="${basedir}/tpls/django_wsgi.template"
dst="${basedir}/conf/django.wsgi"
params="${basedir}/${cumulative_config}"/>
<parse_template src="${basedir}/tpls/db_mysql_create.template"
dst="${basedir}/conf/db_mysql_create.sql"
params="${basedir}/${cumulative_config}"/>
<parse_template src="${basedir}/tpls/db_mysql_drop.template"
dst="${basedir}/conf/db_mysql_drop.sql"
params="${basedir}/${cumulative_config}"/>
<parse_template src="${basedir}/tpls/django_settings.template"
dst="${basedir}/src/settings.py"
params="${basedir}/${cumulative_config}"/>
<if>
<equals arg1="${db_engine}" arg2="django.db.backends.mysql"/>
<then>
<parse_template src="${basedir}/tpls/db_mysql_create.template"
dst="${basedir}/conf/db_mysql_create.sql"
params="${basedir}/${cumulative_config}"/>
<parse_template src="${basedir}/tpls/db_mysql_drop.template"
dst="${basedir}/conf/db_mysql_drop.sql"
params="${basedir}/${cumulative_config}"/>
</then>
</if>
<echo message="Create directories..."/>
<echo message="mkdir ${logging_dir}"/>
<!-- <mkdir dir="${logging_dir}"/> -->
</target>
<target name="genkey">
<condition property="no_gpg_db">
<not>
<available file="${gpg_homedir}/trustdb.gpg" type="file"/>
</not>
</condition>
<if> <!-- ant-contrib -->
<isset property="no_gpg_db"/>
<then>
<sequential>
<echo message="Create GPG directory..."/>
<mkdir dir="${gpg_homedir}"/>
<chmod file="${gpg_homedir}" type="dir" perm="700"/>
<echo message="Create GPG keys. This could take some time..."/>
<exec executable="gpg" failonerror="true">
<arg line="--homedir=${gpg_homedir} --batch --gen-key ./conf/gen_key.gpg"/>
</exec>
</sequential>
</then>
</if>
</target>
<target name="build">
<!--
<echo message="Compile i18n resources"/>
<exec executable="django-admin.py" dir="${basedir}/src" failonerror="true">
<arg value="compilemessages"/>
</exec>
//-->
<echo message="Install project into temporary directory"/>
<delete includeemptydirs="true" quiet="yes">
<fileset dir="${build_to}"/>
</delete>
<mkdir dir="${build_to}"/>
<copy todir="${build_to}" encoding="utf-8">
<fileset dir="${basedir}">
<include name="conf/**/*"/>
<include name="src/**/*"/>
<exclude name="src/static/"/>
<exclude name="src/haystack_index/"/>
<exclude name="src/media/"/>
<exclude name="src/database.sqlite"/>
<exclude name="src/**/*.sh"/>
<exclude name="src/**/*.bat"/>
<exclude name="src/**/*.po"/>
<exclude name="src/**/*.pyc"/>
<include name="DEPLOY*"/>
<include name="deps.txt"/>
</fileset>
</copy>
<echo message="Move collected static files into STATIC directory"/>
<move file="${build_to}/src/static_root" tofile="${build_to}/src/static"/>
<echo message="Compilation"/>
<apply dir="${build_to}" failonerror="true" executable="py_compilefiles" osfamily="unix">
<srcfile/>
<fileset dir="${build_to}">
<include name="src/**/*.py"/>
<exclude name="src/**/migrations/*.py"/>
<exclude name="src/**/commands/*.py"/>
</fileset>
</apply>
<echo message="Copy settings"/>
<copy file="${basedir}/src/settings.py"
tofile="${ant_build_dir}/${project_name}.settings"
overwrite="true" encoding="utf-8"/>
<echo message="Remove sources from distribution"/>
<delete verbose="true">
<fileset dir="${build_to}/" defaultexcludes="no">
<include name="src/**/*.py"/>
<exclude name="src/**/migrations/*.py"/>
<exclude name="src/**/commands/*.py"/>
</fileset>
</delete>
</target>
<target name="rsync">
<echo message="Rsync project using ${hosting_ssh}"/>
<exec executable="rsync" failonerror="true">
<arg value="--verbose"/>
<arg value="--recursive"/>
<arg value="--update"/>
<arg value="--rsh=ssh"/>
<arg value="${build_to}"/>
<arg value="${hosting_ssh}:${hosting_code_dir}/../"/>
</exec>
</target>
<target name="deploy">
<echo message="Deployment to ${hosting_ssh}"/>
<antcall target="clean"/>
<antcall target="configure"/>
<antcall target="build"/>
<antcall target="rsync"/>
<echo message="Restart web service manually!"/>
</target>
<target name="clean">
<delete verbose="true">
<fileset dir="." defaultexcludes="no">
<exclude name="env/**/*"/> <!-- environment -->
<include name="**/*~"/> <!-- emacs -->
<include name="**/*.pyc"/> <!-- python -->
</fileset>
</delete>
<delete file="${basedir}/${cumulative_config}" quiet="yes"/>
<delete file="${basedir}/src/settings.py" quiet="yes"/>
<delete file="${basedir}/pip-log.txt" quiet="yes"/>
<delete includeemptydirs="true" quiet="yes">
<fileset dir="conf"/>
</delete>
</target>
<target name="dropenv">
<delete dir="env" includeemptydirs="true" quiet="yes"/>
<delete file="${basedir}/distribute-0.6.10.tar.gz" quiet="yes"/>
</target>
<target name="testenv">
<condition property="no_test_environment">
<not>
<available file="${test_dir}/${test_gpg_file}" type="file"/>
</not>
</condition>
<if> <!-- ant-contrib -->
<isset property="no_test_environment"/>
<then>
<sequential>
<echo message="Initialize test environment."/>
<copy file="${basedir}/tpls/gpg_genkey.template"
tofile="${basedir}/conf/gen_key_test.gpg"
filtering="true" encoding="utf-8" overwrite="true">
<filterset begintoken="$${" endtoken="}">
<filter token="gpg_bits" value="${gpg_bits}"/>
<filter token="gpg_name_real" value="${test_gpg_name}"/>
<filter token="gpg_name_comment" value="${test_gpg_comment}"/>
<filter token="gpg_name_email" value="${test_gpg_email}"/>
<filter token="gpg_passphrase" value="${test_gpg_pass}"/>
</filterset>
</copy>
<echo message="Generate client GPG keyring at ${test_dir}/${test_gpg_homedir}"/>
<mkdir dir="${test_dir}/${test_gpg_homedir}"/>
<chmod file="${test_dir}/${test_gpg_homedir}" type="dir" perm="700"/>
<exec executable="gpg" failonerror="true">
<arg line="--homedir=${test_dir}/${test_gpg_homedir} --batch --gen-key ${basedir}/conf/gen_key_test.gpg"/>
</exec>
<echo message="Export public key into ${test_dir}/${test_gpg_file}"/>
<exec executable="python" failonerror="true">
<arg value="-c"/>
<arg value="import gnupg; g = gnupg.GPG(gnupghome='${test_dir}/${test_gpg_homedir}'); l = g.list_keys(); open('${test_dir}/${test_gpg_file}', 'w').write(g.export_keys(l[0]['keyid']))"/>
</exec>
</sequential>
</then>
</if>
</target>
<target name="testrun">
<echo message="Run tests."/>
<exec executable="python" dir="${basedir}/src" failonerror="true">
<arg value="manage.py"/>
<arg value="test"/>
<arg value="profile"/>
</exec>
</target>
<target name="testdrop">
<delete dir="${test_dir}/${test_gpg_homedir}" includeemptydirs="true" quiet="yes"/>
<delete file="${test_dir}/${test_gpg_file}" quiet="yes"/>
</target>
<target name="epydoc">
<echo message="Generate project documentation"/>
<delete dir="${basedir}/epydoc" includeemptydirs="true" quiet="yes"/>
<exec dir="${basedir}/src" failonerror="true" executable="epydoc" error="/dev/null" osfamily="unix">
<arg line="--quiet --html -o ${basedir}/epydoc --graph all **/*.py"/>
<env key="PYTHONPATH" value="${basedir}/env/lib/python${python_version}/site-packages:${env.PATH}"/>
</exec>
</target>
</project>