Page MenuHomec4science

bamc_students.sh
No OneTemporary

File Metadata

Created
Thu, Jun 6, 03:48

bamc_students.sh

#!/bin/bash
function action_students() {
local rc=0 item
while [ $# -gt 0 ]; do
item=$1
assert_exam $item; if [ $? -ne 0 ]; then ((rc++)); shift; continue; fi
assert_project $item; if [ $? -ne 0 ]; then ((rc++)); shift; continue; fi
assert_template; if [ $? -ne 0 ]; then ((rc++)); shift; continue; fi
perma "Preparing student list for '$item'"
local exam=$DIR_WORKSPACE/$DIR_EXAMS/$item
local project=$DIR_WORKSPACE/$DIR_PROJECTS/$item
local lang=$(get_lang $item)
local conf=$exam/$FILE_EXAM
local IFS=$'\n' key_val
# First page of the list
verbose "Adding cover page"
cp $DIR_DATA/list/$lang/list.tex $project/list.tex
for key_val in $(cat $conf); do
pattern="#$(echo $key_val | cut -d ':' -f 1)#"
string=$(echo $key_val | cut -d ':' -f 2-)
replace_in_file $pattern $string $project/list.tex
done
# Rows (list content)
local rows=$project/rows.tex
rm -f $rows
local i=0 tab=1 prev_section='' line id name sciper section comment
for line in $(tail -n +2 $project/$FILE_STUDENTS); do
((i++))
# id field
id=$(echo $line | cut -d ',' -f 1)
id=$(printf "%3s" $id)
id=$(echo $id | sed "s/ /~/g")
# name field
name=$(echo $line | cut -d ',' -f 3)
if [ $(echo -n $name | wc -c) -gt 30 ]; then name=$(echo $name | cut -c 1-$LIST_MAX_CHAR)"…"; fi
# sciper, section and comment field
sciper=$(echo $line | cut -d ',' -f 2)
section=$(echo $line | cut -d ',' -f 4)
comment=$(echo $line | cut -d ',' -f 6)
# Special cases
if [ "$comment" == "n/a" ]; then comment=''; fi
if [ "$comment" == "OK" ]; then comment=''; fi
# Final formatting
name=$(printf "%-30s" $name)
name=$(echo $name | sed "s/ /~/g")
# Do we need to start a new table ? (first page or new page)
if [ $tab -eq 1 ]; then
verbose "Starting new table (at student #$id)"
cat $DIR_DATA/list/$lang/start_tab.tex >> $rows
tab=0
fi
# Need for a new table ??
if [ "$section" != "$prev_section" ]; then
if [ $i -ne 1 ]; then
verbose "This is a different section, starting new table (at student #$id)"
cat $DIR_DATA/list/$lang/end_tab.tex >> $rows
cat $DIR_DATA/list/$lang/start_tab.tex >> $rows
i=1
fi
prev_section=$section
fi
# Insert row in tex file
echo "\texttt{$id} & \texttt{$sciper} & \texttt{$section} & \texttt{$name} & & & {\tiny \texttt{$comment}} "'\\ \hline' >> $rows
# Page is complete ?
if [ $(($i % 50)) -eq 0 ]; then
verbose "Page is full after $i students (at student #$id)"
cat $DIR_DATA/list/$lang/end_tab.tex >> $rows
tab=1
fi
done
# Finish table if needed
if [ $(($i % 50)) -ne 0 ]; then
verbose "Closing table after last student (at student #$id)"
cat $DIR_DATA/list/$lang/end_tab.tex >> $rows
fi
# Compile list.tex
local cwd=$(pwd)
cd $project
# Run pdflatex twice to get total number of pages
#pdflatex list.tex > /dev/null 2>&1 && pdflatex list.tex > /dev/null 2>&1
pdflatex -interaction=nonstopmode list.tex > /dev/null 2>&1
if [ $? -eq 0 ]; then pdflatex -interaction=nonstopmode list.tex > /dev/null 2>&1; fi
cd $cwd
check_file_exists $project/list.pdf
if [ $? -ne 0 ]; then error "List not generated"; ((rc++)); shift; continue; fi
# Prepare output dir
mkdir -p $DIR_WORKSPACE/$DIR_STUDENTS
# Copy PDF and CSV file
cp $project/list.pdf $DIR_WORKSPACE/$DIR_STUDENTS/STUDENTS-$item-${lang}.pdf
cp $project/$FILE_STUDENTS $DIR_WORKSPACE/$DIR_STUDENTS/STUDENTS-$item-${lang}.csv
# Move on to the next item
shift
done
return $rc
}
# EOF

Event Timeline