diff options
author | Ali Polatel <hawking@gentoo.org> | 2007-10-29 17:04:28 +0000 |
---|---|---|
committer | Ali Polatel <hawking@gentoo.org> | 2007-10-29 17:04:28 +0000 |
commit | 22a9d58b0dbec95f49095ed47e57348e8237e8fd (patch) | |
tree | 8d28fe6e63d5637a1bd5e7558cc6b2afe39409b0 | |
parent | added projects/eselect-python (diff) | |
download | eselect-python-22a9d58b0dbec95f49095ed47e57348e8237e8fd.tar.gz eselect-python-22a9d58b0dbec95f49095ed47e57348e8237e8fd.tar.bz2 eselect-python-22a9d58b0dbec95f49095ed47e57348e8237e8fd.zip |
initial version of python.eselect
-rw-r--r-- | python.eselect | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/python.eselect b/python.eselect new file mode 100644 index 0000000..e5f8f23 --- /dev/null +++ b/python.eselect @@ -0,0 +1,92 @@ +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: $ + +# Heavily based on profile.eselect. + +DESCRIPTION="Manage the /usr/bin/python symlink." +MAINTAINER="marienz@gentoo.org" +VERSION="0.1" + + +INTERPRETER_PATH="${ROOT}/usr/bin/" + +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 + echo ${interpreter#${INTERPRETER_PATH}} + done +} + + +describe_show() { + echo "Show the active python interpreter" +} + +do_show() { + active=$(canonicalise "${INTERPRETER_PATH}python") + echo ${active#${INTERPRETER_PATH}} +} + + +describe_list() { + echo "List installed python interpreters" +} + +do_list() { + local targets=( $(find_targets) ) + + write_list_start "Available python interpreters:" + + if [[ -n ${targets[@]} ]] ; then + # mark the active python + local i active=$(do_show) + for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do + [[ ${targets[${i}]} == $active ]] && \ + targets[${i}]="${targets[${i}]} $(highlight '*' )" + done + write_numbered_list "${targets[@]}" + else + write_kv_list_entry "(none found)" "" + fi +} + + +describe_set() { + echo "Set active python interpreter." +} + +do_set() { + if [[ -z ${1} ]] ; then + die -q "You didn't tell me which python interpreter to use" + fi + + local targets=( $(find_targets) ) target=${1} + + if is_number "${target}"; then + target=${targets[$(( ${target} - 1 ))]} + fi + + if ! has ${target} "${targets[@]}" ; then + die -q "Invalid target ${target}" + fi + + pushd "${INTERPRETER_PATH}" 1>/dev/null + ln -nfs ${target} python + popd 1>/dev/null +} + + +describe_update() { + echo "Switch to the most recent CPython." +} + +do_update() { + local targets=( $(cd "${INTERPRETER_PATH}"; ls python?.?|sort -r) ) target + target=${targets[0]} + echo "Switching to ${target}" + do_set ${target} +} |