From 0e898d6754e9606cf9dd0a21af281f68164a8b82 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Wed, 12 Oct 2016 18:28:32 +0200 Subject: [PATCH] Pmodules/modulecmd.bash.in - get_hierarchy_depth() renamed to get_group_depth() - new function get_group_depth() to compute depth of a single group - is_group() and subcommand_use() are now able to handle groups which are not yet cached --- Pmodules/modulecmd.bash.in | 40 +++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 41f88fd..fcf1a6d 100755 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -481,7 +481,16 @@ is_used_release() { declare used_groups=":${PMODULES_USED_GROUPS}:" is_group () { - [[ -n ${group} ]] && [[ -n ${GroupDepths[${group}]} ]] + local -r group="$1" + # arg isn't emtpy and group already in cache + [[ -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 } is_used_group() { @@ -1135,9 +1144,25 @@ get_groups () { }; } +# compute depths or passed group +# $1: root of Pmodules installation +# $2: group +get_group_depth () { + local -r root="$1" + local -r group="$2" + { + cd "${root}" + local tmp=$(find "${group}/${PMODULES_MODULEFILES_DIR}" -depth -type f -o -type l | head -1) + local -a tmp2=( ${tmp//\// } ) + local depth=${#tmp2[@]} + (( depth-=4 )) + GroupDepths[$group]=${depth} + } +} + # # $1: root of modulefile hierarchy -get_hierarchy_depth () { +get_group_depths () { local -r root="$1" { cd "${root}" @@ -1158,7 +1183,7 @@ get_hierarchy_depth () { subcommand_use() { if (( ${#Groups[@]} == 0 )); then get_groups "${PMODULES_ROOT}" - get_hierarchy_depth "${PMODULES_ROOT}" + get_group_depths "${PMODULES_ROOT}" fi local saved_IFS=${IFS}; IFS=':' @@ -1233,6 +1258,11 @@ subcommand_use() { # releases are always *appended* std::append_path UsedReleases "${arg}" 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 "${CMD} ${FUNCNAME[0]##*_}: cannot add group ${arg} to module path" fi @@ -1651,7 +1681,7 @@ subcommand_search() { if (( ${#Groups[@]} == 0 )) || [[ ${src_prefix} != ${PMODULES_ROOT} ]]; then get_groups "${src_prefix}" - get_hierarchy_depth "${src_prefix}" + get_group_depths "${src_prefix}" fi for module in "${modules[@]}"; do @@ -1848,7 +1878,7 @@ done if (( ${#Groups[@]} == 0 )); then get_groups "${PMODULES_ROOT}" - get_hierarchy_depth "${PMODULES_ROOT}" + get_group_depths "${PMODULES_ROOT}" fi $subcommand "${opts[@]}"