summaryrefslogtreecommitdiffstats
path: root/mkballots.sh
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2017-10-22 17:38:45 +0200
committerH. Peter Anvin <hpa@zytor.com>2017-10-22 17:38:45 +0200
commit390c51c307b31696e3904144e7da9f4cdec5360d (patch)
treea34c0f7490874a9c059ff4ae7fbd2c3291bf8dcd /mkballots.sh
parentf080f2093071c2a25df55eae8eaacd6530ac2af6 (diff)
downloadballot-390c51c307b31696e3904144e7da9f4cdec5360d.tar.gz
ballot-390c51c307b31696e3904144e7da9f4cdec5360d.tar.xz
ballot-390c51c307b31696e3904144e7da9f4cdec5360d.zip
Parameterize as much as possible, using a template system
Diffstat (limited to 'mkballots.sh')
-rwxr-xr-xmkballots.sh55
1 files changed, 42 insertions, 13 deletions
diff --git a/mkballots.sh b/mkballots.sh
index bee2836..d7b8b8d 100755
--- a/mkballots.sh
+++ b/mkballots.sh
@@ -2,32 +2,60 @@
export PATH=$(realpath -s $(dirname "$0"))/bin:"$PATH"
if [ -z "$1" -o -z "$2" ]; then
set +x
- echo "Usage: $0 prefix numballots [batches [scoresheets]]" 1>&2
+ echo "Usage: $0 project numballots [batches [scoresheets]]" 1>&2
exit 1
fi
nbatch="${3:-1}"
perbatch="${2:-100}"
scoresheets="${4:-1}"
-prefix="$1"
-proj="${proj:-tab2016}"
-shuf='shuf --random-source=/dev/urandom'
-if [ -z "$proj" ]; then
- proj=tab2016
+proj="${1:-test}"
+declare -A sub
+. "${proj}.conf"
+paper="${paper:-letter}"
+sub[PAPER]="${paper}"
+writeins="${writeins:-2}"
+template="${template:-$proj.tex}"
+if [ ! -f "$template" ]; then
+ set +x
+ echo "$0: template file $template missing!" 1>&2
+ exit 1
fi
+shuf='shuf --random-source=/dev/urandom'
sdaps="sdaps $proj"
rm -rf "$proj"
-sed -e "s:%%CANDIDATES%%:$shuf < '$proj'.cand:e" \
- -e 'T' -e 's/^\(.*\)$/\\choiceline{\1}/mg' \
- "$proj".tex > "$proj".pp.tex
+rm -f "$proj".sub.sed
+for s in "${!sub[@]}"; do
+ echo "s/%%${s//\//\\\/}%%/${sub[$s]//\//\\\/}/g" >> "$proj".sub.sed
+done
+cat >> "$proj".sub.sed <<EOF
+t
+s:%%WRITEINS%%::
+t writeins
+s:%%CANDIDATES%%:$shuf < '$proj'.cand:e
+T
+s/^\\(.*\\)\$/\\\\choiceline{\\1}/mg
+b
+: writeins
+EOF
+# Note: n-1 p commands as sed itself will print one
+for (( x=1 ; x < writeins ; x=x+1 )); do
+ echo 'p' >> "$proj".sub.sed
+done
+sed -f "$proj".sub.sed < "$template" > "$proj".pp.tex
$sdaps setup_tex "$proj".pp.tex
-rm "$proj".pp.tex
+rm "$proj".sub.sed "$proj".pp.tex
+if [ ! -f "$proj"/questionnaire.pdf ]; then
+ set +x
+ echo "$0: project $proj failed to compile!" 1>&2
+ exit 1
+fi
# Produce a tiebreakers file for csvconv.pl so we can reproduce the output
seq 1 $(wc -l < "$proj".cand) | $shuf | tr '\n' ',' | \
sed -e 's/,$/\n/' > "$proj"/tiebreakers.csv
# Generate score sheets (one PDF with blank ID, one with individual numbers)
-scoresheet.pl "$proj" > "$proj"/scoresheet.tex
+scoresheet.pl "$proj" "$paper" > "$proj"/scoresheet.tex
genids.pl "$prefix"/MT $scoresheets 1 > "$proj"/scoresheet.ids
-scoresheet.pl "$proj" "$proj"/scoresheet.ids > "$proj"/scoresheets.tex
+scoresheet.pl "$proj" "$paper" "$proj"/scoresheet.ids > "$proj"/scoresheets.tex
cd "$proj"
pdflatex scoresheet.tex && pdflatex scoresheet.tex
pdfmerge questionnaire.pdf scoresheet.pdf chkalign.pdf
@@ -43,4 +71,5 @@ for (( batch=1 ; batch <= nbatch ; batch++ )); do
start=$((start + perbatch))
done
# Make a backup copy of the project directory
-tar cvvfJ "$proj".sdaps.tar.xz "$proj" "$proj".tex "$proj".cand
+tar cvvfJ "$proj".sdaps.tar.xz "$proj" "$template" \
+ "$proj".cand "$proj".conf mkballots.sh