# Copyright 1999-2010 Gentoo Foundation # Copyright 2013 Ryan P. Harris # Distributed under the terms of the GNU General Public License v2 # $Id: $ DESCRIPTION="Manage Jython symlinks" MAINTAINER="rh1@funtoo.org" VERSION="1.0" INTERPRETER_PATH="${EROOT%/}/usr/bin/" ### HELPER FUNCTIONS ### # PUBLIC # Converts number from list to jython version # $1 = number to convert convert_list_number() { local number="${1}" local interpreters=( $(find_targets) ) if [[ "${number}" < 0 || "${number}" == 0 || "${number}" > "${#interpreters[@]}" ]] ; then die -q "Invalid number. No matching entry." fi number=$(( ${1} - 1 )) echo "${interpreters[number]}" } # PUBLIC # Finds jython targets. find_targets() { local interpreters="jython?.?" for interpreter in "${INTERPRETER_PATH}"${interpreters}; do if [[ -f "${interpreter}" ]]; then echo ${interpreter#${INTERPRETER_PATH}} fi done } ### LIST ACTION ### # PUBLIC # Descritpion of list action describe_list() { echo "Lists installed Jython versions" } # PUBLIC # Called by eselect when passed list as an action do_list() { local interpreters=( $(find_targets) ) write_list_start "Available Jython targets:" for (( i = 0; i < ${#interpreters[@]}; i++ )) ; do local number=$(( ${i} + 1 )) if [[ "${interpreters[${i}]}" == "$(do_show)" ]] ; then write_numbered_list_entry "${number}" "${interpreters[${i}]} *" else write_numbered_list_entry "${number}" "${interpreters[${i}]}" fi done } ### SHOW ACTION ### # PUBLIC # Description of show action. describe_show() { echo "Show main active Jython version" } # PUBLIC # Called by eselect when passed show as an action. do_show() { echo "$(basename $(readlink -e ${INTERPRETER_PATH}jython))" } ### SET ACTION ### # PUBLIC # Removes the old jython symlink and sets the new one. # $1 = Target version for new symlink. (Ex: jython2.5) set_jython_symlink() { local target="${1}" cd "${INTERPRETER_PATH}" if [[ ! -e "${target}" ]] ; then die -q "Target ${target} does not exist" fi if [[ -e jython ]] ; then if [[ -h jython ]] ; then rm jython else die -q "'${INTERPRETER_PATH}jython' is not a symlink." fi fi ln -sf "${target}" jython } # PUBLIC # Description of set action describe_set() { echo "Set the main active Jython version" } # PUBLIC # Desciption of set parameters describe_set_parameters() { echo "" } # PUBLIC # Called by eselect when passed set as an action do_set() { local target="${1}" if [[ ${#} != 1 ]] ; then die -q "'eselect jython set' requires 1 argument" fi if is_number "${target}" ; then target="$(convert_list_number ${target})" if [[ $? != 0 ]] ; then exit 1 fi fi set_jython_symlink "${target}" }