From 17e1161fb1b691f6ba4301fd4022677efe3fb347 Mon Sep 17 00:00:00 2001 From: John Freeman Date: Tue, 16 Apr 2024 10:14:32 -0500 Subject: [PATCH] JCF: Issue #273: add a DUNEDAQ_DB_PATH environment variable to dbt-workarea-env --- scripts/dbt-setup-tools.sh | 52 +++++++++++++++++++++++++++++++++++++ scripts/dbt-workarea-env.sh | 8 +++--- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/scripts/dbt-setup-tools.sh b/scripts/dbt-setup-tools.sh index 8bf546b..14c7c5b 100644 --- a/scripts/dbt-setup-tools.sh +++ b/scripts/dbt-setup-tools.sh @@ -319,3 +319,55 @@ function load_yaml() { python3 -c "import yaml;print(yaml.safe_load(open('$1'))$2)" } #------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ + +# JCF, Apr-16-2024 +# Based on the requirements in Issue #273, this function will take the +# name of an environment variable (DUNEDAQ_DB_PATH, e.g.) and proceed +# to prioritize directories as follows: + +# 1) User directories that aren't a source code or local installation directory +# 2) Source code directories in the work area +# 3) Installation directories in the work area +# 4) Any other directories (/cvmfs, etc.) + +function prioritize_directories() { + + local dirlist_name="$1" + + local install_patt="$DBT_INSTALL_DIR/*" + local sourcecode_patt="$DBT_AREA_ROOT/sourcecode/*" + local user_patt="$HOME/*" + + local priority_level1=() + local priority_level2=() + local priority_level3=() + local priority_level4=() + + local dirlist="${!dirlist_name}" + IFS=':' read -r -a dirs <<< "$dirlist" + + for dir in "${dirs[@]}"; do + + if [[ "$dir" == $user_patt && ! "$dir" == $sourcecode_patt && ! "$dir" == $install_patt ]]; then + priority_level1+=("$dir") + elif [[ "$dir" == $sourcecode_patt ]]; then + priority_level2+=("$dir") + elif [[ "$dir" == $install_patt ]]; then + priority_level3+=("$dir") + else + priority_level4+=("$dir") + fi + done + + # First sed command is swapping whitespace for a ":", second is to remove leading and trailing ":"s + + local reordered_dirs=$( echo "${priority_level1[*]}" "${priority_level2[*]}" "${priority_level3[*]}" "${priority_level4[*]}" | sed -r 's/\s+/:/g' | sed -r 's/^:*(.*[^:]).*$/\1/' ) + + eval "$dirlist_name=\"$reordered_dirs\"" + +} + + +#------------------------------------------------------------------------------ diff --git a/scripts/dbt-workarea-env.sh b/scripts/dbt-workarea-env.sh index 4073dae..7bdb09c 100644 --- a/scripts/dbt-workarea-env.sh +++ b/scripts/dbt-workarea-env.sh @@ -201,15 +201,17 @@ for p in ${DBT_PACKAGES}; do # Share pkg_share="${PNAME//-/_}_SHARE" declare -xg "${pkg_share}"="${DBT_INSTALL_DIR}/${p}/share" - add_many_paths PATH "${PKG_INSTALL_PATH}/bin" "${PKG_INSTALL_PATH}/test/bin" add_many_paths PYTHONPATH "${PKG_INSTALL_PATH}/lib64/python" add_many_paths LD_LIBRARY_PATH "${PKG_INSTALL_PATH}/lib64" "${PKG_INSTALL_PATH}/test/lib64" add_many_paths CET_PLUGIN_PATH "${PKG_INSTALL_PATH}/lib64" "${PKG_INSTALL_PATH}/test/lib64" - add_many_paths DUNEDAQ_SHARE_PATH "${PKG_INSTALL_PATH}/share" + add_many_paths DUNEDAQ_SHARE_PATH "${PKG_INSTALL_PATH}/share" + add_many_paths DUNEDAQ_DB_PATH "${SOURCE_DIR}/$p" done -export PATH PYTHONPATH LD_LIBRARY_PATH CET_PLUGIN_PATH DUNEDAQ_SHARE_PATH +prioritize_directories DUNEDAQ_DB_PATH + +export PATH PYTHONPATH LD_LIBRARY_PATH CET_PLUGIN_PATH DUNEDAQ_SHARE_PATH DUNEDAQ_DB_PATH echo -e "${COL_GREEN}...done${COL_RESET}" echo