Skip to content

Commit

Permalink
post-processing of log-files
Browse files Browse the repository at this point in the history
  • Loading branch information
h-dh committed Feb 3, 2016
1 parent bd97252 commit c2fc1ed
Showing 1 changed file with 59 additions and 84 deletions.
143 changes: 59 additions & 84 deletions scripts/updateConfigFile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,46 @@
# a parameter ARG: is prefixed if the parameter could be empty

# return 1 if a single parameter was passed whose value is 'disable'
retVal=0

# conversion from former usage
if [ ! -f ${CONFIG_FILE} ] ; then
if [ -f ${CONFIG_FILE%/*}/config.conda ] ; then
if [ ${CONDA_ENV} ] ; then
echo -e "\n${QA_PATH}:" >> $CONFIG_FILE
cat ${CONFIG_FILE%/*}/config.conda >> ${CONFIG_FILE}
else
fs_x=( $( which -a qa-dkrz ) )

for f_x in ${fs_x[*]} ; do
conda_qa_path=
getCondaPath $f_x conda_qa_path

if [ ${conda_qa_path} ] ; then
echo -e "\n${conda_qa_path}:" >> $CONFIG_FILE
cat ${CONFIG_FILE%/*}/config.conda >> ${CONFIG_FILE}
break
fi
done
fi
fi

# check for a src generated file
if [ -f ${CONFIG_FILE%/*}/config.src ] ; then
echo -e "\n${QA_PATH}:" >> $CONFIG_FILE
cat ${CONFIG_FILE%/*}/config.src >> ${CONFIG_FILE}
fi
fi

test $# -eq 0 && return $retVal

# find the corresponding section in the config file
test ! -f ${CONFIG_FILE} && touch $CONFIG_FILE

# adjust for spaces a user may have edited into the section
blkBeg=0
num=0

while read line ; do
test "${is}" -a ! "${line}" && break
if [ ! "${uCF_str}" ] ; then
uCF_blkBeg=0
uCF_num=0

num=$((num + 1))
while read line ; do
uCF_num=$((uCF_num + 1))

if [ "${line}" = ${QA_PATH}: ] ; then
is=t
blkBeg=$num
str=${QA_PATH}:
continue
fi
test "${uCF_is}" -a ! "${line}" && break

if [ ${is} ] ; then
line=${line// /}
if [ "${line}" = ${QA_PATH}: ] ; then
uCF_is=t
uCF_blkBeg=$uCF_num
uCF_str=${QA_PATH}:
continue
fi

while [ ${line/==/=} != ${line} ] ; do
line=${line/==/=}
done
if [ ${uCF_is} ] ; then
line=${line// /}

str="${str} ${line}"
fi
done < ${CONFIG_FILE}
while [ ${line/==/=} != ${line} ] ; do
line=${line/==/=}
done

uCF_str="${uCF_str} ${line}"
fi
done < ${CONFIG_FILE}

blkEnd=$num
uCF_blkEnd=$uCF_num
fi

sctn=( ${str} )
str=
sctn=( ${uCF_str} )

if [ ${blkBeg} -eq 0 ] ; then
# append a new section
# append a new section
if [ ${uCF_blkBeg:-0} -eq 0 ] ; then
echo -e "\n${QA_PATH}:" >> $CONFIG_FILE

for item in $* ; do
Expand All @@ -99,42 +69,47 @@
return $retVal
fi

for item in $* ; do
test "${item}" = "${item%%=*} && item=${item}=enabled
# check items
item=$1
name=${item%=*}
value=${item#*=}

name=${item%=*}
value=${item#*=}
if [ ${value:0:7} = disable ] ; then
item=${name}=d
elif [ ${value} = ${name} ] ; then
value=
fi

test ${value} = d -o ${value} = disabled && item=${name}=d
for(( i=0 ; i < ${#sctn[*]} ; ++i )) ; do
sctn_val=${sctn[i]#*=}

for(( i=0 ; i < ${#sctn[*]} ; ++i )) ; do
if [ ${sctn[i]} = ${item} ] ; then
retVal=1
continue 2
fi
if [ ${sctn[i]%=*} = ${name} ] ; then
uCF_num=$((uCF_blkBeg+i))

if [ ${sctn[i]%=*} = ${name} ] ; then
num=$((blkBeg+i))
if [ "${value}" = d ] ; then
sed -i "${num} d" $CONFIG_FILE &> /dev/null
blkEnd=$((blkEnd -1 ))
unset sctn[i]
sctn=( ${sctn[*]} )
test $# -eq 1 && retval=1
if [ ${sctn[i]} = ${item} ] ; then
if [ "${sctn_val}" = enabled ] ; then
return 0
else
sed -i "${num} c${item}" $CONFIG_FILE &> /dev/null
return 1
fi

continue 2
elif [ "${value}" = d ] ; then
sed -i "${uCF_num} d" $CONFIG_FILE &> /dev/null
return 1
elif [ "${value}" ] ; then
sed -i "${uCF_num} c${item}" $CONFIG_FILE &> /dev/null
return 0
else
eval ${sctn[i]} # assign config file value
return 0
fi
done

if [ ${item#*=} != d ] ; then
sed -i "$((blkEnd++)) a${item}" $CONFIG_FILE &> /dev/null
sctn[i]="${item} ${sctn[i]}"
sctn=( ${sctn[*]} )
fi
done

return $retVal
# not defined
test ! "${value}" && return 1

# new
sed -i "$((uCF_blkEnd)) a${item}" $CONFIG_FILE &> /dev/null

return 0
#}

0 comments on commit c2fc1ed

Please sign in to comment.