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
|
SHELL := /bin/bash
NB_PROCESS=8
# if a virtualenv is used put the full python path
# e.g.: PYTHON=$$HOME/.virtualenvs/ishtar/bin/python
PYTHON=python3
TMP='/tmp/tmp-ishtar'
export PATH := $(HOME)/bin/geckodriver:$(PATH)
# put name of your current project
project=example_project
# list used apps
apps="archaeological_operations" "ishtar_common" "archaeological_context_records" "archaeological_files" "archaeological_finds" "archaeological_warehouse"
default_data='fr'
version=`head -n 1 version.py | cut -d' ' -f2`
branch_name=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"`
BRANCH_NAME := $(shell git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/")
## Check dependencies
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Cleanup
clean: ## remove temporary files
-rm -rf *~*
-find . -name '*.pyc' -exec rm {} \;
-find . -name '.*.swp' -exec rm {} \;
-find . -name '__pycache__' -exec rm -rf {} \; 2> /dev/null
-rm -rf dist ishtar.egg-info
##@ General management
update: clean syncdb compilemessages collectstatic ## update the instance
migrations: ## generate database migrations
cd $(project);\
for APP in "overload_translation" $(apps); do \
echo "* makemigrations for "$$APP; \
$(PYTHON) ./manage.py makemigrations $$APP; \
done
migrate: ## migrate database
cd $(project); $(PYTHON) manage.py migrate
collectstatic: ## collect all static files
cd $(project);$(PYTHON) manage.py collectstatic --noinput
makemessages: ## generate translation messages
cd $(CURDIR); \
$(PYTHON) $(project)/manage.py makemessages --all; \
#msgfilter -i locale/fr/LC_MESSAGES/django.po sed -e d | sed -e "s/fuzzy//g" > locale/django.pot ;\
compilemessages: ## compile translations
cd $(CURDIR); \
$(PYTHON) $(project)/manage.py compilemessages; \
build_doc_values:
cd $(project);\
echo 'exec(open("../docs/generate_values_doc.py").read())' | $(PYTHON) ./manage.py shell
build_doc_model_graph:
cd $(project);\
echo 'exec(open("../docs/generate_values_doc.py").read())' | $(PYTHON) ./manage.py shell
cd $(project);\
$(PYTHON) manage.py graph_models --pydot -g -I "ImporterModel,ImporterType,ImporterDefault,ImporterDefaultValues,ImporterColumn,Regexp,ImportTarget,FormaterType,Import" ishtar_common > /tmp/ishtar-imports.dot ;\
dot -Tsvg /tmp/ishtar-imports.dot -o ../docs/source/_static/db-imports.svg
rm /tmp/ishtar-imports.dot
cd $(project);\
for APP in $(apps); do \
$(PYTHON) manage.py graph_models -g --pydot $$APP > /tmp/ishtar-$$APP.dot; \
dot -Tsvg /tmp/ishtar-$$APP.dot -o ../docs/source/_static/db-$$APP.svg; \
rm /tmp/ishtar-$$APP.dot ; \
done
build_doc_changelog:
mkdir -p docs/changelog/build/
cp -r docs/changelog/css docs/changelog/build/
cp -r docs/changelog/img docs/changelog/build/
# generate menu
rm -f $(TMP)-menu $(TMP)-menu-base.md
touch $(TMP)-menu $(TMP)-menu-base.md
echo "# Ishtar - changelog " >> $(TMP)-menu ; \
echo "# Ishtar - changelog " >> $(TMP)-menu-base.md ; \
for LANG in `ls changelog`; do \
echo "- $$LANG: " >> $(TMP)-menu ; \
echo "- $$LANG: " >> $(TMP)-menu-base.md ; \
for FILE in `ls -r changelog/$$LANG`; do \
EXTFILE="$${FILE%%.*}" ; \
DATE="$${EXTFILE##*_}" ; \
echo "[$$DATE](../$$LANG/$$EXTFILE.html) ; " >> $(TMP)-menu ; \
echo "[$$DATE]($$LANG/$$EXTFILE.html) ; " >> $(TMP)-menu-base.md ; \
done ;\
done
echo "" >> $(TMP)-menu ; \
echo "---" >> $(TMP)-menu ; \
echo "" >> $(TMP)-menu ; \
pandoc --metadata title="Ishtar - changelog" --standalone --template docs/changelog/template.html $(TMP)-menu-base.md > docs/changelog/build/changelog.html ; \
# generate changelog
for LANG in `ls changelog`; do \
mkdir -p docs/changelog/build/$$LANG ; \
ln -s ../img img ; mv img docs/changelog/build/$$LANG/ ; \
ln -s ../css css ; mv css docs/changelog/build/$$LANG/ ; \
for FILE in `ls changelog/$$LANG`; do \
cp $(TMP)-menu $(TMP).md ; \
FILE="$${FILE%%.*}" ; \
cat "changelog/$$LANG/$$FILE.md" >> $(TMP).md ; \
pandoc --metadata title="Ishtar - changelog" --standalone --template docs/changelog/template.html $(TMP).md > docs/changelog/build/$$LANG/$$FILE.html ; \
done ;\
done
build_doc: build_doc_values build_doc_model_graph build_doc_changelog ## generate documentation
##@ Development: tests
test: clean ## launch tests
cd $(project); $(PYTHON) manage.py test $(apps)
soft_test: clean ## launch tests without database regeneration
cd $(project); $(PYTHON) manage.py test -k --tag gis --exclude-tag ui --exclude-tag libreoffice $(apps)
cd $(project); $(PYTHON) manage.py test -k --exclude-tag gis --exclude-tag ui $(apps)
soft_test_verbose: clean ## launch tests without database regeneration - verbose
cd $(project); $(PYTHON) manage.py test -k --verbosity 2 $(apps)
soft_test_multi: clean ## launch multi-process tests without database regeneration
cd $(project); $(PYTHON) manage.py test -k --parallel $(NB_PROCESS) --exclude-tag libreoffice --exclude-tag ui --tag gis $(apps)
cd $(project); $(PYTHON) manage.py test -k --parallel $(NB_PROCESS) --exclude-tag libreoffice --exclude-tag ui --exclude-tag gis $(apps)
test_ui: clean ## launch tests for UI
cd $(project); $(PYTHON) manage.py test --tag ui $(apps)
soft_test_ui: clean ## launch soft tests for UI
cd $(project); $(PYTHON) manage.py test -k --tag ui $(apps)
build_gitlab: clean collectstatic makemessages ## specific build for gitlab
cd $(project); $(PYTHON) ./manage.py migrate
test_gitlab: clean collectstatic makemessages ## specific test for gitlab
cd $(project); $(PYTHON) manage.py test --exclude-tag no_ci --exclude-tag gis --exclude-tag ui --exclude-tag libreoffice $(apps)
soft_test_gitlab: build_gitlab ## run test for gitlab - do not erase previous database
cd $(project); $(PYTHON) manage.py -k test $(apps)
run_libreoffice: ## run libreoffice daemon for testing purpose
/usr/bin/libreoffice --headless --accept="socket,host=127.0.0.1,port=8101;urp;" --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --invisible --pidfile=/var/run/libreoffice.pid
##@ Development: checks
coverage: clean ## launch test coverage
cd $(project); coverage run --source="ishtar_common,archaeological_operations,\
archaeological_context_records,archaeological_files,archaeological_finds,archaeological_warehouse"\
./manage.py test $(apps) && coverage report -m > ../coverage/result-`date '+%Y-%m-%d-%H%M'`
soft_coverage: clean ## launch test coverage (no db reinit)
cd $(project); coverage run --rcfile=../.coveragerc --source="ishtar_common,archaeological_operations,\
archaeological_context_records,archaeological_files,archaeological_finds,archaeological_warehouse"\
./manage.py test -k $(apps) && coverage report -m > ../coverage/result-`date '+%Y-%m-%d-%H%M'`
pep8:
pep8 --filename=*.py --ignore=W --exclude="manage.py,settings.py,migrations" --statistics --repeat .
pylint:
for DIR in $(apps); do \
pylint "$(CURDIR)/$$DIR" --ignore=.git,migrations --max-public-methods=50 --ignored-classes=Item.Meta --method-rgx='[a-z_][a-z0-9_]{2,40}$$'; \
done
bandit: ## audit for security with bandit tool
bandit -r -s B322 -n 3 ishtar_common/ archaeological_context_records/ archaeological_files archaeological_finds/ archaeological_operations/ archaeological_warehouse/ example_project/
bandit_no_marksafe: ## audit for security with bandit tool
bandit -r -s B322,B308,B703 -n 3 ishtar_common/ archaeological_context_records/ archaeological_files archaeological_finds/ archaeological_operations/ archaeological_warehouse/ example_project/
##@ Development: run
shell: ## launch shell
cd $(project);$(PYTHON) manage.py shell
run: ## run test server
cd $(project); $(PYTHON) manage.py runserver 0.0.0.0:8000
runalt: ## run test server on port 9000
cd $(project); $(PYTHON) manage.py runserver 0.0.0.0:9000
runcelery: ## run a celery worker
celery -A example_project worker -l INFO # -l DEBUG -f debug-celery.log
blackd: ## blackd service
$(VENV)bin/blackd
##@ Manage fixtures
fixtures: fixtures_auth fixtures_common fixtures_operations fixtures_context_records fixtures_finds fixtures_warehouse fixtures_files
fixtures_auth:
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
auth.permission auth.group \
> '../fixtures/initial_data-auth-'$(default_data)'.json'
fixtures_common: fixtures_common_importers fixtures_geo
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
ishtar_common.authortype \
ishtar_common.profiletype \
ishtar_common.persontype \
ishtar_common.organizationtype \
ishtar_common.sourcetype \
ishtar_common.operationtype \
ishtar_common.titletype \
ishtar_common.supporttype \
ishtar_common.format \
ishtar_common.language \
ishtar_common.documenttag \
ishtar_common.documenttemplate \
ishtar_common.geoorigintype \
ishtar_common.geodatatype \
ishtar_common.geoprovidertype
> '../ishtar_common/fixtures/initial_data-'$(default_data)'.json'
fixtures_common_importers:
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
ishtar_common.importermodel \
ishtar_common.documenttemplate \
ishtar_common.importertype \
ishtar_common.regexp \
ishtar_common.valueformater \
ishtar_common.importerdefault \
ishtar_common.importerdefaultvalues \
ishtar_common.importercolumn \
ishtar_common.importtarget \
ishtar_common.formatertype \
ishtar_common.importerduplicatefield \
> '../ishtar_common/fixtures/initial_importtypes-'$(default_data)'.json'
fixtures_common_towns:
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
ishtar_common.state \
ishtar_common.department \
ishtar_common.town \
ishtar_common.area \
> '../ishtar_common/fixtures/towns-'$(default_data)'.json'
cat 'ishtar_common/fixtures/towns-'$(default_data)'.json' | tr '\n' '\r' | \
sed -e 's/"children": *\[\r *\[\r *"[0-9-]*", *\r *[0-9]*\ *\r *\]\r *\]/"children": []/g' | \
tr '\r' '\n' > 'ishtar_common/fixtures/towns_norel-'$(default_data)'.json'
fixtures_geo:
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
ishtar_common.spatialreferencesystem \
ishtar_common.geobuffertype \
ishtar_common.geoorigintype \
ishtar_common.geodatatype \
ishtar_common.geoprovidertype \
> '../ishtar_common/fixtures/initial_geo-'$(default_data)'.json'
fixtures_operations:
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
archaeological_operations.acttype \
archaeological_operations.period \
archaeological_operations.remaintype \
archaeological_operations.reportstate \
archaeological_operations.recordqualitytype \
> '../archaeological_operations/fixtures/initial_data-'$(default_data)'.json'
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
archaeological_operations.relationtype \
> '../archaeological_operations/fixtures/initial_data_relation_type-'$(default_data)'.json'
cat archaeological_operations/fixtures/initial_data_relation_type-$(default_data).json | tr '\n' '\r' | \
sed -e 's/"inverse_relation": *\[\r *\"[-_a-z0-9]*\" *\r *\]/"inverse_relation": null/g' | \
tr '\r' '\n' > archaeological_operations/fixtures/initial_data_relation_type_norel-'$(default_data)'.json
fixtures_context_records:
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
archaeological_context_records.datingquality \
archaeological_context_records.activitytype \
archaeological_context_records.identificationtype \
archaeological_context_records.unit \
archaeological_context_records.datingtype \
archaeological_context_records.excavationtechnictype \
archaeological_context_records.documentationtype \
> '../archaeological_context_records/fixtures/initial_data-'$(default_data)'.json'
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
archaeological_context_records.relationtype \
> '../archaeological_context_records/fixtures/initial_data_relation_type-'$(default_data)'.json'
cat archaeological_context_records/fixtures/initial_data_relation_type-$(default_data).json | tr '\n' '\r' | \
sed -e 's/"inverse_relation": *\[\r *\"[-_a-z0-9]*\" *\r *\]/"inverse_relation": null/g' | \
tr '\r' '\n' > archaeological_context_records/fixtures/initial_data_relation_type_norel-'$(default_data)'.json
fixtures_finds:
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
archaeological_finds.materialtype \
archaeological_finds.materialtypequalitytype \
archaeological_finds.treatmenttype \
archaeological_finds.treatmentstate \
archaeological_finds.conservatorystate \
archaeological_finds.remarkabilitytype \
archaeological_finds.objecttype \
archaeological_finds.objecttypequalitytype \
archaeological_finds.integritytype \
archaeological_finds.batchtype \
archaeological_finds.checkedtype \
archaeological_finds.treatmentfiletype \
archaeological_finds.checkedtype \
> '../archaeological_finds/fixtures/initial_data-'$(default_data)'.json'
fixtures_warehouse:
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
archaeological_warehouse.containertype \
archaeological_warehouse.warehousetype \
archaeological_warehouse.warehousedivision \
> '../archaeological_warehouse/fixtures/initial_data-'$(default_data)'.json'
fixtures_files:
cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 --natural-primary --natural-foreign \
archaeological_files.saisinetype \
archaeological_files.filetype \
archaeological_files.permittype \
archaeological_files.priceagreement \
archaeological_files.job \
archaeological_files.genericequipmentservicetype \
archaeological_files.equipmentservicetype \
archaeological_files.equipmentservicecost \
archaeological_files.operationtypeforroyalties \
archaeological_files.agreementtype \
> '../archaeological_files/fixtures/initial_data-'$(default_data)'.json'
readme_md_to_rst:
pandoc --from=markdown --to=rst --output=README.rst README.md
sdist: clean
$(PYTHON) setup.py sdist
distribute_test: sdist
twine upload -r pypitest dist/*
rm -rf ishtar.egg-info
distribute_main: sdist
twine upload -r pypi dist/*
rm -rf ishtar.egg-info
deb: clean
debuild -i -us -uc -b
push_install: clean
INSTALL_PATH=/var/www/ishtar/install/ ; \
ARCHIVE_NAME=install-ishtar-$(version).tar.bz2 ; \
tar cvjf $$ARCHIVE_NAME install/ ; \
scp $$ARCHIVE_NAME root@git.iggdrasil.net:$$INSTALL_PATH ; \
rm $$ARCHIVE_NAME ;
#ifeq ($(BRANCH_NAME),main) \
# ssh root@git rm $$INSTALL_PATH"install-ishtar-latest.tar.bz2" ; \
# ssh root@git ln -s $$INSTALL_PATH$$ARCHIVE_NAME $$INSTALL_PATH"install-ishtar-latest.tar.bz2" ;\
#endif \
#ifeq ($(BRANCH_NAME),develop) \
# ssh root@git rm $$INSTALL_PATH"install-ishtar-develop.tar.bz2" ; \
# ssh root@git ln -s $$INSTALL_PATH$$ARCHIVE_NAME $$INSTALL_PATH"install-ishtar-develop.tar.bz2" ;\
#endif
sass:
sassc scss/custom.scss -t compressed > ishtar_common/static/bootstrap/bootstrap.css
sass_watch:
./node_modules/node-sass/bin/node-sass --watch scss/custom.scss --output-style compressed > ishtar_common/static/bootstrap/bootstrap.css
|