#!/usr/bin/make -f

export PYBUILD_NAME=zaqar

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

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

override_dh_clean:
	dh_clean
	rm -rf build \
		debian/zaqar-common.postinst \
		debian/zaqar-common.config \
		debian/zaqar-server.postinst \
		debian/zaqar-server.config \
		debian/*.service debian/*.init debian/*.upstart
	rm -rf debian/*.templates debian/po

override_dh_auto_build:
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func zaqar-common.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func zaqar-common.postinst
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func zaqar-server.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func zaqar-server.postinst
	pkgos-merge-templates zaqar-server zaqar endpoint
	pkgos-merge-templates zaqar-common zaqar rabbit ksat

override_dh_auto_test:
	echo "Do nothing..."

override_dh_auto_install:
	echo "Do nothing..."

override_dh_install:
	pkgos-dh_auto_install --no-py2

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	export ZAQAR_TESTS_CONFIGS_DIR=$(CURDIR)/zaqar/tests/etc ; pkgos-dh_auto_test --no-py2 'zaqar\.tests\.unit.(?!(.*transport\.websocket.*|.*transport\.wsgi.*|.*test_bootstrap\.TestBootstrap.*))'
	#(?!(.*transport\.websocket\.v2\.test_subscriptions\.SubscriptionTest\.test_subscription_sustainable_notifications_format.*|.*transport\.websocket\.v2\.test_messages\.MessagesBaseTest\.test_unsupported_json_1___overflow___9223372036854775808_.*|.*transport\.websocket\.v2\.test_subscriptions\.SubscriptionTest\.test_subscription_create.*))'
endif

	mkdir -p $(CURDIR)/debian/zaqar-common/usr/share/zaqar-common
	PYTHONPATH=$(CURDIR)/debian/python3-zaqar/usr/lib/python3/dist-packages oslo-config-generator \
		--output-file $(CURDIR)/debian/zaqar-common/usr/share/zaqar-common/zaqar.conf \
		--wrap-width 140 \
		--namespace zaqar.common.auth \
		--namespace zaqar.common.configs \
		--namespace zaqar.storage.pipeline \
		--namespace zaqar.storage.pooling \
		--namespace zaqar.storage.mongodb \
		--namespace zaqar.storage.redis \
		--namespace zaqar.storage.sqlalchemy \
		--namespace zaqar.storage.swift \
		--namespace zaqar.transport.wsgi \
		--namespace zaqar.transport.websocket \
		--namespace zaqar.transport.base \
		--namespace zaqar.transport.validation \
		--namespace keystonemiddleware.auth_token \
		--namespace oslo.cache \
		--namespace oslo.log \
		--namespace oslo.messaging \
		--namespace oslo.middleware.cors \
		--namespace osprofiler \
		--namespace oslo.policy \
		--namespace oslo.reports
	pkgos-readd-keystone-authtoken-missing-options $(CURDIR)/debian/zaqar-common/usr/share/zaqar-common/zaqar.conf keystone_authtoken zaqar

	PYTHONPATH=$(CURDIR)/debian/python3-zaqar/usr/lib/python3/dist-packages oslopolicy-sample-generator \
		--output-file $(CURDIR)/debian/zaqar-common/usr/share/zaqar-common/policy.json \
		--format json \
		--namespace zaqar

	dh_install
	dh_missing --fail-missing

	for i in zaqar-benchmark.conf logging.conf ; do \
		cp etc/$$i.sample $(CURDIR)/debian/zaqar-common/usr/share/zaqar-common/$$i ; \
	done
	cp etc/zaqar-benchmark-messages.json $(CURDIR)/debian/zaqar-common/usr/share/zaqar-common

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
