File indexing completed on 2024-04-06 12:12:54
0001
0002
0003
0004
0005
0006 function findFileFor(){
0007
0008
0009
0010
0011
0012 local FILE_NAME
0013 if [ ${1:0:1} == "/" ]; then
0014 [ -f $1 ] && FOUND_FILE=$1 && return 0
0015 else
0016 FILE_NAME=$( echo $1 | sed -n -e 's:\([[:alnum:]_]\+\)[/.]\([[:alnum:]_]\+\)[/.]\([[:alnum:]_/.]\+\)$:\1/\2/python/\3:p' | sed -e 's:[\.]:/:g' ).py
0017 IFS=:
0018 for SEARCH_PATH in $CMSSW_SEARCH_PATH; do
0019 [ -f $SEARCH_PATH/$FILE_NAME ] && FOUND_FILE=$SEARCH_PATH/$FILE_NAME && return 0
0020 done
0021 fi
0022
0023
0024
0025 FOUND_FILE=""
0026 return 1
0027 }
0028
0029 function findInFile(){
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 IFS="
0051 "
0052 local -a IMPORTS_AND_LOADS_ARRAY
0053 IMPORTS_AND_LOADS_ARRAY=( $( sed -n -e "s:^[[:space:]]*\(exec[[:space:]]\+[\"']\)\?\(from[[:space:]]\+\|import[[:space:]]\+\|process\.load[[:space:]]*([[:space:]]*[\"']\|execfile[[:space:]]*([[:space:]]*[\"']\)[[:space:]]*\(\([^[:space:])\"'#]\+[/.]\)\+[^[:space:])\"'#]\+\).*:\3:p" $2 | grep -v "^FWCore.ParameterSet" ) )
0054
0055
0056
0057
0058 if [ ${
0059 if [ $EDMCONFIGTREE_TREE == "false" ]; then
0060 grep -H -n $3 $2
0061 else
0062 grep $3 $2 | while read LINE_WITH_MATCH; do
0063 if [ $EDMCONFIGTREE_COLOR == "false" ]; then
0064 [ ${
0065 echo " $LINE_WITH_MATCH" | grep $3
0066 else
0067 [ ${
0068 echo " $LINE_WITH_MATCH" | grep --color $3
0069 fi
0070 done
0071 fi
0072 fi
0073
0074
0075
0076
0077 local I
0078 for (( I=0; I<${
0079 local PYTHON_NAME=${IMPORTS_AND_LOADS_ARRAY[$I]}
0080 local INDENT
0081 local II
0082 ((II=I+1))
0083 if [ $EDMCONFIGTREE_TREE == "false" ]; then
0084 if findFileFor "$PYTHON_NAME"; then
0085 [ $SHOW_ABSOLUTE_PATH == "true" ] && echo "$FOUND_FILE" || echo "$PYTHON_NAME"
0086 findInFile "" "$FOUND_FILE" "$3"
0087 else
0088 echo "${PYTHON_NAME} *** not found in CMSSW_SEARCH_PATH ***"
0089 fi
0090 else
0091 if findFileFor "$PYTHON_NAME"; then
0092 [ $SHOW_ABSOLUTE_PATH == "true" ] && NAME_TO_SHOW=FOUND_FILE || NAME_TO_SHOW=PYTHON_NAME
0093 if [ $EDMCONFIGTREE_COLOR == "false" ]; then
0094 echo "$1 |- ${!NAME_TO_SHOW}"
0095 [ $II -ge ${
0096 else
0097 [[ $SHOW_ABSOLUTE_PATH == "true" || ${PYTHON_NAME:0:1} == "/" ]] && echo "$1 [1;44m [0m [33m${FOUND_FILE%%*([^/])}[0m${FOUND_FILE##*/}" || echo "$1 [1;44m [0m [33m${PYTHON_NAME%%*([^.])}[0m${PYTHON_NAME##*.}"
0098 [ $II -ge ${
0099 fi
0100 findInFile "$INDENT" "$FOUND_FILE" "$3"
0101 else
0102 if [ $EDMCONFIGTREE_COLOR == "false" ]; then
0103 echo "$1 |- ${PYTHON_NAME} *** not found in CMSSW_SEARCH_PATH ***"
0104 else
0105 [ ${PYTHON_NAME:0:1} == "/" ] && echo "$1 [1;44m [0m [33m${PYTHON_NAME%%*([^/])}[0m${PYTHON_NAME##*/}" || echo -n "$1 [1;44m [0m [33m${PYTHON_NAME%%*([^.])}[0m${PYTHON_NAME##*.} "
0106 echo "[43m not found in CMSSW_SEARCH_PATH [0m"
0107 fi
0108 fi
0109 fi
0110 done
0111
0112 }
0113
0114
0115 ${EDMCONFIGTREE_COLOR:=true}
0116 ${EDMCONFIGTREE_TREE:=true}
0117 [ $EDMCONFIGTREE_TREE == "false" ] && EDMCONFIGTREE_COLOR=false
0118
0119
0120 if [ $
0121 cat <<EOF
0122 edmConfigTree displays the complete tree of imported files in a given CMSSW configuration file,
0123 and optionally searches them recursively for a regular expression.
0124
0125 Usage:
0126 [34medmConfigTree [regex] configuration_file[0m
0127 regex : regular expression, as with grep
0128 configuration_file: CMSSW configuration python file
0129 (Give absolute path to display imported files' resolved absolute path.)
0130
0131 Note that the shell variable CMSSW_SEARCH_PATH must be set before edmConfigTree is invoked.
0132
0133 To suppress colors, set the shell variable EDMCONFIGTREE_COLOR=false
0134 To suppress the tree structure (and the colors), set the shell variable EDMCONFIGTREE_TREE=false
0135
0136 Examples:
0137 Display the tree of all imported files in FullChainExample_cfg.py:
0138 [34medmConfigTree FullChainExample_cfg.py[0m
0139 Display with absolute paths the tree of all imported files in FullChainExample_cfg.py:
0140 [34medmConfigTree /full/path/to/FullChainExample_cfg.py[0m
0141 Recursively search all imported files for "Verbosity":
0142 [34medmConfigTree Verbosity FullChainExample_cfg.py[0m
0143 Recursively search all imported files for "Time" or "time":
0144 [34medmConfigTree "[Tt]ime" FullChainExample_cfg.py[0m
0145 EOF
0146 exit 1
0147 fi
0148
0149 # Exit if CMSSW_SEARCH_PATH is not set.
0150 if [ ${#CMSSW_SEARCH_PATH} -eq 0 ]; then
0151 echo "CMSSW_SEARCH_PATH is not set. Exiting."
0152 exit 1
0153 fi
0154
0155 # Set extglob for extended pattern matching features in parameter expansion.
0156 shopt -s extglob
0157
0158 # If invoked with one argument, list files.
0159 if [ $# -eq 1 ]; then
0160 FILE=$1
0161 [ ${FILE:0:1} == "/" ] && SHOW_ABSOLUTE_PATH=true || SHOW_ABSOLUTE_PATH=false
0162 [ $EDMCONFIGTREE_COLOR == "false" ] && echo "$FILE" || echo "[1;44m [0m [33m${FILE%%*([^/])}[0m${FILE##*/}"
0163 findInFile " " $1
0164 fi
0165
0166 # If invoked with two arguments, list files and search them.
0167 if [ $# -eq 2 ]; then
0168 FILE=$2
0169 [ ${FILE:0:1} == "/" ] && SHOW_ABSOLUTE_PATH=true || SHOW_ABSOLUTE_PATH=false
0170 [ $EDMCONFIGTREE_COLOR == "false" ] && echo "$FILE" || echo "[1;44m [0m [33m${FILE%%*([^/])}[0m${FILE##*/}"
0171 findInFile " " $2 "$1"
0172 fi