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\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 test -k --exclude-tag no_ci --exclude-tag gis --exclude-tag ui --exclude-tag libreoffice $(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