commit:     e244f5dc8742446047c0292fe224c422577a8afa
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Feb  4 21:52:51 2016 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Feb  4 21:52:51 2016 +0000
URL:        
https://gitweb.gentoo.org/proj/eselect-python.git/commit/?id=e244f5dc

big cleanup

 python.eselect.in | 96 +++++++++++++++++++++++++++----------------------------
 1 file changed, 48 insertions(+), 48 deletions(-)

diff --git a/python.eselect.in b/python.eselect.in
index d1e2836..2680d69 100644
--- a/python.eselect.in
+++ b/python.eselect.in
@@ -9,7 +9,7 @@ VERSION=20160202
 CONFIG_PATH="${EROOT%/}/etc/python-exec/python-exec.conf"
 ENV_D_PATH="${EROOT%/}/etc/env.d"
 INTERPRETER_DIR="${EROOT%/}/usr/bin"
-MAN_PATH="${EROOT%/}/usr/share/man/man1/"
+MAN_PATH="${EROOT%/}/usr/share/man/man1"
 
 # Get list of all installed Python interpreters, in lexical order.
 # $1 can be --pyN to filter results to pythonN.?.
@@ -74,6 +74,7 @@ get_all_pythons() {
        local targets=( $(get_installed_pythons "${@}") )
        local preferred=( $(get_preferred_pythons "${@}") )
        local disabled=( $(get_disabled_pythons "${@}") )
+       local i
 
        # preferred first
        for i in "${preferred[@]}"; do
@@ -104,25 +105,23 @@ write_preferences() {
 
 # Set a man page symlink
 set_man_symlink() {
-       local target="${1}" x extension
+       local target=${1} x suffix
 
-       rm -f "${MAN_PATH}"python.1{,.gz,.bz2,.lzma,.xz,.lz}
+       rm -f "${MAN_PATH}"/python.1{,.gz,.bz2,.lzma,.xz,.lz} || die
 
-       for x in ".1" ".1.bz2" ".1.gz" ".1.lzma" ".1.xz" ".1.lz"; do
-               if [[ -e "${MAN_PATH}${target}${x}" ]]; then
-                       extension="${x}"
+       for x in .1{,.gz,.bz2,.lzma,.xz,.lz}; do
+               if [[ -e "${MAN_PATH}/${target}${x}" ]]; then
+                       suffix=${x}
                        break
                fi
        done
 
-       if [[ -z "${extension}" ]]; then
+       if [[ ! ${suffix} ]]; then
                echo "Couldn't find a man page for ${target}; skipping." 1>&2
                return 1
        fi
 
-       pushd "${MAN_PATH}" 1> /dev/null
-       ln -nfs "${target}${extension}" "python${extension}"
-       popd 1> /dev/null
+       ln -nfs "${target}${extension}" "${MAN_PATH}/python${extension}" || die
 }
 
 # Set OSX framework symlinks
@@ -130,22 +129,22 @@ set_osx_framework() {
        local target=${1}
 
        # Files of Mac OS X framework
-       local framework_dir="${INTERPRETER_PATH%/bin/}/lib/Python.framework"
-       if [[ -d "${framework_dir}" ]]; then
-               local version="${target#python}"
-               pushd "${framework_dir}" 1> /dev/null
-               rm -f Headers Python Resources
-               ln -nfs "Versions/${version}/Headers"
-               ln -nfs "Versions/${version}/Python"
-               ln -nfs "Versions/${version}/Resources"
-               popd 1> /dev/null
+       local framework_dir="${INTERPRETER_DIR%/bin}"/lib/Python.framework
+       if [[ -d ${framework_dir} ]]; then
+               local version=${target#python}
+               pushd "${framework_dir}" >/dev/null || die
+               rm -f Headers Python Resources || die
+               ln -nfs "Versions/${version}/Headers" || die
+               ln -nfs "Versions/${version}/Python" || die
+               ln -nfs "Versions/${version}/Resources" || die
+               popd >/dev/null || die
        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"
+       local path target=${1#python} variable
+       rm -f "${ENV_D_PATH}/65python-docs" || die
        if [[ -f ${ENV_D_PATH}/60python-docs-${target} ]]; then
                variable="PYTHONDOCS_${target//./_}"
                path="$(. "${ENV_D_PATH}/60python-docs-${target}"; echo 
"${!variable}")"
@@ -169,21 +168,21 @@ post_update() {
 ### show action ###
 
 describe_show() {
-       echo "Show main active Python interpreter"
+       echo "Show the most preferred Python interpreter"
 }
 
 describe_show_options() {
-       echo "--ABI         : Show Python ABI in format of PYTHON_ABI variable"
-       echo "--python2     : Show active Python 2 interpreter"
-       echo "--python3     : Show active Python 3 interpreter"
+       echo "--ABI         : use PYTHON_ABI variable format (deprecated)"
+       echo "--python2     : show the preferred version of Python 2"
+       echo "--python3     : show the preferred version of Python 3"
 }
 
 do_show() {
-       local ABI filter interpreter
-       while [[ $# > 0 ]]; do
-               case "$1" in
+       local abi filter interpreter
+       while [[ ${#} -gt 0 ]]; do
+               case ${1} in
                        --ABI)
-                               ABI=1
+                               abi=1
                                ;;
                        --python2|--py2)
                                filter=--py2
@@ -198,7 +197,8 @@ do_show() {
                shift
        done
 
-       local all_interpreters=( $(get_preferred_pythons ${filter}) ) i
+       local all_interpreters=( $(get_preferred_pythons ${filter}) )
+       local i
        for i in "${all_interpreters[@]}"; do
                # skip if not installed
                [[ -x ${INTERPRETER_DIR}/${i}@EXEEXT@ ]] || continue
@@ -206,7 +206,7 @@ do_show() {
                break
        done
 
-       if [[ "${ABI}" == "1" ]]; then
+       if [[ ${abi} ]]; then
                echo "${interpreter#python}"
        else
                echo "${interpreter}"
@@ -220,14 +220,14 @@ describe_list() {
 }
 
 describe_list_options() {
-       echo "--python2     : List installed Python 2 interpreters"
-       echo "--python3     : List installed Python 3 interpreters"
+       echo "--python2     : list only Python 2 interpreters"
+       echo "--python3     : list only Python 3 interpreters"
 }
 
 do_list() {
        local filter
-       while [[ $# > 0 ]]; do
-               case "$1" in
+       while [[ ${#} -gt 0 ]]; do
+               case ${1} in
                        --python2|--py2)
                                filter=--py2
                                ;;
@@ -260,12 +260,12 @@ do_list() {
 ### set action ###
 
 describe_set() {
-       echo "Set main active Python interpreter"
+       echo "Set the preferred Python interpreter"
 }
 
 describe_set_options() {
-       echo "--python2     : Set active Python 2 interpreter without setting 
of main active Python interpreter if it is not set to Python 2"
-       echo "--python3     : Set active Python 3 interpreter without setting 
of main active Python interpreter if it is not set to Python 3"
+       echo "--python2     : update preference for Python 2 versions only"
+       echo "--python3     : update preference for Python 3 versions only"
 }
 
 describe_set_parameters() {
@@ -274,8 +274,8 @@ describe_set_parameters() {
 
 do_set() {
        local filter
-       while [[ $# > 0 ]]; do
-               case "$1" in
+       while [[ ${#} -gt 0 ]]; do
+               case ${1} in
                        --python2|--py2)
                                filter=--py2
                                ;;
@@ -289,14 +289,14 @@ do_set() {
                shift
        done
 
-       [[ $# -eq 1 ]] || die "Usage: eselect python set <interpreter>"
+       [[ ${#} -eq 1 ]] || die "Usage: eselect python set <interpreter>"
 
        local target=${1}
        local targets=( $(get_all_pythons ${filter}) )
        if is_number "${target}" \
                && [[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]]
        then
-               target=${targets[$((${target} - 1))]}
+               target=${targets[target-1]}
        fi
 
        has "${target}" "${targets[@]}" || die "Invalid target: ${target}"
@@ -333,16 +333,16 @@ describe_update() {
 }
 
 describe_update_options() {
-       echo "--if-unset    : Do not override existing implementation"
-       echo "--ignore SLOT : Ignore SLOT when setting symlinks"
-       echo "--python2     : Set active Python 2 interpreter without setting 
of main active Python interpreter if it is not set to Python 2"
-       echo "--python3     : Set active Python 3 interpreter without setting 
of main active Python interpreter if it is not set to Python 3"
+       echo "--if-unset    : do not alter preferences unless there is no valid 
preference set"
+       echo "--ignore SLOT : ignore specified Python slots"
+       echo "--python2     : update only Python 2 preferences"
+       echo "--python3     : update only Python 3 preferences"
 }
 
 do_update() {
        local if_unset ignored_slots=() filter
-       while [[ $# > 0 ]]; do
-               case "$1" in
+       while [[ ${#} -gt 0 ]]; do
+               case ${1} in
                        --if-unset)
                                if_unset=1
                                ;;

Reply via email to