diff options
author | 2009-05-28 15:09:39 +0000 | |
---|---|---|
committer | 2009-05-28 15:09:39 +0000 | |
commit | 77007df99771f0e3703bfc393f6b87ea606f846d (patch) | |
tree | 676f96df36a0bcb116debbd551032c9b7cb1dbc7 | |
parent | Improve handling of symlinks. (diff) | |
download | eselect-python-77007df99771f0e3703bfc393f6b87ea606f846d.tar.gz eselect-python-77007df99771f0e3703bfc393f6b87ea606f846d.tar.bz2 eselect-python-77007df99771f0e3703bfc393f6b87ea606f846d.zip |
Make `eselect python` update the content of /etc/env.d/65python-docs.
-rw-r--r-- | python.eselect | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/python.eselect b/python.eselect index 82ba77f..debd009 100644 --- a/python.eselect +++ b/python.eselect @@ -1,55 +1,56 @@ -# Copyright 1999-2008 Gentoo Foundation +# Copyright 1999-2009 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: $ DESCRIPTION="Manage the /usr/bin/python and python.1 man symlinks." -MAINTAINER="hawking@gentoo.org" +MAINTAINER="python@gentoo.org" SVN_DATE='$Date$' VERSION=$(svn_date_to_version "${SVN_DATE}" ) +ENV_D_PATH="${ROOT%/}/etc/env.d" INTERPRETER_PATH="${ROOT%/}/usr/bin/" MAN_PATH="${ROOT%/}/usr/share/man/man1/" -# find a list of python versions +# Find a list of python versions find_targets() { local interpreter # Think twice before adding jython to this list. /usr/bin/jython # is a bash wrapper that calls java-config, which is a python # script, so you need a valid /usr/bin/python to start jython. - for interpreter in "${INTERPRETER_PATH}"python?.? ; do + for interpreter in "${INTERPRETER_PATH}"python?.?; do echo ${interpreter#${INTERPRETER_PATH}} done } -# try to remove python and python.1 symlinks +# Try to remove python and python.1 symlinks remove_symlinks() { local symlink symlink_target symlink_target_found rm -f "${INTERPRETER_PATH}"{idle,pydoc,python,python-config} &>/dev/null && \ rm -f "${MAN_PATH}"python.1{,.gz,.bz2,.lzma} &>/dev/null - for symlink in "${INTERPRETER_PATH}python"? ; do + for symlink in "${INTERPRETER_PATH}python"?; do [[ ! -L "${symlink}" ]] && continue symlink_target_found=0 - for symlink_target in "${symlink}".? ; do + for symlink_target in "${symlink}".?; do [[ -f "${symlink_target}" ]] && symlink_target_found=1 done - if [[ "${symlink_target_found}" -eq 0 ]] ; then + if [[ "${symlink_target_found}" -eq 0 ]]; then rm -f "${symlink}" fi done } -# set a man page symlink +# Set a man page symlink set_man_symlink() { local target="${1}" x extension - for x in ".1" ".1.bz2" ".1.gz" ".1.lzma" ; do - if [[ -e "${MAN_PATH}${target}${x}" ]] ; then + for x in ".1" ".1.bz2" ".1.gz" ".1.lzma"; do + if [[ -e "${MAN_PATH}${target}${x}" ]]; then extension="${x}" break fi done - if [[ -z "${extension}" ]] ; then + if [[ -z "${extension}" ]]; then echo "Couldn't find a man page for ${target}; skipping." 1>&2 return 1 fi @@ -59,14 +60,14 @@ set_man_symlink() { popd 1>/dev/null } -# set python and python.1 symlinks +# Set python and python.1 symlinks set_symlinks() { local target="${1}" targets=($(find_targets )) - if is_number "${target}" && [[ ${target} -ge 1 ]] ; then + if is_number "${target}" && [[ ${target} -ge 1 ]]; then target=${targets[$(( ${target} - 1 ))]} fi - if ! has ${target} "${targets[@]}" ; then + if ! has ${target} "${targets[@]}"; then die -q "Invalid target ${target}" fi if [[ -f "${INTERPRETER_PATH}${target}" ]]; then @@ -90,6 +91,19 @@ set_symlinks() { fi } +# Set the content of /etc/env.d/65python-docs +set_python_docs() { + local path target="${1#python}" variable + rm -f "${ENV_D_PATH}/65python-docs" + if [[ -f "${ENV_D_PATH}/60python-docs-${target}" ]]; then + variable="PYTHONDOCS_${target//./_}" + path="$(. "${ENV_D_PATH}/60python-docs-${target}"; echo -n "${!variable}")" + if [[ -d "${path}" ]]; then + echo "PYTHONDOCS=\"${path}\"" > "${ENV_D_PATH}/65python-docs" + fi + fi +} + ### show action describe_show() { @@ -112,10 +126,10 @@ do_list() { write_list_start "Available python interpreters:" - if [[ -n ${targets[@]} ]] ; then + if [[ -n ${targets[@]} ]]; then # mark the active python local i active=$(do_show) - for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do + for ((i = 0; i < ${#targets[@]}; i = i + 1)); do [[ ${targets[${i}]} == $active ]] && \ targets[${i}]="${targets[${i}]} $(highlight '*' )" done @@ -132,17 +146,18 @@ describe_set() { } do_set() { - if [[ -z "${1}" ]] ; then + if [[ -z "${1}" ]]; then die -q "You didn't tell me which python interpreter to use" elif [[ -n "${2}" ]]; then die -q "Too many parameters" - elif [[ -L "${INTERPRETER_PATH}python" ]] ; then + elif [[ -L "${INTERPRETER_PATH}python" ]]; then if ! remove_symlinks; then die -q "Can't remove existing provider" - elif ! set_symlinks "${1}" ; then + elif ! set_symlinks "${1}"; then die -q "Can't set new provider" fi - elif [[ -e "${INTERPRETER_PATH}python" ]] ; then + set_python_docs "${1}" + elif [[ -e "${INTERPRETER_PATH}python" ]]; then die -q "Sorry, ${INTERPRETER_PATH}python is not a symlink" else set_symlinks "${1}" || die -q "Can't set a new provider" |