#! /bin/sh -e

if [ "$1" = configure ]; then
    (
    files=$(dpkg -L @PVER@ | sed -n '/^\/usr\/lib\/@PVER@\/.*\.py$/p')
	@PVER@ /usr/lib/@PVER@/py_compile.py $files
	if grep -sq '^byte-compile[^#]*optimize' /etc/python/debian_config; then
	    @PVER@ -O /usr/lib/@PVER@/py_compile.py $files
	fi
    )
fi

oldlocalsite=/usr/local/lib/@PVER@/site-packages
case "$1" in
    configure|abort-upgrade|abort-remove|abort-deconfigure)
	# issue #623057
	if [ -d $oldlocalsite -a ! -h $oldlocalsite ]; then
	    rmdir --ignore-fail-on-non-empty $oldlocalsite 2>/dev/null || true
	fi
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

#DEBHELPER#

exit 0
