Index: python.eclass =================================================================== RCS file: /var/cvsroot/gentoo-x86/eclass/python.eclass,v retrieving revision 1.41 diff -u -r1.41 python.eclass --- python.eclass 30 May 2008 09:58:28 -0000 1.41 +++ python.eclass 5 Jun 2008 14:05:02 -0000 @@ -238,7 +238,7 @@ } # @FUNCTION: python_mod_cleanup -# @USAGE: [ dir ] +# @USAGE: [ --mod ] [ dir ] # @DESCRIPTION: # Run with optional arguments, where arguments are directories of # python modules. if none given, it will look in /usr/lib/python[0-9].[0-9] @@ -247,9 +247,12 @@ # and determine if they are orphaned (eg. their corresponding .py is missing.) # if they are, then it will remove their corresponding .pyc and .pyo # +# Argument --mod can be passed to cleanup orphaned files for module . +# # This function should only be run in pkg_postrm() python_mod_cleanup() { local SEARCH_PATH myroot + declare -a SEARCH_PATH # Check if phase is pkg_postrm() [[ ${EBUILD_PHASE} != postrm ]] &&\ @@ -258,28 +261,50 @@ # strip trailing slash myroot="${ROOT%/}" - if [ $# -gt 0 ]; then - for path in $@; do - SEARCH_PATH="${SEARCH_PATH} ${myroot}/${path#/}" + if [[ $# > 0 ]]; then + while [[ $# > 0 ]]; do + case "$1" in + --mod) + local moddir= modfile= + for moddir in \ + $(ls -d "${myroot}"/usr/$(get_libdir)/python*/site-packages/"$2" 2>/dev/null); do + SEARCH_PATH=( ${SEARCH_PATH[@]} "${moddir}" ) + done + + for modfile in \ + "${myroot}"/usr/$(get_libdir)/python*/site-packages/"$2"*.py[co]; do + src_py="${modfile%[co]}" + if [[ ! -f "${src_py}" && ! -h "${src_py}" ]]; then + einfo "Purging ${src_py}[co]" + rm -f "${src_py}"[co] + fi + done + shift;; + *) + SEARCH_PATH=( ${SEARCH_PATH[@]} "${myroot}/${1#/}" ) + ;; + esac + shift done else - for path in ${myroot}/usr/lib*/python*/site-packages; do - SEARCH_PATH="${SEARCH_PATH} ${path}" - done + SEARCH_PATH=( "${myroot}"/usr/$(get_libdir)/python*/site-packages ) fi - for path in ${SEARCH_PATH}; do - einfo "Cleaning orphaned Python bytecode from ${path} .." - for obj in $(find ${path} -name '*.py[co]'); do - src_py="${obj%[co]}" - if [ ! -f "${src_py}" ]; then - einfo "Purging ${src_py}[co]" - rm -f ${src_py}[co] - fi - done - # attempt to remove directories that maybe empty - for dir in $(find ${path} -type d | sort -r); do - rmdir ${dir} 2>/dev/null - done - done + einfo "Cleaning orphaned Python bytecode.." + + local src_py= obj= + while read -rd '' obj; do + src_py="${obj%[co]}" + if [[ ! -f "${src_py}" && ! -h "${src_py}" ]]; then + einfo "Purging ${src_py}[co]" + rm -f "${src_py}"[co] + fi + done < <(find "${SEARCH_PATH[@]}" -name "*.py[co]" -print0) + + # Attempt to remove empty directories + local dir= + while read -rd '' dir; do + rmdir "${dir}" 2>/dev/null + [[ $? == 0 ]] && einfo "Removing empty directory ${dir}" + done < <(find "${SEARCH_PATH[@]}" -depth -type d -print0) } Index: distutils.eclass =================================================================== RCS file: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v retrieving revision 1.48 diff -u -r1.48 distutils.eclass --- distutils.eclass 30 May 2008 10:22:35 -0000 1.48 +++ distutils.eclass 5 Jun 2008 14:05:09 -0000 @@ -96,9 +96,7 @@ ebegin "Performing Python Module Cleanup .." if [ -n "${PYTHON_MODNAME}" ]; then for pymod in ${PYTHON_MODNAME}; do - for moddir in "`ls -d --color=none -1 ${ROOT}usr/$(get_libdir)/python*/site-packages/${pymod} 2> /dev/null`"; do - python_mod_cleanup ${moddir} - done + python_mod_cleanup --mod "${pymod}" done else python_mod_cleanup