From 47843c573b9a1510303028e9f9470be35b4000a1 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Oct 11 2013 14:27:22 +0000 Subject: Update centos-art.sh scripts. - Previously, sibling modules could not execute to themselves without trying to add another position in the chain of modules. This made all the related function scripts and variables to be loaded again in a new position which is a waste of resources. This update changes the tcar_setModuleEnvironment function to support recursive module execution. In recursive module execution, the last module in the chain can execute itself without creating a new position in the chain of modules. In these cases, the information set by the last module in the chain is reused. - Tuneup debugging output to introduce recursive execution of modules. - Previously, there was not debugging information output for executed module's related function scripts. This update changes the tcar_setModuleEnvironmentScripts function to print out debugging information for module's related function scripts. - Previously, there was not debugging information for destroyed module's related function scripts. This update changes the tcar_setModuleEnvironmentScripts function to print out debugging information for module's related function scripts. --- diff --git a/Automation/Scripts/tcar_setModuleEnvironment.sh b/Automation/Scripts/tcar_setModuleEnvironment.sh index c8cbb0b..d670058 100755 --- a/Automation/Scripts/tcar_setModuleEnvironment.sh +++ b/Automation/Scripts/tcar_setModuleEnvironment.sh @@ -49,7 +49,23 @@ function tcar_setModuleEnvironment { # Initialize module's global counter. TCAR_MODULE_COUNT=${TCAR_MODULE_COUNT:-0} - tcar_printMessage "FUNCNAME : ${FUNCNAME[1]}" --as-debugger-line + # When the last module in the chain of executed modules is the + # same module being currently executed, don't create a new + # position for it in the chain of modules. Instead, use the + # information it already has from its previous execution. In order + # for this to work, the current module must be executed as sibling + # module of other module or itself. + if [[ ${TCAR_MODULE_COUNT} -gt 0 ]];then + if [[ ${TCAR_MODULE_NAMES[((${TCAR_MODULE_COUNT} - 1))]} == ${ARG_MODULE_NAME} ]];then + if [[ ${ARG_MODULE_TYPE} == 'sibling' ]];then + tcar_printMessage '~~~~~~~~~~~~~~~~~~~~~~~~~> : '"${TCAR_MODULE_NAME} ${TCAR_MODULE_ARGUMENT}" --as-debugger-line + ${ARG_MODULE_NAME} ${ARG_MODULE_ARGS} ${@} + return + fi + fi + fi + + tcar_printMessage '=========================>: ['${TCAR_MODULE_COUNT}'] | '${FUNCNAME[1]} --as-debugger-line # Define module's base directory. This is the directory where the # initialization script is stored in. @@ -82,7 +98,7 @@ function tcar_setModuleEnvironment { # Define module's arguments. This variable is used in different # module environments to pass positional parameters from one # environment to another using local definitions. - TCAR_MODULE_ARGUMENTS[${TCAR_MODULE_COUNT}]="${ARG_MODULE_ARGS:-''} ${@}" + TCAR_MODULE_ARGUMENTS[${TCAR_MODULE_COUNT}]="${ARG_MODULE_ARGS:-} ${@}" local TCAR_MODULE_ARGUMENT=${TCAR_MODULE_ARGUMENTS[${TCAR_MODULE_COUNT}]} tcar_printMessage "TCAR_MODULE_ARGUMENT : ${TCAR_MODULE_ARGUMENT}" --as-debugger-line @@ -124,8 +140,6 @@ function tcar_setModuleEnvironment { local TEXTDOMAINDIR=${TCAR_MODULE_DIR_LOCALES} tcar_printMessage "TEXTDOMAINDIR: ${TEXTDOMAINDIR}" --as-debugger-line - tcar_printMessage "=========================>: [${TCAR_MODULE_COUNT}]=${TCAR_MODULE_NAME} ${TCAR_MODULE_ARGUMENT}" --as-debugger-line - # Increment module's counter just before creating next module's # base directory. TCAR_MODULE_COUNT=$(( ${TCAR_MODULE_COUNT} + 1 )) @@ -142,17 +156,17 @@ function tcar_setModuleEnvironment { tcar_setModuleEnvironmentScripts # Execute module's initialization script with its arguments. + tcar_printMessage '-------------------------> : '"${TCAR_MODULE_NAME} ${TCAR_MODULE_ARGUMENT}" --as-debugger-line ${TCAR_MODULE_NAME} ${TCAR_MODULE_ARGUMENT} # Unset module-specific environment. + tcar_printMessage '<------------------------- : '"${TCAR_MODULE_NAME} ${TCAR_MODULE_ARGUMENT}" --as-debugger-line tcar_unsetModuleEnvironment # Decrement module counter just after unset unused module # environments. TCAR_MODULE_COUNT=$(( ${TCAR_MODULE_COUNT} - 1 )) - tcar_printMessage "<=========================: [${TCAR_MODULE_COUNT}]=${TCAR_MODULE_NAME} ${TCAR_MODULE_ARGUMENT}" --as-debugger-line - # Unset array and non-array variables used in this function. if [[ ${TCAR_MODULE_COUNT} -eq 0 ]];then unset TCAR_MODULE_NAMES @@ -169,4 +183,7 @@ function tcar_setModuleEnvironment { unset TCAR_MODULE_DIR_LOCALES unset TCAR_MODULE_DIR_CONFIGS fi + + tcar_printMessage '<=========================: ['${TCAR_MODULE_COUNT}'] | '${FUNCNAME[1]} --as-debugger-line + } diff --git a/Automation/Scripts/tcar_setModuleEnvironmentScripts.sh b/Automation/Scripts/tcar_setModuleEnvironmentScripts.sh index 52bff23..c575d08 100755 --- a/Automation/Scripts/tcar_setModuleEnvironmentScripts.sh +++ b/Automation/Scripts/tcar_setModuleEnvironmentScripts.sh @@ -38,9 +38,10 @@ function tcar_setModuleEnvironmentScripts { local FUNCTION_PATTERN="^function[[:space:]]+${TCAR_MODULE_NAME}(_[[:alnum:]]+)?[[:space:]]+{[[:space:]]*$" # Define the list of files. - local MODULE_SCRIPTS="${TCAR_MODULE_INIT_FILE}" + local TCAR_MODULE_SCRIPT='' + local TCAR_MODULE_SCRIPTS="${TCAR_MODULE_INIT_FILE}" if [[ -d ${TCAR_MODULE_DIR} ]];then - MODULE_SCRIPTS="${MODULE_SCRIPTS} + TCAR_MODULE_SCRIPTS="${TCAR_MODULE_SCRIPTS} $(tcar_getFilesList ${TCAR_MODULE_DIR} \ --pattern="${TCAR_MODULE_DIR}/${TCAR_MODULE_NAME}_[[:alnum:]]+\.sh$" --type='f')" fi @@ -49,30 +50,36 @@ function tcar_setModuleEnvironmentScripts { # location specified stop the script execution. Otherwise the # script will surely try to execute a function that haven't been # exported yet and report an error about it. - if [[ -z ${MODULE_SCRIPTS} ]];then + if [[ -z ${TCAR_MODULE_SCRIPTS} ]];then tcar_printMessage "${FUNCNAME}: `gettext "No function file was found."`" --as-error-line fi # Process the list of files. - for MODULE_SCRIPT in ${MODULE_SCRIPTS};do + for TCAR_MODULE_SCRIPT in ${TCAR_MODULE_SCRIPTS};do # Verify the execution rights for function file. - tcar_checkFiles -ex ${MODULE_SCRIPT} + tcar_checkFiles -ex ${TCAR_MODULE_SCRIPT} # Verify that function files have not been already exported. # If they have been already exported don't export them again. # Instead, continue with the next function file in the list. - declare -F | gawk '{ print $3 }' | egrep "^${MODULE_SCRIPT}$" > /dev/null + declare -F | gawk '{ print $3 }' | egrep "^${TCAR_MODULE_SCRIPT}$" > /dev/null if [[ $? -eq 0 ]];then continue fi # Initialize the function file. - . ${MODULE_SCRIPT} + . ${TCAR_MODULE_SCRIPT} + + # Retrieve the function's name from function's file. + local TCAR_MODULE_SCRIPT_FN=$(egrep "${FUNCTION_PATTERN}" ${TCAR_MODULE_SCRIPT} \ + | gawk '{ print $2 }') # Export the function names inside the file to current shell # script environment. - export -f $(egrep "${FUNCTION_PATTERN}" ${MODULE_SCRIPT} | gawk '{ print $2 }') + export -f ${TCAR_MODULE_SCRIPT_FN} + + tcar_printMessage "export -f : ${TCAR_MODULE_SCRIPT_FN}" --as-debugger-line done diff --git a/Automation/Scripts/tcar_unsetModuleEnvironment.sh b/Automation/Scripts/tcar_unsetModuleEnvironment.sh index 6a77d98..69d3ae3 100755 --- a/Automation/Scripts/tcar_unsetModuleEnvironment.sh +++ b/Automation/Scripts/tcar_unsetModuleEnvironment.sh @@ -41,12 +41,13 @@ function tcar_unsetModuleEnvironment { # of function definitions previously exported by # `tcar_setModuleEnvironmentScripts'. Be sure to limit the list # to function names that start with the suffix specified only. - local FUNCTION_DEF='' - local FUNCTION_DEFS=$(declare -F | gawk '{ print $3 }' | egrep "^${TCAR_MODULE_NAME}") + local TCAR_MODULE_SCRIPT_FN='' + local TCAR_MODULE_SCRIPT_FNS=$(declare -F | gawk '{ print $3 }' | egrep "^${TCAR_MODULE_NAME}") # Unset function names from current execution environment. - for FUNCTION_DEF in ${FUNCTION_DEFS};do - unset -f ${FUNCTION_DEF} + for TCAR_MODULE_SCRIPT_FN in ${TCAR_MODULE_SCRIPT_FNS};do + unset -f ${TCAR_MODULE_SCRIPT_FN} + tcar_printMessage "unset -f : ${TCAR_MODULE_SCRIPT_FN}" --as-debugger-line done }