mirror of
https://github.com/Pmodules/Pmodules.git
synced 2026-06-29 02:39:39 +02:00
review and cleanup
- libmodules.tcl: rename implementation to variant, fixes in file name joining - modulecmd.bash.in: get available groups from 'GroupDepths'. There is no need to use a dedicated variable for housekeeping available groups.
This commit is contained in:
+20
-63
@@ -37,7 +37,6 @@ declare verbosity_lvl=${PMODULES_VERBOSITY:-'verbose'}
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
declare -a Groups='()'
|
||||
declare -A GroupDepths='()'
|
||||
declare current_modulefile=''
|
||||
declare g_shell=''
|
||||
@@ -77,7 +76,7 @@ pbuild::save_env() {
|
||||
pbuild::export_env ${shell} PMODULES_ENV
|
||||
}
|
||||
|
||||
trap 'pbuild::save_env ${g_shell} Groups GroupDepths UsedReleases UseFlags UsedGroups PMODULES_DEFAULT_GROUPS PMODULES_DEFINED_RELEASES PMODULES_DEFAULT_RELEASES' EXIT
|
||||
trap 'pbuild::save_env ${g_shell} GroupDepths UsedReleases UseFlags UsedGroups PMODULES_DEFAULT_GROUPS PMODULES_DEFINED_RELEASES PMODULES_DEFAULT_RELEASES' EXIT
|
||||
|
||||
print_version() {
|
||||
echo "
|
||||
@@ -485,11 +484,7 @@ is_group () {
|
||||
[[ -n ${group} ]] && [[ -n ${GroupDepths[${group}]} ]] && return 0
|
||||
|
||||
# not yet cached or not a group
|
||||
if [[ -d "${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}" ]]; then
|
||||
Groups+=( "${group}" )
|
||||
get_group_depths "${PMODULES_ROOT}" "${group}"
|
||||
fi
|
||||
return 1
|
||||
get_group_depths "${PMODULES_ROOT}" "${group}"
|
||||
}
|
||||
|
||||
is_used_group() {
|
||||
@@ -1077,28 +1072,14 @@ subcommand_avail() {
|
||||
done
|
||||
}
|
||||
|
||||
# get available groups
|
||||
# $1: root of modulefile hierarchy
|
||||
#
|
||||
get_groups () {
|
||||
local -r root="$1"
|
||||
{
|
||||
cd "${root}"
|
||||
# for some unknown reason [A-Z]* doesn't work on (some?) SL6 systems
|
||||
for f in [ABCDEFGHIJKLMNOPQRSTUVWXYZ]*; do
|
||||
Groups+=( $f )
|
||||
done
|
||||
};
|
||||
}
|
||||
|
||||
# compute depths or passed group
|
||||
# Note: cwd must be Pmodules root directory
|
||||
# $1: group
|
||||
#
|
||||
get_group_depth2 () {
|
||||
get_group_depth () {
|
||||
local -r group="$1"
|
||||
local -r dir="${group}/${PMODULES_MODULEFILES_DIR}"
|
||||
test -d "${dir}" || return 0
|
||||
test -d "${dir}" || return 1
|
||||
local tmp=$(find "${dir}" -depth -type f -o -type l 2>/dev/null| head -1)
|
||||
local -a tmp2=( ${tmp//\// } )
|
||||
local depth=${#tmp2[@]}
|
||||
@@ -1110,20 +1091,6 @@ get_group_depth2 () {
|
||||
GroupDepths[$group]=${depth}
|
||||
}
|
||||
|
||||
# compute depths or passed group
|
||||
# $1: root
|
||||
# $2: group
|
||||
#
|
||||
get_group_depth () {
|
||||
local -r root="$1"
|
||||
local -r group="$2"
|
||||
|
||||
{
|
||||
cd "${root}"
|
||||
get_group_depth2 "${group}"
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Compute depth for all known groups
|
||||
# $1: root of modulefile hierarchy
|
||||
@@ -1132,8 +1099,8 @@ get_group_depths () {
|
||||
{
|
||||
cd "${root}"
|
||||
local group
|
||||
for group in "${Groups[@]}"; do
|
||||
get_group_depth2 "${group}"
|
||||
for group in [ABCDEFGHIJKLMNOPQRSTUVWXYZ]*; do
|
||||
get_group_depth "${group}"
|
||||
done
|
||||
};
|
||||
}
|
||||
@@ -1152,8 +1119,7 @@ rescan_groups() {
|
||||
# for some unknown reason [A-Z]* doesn't work with some bash versions
|
||||
for group in [ABCDEFGHIJKLMNOPQRSTUVWXYZ]*; do
|
||||
if [[ -z "${GroupDepths[${group}]}" ]]; then
|
||||
Groups+=( "${group}" )
|
||||
get_group_depth2 "${group}"
|
||||
get_group_depth "${group}"
|
||||
fi
|
||||
done
|
||||
};
|
||||
@@ -1163,8 +1129,7 @@ rescan_groups() {
|
||||
# use [-a|--append|-p|--prepend] [directory|group|release...]
|
||||
#
|
||||
subcommand_use() {
|
||||
if (( ${#Groups[@]} == 0 )); then
|
||||
get_groups "${PMODULES_ROOT}"
|
||||
if (( ${#GroupDepths[@]} == 0 )); then
|
||||
get_group_depths "${PMODULES_ROOT}"
|
||||
fi
|
||||
local saved_IFS=${IFS};
|
||||
@@ -1181,7 +1146,7 @@ subcommand_use() {
|
||||
done
|
||||
std::info "\nUnused groups:\n"
|
||||
local _group
|
||||
for _group in "${Groups[@]}"; do
|
||||
for _group in "${!GroupDepths[@]}"; do
|
||||
local -i depth=${GroupDepths[${_group}]}
|
||||
if ! is_used_group "${_group}" && (( depth == 0 )); then
|
||||
std::info "\t${_group}\n"
|
||||
@@ -1243,11 +1208,6 @@ subcommand_use() {
|
||||
elif [[ "${arg}" =~ "flag=" ]]; then
|
||||
std::append_path UseFlags "${arg/flag=}"
|
||||
elif [[ ! ${arg} =~ */* ]] && [[ -d ${modulefiles_dir} ]]; then
|
||||
if [[ -z "${GroupDepths[$arg]}" ]]; then
|
||||
# not yet cached group
|
||||
Groups+=( "${arg}" )
|
||||
get_group_depth "${PMODULES_ROOT}" "${arg}"
|
||||
fi
|
||||
if (( ${GroupDepths[$arg]} != 0 )); then
|
||||
std::die 3 "%s %s: cannot add group to module path -- %s\n" \
|
||||
"${CMD}" "${FUNCNAME[0]##*_}" "${arg}"
|
||||
@@ -1472,10 +1432,10 @@ init_manpath() {
|
||||
fi
|
||||
}
|
||||
|
||||
export LOADEDMODULES
|
||||
export _LMFILES_
|
||||
export UsedGroups
|
||||
export MODULEPATH
|
||||
#export LOADEDMODULES
|
||||
#export _LMFILES_
|
||||
#export UsedGroups
|
||||
#export MODULEPATH
|
||||
|
||||
##############################################################################
|
||||
pmodules_init() {
|
||||
@@ -1484,7 +1444,6 @@ pmodules_init() {
|
||||
declare -gx UsedGroups=''
|
||||
declare -gx MODULEPATH=''
|
||||
|
||||
declare -ag Groups='()'
|
||||
declare -Ag GroupDepths='()'
|
||||
declare -g UseFlags=()
|
||||
reset_modulepath
|
||||
@@ -1594,14 +1553,14 @@ subcommand_search() {
|
||||
# write results to a temporary file for later processing
|
||||
local -r tmpfile=$( "${mktemp}" /tmp/Pmodules.XXXXXX ) \
|
||||
|| std::die 1 "Oops: unable to create tmp file!\n"
|
||||
local _group
|
||||
local group
|
||||
# loop over all groups
|
||||
for _group in "${Groups[@]}"; do
|
||||
for group in "${!GroupDepths[@]}"; do
|
||||
# loop over all directories which can be added to
|
||||
# MODULEPATH inside current group
|
||||
local depth=${GroupDepths[${_group}]}
|
||||
local depth=${GroupDepths[${group}]}
|
||||
local mpaths=( $(find \
|
||||
"${src_prefix}/${_group}/modulefiles" \
|
||||
"${src_prefix}/${group}/modulefiles" \
|
||||
-type d \
|
||||
-mindepth ${depth} -maxdepth ${depth} \
|
||||
2>/dev/null))
|
||||
@@ -1627,7 +1586,7 @@ subcommand_search() {
|
||||
[[ ${#mods[@]} == 0 ]] && continue
|
||||
for (( i=0; i<${#mods[@]}; i+=2 )); do
|
||||
printf "${fmt}" ${mods[i]} "${mods[i+1]}" \
|
||||
${_group} "${requires}" >> "${tmpfile}"
|
||||
${group} "${requires}" >> "${tmpfile}"
|
||||
done
|
||||
done
|
||||
done
|
||||
@@ -1707,8 +1666,7 @@ subcommand_search() {
|
||||
modules+=( '' )
|
||||
fi
|
||||
|
||||
if (( ${#Groups[@]} == 0 )) || [[ ${src_prefix} != ${PMODULES_ROOT} ]]; then
|
||||
get_groups "${src_prefix}"
|
||||
if (( ${#GroupDepths[@]} == 0 )) || [[ ${src_prefix} != ${PMODULES_ROOT} ]]; then
|
||||
get_group_depths "${src_prefix}"
|
||||
fi
|
||||
|
||||
@@ -1912,8 +1870,7 @@ if [[ -z "${subcommand}" ]]; then
|
||||
std::die 1 "${CMD}: no sub-command specified.\n"
|
||||
fi
|
||||
|
||||
if (( ${#Groups[@]} == 0 )); then
|
||||
get_groups "${PMODULES_ROOT}"
|
||||
if (( ${#GroupDepths[@]} == 0 )); then
|
||||
get_group_depths "${PMODULES_ROOT}"
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user