#!/usr/bin/make -f

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

export PYBUILD_NAME=watcher-dashboard

export OSLO_PACKAGE_VERSION=$(shell dpkg-parsechangelog | grep Version: | cut -d' ' -f2 | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~/.0/' | head -n 1)

DEB_VERSION := $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
DEB_NOEPOCH_VERSION := $(shell echo $(DEB_VERSION) | cut -d: -f2-)
DEB_UPSTREAM_VERSION := $(shell echo $(DEB_NOEPOCH_VERSION) | sed 's/-[^-]*$$//')

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

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	PYTHONPATH=$(CURDIR) \
		NOSE_WITH_OPENSTACK=1 \
		NOSE_OPENSTACK_COLOR=1 \
		NOSE_OPENSTACK_RED=0.05 \
		NOSE_OPENSTACK_YELLOW=0.025 \
		NOSE_OPENSTACK_SHOW_ELAPSED=1 \
		python3 $(CURDIR)/manage.py test -v 2 \
			--settings=watcher_dashboard.test.settings \
			--exclude-tag integration \
			watcher_dashboard ;
endif

override_dh_clean:
	dh_clean
	rm -rf .coverage*

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2

	# Activates the watcher_dashboard plugin in Horizon
	mkdir -p $(CURDIR)/debian/python3-watcher-dashboard/usr/lib/python3/dist-packages/openstack_dashboard/enabled
	cp $(CURDIR)/watcher_dashboard/local/enabled/_31*.py $(CURDIR)/debian/python3-watcher-dashboard/usr/lib/python3/dist-packages/openstack_dashboard/enabled

	# Install common files
	mkdir -p $(CURDIR)/debian/python3-watcher-dashboard/usr/lib/python3/dist-packages/openstack_dashboard/conf
	cp $(CURDIR)/watcher_dashboard/conf/* $(CURDIR)/debian/python3-watcher-dashboard/usr/lib/python3/dist-packages/openstack_dashboard/conf
