VENV = .venv
ifdef NOSE_HTML_FILE
	# This is needed because NOSE_HTML_FILE isn't a valid env variable for nose-htmloutput
	FILE_ARGUMENT=--html-file="$(NOSE_HTML_FILE)"
endif

venv: venv/bin/activate
venv/bin/activate: requirements.txt
	test -d $(VENV) || virtualenv $(VENV)
	$(VENV)/bin/pip install -Ur requirements.txt
	touch $(VENV)/bin/activate

test: venv
	source $(VENV)/bin/activate; \
	nosetests -x -s --logging-level=CRITICAL --with-xunit --with-html $(FILE_ARGUMENT)

testw: venv
	watchmedo shell-command \
		--patterns="*.py;*.txt" \
		--recursive \
		--command='clear; make test' \
		.

login:
	cd login; rm -Rf .build; make build
	rm -Rf www/login
	cp -Rf login/.build www/login
	# Replace resource paths in source
	cd www/login; find . -type f  -name '*.html' -print0 | xargs -0 sed -i '' 's#/assets/static/#/_server/login/assets/static/#g'
	cd www/login; find . -type f  -name '*.css' -print0 | xargs -0 sed -i '' 's#/assets/static/#/_server/login/assets/static/#g'

.PHONY: test login
