hpr-tools/Database/validate_edits.awk

54 lines
1.6 KiB
Awk
Raw Normal View History

#
# Needs to be called with a definition for variable 'csv', a file containing
# the current state of shows needing a summary and/or tags. Here we slurp the
# contents of this file into an array for the main loop to check against.
#
# Called in edit_tsu_blank thus:
#
# awk --assign "csv=$STATUSFILE" -f "$VALIDATOR" "$choice"
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Note: The chain of what does what when in this system is getting pretty
# complex, so perhaps this explanation is needed!
#
# The file denoted by $STATUSFILE above is tag_summary_actions.csv. This is
# generated by the Perl script report_missing_tags, so is only current after
# a run of this script. This is usually run though Pdmenu using Bash script
# generate_tag_reports, and this is normally done after new tags have been
# added to the system.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
BEGIN{
FS=","
while ((getline < csv) > 0) {
pending[$1] = $0
}
close(csv)
FS=" "
}
#
# Look for the show numbers and check whether they are known to be processed
#
/^show/{
if (!($2 in pending)) {
printf "Show %s is already up to date. Commented out\n",$2
errors++
#
# A bit dirty, but run sed to comment out the faulty lines
#
cmd = "sed -i -e '/^show:\\s\\?" $2 "/,/^\\s*$/{s/^/#/}' " ARGV[1]
system(cmd)
}
}
#
# Exit showing the calling Bash script whether there are errors
#
END {
exit errors > 0
}
# vim: syntax=awk:ts=8:sw=4:ai:et:tw=78:fo=tcrqn21