mirror of
https://github.com/Pmodules/Pmodules.git
synced 2026-06-29 02:39:39 +02:00
libpmodules.bash reviewed
- cleanup code in lib - function we need in modmanage moved to lib - some cleanup in modulecmd
This commit is contained 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
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user