Add duplicate abbr check (r8, r7, r6, r5)

Add a check for duplicate :abbr: anchor strings to prebuild phase
and error on duplicates.

Change-Id: I034c321a3c83aa4c0cbcf551fd90161e9e221c18
Signed-off-by: Ron Stone <ronald.stone@windriver.com>
This commit is contained in:
Ron Stone 2023-11-30 14:03:40 +00:00
parent 28afd59a74
commit 430d6fa0fe
3 changed files with 86 additions and 2 deletions

View File

@ -1,13 +1,14 @@
declare RED='\033[0;31m' declare RED='\033[0;31m'
declare OG="\033[93m"
declare GR='\033[0;32m' declare GR='\033[0;32m'
declare NC='\033[0m' declare NC='\033[0m'
# Output functions. Colorize various types of messages. # Output functions. Colorize various types of messages.
message () { echo -e "$@" 1>&2; } message () { echo -e "$@" 1>&2; }
confirmation () { message $GR$@$NC; } confirmation () { message $GR$@$NC; }
warn () { message $RED$@$NC; } warn () { message $OG$@$NC; }
error () { message $RED$@$NC; exit 1; } error () { message $RED$0:$?: $@$NC; exit 1; }
# Check for and exit if file dependancies are not met. Takes a list of full or # Check for and exit if file dependancies are not met. Takes a list of full or
# relative paths. # relative paths.
@ -52,4 +53,62 @@ trimspaces () {
echo $_s echo $_s
} }
# Sets a global hash of acronyms and definitions from rst :abbr: defs. Also
# sets an array of hash keys to facilitate sorting.
#
# Takes path to the file to parse. Optional "1" flag as second option
# suppresses plural forms such as "PVCs".
get_abbrs () {
local ABBREVS
declare -a -g acro_keys
declare -A -g acro_keyvals
local regex=":abbr:\`([A-Za-z]+)\s+\((.*)\)\`"
[[ ! -z ${1+x} ]] && [[ -e $1 ]] && ABBREVS="$1" \
|| error "Can't find abbrevs file $1"
[[ ! -z $2{+x} ]] && [[ ${2} == "1" ]] \
&& local strip_plurals=$2
while IFS= read -r line
do
if [[ $line =~ $regex ]]; then
if [[ ${strip_plurals} -eq 1 ]] && [[ ${BASH_REMATCH[1]:0-1} == "s" ]]; then
message " Skipping pluralization \"${BASH_REMATCH[1]}\""
continue
fi
acro_keys+=("${BASH_REMATCH[1]}")
acro_keyvals["${BASH_REMATCH[1]}"]="${BASH_REMATCH[2]}"
fi
done < "$ABBREVS" || error "Cannot read $ABBREVS"
}
# Report duplicate :abbr: anchor strings. (Duplicate placeholders cause
# Sphinx warnings.)
#
# Takes an array of anchor strings. Echos duplicates and returns a duplicate
# count
check_abbr_dups () {
local -a _anchors=("$@")
declare -a dups; declare -i _dup_count=0
IFS=$'\n'; dups=($(sort -f <<<"${_anchors[*]}")); unset IFS
message "... Checking for duplicate anchor strings"
for ((i=0; i < ${#dups[@]}; i++)); do
if [[ ${dups[$i]} == ${dups[$i-1]} ]]; then
warn " Duplicate anchor string \"${dups[$i]}\" found"
((_dup_count=$_dup_count+1))
fi
done
echo $_dup_count
}
declare utils_loaded=1 declare utils_loaded=1

24
dup-abbr-check.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Read a file (typlically source/shared/abbrevs.txt) and report on duplicate
# entries
. $(pwd)/_utils.sh
if [[ -z ${utils_loaded+x} ]]; then echo "Could not load utilities"; exit 1; fi
declare ABBREVS="doc/source/shared/abbrevs.txt"
# declare ABBREVS=".stx-docs/doc/source/shared/abbrevs.txt" # for testing
message "Checking for duplicate acronyms ..."
# acro_keys: array of anchor strings
# acro_keyvals: hash of anchors/definitions
get_abbrs "${ABBREVS}"
# Check for duplicate anchors in :abbr: defs. We've had problems with these
# in the past.
dup_count=$(check_abbr_dups "${acro_keys[@]}")
[[ $dup_count -gt 0 ]] && error "Duplicate(s) MUST be fixed in $ABBREVS"
confirmation "... Done"

View File

@ -21,6 +21,7 @@ commands =
python parser.py -l templates/alarms_template.rst -e tmp/events.yaml -s 100,200,300,400,500,700,800,900 -ts = -type Alarm -outputPath doc/source/fault-mgmt/openstack/ -sort Yes -product openstack -replace "|,OR" python parser.py -l templates/alarms_template.rst -e tmp/events.yaml -s 100,200,300,400,500,700,800,900 -ts = -type Alarm -outputPath doc/source/fault-mgmt/openstack/ -sort Yes -product openstack -replace "|,OR"
python parser.py -l templates/logs_template.rst -e tmp/events.yaml -s 100,200,300,400,500,700,800,900 -ts = -type Log -outputPath doc/source/fault-mgmt/openstack/ -sort Yes -product openstack -replace "|,OR" python parser.py -l templates/logs_template.rst -e tmp/events.yaml -s 100,200,300,400,500,700,800,900 -ts = -type Log -outputPath doc/source/fault-mgmt/openstack/ -sort Yes -product openstack -replace "|,OR"
bash ./normalize-includes.sh bash ./normalize-includes.sh
bash ./dup-abbr-check.sh
[testenv:postbuild-docs] [testenv:postbuild-docs]
commands = commands =