#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1


DEB_PYTHON_SYSTEM=pysupport

#export DH_VERBOSE=1

%:
	dh $@

override_dh_auto_build:
	dh_auto_build
	python setup.py build_sphinx

get-orig-source:
	uscan --verbose --force-download --rename --destdir=../build-area

override_dh_install:
	dh_install
	chmod 440 $(CURDIR)/debian/nova-common/etc/sudoers.d/nova_sudoers

override_dh_fixperms:
	dh_fixperms -Xnova_sudoers

override_dh_auto_test:
	echo $(DEB_BUILD_OPTIONS) | grep nocheck || (python run_tests.py --redis_port=`debian/start-redis` ; kill `cat redis.pid`)

override_dh_installinit:
	dh_installinit --error-handler=true

refresh_bzr_patches:
	quilt pop -af ; \
	mv debian/patches debian/patches.old ; \
	mkdir debian/patches ; \
	bzr branch lp:nova testcheckout; \
	cd testcheckout; \
	while read url; \
	do \
		echo "Grabbing $$url" ; \
		bzr merge --force --preview "lp:~$$url" > ../debian/patches/$$(echo "$$url" | sed -e 's%/%_%g').patch ; \
		echo "$$url.patch -p0" | sed -e 's%/%_%g' >> ../debian/patches/series ; \
	done < ../debian/patch-branches ; \
	cd .. ; \
	quilt push -a ; \
	sed -i -e 's% -p0$%%%g' debian/patches/series ; \
	while true; \
	do \
	    quilt refresh; \
		if quilt pop 2>&1 | grep -q No.patch.removed; \
		then \
			break ;\
		fi ; \
	done ; \
	rm -rf testcheckout debian/patches.old
