#!/usr/bin/make -f

PYTHONS:=$(shell pyversions -vr)

include /usr/share/openstack-pkg-tools/pkgos.make
export OSLO_PACKAGE_VERSION=$(VERSION)

%:
	dh $@ --with python2

override_dh_auto_install:
	set -e && for pyvers in $(PYTHONS); do \
		python$$pyvers setup.py install \
			--install-layout=deb \
			--root $(CURDIR)/debian/python-django-horizon \
			--no-compile -O0; \
	done

	install -d -m 755  $(CURDIR)/debian/tmp/usr/share/openstack-dashboard
	install -d -m 755 $(CURDIR)/debian/tmp/etc/openstack-dashboard

	cp -a $(CURDIR)/openstack_dashboard/ $(CURDIR)/debian/tmp/usr/share/openstack-dashboard/

	# Sets memcached by default in local_settings.py
	cp $(CURDIR)/openstack_dashboard/local/local_settings.py.example \
		$(CURDIR)/debian/tmp/etc/openstack-dashboard/local_settings.py
	sed -i -e 's/SECRET_KEY = secret_key.generate_or_read_from_file(os.path.join(LOCAL_PATH,/SECRET_KEY = secret_key.generate_or_read_from_file(os.path.join("\/","var","lib","openstack-dashboard","secret-key",/' \
		$(CURDIR)/debian/tmp/etc/openstack-dashboard/local_settings.py
	echo "COMPRESS_OFFLINE=True" >> $(CURDIR)/debian/tmp/etc/openstack-dashboard/local_settings.py

	cp $(CURDIR)/manage.py \
		$(CURDIR)/debian/tmp/usr/share/openstack-dashboard/
	ln -fs /etc/openstack-dashboard/local_settings.py \
		$(CURDIR)/debian/tmp/usr/share/openstack-dashboard/openstack_dashboard/local/local_settings.py

override_dh_auto_clean:
	dh_auto_clean
	python setup.py clean
	rm -rf $(CURDIR)/static
	rm -rf $(CURDIR)/horizon/build
	rm -rf $(CURDIR)/horizon.egg-info
	rm -rf $(CURDIR)/openstack_dashboard/openstack_dashboard.egg-info
	rm -rf doc/source/sourcecode
	rm -rf $(CURDIR)/doc/build
	rm -f horizon/openstack_dashboard/test/.secret_key_store
	find $(CURDIR)/openstack_dashboard -iname '*.pyc' -delete

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	./run_tests.sh -N -P
endif
