ENH: Only add new data to report.

When the last reported values are identical to the current values, do not append the same information (just with a new timestamp) to the report. Instead, just print the last report line.

With this, the report action can be scheduled periodically (e.g. via cron) without artificially inflating the report file.
This commit is contained in:
Ingo Karkat
2012-01-14 15:21:53 +01:00
parent 20b7ef6964
commit 8e3f2712a8
2 changed files with 13 additions and 4 deletions

View File

@@ -167,7 +167,7 @@ TODO: Report file updated.
>>> todo.sh report
2009-02-13T04:40:00 5 2
TODO: Report file updated.
TODO: Report file is up-to-date.
>>> todo.sh remdup
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]

13
todo.sh
View File

@@ -1193,9 +1193,18 @@ note: PRIORITY must be anywhere from A to Z."
TOTAL=$( sed -n '$ =' "$TODO_FILE" )
TDONE=$( sed -n '$ =' "$DONE_FILE" )
echo "$(date +%Y-%m-%dT%T) ${TOTAL:-0} ${TDONE:-0}" >> "$REPORT_FILE"
sed -ne '$p' "$REPORT_FILE"
NEWDATA="${TOTAL:-0} ${TDONE:-0}"
LASTREPORT=$(sed -ne '$p' "$REPORT_FILE")
LASTDATA=${LASTREPORT#* } # Strip timestamp.
if [ "$LASTDATA" = "$NEWDATA" ]; then
echo "$LASTREPORT"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file is up-to-date."
else
NEWREPORT="$(date +%Y-%m-%dT%T) ${NEWDATA}"
echo "${NEWREPORT}" >> "$REPORT_FILE"
echo "${NEWREPORT}"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
fi
;;
* )