Skip to content

Instantly share code, notes, and snippets.

@skyscribe
Created January 7, 2023 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyscribe/6f54eedd8919fe6d32fc6c88c15251d3 to your computer and use it in GitHub Desktop.
Save skyscribe/6f54eedd8919fe6d32fc6c88c15251d3 to your computer and use it in GitHub Desktop.
Filter out errors generated by sphinx build, and filterout those accepted problems, support color print based on parsed problems.
#!/usr/bin/env bash
function cecho(){
RED="\033[0;31m"
GREEN="\033[0;32m" # <-- [0 means not bold
YELLOW="\033[1;33m" # <-- [1 means bold
CYAN="\033[1;36m"
# ... Add more colors if you like
NC="\033[0m" # No Color
# printf "${(P)1}${2} ${NC}\n" # <-- zsh
printf "${!1}${2} ${NC}\n" # <-- bash
}
if [ $# -ne 1 ]; then
echo "Usage: $0 <logfile>"
exit 2
fi
logFile=$1
cat ${logFile} | gawk -F ":" '{
if ((NF < 3) || ($0 !~ /((WARNING)|(ERROR)|(CRITICAL))/)) {
next;
}
if ((NF > 3) && ($2 ~ /[0-9]+/)) {
filename=$1
lineNo=$2
level=$3;
detail=$4;
} else if (NF == 3) {
# No line number? like /builds/fJxzsioR/0/oam/interfaces/fronthaul/hwmodels/Ald.rst: WARNING: document isnt
### included in any toctree
filename=$1
lineNo=0
level=$2
detail=$3
} else {
printf("Unexpected line=%s\n", $0);
next;
}
if (filename ~ /tables\/([A-Z_0-9]+)-definitions/) {
printf("~~~~ ignore error in %s, error=%s\n", filename, $4);
next;
}
# Check others
level=gensub(/\s*/, "", "g", $3);
if (level == "CRITICAL") {
print $0;
stats[level]++;
}
if (level == "ERROR") {
print $0;
stats[level]++;
}
if (level == "WARNING") {
if ($4 !~ /duplicate label/) {
print $0;
stats[level]++;
}
}
} END {
errors = 0;
for (level in stats) {
errors += stats[level];
}
if (errors == 0) {
printf("====== Validation pass without any errors!\n");
} else {
printf("@@@@@@ Totally %d errors identified", errors);
for (level in stats) {
printf(", %ss: %d", level, stats[level]);
}
printf("\n");
}
}' 2>&1 | tee filter.log
lastLine=$(tail -1 filter.log)
rm filter.log
if echo "${lastLine}" | grep -q "Totally"; then
cecho "YELLOW" "$lastLine"
cecho "RED" "!!!!!! You must fix all of those problems to proceed!!!!!!"
exit 1
else
cecho "GREEN" "$lastLine"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment