Skip to content

Commit e190f40

Browse files
Yossi Farjounjonn-smith
Yossi Farjoun
authored andcommitted
tidy up code in cleanup function (#77)
* - fixed the ability to have multiple states (-s) in cleanup * - print out records to be removed before removing them
1 parent e1fa14d commit e190f40

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

cromshell

+32-26
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ function cleanup()
10711071
invalidSubCommand cleanup STATUS ${OPTARG}
10721072
fi
10731073

1074-
st=${OPTARG}
1074+
st="${st} ${OPTARG}"
10751075
;;
10761076
*)
10771077
invalidSubCommand cleanup flag ${OPTARG}
@@ -1086,47 +1086,52 @@ function cleanup()
10861086
fi
10871087

10881088
# Get all states if we don't specify one:
1089-
if [[ ${#st} -eq 0 ]] ; then
1089+
if [[ ${#st} -eq 0 ]] ; then
10901090
st=${TERMINAL_STATES}
10911091
fi
10921092

10931093
# Display the logo:
10941094
turtle
1095+
echo
1096+
1097+
# Remove the lines:
1098+
local tmpFile=$( makeTemp )
1099+
local tmpFile_remove=$( makeTemp )
10951100

1096-
echo
1097-
echo "State(s) selected: ${st}"
1101+
echo "I'm looking for records with the following states: ${st}"
10981102
echo
1103+
while read line ; do
1104+
for s in ${st} ; do
1105+
# Go through each line and filter by status, which is the last column:
1106+
lineStatus=$( echo $line | awk '{print $NF}' )
1107+
if [[ "${lineStatus}" == "${s}" ]] ; then
1108+
echo $line >> ${tmpFile_remove}
1109+
continue 2
1110+
fi
1111+
done
1112+
echo $line >> ${tmpFile}
1113+
done < ${CROMWELL_SUBMISSIONS_FILE}
1114+
1115+
echo "The following records are about to be removed:"
1116+
echo
1117+
1118+
cat ${tmpFile_remove}| column -t
1119+
1120+
echo
1121+
getAnswerFromUser "Are you sure you want to CLEAR the listed records? " 'Yes No' answer
10991122

1100-
getAnswerFromUser "Are you sure you want to CLEAR ALL RECORDS from these states: ${st}" 'Yes No' answer
1101-
11021123
if [[ $( echo "${answer}" | tr A-Z a-z ) == "yes" ]] ; then
11031124
echo "User answered 'Yes'."
11041125
echo
11051126

11061127
#Backup the file:
11071128
echo "Creating backup of records file:"
11081129
cp -v ${CROMWELL_SUBMISSIONS_FILE} ${CROMWELL_SUBMISSIONS_FILE}.$(date +%Y%m%dT%H%M%S ).bak
1109-
echo
1110-
1111-
# Remove the lines:
1112-
local tmpFile=$( makeTemp )
1113-
for s in ${st} ; do
1114-
echo -n "Removing records with state: ${s}"
1115-
1116-
# Go through each line and filter by status, which is the last column:
1117-
while read line ; do
1118-
lineStatus=$( echo $line | awk '{print $NF}' )
1119-
if [[ "${lineStatus}" != "${s}" ]] ; then
1120-
echo $line
1121-
fi
1122-
done < ${CROMWELL_SUBMISSIONS_FILE} > ${tmpFile}
1123-
1124-
# Copy the temp file to the final file location for the next
1125-
# iteration or for when we're done
1126-
cp ${tmpFile} ${CROMWELL_SUBMISSIONS_FILE}
1130+
echo
11271131

1128-
echo -e '\t\tDONE!'
1129-
done
1132+
# Copy the temp file to the final file location for the next
1133+
# iteration or for when we're done
1134+
cp ${tmpFile} ${CROMWELL_SUBMISSIONS_FILE}
11301135

11311136
echo 'Your cromshell logs are now clean.'
11321137
return 0
@@ -1136,6 +1141,7 @@ function cleanup()
11361141
fi
11371142
}
11381143

1144+
11391145
function assertDialogExists()
11401146
{
11411147
which dialog &>/dev/null

0 commit comments

Comments
 (0)