The patch for distutils.eclass is divided into 2 subpatches:
Subpatch #1 fixes a typo in a regular expression and removes needless '/' 
characters.
Subpatch #2 replaces checks for SUPPORT_PYTHON_ABIS variable with more portable 
calls
to _python_package_supporting_installation_for_multiple_python_abis() function.

The patch for twisted.eclass is divided into 3 subpatches:
Subpatch #1 updates comments, removes inheriting of unused eclass, removes 
exporting of
twisted_src_test() for packages other than dev-python/twisted* (this function 
is intended
only for dev-python/twisted*), removes needless MY_VERSION variable and causes 
that some
variables are set only for dev-python/twisted* (the values of these variables 
are incorrect
for other packages).
Subpatch #2 removes support for <=dev-python/twisted*-8.2.0 (removed from the 
tree over
9 months ago) in twisted_src_test(), adds sanity check about package name to 
twisted_src_test()
and cleans twisted_src_test().
Subpatch #3 fixes some bugs in twisted_pkg_postrm() and twisted_pkg_postinst():
 - Bug #258698:    Addition of support for TWISTED_PLUGINS variable. Default 
value is "twisted.plugins"
                   for dev-python/twisted* and unset for other packages. This 
variable will also allow
                   to easily fix bug #329313 (dev-python/axiom, 
dev-python/mantissa, dev-python/nevow).
                   E.g. dev-python/mantissa will set 
TWISTED_PLUGINS="axiom.plugins nevow.plugins xmantissa.plugins".
 - Bug #327111:    ImportErrors during uninstallation will be ignored.
 - Unreported bug: dropin.cache files will be created in "${EROOT}" instead of 
"/".
 - Unreported bug: dropin.cache files of dev-python/axiom, dev-python/mantissa 
and dev-python/nevow
                   won't be left after uninstallation.
 - Unreported bug: Empty directories won't be left after uninstallation.
 - Unreported bug: Uninstallation won't fail after uninstallation of given 
version of Python.

I'm plannning to commit these patches in 1 week, or earlier if they are 
reviewed earlier.

-- 
Arfrever Frehtes Taifersar Arahesis
--- distutils.eclass
+++ distutils.eclass
@@ -97,7 +97,7 @@
 # Additional documentation files installed by distutils_src_install().
 
 _distutils_get_build_dir() {
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" && -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
+	if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
 		echo "build-${PYTHON_ABI}"
 	else
 		echo "build"
@@ -105,7 +105,7 @@
 }
 
 _distutils_get_PYTHONPATH() {
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" && -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
+	if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
 		ls -d build-${PYTHON_ABI}/lib* 2> /dev/null
 	else
 		ls -d build/lib* 2> /dev/null
@@ -180,7 +180,7 @@
 
 	_python_set_color_variables
 
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+	if _python_package_supporting_installation_for_multiple_python_abis; then
 		distutils_building() {
 			_distutils_hook pre
 
@@ -207,7 +207,7 @@
 		die "${FUNCNAME}() requires 1 arguments"
 	fi
 
-	if [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
+	if ! _python_package_supporting_installation_for_multiple_python_abis; then
 		return
 	fi
 
@@ -237,7 +237,7 @@
 	_python_set_color_variables
 
 	if [[ "${DISTUTILS_SRC_TEST}" == "setup.py" ]]; then
-		if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+		if _python_package_supporting_installation_for_multiple_python_abis; then
 			distutils_testing() {
 				_distutils_hook pre
 
@@ -297,7 +297,7 @@
 	_python_initialize_prefix_variables
 	_python_set_color_variables
 
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+	if _python_package_supporting_installation_for_multiple_python_abis; then
 		if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge 4 ]]; then
 			declare -A wrapper_scripts=()
 
@@ -307,7 +307,7 @@
 
 					local nonversioned_file file
 					for file in *; do
-						if [[ -f "${file}" && ! "${file}" =~ [[:digit:]]+\.[[:digit:]](-jython)?+$ && "$(head -n1 "${file}")" =~ ^'#!'.*(python|jython-)[[:digit:]]+\.[[:digit:]]+ ]]; then
+						if [[ -f "${file}" && ! "${file}" =~ [[:digit:]]+\.[[:digit:]]+(-jython)?$ && "$(head -n1 "${file}")" =~ ^'#!'.*(python|jython-)[[:digit:]]+\.[[:digit:]]+ ]]; then
 							for nonversioned_file in "${distutils_nonversioned_python_scrip...@]}"; do
 								[[ "${nonversioned_file}" == "/usr/bin/${file}" ]] && continue 2
 							done
@@ -383,7 +383,7 @@
 
 	local pylibdir pymod
 	if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
-		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"/usr/share/jython-*/Lib; do
+		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
 			if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
 				PYTHON_MODNAME="${PN}"
 			fi
@@ -391,7 +391,7 @@
 	fi
 
 	if [[ -n "${PYTHON_MODNAME}" ]]; then
-		if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+		if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 			python_mod_optimize ${PYTHON_MODNAME}
 		else
 			for pymod in ${PYTHON_MODNAME}; do
@@ -416,7 +416,7 @@
 
 	local pylibdir pymod
 	if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
-		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"/usr/share/jython-*/Lib; do
+		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
 			if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
 				PYTHON_MODNAME="${PN}"
 			fi
@@ -424,7 +424,7 @@
 	fi
 
 	if [[ -n "${PYTHON_MODNAME}" ]]; then
-		if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+		if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 			python_mod_cleanup ${PYTHON_MODNAME}
 		else
 			for pymod in ${PYTHON_MODNAME}; do
--- distutils.eclass
+++ distutils.eclass
@@ -307,7 +307,7 @@
 
 					local nonversioned_file file
 					for file in *; do
-						if [[ -f "${file}" && ! "${file}" =~ [[:digit:]]+\.[[:digit:]](-jython)?+$ && "$(head -n1 "${file}")" =~ ^'#!'.*(python|jython-)[[:digit:]]+\.[[:digit:]]+ ]]; then
+						if [[ -f "${file}" && ! "${file}" =~ [[:digit:]]+\.[[:digit:]]+(-jython)?$ && "$(head -n1 "${file}")" =~ ^'#!'.*(python|jython-)[[:digit:]]+\.[[:digit:]]+ ]]; then
 							for nonversioned_file in "${distutils_nonversioned_python_scrip...@]}"; do
 								[[ "${nonversioned_file}" == "/usr/bin/${file}" ]] && continue 2
 							done
@@ -383,7 +383,7 @@
 
 	local pylibdir pymod
 	if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
-		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"/usr/share/jython-*/Lib; do
+		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
 			if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
 				PYTHON_MODNAME="${PN}"
 			fi
@@ -416,7 +416,7 @@
 
 	local pylibdir pymod
 	if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
-		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"/usr/share/jython-*/Lib; do
+		for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
 			if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
 				PYTHON_MODNAME="${PN}"
 			fi
--- distutils.eclass
+++ distutils.eclass
@@ -97,7 +97,7 @@
 # Additional documentation files installed by distutils_src_install().
 
 _distutils_get_build_dir() {
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" && -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
+	if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
 		echo "build-${PYTHON_ABI}"
 	else
 		echo "build"
@@ -105,7 +105,7 @@
 }
 
 _distutils_get_PYTHONPATH() {
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" && -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
+	if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
 		ls -d build-${PYTHON_ABI}/lib* 2> /dev/null
 	else
 		ls -d build/lib* 2> /dev/null
@@ -180,7 +180,7 @@
 
 	_python_set_color_variables
 
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+	if _python_package_supporting_installation_for_multiple_python_abis; then
 		distutils_building() {
 			_distutils_hook pre
 
@@ -207,7 +207,7 @@
 		die "${FUNCNAME}() requires 1 arguments"
 	fi
 
-	if [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
+	if ! _python_package_supporting_installation_for_multiple_python_abis; then
 		return
 	fi
 
@@ -237,7 +237,7 @@
 	_python_set_color_variables
 
 	if [[ "${DISTUTILS_SRC_TEST}" == "setup.py" ]]; then
-		if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+		if _python_package_supporting_installation_for_multiple_python_abis; then
 			distutils_testing() {
 				_distutils_hook pre
 
@@ -297,7 +297,7 @@
 	_python_initialize_prefix_variables
 	_python_set_color_variables
 
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+	if _python_package_supporting_installation_for_multiple_python_abis; then
 		if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge 4 ]]; then
 			declare -A wrapper_scripts=()
 
@@ -391,7 +391,7 @@
 	fi
 
 	if [[ -n "${PYTHON_MODNAME}" ]]; then
-		if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+		if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 			python_mod_optimize ${PYTHON_MODNAME}
 		else
 			for pymod in ${PYTHON_MODNAME}; do
@@ -424,7 +424,7 @@
 	fi
 
 	if [[ -n "${PYTHON_MODNAME}" ]]; then
-		if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+		if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 			python_mod_cleanup ${PYTHON_MODNAME}
 		else
 			for pymod in ${PYTHON_MODNAME}; do
--- twisted.eclass
+++ twisted.eclass
@@ -1,78 +1,67 @@
-# Copyright 2005 Gentoo Foundation
+# Copyright 2005-2010 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License, v2 or later
 # $Header: /var/cvsroot/gentoo-x86/eclass/twisted.eclass,v 1.7 2009/10/30 13:14:17 arfrever Exp $
-#
-# Author: Marien Zwart <mari...@gentoo.org>
-#
-# eclass to aid installing and testing twisted packages.
-#
-# you should set MY_PACKAGE to something like 'Names' before inheriting.
-# you may set MY_PV to the right version (defaults to PV).
-#
-# twisted_src_test relies on the package installing twisted.names to
-# have a ${PN} of twisted-names.
-
-inherit distutils eutils versionator
-
-MY_PV="${MY_PV:-${PV}}"
-MY_VERSION="$(get_version_component_range 1-2 ${MY_PV})"
-MY_P="Twisted${MY_PACKAGE}-${MY_PV}"
-
-HOMEPAGE="http://www.twistedmatrix.com/";
-SRC_URI="http://tmrc.mit.edu/mirror/twisted/${MY_PACKAGE}/${MY_VERSION}/${MY_P}.tar.bz2";
-
-LICENSE="MIT"
-SLOT="0"
-IUSE=""
 
-S="${WORKDIR}/${MY_P}"
+# @ECLASS: twisted.eclass
+# @MAINTAINER:
+# Gentoo Python Project <pyt...@gentoo.org>
+# @BLURB: Eclass for Twisted packages
+# @DESCRIPTION:
+# The twisted eclass defines phase functions for Twisted packages.
+
+# The following variables can be set in dev-python/twisted* packages before inheriting this eclass:
+#   MY_PACKAGE - Package name suffix (required)
+#   MY_PV      - Package version (optional)
+
+inherit distutils versionator
+
+EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
+
+if [[ "${CATEGORY}/${PN}" == "dev-python/twisted"* ]]; then
+	EXPORT_FUNCTIONS src_test
+
+	MY_PV="${MY_PV:-${PV}}"
+	MY_P="Twisted${MY_PACKAGE}-${MY_PV}"
+
+	HOMEPAGE="http://www.twistedmatrix.com/";
+	SRC_URI="http://tmrc.mit.edu/mirror/twisted/${MY_PACKAGE}/$(get_version_component_range 1-2 ${MY_PV})/${MY_P}.tar.bz2"
+
+	LICENSE="MIT"
+	SLOT="0"
+	IUSE=""
+
+	S="${WORKDIR}/${MY_P}"
+
+	TWISTED_PLUGINS="${TWISTED_PLUGINS:-twisted.plugins}"
+fi
+
+# @ECLASS-VARIABLE: TWISTED_PLUGINS
+# @DESCRIPTION:
+# Twisted plugins, whose cache is regenerated in pkg_postinst() and pkg_postrm() phases.
 
 twisted_src_test() {
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
-		testing() {
-			# This is a hack to make tests work without installing to the live
-			# filesystem. We copy the twisted site-packages to a temporary
-			# dir, install there, and run from there.
-			local spath="$(python_get_sitedir)"
-			mkdir -p "${T}/${spath}"
-			cp -R "${ROOT}${spath}/twisted" "${T}/${spath}" || die "Copying of files failed with Python ${PYTHON_ABI}"
-
-			# We have to get rid of the existing version of this package
-			# instead of just installing on top of it, since if the existing
-			# package has tests in files the version we are installing does
-			# not have we end up running e.g. twisted-names-0.3.0 tests when
-			# downgrading to twisted-names-0.1.0-r1.
-			rm -fr "${T}/${spath}/${PN/-//}"
-
-			"$(PYTHON)" setup.py build -b "build-${PYTHON_ABI}" install --root="${T}" --no-compile --force || die "Installation for tests failed with Python ${PYTHON_ABI}"
-			cd "${T}/${spath}" || die
-			PATH="${T}/usr/bin:${PATH}" PYTHONPATH="${T}/${spath}" trial ${PN/-/.} || die "trial failed with Python ${PYTHON_ABI}"
-			cd "${S}"
-			rm -fr "${T}/${spath}"
-		}
-		python_execute_function testing
-	else
-		# This is a hack to make tests work without installing to the live
-		# filesystem. We copy the twisted site-packages to a temporary
-		# dir, install there, and run from there.
-		local spath="$(python_get_sitedir)"
-		mkdir -p "${T}/${spath}"
-		cp -R "${ROOT}${spath}/twisted" "${T}/${spath}" || die
-
-		# We have to get rid of the existing version of this package
-		# instead of just installing on top of it, since if the existing
-		# package has tests in files the version we are installing does
-		# not have we end up running fex twisted-names-0.3.0 tests when
-		# downgrading to twisted-names-0.1.0-r1.
-		rm -rf "${T}/${spath}/${PN/-//}"
-
-		"${python}" setup.py install --root="${T}" --no-compile --force || die
-		cd "${T}/${spath}" || die
-		PATH="${T}/usr/bin:${PATH}" PYTHONPATH="${T}/${spath}" \
-			trial ${PN/-/.} || die "trial failed"
-		cd "${S}"
-		rm -rf "${T}/${spath}"
+	if [[ "${CATEGORY}/${PN}" != "dev-python/twisted"* ]]; then
+		die "${FUNCNAME}() can be used only in dev-python/twisted* packages"
 	fi
+
+	testing() {
+		local sitedir="${EPREFIX}$(python_get_sitedir)"
+
+		# Copy modules of other Twisted packages from site-packages directory to temporary directory.
+		mkdir -p "${T}/${sitedir}"
+		cp -R "${ROOT}${sitedir}/twisted" "${T}/${sitedir}" || die "Copying of modules of other Twisted packages failed with $(python_get_implementation) $(python_get_version)"
+		rm -fr "${T}/${sitedir}/${PN/-//}"
+
+		# Install modules of current package to temporary directory.
+		"$(PYTHON)" setup.py build -b "build-${PYTHON_ABI}" install --force --no-compile --root="${T}" || die "Installation into temporary directory failed with $(python_get_implementation) $(python_get_version)"
+
+		pushd "${T}/${sitedir}" > /dev/null || return 1
+		PATH="${T}${EPREFIX}/usr/bin:${PATH}" PYTHONPATH="${T}/${sitedir}" trial ${PN/-/.} || return 1
+		popd > /dev/null || return 1
+
+		rm -fr "${T}/${sitedir}"
+	}
+	python_execute_function testing
 }
 
 twisted_src_install() {
@@ -88,31 +77,62 @@
 	fi
 }
 
-update_plugin_cache() {
-	einfo "Updating twisted plugin cache..."
-	# we have to remove the cache or removed plugins won't be removed
-	# from the cache (http://twistedmatrix.com/bugs/issue926)
-	rm "${ROOT}$(python_get_sitedir)/twisted/plugins/dropin.cache"
-	# notice we have to use getPlugIns here for <=twisted-2.0.1 compatibility
-	python -c "from twisted.plugin import IPlugin, getPlugIns;list(getPlugIns(IPlugin))"
+_twisted_update_plugin_cache() {
+	local dir exit_status="0" module
+
+	for module in ${TWISTED_PLUGINS}; do
+		if [[ -d "${EROOT}$(python_get_sitedir -b)/${module//.//}" ]]; then
+			find "${EROOT}$(python_get_sitedir -b)/${module//.//}" -name dropin.cache -print0 | xargs -0 rm -f
+		fi
+	done
+
+	if [[ -n "$(type -p "$(PYTHON)")" ]]; then
+		for module in ${TWISTED_PLUGINS}; do
+			# http://twistedmatrix.com/documents/current/core/howto/plugin.html
+			"$(PYTHON)" -c \
+"import sys
+sys.path.insert(0, '${EROOT}$(python_get_sitedir -b)')
+
+try:
+	import twisted.plugin
+	import ${module}
+except ImportError:
+	if '${EBUILD_PHASE}' == 'postinst':
+		raise
+	else:
+	    # Twisted, zope.interface or given plugins might have been uninstalled.
+		sys.exit(0)
+
+list(twisted.plugin.getPlugins(twisted.plugin.IPlugin, ${module}))" || exit_status="1"
+		done
+	fi
+
+	for module in ${TWISTED_PLUGINS}; do
+		# Delete empty parent directories.
+		local dir="${EROOT}$(python_get_sitedir -b)/${module//.//}"
+		while [[ "${dir}" != "${EROOT%/}" ]]; do
+			rmdir "${dir}" 2> /dev/null || break
+			dir="${dir%/*}"
+		done
+	done
+
+	return "${exit_status}"
 }
 
 twisted_pkg_postrm() {
 	distutils_pkg_postrm
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
-		python_execute_function update_plugin_cache
-	else
-		update_plugin_cache
-	fi
+	python_execute_function \
+		--action-message 'Regeneration of Twisted plugin cache with $(python_get_implementation) $(python_get_version)' \
+		--failure-message 'Regeneration of Twisted plugin cache failed with $(python_get_implementation) $(python_get_version)' \
+		--nonfatal \
+		_twisted_update_plugin_cache
 }
 
 twisted_pkg_postinst() {
 	distutils_pkg_postinst
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
-		python_execute_function update_plugin_cache
-	else
-		update_plugin_cache
-	fi
+	python_execute_function \
+		--action-message 'Regeneration of Twisted plugin cache with $(python_get_implementation) $(python_get_version)' \
+		--failure-message 'Regeneration of Twisted plugin cache failed with $(python_get_implementation) $(python_get_version)' \
+		--nonfatal \
+		_twisted_update_plugin_cache
 }
-
-EXPORT_FUNCTIONS src_test src_install pkg_postrm pkg_postinst
--- twisted.eclass
+++ twisted.eclass
@@ -1,31 +1,37 @@
-# Copyright 2005 Gentoo Foundation
+# Copyright 2005-2010 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License, v2 or later
 # $Header: /var/cvsroot/gentoo-x86/eclass/twisted.eclass,v 1.7 2009/10/30 13:14:17 arfrever Exp $
-#
-# Author: Marien Zwart <mari...@gentoo.org>
-#
-# eclass to aid installing and testing twisted packages.
-#
-# you should set MY_PACKAGE to something like 'Names' before inheriting.
-# you may set MY_PV to the right version (defaults to PV).
-#
-# twisted_src_test relies on the package installing twisted.names to
-# have a ${PN} of twisted-names.
-
-inherit distutils eutils versionator
-
-MY_PV="${MY_PV:-${PV}}"
-MY_VERSION="$(get_version_component_range 1-2 ${MY_PV})"
-MY_P="Twisted${MY_PACKAGE}-${MY_PV}"
-
-HOMEPAGE="http://www.twistedmatrix.com/";
-SRC_URI="http://tmrc.mit.edu/mirror/twisted/${MY_PACKAGE}/${MY_VERSION}/${MY_P}.tar.bz2";
-
-LICENSE="MIT"
-SLOT="0"
-IUSE=""
 
-S="${WORKDIR}/${MY_P}"
+# @ECLASS: twisted.eclass
+# @MAINTAINER:
+# Gentoo Python Project <pyt...@gentoo.org>
+# @BLURB: Eclass for Twisted packages
+# @DESCRIPTION:
+# The twisted eclass defines phase functions for Twisted packages.
+
+# The following variables can be set in dev-python/twisted* packages before inheriting this eclass:
+#   MY_PACKAGE - Package name suffix (required)
+#   MY_PV      - Package version (optional)
+
+inherit distutils versionator
+
+EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
+
+if [[ "${CATEGORY}/${PN}" == "dev-python/twisted"* ]]; then
+	EXPORT_FUNCTIONS src_test
+
+	MY_PV="${MY_PV:-${PV}}"
+	MY_P="Twisted${MY_PACKAGE}-${MY_PV}"
+
+	HOMEPAGE="http://www.twistedmatrix.com/";
+	SRC_URI="http://tmrc.mit.edu/mirror/twisted/${MY_PACKAGE}/$(get_version_component_range 1-2 ${MY_PV})/${MY_P}.tar.bz2"
+
+	LICENSE="MIT"
+	SLOT="0"
+	IUSE=""
+
+	S="${WORKDIR}/${MY_P}"
+fi
 
 twisted_src_test() {
 	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
@@ -114,5 +120,3 @@
 		update_plugin_cache
 	fi
 }
-
-EXPORT_FUNCTIONS src_test src_install pkg_postrm pkg_postinst
--- twisted.eclass
+++ twisted.eclass
@@ -34,51 +34,28 @@
 fi
 
 twisted_src_test() {
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
-		testing() {
-			# This is a hack to make tests work without installing to the live
-			# filesystem. We copy the twisted site-packages to a temporary
-			# dir, install there, and run from there.
-			local spath="$(python_get_sitedir)"
-			mkdir -p "${T}/${spath}"
-			cp -R "${ROOT}${spath}/twisted" "${T}/${spath}" || die "Copying of files failed with Python ${PYTHON_ABI}"
-
-			# We have to get rid of the existing version of this package
-			# instead of just installing on top of it, since if the existing
-			# package has tests in files the version we are installing does
-			# not have we end up running e.g. twisted-names-0.3.0 tests when
-			# downgrading to twisted-names-0.1.0-r1.
-			rm -fr "${T}/${spath}/${PN/-//}"
-
-			"$(PYTHON)" setup.py build -b "build-${PYTHON_ABI}" install --root="${T}" --no-compile --force || die "Installation for tests failed with Python ${PYTHON_ABI}"
-			cd "${T}/${spath}" || die
-			PATH="${T}/usr/bin:${PATH}" PYTHONPATH="${T}/${spath}" trial ${PN/-/.} || die "trial failed with Python ${PYTHON_ABI}"
-			cd "${S}"
-			rm -fr "${T}/${spath}"
-		}
-		python_execute_function testing
-	else
-		# This is a hack to make tests work without installing to the live
-		# filesystem. We copy the twisted site-packages to a temporary
-		# dir, install there, and run from there.
-		local spath="$(python_get_sitedir)"
-		mkdir -p "${T}/${spath}"
-		cp -R "${ROOT}${spath}/twisted" "${T}/${spath}" || die
-
-		# We have to get rid of the existing version of this package
-		# instead of just installing on top of it, since if the existing
-		# package has tests in files the version we are installing does
-		# not have we end up running fex twisted-names-0.3.0 tests when
-		# downgrading to twisted-names-0.1.0-r1.
-		rm -rf "${T}/${spath}/${PN/-//}"
-
-		"${python}" setup.py install --root="${T}" --no-compile --force || die
-		cd "${T}/${spath}" || die
-		PATH="${T}/usr/bin:${PATH}" PYTHONPATH="${T}/${spath}" \
-			trial ${PN/-/.} || die "trial failed"
-		cd "${S}"
-		rm -rf "${T}/${spath}"
+	if [[ "${CATEGORY}/${PN}" != "dev-python/twisted"* ]]; then
+		die "${FUNCNAME}() can be used only in dev-python/twisted* packages"
 	fi
+
+	testing() {
+		local sitedir="${EPREFIX}$(python_get_sitedir)"
+
+		# Copy modules of other Twisted packages from site-packages directory to temporary directory.
+		mkdir -p "${T}/${sitedir}"
+		cp -R "${ROOT}${sitedir}/twisted" "${T}/${sitedir}" || die "Copying of modules of other Twisted packages failed with $(python_get_implementation) $(python_get_version)"
+		rm -fr "${T}/${sitedir}/${PN/-//}"
+
+		# Install modules of current package to temporary directory.
+		"$(PYTHON)" setup.py build -b "build-${PYTHON_ABI}" install --force --no-compile --root="${T}" || die "Installation into temporary directory failed with $(python_get_implementation) $(python_get_version)"
+
+		pushd "${T}/${sitedir}" > /dev/null || return 1
+		PATH="${T}${EPREFIX}/usr/bin:${PATH}" PYTHONPATH="${T}/${sitedir}" trial ${PN/-/.} || return 1
+		popd > /dev/null || return 1
+
+		rm -fr "${T}/${sitedir}"
+	}
+	python_execute_function testing
 }
 
 twisted_src_install() {
--- twisted.eclass
+++ twisted.eclass
@@ -31,8 +31,14 @@
 	IUSE=""
 
 	S="${WORKDIR}/${MY_P}"
+
+	TWISTED_PLUGINS="${TWISTED_PLUGINS:-twisted.plugins}"
 fi
 
+# @ECLASS-VARIABLE: TWISTED_PLUGINS
+# @DESCRIPTION:
+# Twisted plugins, whose cache is regenerated in pkg_postinst() and pkg_postrm() phases.
+
 twisted_src_test() {
 	if [[ "${CATEGORY}/${PN}" != "dev-python/twisted"* ]]; then
 		die "${FUNCNAME}() can be used only in dev-python/twisted* packages"
@@ -71,29 +77,62 @@
 	fi
 }
 
-update_plugin_cache() {
-	einfo "Updating twisted plugin cache..."
-	# we have to remove the cache or removed plugins won't be removed
-	# from the cache (http://twistedmatrix.com/bugs/issue926)
-	rm "${ROOT}$(python_get_sitedir)/twisted/plugins/dropin.cache"
-	# notice we have to use getPlugIns here for <=twisted-2.0.1 compatibility
-	python -c "from twisted.plugin import IPlugin, getPlugIns;list(getPlugIns(IPlugin))"
+_twisted_update_plugin_cache() {
+	local dir exit_status="0" module
+
+	for module in ${TWISTED_PLUGINS}; do
+		if [[ -d "${EROOT}$(python_get_sitedir -b)/${module//.//}" ]]; then
+			find "${EROOT}$(python_get_sitedir -b)/${module//.//}" -name dropin.cache -print0 | xargs -0 rm -f
+		fi
+	done
+
+	if [[ -n "$(type -p "$(PYTHON)")" ]]; then
+		for module in ${TWISTED_PLUGINS}; do
+			# http://twistedmatrix.com/documents/current/core/howto/plugin.html
+			"$(PYTHON)" -c \
+"import sys
+sys.path.insert(0, '${EROOT}$(python_get_sitedir -b)')
+
+try:
+	import twisted.plugin
+	import ${module}
+except ImportError:
+	if '${EBUILD_PHASE}' == 'postinst':
+		raise
+	else:
+	    # Twisted, zope.interface or given plugins might have been uninstalled.
+		sys.exit(0)
+
+list(twisted.plugin.getPlugins(twisted.plugin.IPlugin, ${module}))" || exit_status="1"
+		done
+	fi
+
+	for module in ${TWISTED_PLUGINS}; do
+		# Delete empty parent directories.
+		local dir="${EROOT}$(python_get_sitedir -b)/${module//.//}"
+		while [[ "${dir}" != "${EROOT%/}" ]]; do
+			rmdir "${dir}" 2> /dev/null || break
+			dir="${dir%/*}"
+		done
+	done
+
+	return "${exit_status}"
 }
 
 twisted_pkg_postrm() {
 	distutils_pkg_postrm
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
-		python_execute_function update_plugin_cache
-	else
-		update_plugin_cache
-	fi
+	python_execute_function \
+		--action-message 'Regeneration of Twisted plugin cache with $(python_get_implementation) $(python_get_version)' \
+		--failure-message 'Regeneration of Twisted plugin cache failed with $(python_get_implementation) $(python_get_version)' \
+		--nonfatal \
+		_twisted_update_plugin_cache
 }
 
 twisted_pkg_postinst() {
 	distutils_pkg_postinst
-	if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
-		python_execute_function update_plugin_cache
-	else
-		update_plugin_cache
-	fi
+	python_execute_function \
+		--action-message 'Regeneration of Twisted plugin cache with $(python_get_implementation) $(python_get_version)' \
+		--failure-message 'Regeneration of Twisted plugin cache failed with $(python_get_implementation) $(python_get_version)' \
+		--nonfatal \
+		_twisted_update_plugin_cache
 }

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to