#!/usr/bin/make -f

include /usr/share/openstack-pkg-tools/pkgos.make

%:
	dh $@ --buildsystem=python_distutils --with python3

override_dh_clean:
	dh_clean
	rm -rf .coverage*

override_dh_auto_clean:
	python3 setup.py clean

override_dh_auto_build:
	echo "Do nothing..."

override_dh_auto_install:
	echo "Do nothing..."

override_dh_install:
	for i in $(PYTHON3S) ; do \
		python$$i setup.py install --install-layout=deb --root $(CURDIR)/debian/tmp ; \
	done


ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	for i in $(PYTHON3S) ; do \
		PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages \
			NOSE_WITH_OPENSTACK=1 \
			NOSE_OPENSTACK_COLOR=1 \
			NOSE_OPENSTACK_RED=0.05 \
			NOSE_OPENSTACK_YELLOW=0.025 \
			NOSE_OPENSTACK_SHOW_ELAPSED=1 \
			python$$i $(CURDIR)/manage.py test heat_dashboard.test -v 2 --settings=heat_dashboard.test.settings ; \
	done
endif

	# Activates the local_settings.d heat-dashboard plugin in Horizon
	mkdir -p $(CURDIR)/debian/tmp/usr/lib/python3/dist-packages/openstack_dashboard/local/local_settings.d
	cp $(CURDIR)/heat_dashboard/local_settings.d/_1699_orchestration_settings.py $(CURDIR)/debian/tmp/usr/lib/python3/dist-packages/openstack_dashboard/local/local_settings.d

	mkdir -p $(CURDIR)/debian/tmp/usr/share/openstack-dashboard/openstack_dashboard/local/local_settings.d
	cp $(CURDIR)/heat_dashboard/local_settings.d/_1699_orchestration_settings.py $(CURDIR)/debian/tmp/usr/share/openstack-dashboard/openstack_dashboard/local/local_settings.d

	# Copy the enabled files
	mkdir -p $(CURDIR)/debian/tmp/usr/lib/python3/dist-packages/openstack_dashboard/enabled
	cp -axuf heat_dashboard/enabled/_16* $(CURDIR)/debian/tmp/usr/lib/python3/dist-packages/openstack_dashboard/enabled

	mkdir -p $(CURDIR)/debian/tmp/usr/share/openstack-dashboard/openstack_dashboard/enabled
	cp -axuf heat_dashboard/enabled/_16* $(CURDIR)/debian/tmp/usr/share/openstack-dashboard/openstack_dashboard/enabled

	# Copy the static files of heat-dashboard into the folder served
	# as /$WEBROOT/static for the Horizon vhost
	mkdir -p $(CURDIR)/debian/tmp/usr/share/openstack-dashboard/openstack_dashboard/static
	cp -auxf heat_dashboard/static/dashboard $(CURDIR)/debian/tmp/usr/share/openstack-dashboard/openstack_dashboard/static

	dh_install
	dh_missing --fail-missing

	chmod -x $(CURDIR)/debian/python3-heat-dashboard/usr/lib/python3/dist-packages/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/img/icons/*.svg
	chmod -x $(CURDIR)/debian/python3-heat-dashboard/usr/share/openstack-dashboard/openstack_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/img/icons/*.svg

override_dh_auto_test:
	echo "Do nothing..."
