PYTHON_SITELIB=/mingw64/lib/python2.7/site-packages
PYTHON_LIB=/mingw64/lib/python2.7

python_optimize() {
	local pyd

	for pyd in "${@:-${PYTHON_SITELIB}}"
	do
		if [ ! -d ${D}${pyd} ]
		then
			echo "Error: directory ${pyd} does not exist"
		fi

		echo "Compiling ${pyd}..."
		mingw64/bin/python2 ${PYTHON_LIB}/compileall.py -f -q -d ${pyd} ${D}${pyd}
		mingw64/bin/python2 -OO ${PYTHON_LIB}/compileall.py -f -q -d ${pyd} ${D}${pyd}
	done
}

post_install() {
  if test ! -f mingw64/etc/xml/catalog; then
    bin/mkdir -p mingw64/etc/xml
    mingw64/bin/xmlcatalog --noout --create mingw64/etc/xml/catalog
  fi

  if test -f mingw64/bin/python2.exe; then
    python_optimize
    rm -f ${PYTHON_SITELIB}/*.a
  fi
}

post_upgrade() {
	post_install
}
