From d1a66d5e6f838bb5591c3d9a43c531cc309cae23 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Mon, 8 Nov 2021 14:05:05 +0100 Subject: [PATCH] libpmodules.bash reviewed - cleanup code in lib - function we need in modmanage moved to lib - some cleanup in modulecmd --- .../{libpmodules.bash => libpmodules.bash.in} | 0 Pmodules/modulecmd.bash.in | 72 ++----------------- 2 files changed, 7 insertions(+), 65 deletions(-) rename Pmodules/{libpmodules.bash => libpmodules.bash.in} (100%) diff --git a/Pmodules/libpmodules.bash b/Pmodules/libpmodules.bash.in similarity index 100% rename from Pmodules/libpmodules.bash rename to Pmodules/libpmodules.bash.in diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index ccde9f6..5afa784 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -1,9 +1,12 @@ #!@BASH@ --noprofile # -#set -o nounset -# we have to unset CDPATH, otherwise 'cd' prints the directoy! -unset CDPATH +PATH='/bin:/usr/bin' +case +unset CDPATH # unset CDPATH, otherwise 'cd' prints the directoy! +unset IFS # use default IFS + +shopt -s nullglob # used for some output only declare -r CMD='module' @@ -31,20 +34,11 @@ fi declare verbosity_lvl=${PMODULES_VERBOSITY:-'verbose'} -# use default IFS -unset IFS - -shopt -s nullglob - -declare -A GroupDepths='()' declare Shell='' -declare -A Subcommands -declare -A Options -declare -A Help declare -r pmodules_config_file="${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/Pmodules.conf" -# the following settings are used if the Pmodules.conf is not available +# the following settings are used if the Pmodules.conf doesn't exist # set groups which should be available after initialization declare -- DefaultGroups='Tools Programming' @@ -55,22 +49,6 @@ declare -- ReleaseStages=':unstable:stable:deprecated:' # set releases which should be available after initialization declare -- DefaultReleaseStages='stable' -# In the dictionary Help we store the help text of each single command -# and for displaying the version. - -# initialize help text of 'module --version' -Help['version']=" -Pmodules @PMODULES_VERSION@ using Tcl Environment Modules @MODULES_VERSION@ -Copyright GNU GPL v2 -" - -# -# display help text for command given in $1 -# -print_help() { - echo -e "${Help[$1]}" 1>&2 - std::die 1 -} export_env() { case "${Shell}" in @@ -170,42 +148,6 @@ is_release_stage() { [[ ${ReleaseStages} =~ :$1: ]] } -# -# compute depth of modulefile directory. -# -# Args: -# $1: absolute path of a modulefile directory -# -compute_group_depth () { - local -r dir=$1 - test -d "${dir}" || return 1 - local group=${dir%/*} - local group=${group##*/} - [[ -n "${GroupDepths[${group}]}" ]] && return 0 - local -i depth=$(${find} "${dir}" -depth \( -type f -o -type l \) \ - -printf "%d" -quit 2>/dev/null) - (( depth-=2 )) - # if a group doesn't contain a modulefile, depth is negativ - # :FIXME: better solution? - (( depth < 0 )) && (( depth = 0 )) - GroupDepths[$group]=${depth} - g_env_must_be_saved='yes' -} - -# -# (Re-)Scan available groups in given root and compute group depth's -# -# Args: -# $1: root of modulefile hierarchy -# -scan_groups () { - local -r root="$1" - local moduledir - for moduledir in ${root}/*/${PMODULES_MODULEFILES_DIR}; do - compute_group_depth "${moduledir}" - done -} - # # Check whether argument is a group #