diff --git a/lib/bash/functions.sh b/lib/bash/functions.sh index 7e5cdef..e9235a7 100644 --- a/lib/bash/functions.sh +++ b/lib/bash/functions.sh @@ -1,777 +1,778 @@ #!/bin/bash function get_targets() { # TARGETS TARGETS="check:do_check|\ blank:do_blank|\ test:do_test|\ project:do_project|\ clean:do_clean|\ sample:do_sample|\ pdf:do_pdf|\ all:do_check,do_blank,do_sample,do_pdf,do_list|\ webdav_catalog:do_webdav_catalog|\ webdav_sample:do_webdav_sample|\ webdav_list:do_webdav_list|\ webdav_pdf:do_webdav_pdf|\ webdav_all:do_webdav_catalog,do_webdav_sample,do_webdav_list,do_webdav_pdf|\ list:do_list|\ help:do_help|\ scans:do_scans|\ analyse:do_analyse|\ associate:do_associate|\ export:do_export|\ annotate:do_annotate|\ mailing:do_mailing" echo $TARGETS | tr '|' '\n' | grep "^$1:" | cut -d ':' -f 2- | tr ',' ' ' } function parse_arguments() { if [ $# -lt 1 ]; then set 'test'; fi while [ $# -gt 0 ]; do case "$1" in '--only'|'-o') shift echo teacher_list:$1 | tr ',' ' ' shift ;; '--params'|'-p') shift echo parameters:$1 | tr ',' ' ' shift ;; *) echo target:$(get_targets $1) shift ;; esac done } function get_param_value() { local IFS=' ' for p in $(echo $PARAMETERS | tr ',' ' '); do echo $p | grep "$1=" | cut -d '=' -f 2 done } function do_actions() { ACTIONS=$(parse_arguments $@ | grep "^target:" | cut -d ':' -f 2-) TEACHERS=$(parse_arguments $@ | grep "^teacher_list:" | cut -d ':' -f 2-) PARAMETERS=$(parse_arguments $@ | grep "^parameters:" | cut -d ':' -f 2-) local rc=0 if [ -z "$ACTIONS" ]; then echo "Nothing to do!"; exit 0; fi for ACTION in $(echo "$ACTIONS"); do tell_if_verbose "Processing : ($ACTION)" process_action $ACTION rc=$((rc+$?)) done if [ $rc -gt 0 ]; then echo "RC=$rc" fi exit $rc } function tell_if_verbose() { if [ "$(get_param_value 'mode')" = 'verbose' ]; then echo "$@"; fi } function do_help() { echo $(basename $0)" [--only teacher,teacher] [--params ask=no,lang=xx] action [action ...] Options: --only, -o: only process the following teachers (comma separated list) --params, -p: set/force some parameters (e.g. ask=no,mode=verbose,lang=fr) Actions: help: print this help test: do nothing - usefull for testing with --only ... # Exam preparation project: build AMC project clean: clean output dirs, projects, etc sample: build samples PDF (sample) blank: build blank exam PDF (blank and catalog) pdf: build final PDF (exam and correction) list: build exam students list all: build blank, sample, final and list PDF files # Exam publication webdav_catalog: publish catalog PDF files to \$DIR_WEBDAV_CATALOGS webdav_sample: publish sample PDF files to \$DIR_WEBDAV_SAMPLES [...]" #echo $TARGETS | tr '|' '\n' | sed "s/:/ => /g" | sed "s/,/, /g" } function process_action() { case "$1" in "do_clean") do_clean;; "do_project") do_project;; "do_sample") do_sample;; "do_pdf") do_pdf;; "do_help") do_help;; "do_scans") do_scans;; "do_analyse") do_analyse;; "do_associate") do_associate;; "do_annotate") do_annotate;; "do_export") do_export;; "do_mailing") do_mailing;; "do_test") do_test;; "do_blank") do_blank;; "do_check") do_check;; "do_list") do_list;; "do_webdav_catalog") do_webdav_catalog;; "do_webdav_sample") do_webdav_sample;; "do_webdav_list") do_webdav_list;; "do_webdav_pdf") do_webdav_pdf;; *) echo "Unimplemented action: '$1'" return 1 ;; esac return $? } function do_list() { local rc=0 local lang line id sciper name section IFS i tab FILE list_file for teacher in $(get_teachers); do tell_if_verbose " - $teacher" if [ ! -d $DIR_TEACHERS/$teacher ]; then echo "ERROR: [$teacher] teacher not found." ((rc++)) else lang=$(get_lang $teacher) FILE=$DIR_TEACHERS/$teacher/$FILE_PROF IFS=$'\n' cp $DIR_LIST/$lang/list.tex $DIR_EXAMS/$teacher/$FILE_LIST_MAIN list_file=$DIR_EXAMS/$teacher/$FILE_LIST_MAIN check_file_exists $list_file for replace in $(cat $FILE); do pattern="#$(echo $replace | cut -d ':' -f 1)#" string=$(echo $replace | cut -d ':' -f 2-) sed "s/$pattern/$string/g" $list_file > tmp.$$ mv tmp.$$ $list_file done rm -f $DIR_EXAMS/$teacher/$FILE_LIST_ROWS i=0 tab=1 prev_section='' for line in $(tail -n +2 $DIR_EXAMS/$teacher/$FILE_STUDENTS); do ((i++)) if [ $tab -eq 1 ]; then cat $DIR_LIST/$lang/$FILE_LIST_TSTART >> $DIR_EXAMS/$teacher/$FILE_LIST_ROWS tab=0 fi # id field id=$(echo $line | cut -d ',' -f 1) id=$(printf "%3s" $id) id=$(echo $id | sed "s/ /~/g") name=$(echo $line | cut -d ',' -f 2) if [ $(echo -n $name | wc -c) -gt $LIST_MAX_CHAR ]; then name=$(echo $name | cut -c 1-$LIST_MAX_CHAR)"…"; fi sciper=$(echo $line | cut -d ',' -f 3) section=$(echo $line | cut -d ',' -f 4) comment=$(echo $line | cut -d ',' -f 10) if [ "$comment" == "n/a" ]; then comment=''; fi if [ "$section" == "XXX" ]; then section=''; name="SCIPER:"; fi name=$(printf "%-${LIST_MAX_CHAR}s" $name) name=$(echo $name | sed "s/ /~/g") if [ "$section" != "$prev_section" ]; then if [ $i -ne 1 ]; then cat $DIR_LIST/$lang/$FILE_LIST_TEND >> $DIR_EXAMS/$teacher/$FILE_LIST_ROWS cat $DIR_LIST/$lang/$FILE_LIST_TSTART >> $DIR_EXAMS/$teacher/$FILE_LIST_ROWS i=1 fi prev_section=$section fi echo "\texttt{$id} & \texttt{$sciper} & \texttt{$section} & \texttt{$name} & & & {\tiny \texttt{$comment}} "'\\ \hline' >> $DIR_EXAMS/$teacher/$FILE_LIST_ROWS if [ $(($i % $LIST_ROWS_PER_PAGE)) -eq 0 ]; then cat $DIR_LIST/$lang/$FILE_LIST_TEND >> $DIR_EXAMS/$teacher/$FILE_LIST_ROWS tab=1 fi done if [ $(($i % $LIST_ROWS_PER_PAGE)) -ne 0 ]; then cat $DIR_LIST/$lang/$FILE_LIST_TEND >> $DIR_EXAMS/$teacher/$FILE_LIST_ROWS fi pdf_list=$(echo $FILE_LIST_MAIN | cut -d '.' -f 1)'.pdf' cd $DIR_EXAMS/$teacher/ # Run pdflatex twice to get total number of pages pdflatex ./$FILE_LIST_MAIN 2>&1 > /dev/null pdflatex ./$FILE_LIST_MAIN 2>&1 > /dev/null cd - > /dev/null mkdir -p $DIR_LIST_OUT cp $DIR_EXAMS/$teacher/$pdf_list $DIR_LIST_OUT/List-$teacher.pdf cp $DIR_TEACHERS/$teacher/$FILE_STUDENTS $DIR_LIST_OUT/List-$teacher.csv fi done return $rc } function check_project_exists() { local teacher=$1 if [ ! -d $DIR_EXAMS/$teacher ]; then echo "No project found for teacher: $1" echo "Did you run \"project\" action ?" exit 1 fi } function get_teachers() { if [ -n "$TEACHERS" ]; then echo "$TEACHERS"; return; fi find $DIR_TEACHERS -maxdepth 1 -mindepth 1 -type d -exec basename {} \; | grep -v ".ignore$" | sort } function do_test() { local rc=0 for teacher in $(get_teachers); do tell_if_verbose " - $teacher" if [ ! -d $DIR_TEACHERS/$teacher ]; then echo "ERROR: [$teacher] teacher not found." ((rc++)) else echo " Nothing done. just testing." fi done return $rc } function check_file_exists() { if [ ! -r $1 ]; then if [ $# -lt 2 ]; then echo "ERROR: File not found: $1"; fi if [ -n "$2" ]; then return $2; else exit 1; fi fi return 0 } function get_lang() { local forced_lang=$(get_param_value 'lang') if [ -n "$forced_lang" ]; then echo $forced_lang; else local FILE=$DIR_TEACHERS/$1/$FILE_LANG check_file_exists $FILE cat $FILE fi } function import_tex_files() { local teacher=$1 local lang=$(get_lang $teacher) cp $DIR_DATA/base/* $DIR_EXAMS/$teacher/ cp $DIR_DATA/$lang/* $DIR_EXAMS/$teacher/ } function override_tex_files() { local teacher=$1 find $DIR_TEACHERS/$teacher/ -name '*.tex' -exec cp {} $DIR_EXAMS/$teacher/ \; } function import_student_file() { local teacher=$1 local lang=$(get_lang $teacher) local FILE=$DIR_TEACHERS/$teacher/$FILE_STUDENTS check_file_exists $FILE cp $FILE $DIR_EXAMS/$teacher/$FILE_STUDENTS # Add extra students local nb=0 local IFS=$'\n' local id=$(tail -n 1 $DIR_EXAMS/$teacher/$FILE_STUDENTS | cut -d ',' -f 1) local sample=$(head -n 1 $DIR_CSV/extra.csv) while [ $nb -lt $EXTRA_COPIES ]; do ((nb++)) ((id++)) echo $sample | sed "s/#NB#/$nb/g" | sed "s/#ID#/$id/g" | sed "s/#SCIPER#/FAKE-$nb/g" | sed "s/#EMAIL#/$DEFAULT_EMAIL/g" | sed "s/#SEMESTER#/$SEMESTER/g" >> $DIR_EXAMS/$teacher/$FILE_STUDENTS done } function get_expected_page_per_exam() { local teacher=$1 local FILE=$DIR_TEACHERS/$teacher/$FILE_PROF cat $FILE | grep '^TOTAL_PAGES:' | cut -d ':' -f 2 } function customize_tex_files() { local teacher=$1 replace local lang=$(get_lang $teacher) local FILE=$DIR_TEACHERS/$teacher/$FILE_PROF check_file_exists $FILE # professor.tex local prof_file=$DIR_EXAMS/$teacher/$FILE_PROF_TEX IFS=$'\n' check_file_exists $prof_file for replace in $(cat $FILE); do pattern="#$(echo $replace | cut -d ':' -f 1)#" string=$(echo $replace | cut -d ':' -f 2-) sed "s/$pattern/$string/g" $prof_file > tmp.$$ mv tmp.$$ $prof_file done # exam.tex lang=$(echo $lang | tr '[a-z]' '[A-Z]') sed "s/#LANG#/$lang/g" $DIR_EXAMS/$teacher/$FILE_EXAM_BASENAME.tex > tmp.$$ mv tmp.$$ $DIR_EXAMS/$teacher/$FILE_EXAM_BASENAME.tex # Add specific.tex file if [ -r $DIR_EXAMS/$teacher/specific.tex ]; then sed 's?% #SPECIFIC#?\\input{./specific.tex}?g' $DIR_EXAMS/$teacher/$FILE_EXAM_BASENAME.tex > tmp.$$ mv tmp.$$ $DIR_EXAMS/$teacher/$FILE_EXAM_BASENAME.tex fi } function build_sections() { local question_file question section_file section teacher=$1 local lang=$(get_lang $teacher) IFS=$'\n' FILE=$DIR_TEACHERS/$teacher/$FILE_SECTIONS mkdir -p $DIR_EXAMS/$teacher check_file_exists $FILE local section_num=0 rm -f $DIR_EXAMS/$teacher/sections.tex $DIR_EXAMS/$teacher/random-sections.tex for section in $(cat $FILE); do ((section_num++)) section_file=$DIR_EXAMS/$teacher/section_${section_num}.tex rm -f $section_file for question in $(echo $section | tr ',' '\n'); do #echo "Adding $question to section $section_file..."; question_file=$DIR_QUESTIONS/$lang/$question check_file_exists $question_file echo "%% From $lang/$question =======================================" >> $section_file echo '\element{section'$section_num'}{' >> $section_file cat $question_file >> $section_file echo '}' >> $section_file done #echo "Updating 'sections.tex' file" echo "\input{./section_${section_num}.tex}" >> $DIR_EXAMS/$teacher/sections.tex #echo "Updating 'random-sections.tex' file" echo "\input{./header_${section_num}.tex} \melangegroupe{section${section_num}} \restituegroupe{section${section_num}} " >> $DIR_EXAMS/$teacher/random-sections.tex done } function do_sample() { local teacher local lang local runs local ok local rc=0 for teacher in $(get_teachers); do ok=0 tell_if_verbose " - $teacher" check_project_exists $teacher if [ -r $DIR_EXAMS/$teacher/INVALID ]; then ((rc++)); break; fi runs=$PDFLATEX_RUNS mv $DIR_EXAMS/$teacher/$FILE_STUDENTS $DIR_EXAMS/$teacher/$FILE_STUDENTS.sav cp $DIR_CSV/$FILE_SAMPLE_CSV $DIR_EXAMS/$teacher/$FILE_STUDENTS cd $DIR_EXAMS/$teacher rm -f DOC-subject.pdf DOC-correction.pdf catalog.pdf while [ $runs -gt 0 ]; do auto-multiple-choice prepare --mode s --with pdflatex --filter latex --prefix ./ ./$FILE_EXAM_BASENAME.tex --out-sujet DOC-subject.pdf --out-corrige DOC-correction.pdf 2>&1 > /dev/null | grep -v 'deprecated' check_file_exists DOC-subject.pdf 1 if [ $? -ne 0 ]; then runs=0; else ok=1; fi; ((runs--)) done cd - 2>&1 > /dev/null mv $DIR_EXAMS/$teacher/$FILE_STUDENTS.sav $DIR_EXAMS/$teacher/$FILE_STUDENTS if [ $ok -eq 1 ]; then mkdir -p $DIR_SAMPLES lang=$(get_lang $teacher) mv $DIR_EXAMS/$teacher/DOC-subject.pdf $DIR_SAMPLES/Sample-$teacher-$lang.pdf else ((rc++)) echo "ERROR: [$teacher] Sample not generated." fi done; return $rc } function do_check() { local teacher local runs local ok local rc=0 for teacher in $(get_teachers); do ok=0 tell_if_verbose " - $teacher" check_project_exists $teacher runs=$PDFLATEX_RUNS mv $DIR_EXAMS/$teacher/$FILE_STUDENTS $DIR_EXAMS/$teacher/$FILE_STUDENTS.sav cp $DIR_CSV/$FILE_BLANK_CSV $DIR_EXAMS/$teacher/$FILE_STUDENTS cd $DIR_EXAMS/$teacher rm -f DOC-subject.pdf DOC-correction.pdf catalog.pdf while [ $runs -gt 0 ]; do auto-multiple-choice prepare --mode s --with pdflatex --filter latex --prefix ./ ./$FILE_EXAM_BASENAME.tex --out-sujet DOC-subject.pdf --out-corrige DOC-correction.pdf 2>&1 > /dev/null | grep -v 'deprecated' if [ ! -r DOC-subject.pdf ]; then runs=0; else ok=1; fi; if [ ! -r DOC-correction.pdf ]; then runs=0; else ok=1; fi; if [ ! -r catalog.pdf ]; then runs=0; else ok=1; fi; ((runs--)) done cd - 2>&1 > /dev/null mv $DIR_EXAMS/$teacher/$FILE_STUDENTS.sav $DIR_EXAMS/$teacher/$FILE_STUDENTS if [ $ok -eq 0 ]; then echo "ERROR: [$teacher] exam.tex does not compile." touch $DIR_EXAMS/$teacher/INVALID ((rc++)) else rm -f $DIR_EXAMS/$teacher/INVALID fi done; return $rc } function do_blank() { local teacher local lang local runs local ok local rc=0 for teacher in $(get_teachers); do ok=0 tell_if_verbose " - $teacher" check_project_exists $teacher if [ -r $DIR_EXAMS/$teacher/INVALID ]; then ((rc++)); break; fi runs=$PDFLATEX_RUNS mv $DIR_EXAMS/$teacher/$FILE_STUDENTS $DIR_EXAMS/$teacher/$FILE_STUDENTS.sav cp $DIR_CSV/$FILE_BLANK_CSV $DIR_EXAMS/$teacher/$FILE_STUDENTS cd $DIR_EXAMS/$teacher rm -f DOC-subject.pdf DOC-correction.pdf catalog.pdf while [ $runs -gt 0 ]; do auto-multiple-choice prepare --mode s --with pdflatex --filter latex --prefix ./ ./$FILE_EXAM_BASENAME.tex --out-sujet DOC-subject.pdf --out-corrige DOC-correction.pdf 2>&1 > /dev/null | grep -v 'deprecated' check_file_exists DOC-subject.pdf 1 if [ $? -ne 0 ]; then runs=0; else ok=1; fi; check_file_exists DOC-correction.pdf 1 if [ $? -ne 0 ]; then runs=0; else ok=1; fi; check_file_exists catalog.pdf 1 if [ $? -ne 0 ]; then runs=0; else ok=1; fi; ((runs--)) done cd - 2>&1 > /dev/null mv $DIR_EXAMS/$teacher/$FILE_STUDENTS.sav $DIR_EXAMS/$teacher/$FILE_STUDENTS if [ $ok -eq 1 ]; then mkdir -p $DIR_BLANKS lang=$(get_lang $teacher) mv $DIR_EXAMS/$teacher/DOC-subject.pdf $DIR_BLANKS/Blank-$teacher-$lang.pdf mv $DIR_EXAMS/$teacher/DOC-correction.pdf $DIR_BLANKS/Correction-Blank-$teacher-$lang.pdf mv $DIR_EXAMS/$teacher/catalog.pdf $DIR_BLANKS/Catalog-$teacher-$lang.pdf else ((rc++)) echo "ERROR: [$teacher] Blank not generated." fi done; return $rc } function do_pdf() { local teacher local lang local runs local ok=0 local rc for teacher in $(get_teachers); do ok=0 tell_if_verbose " - $teacher" check_project_exists $teacher if [ -r $DIR_EXAMS/$teacher/INVALID ]; then ((rc++)); break; fi runs=$PDFLATEX_RUNS cd $DIR_EXAMS/$teacher while [ $runs -gt 0 ]; do tell_if_verbose " (step 1/3)" auto-multiple-choice prepare --mode s --with pdflatex --filter latex --prefix ./ ./$FILE_EXAM_BASENAME.tex --out-sujet DOC-subject.pdf --out-corrige DOC-correction.pdf --out-calage DOC-calage.xy 2>&1 > /dev/null | grep -v 'deprecated' ((runs--)) check_file_exists DOC-subject.pdf 1 if [ $? -ne 0 ]; then runs=0; else ok=1; fi; check_file_exists DOC-correction.pdf 1 if [ $? -ne 0 ]; then runs=0; else ok=1; fi; check_file_exists DOC-calage.xy 1 if [ $? -ne 0 ]; then runs=0; else ok=1; fi; done if [ $ok -eq 1 ]; then tell_if_verbose " (step 2/3)" auto-multiple-choice prepare --mode b --with pdflatex --filter latex --prefix ./ ./$FILE_EXAM_BASENAME.tex --data ./data/ 2>&1 > /dev/null | grep -v 'deprecated' tell_if_verbose " (step 3/3)" auto-multiple-choice meptex --src ./DOC-calage.xy --data ./data --debug /dev/null 2>&1 > /dev/null fi cd - 2>&1 > /dev/null if [ $ok -eq 1 ]; then mkdir -p $DIR_PDF lang=$(get_lang $teacher) cp $DIR_EXAMS/$teacher/DOC-subject.pdf $DIR_PDF/Exam-$teacher-$lang.pdf cp $DIR_EXAMS/$teacher/DOC-correction.pdf $DIR_PDF/Exam-$teacher-$lang-CORRECTION.pdf # Validate page count nb_of_students=$(tail -n 1 $DIR_EXAMS/$teacher/$FILE_STUDENTS | cut -d ',' -f 1) ppe=$(get_expected_page_per_exam $teacher) expected_page_count=$(echo "$ppe * $nb_of_students" | bc) actual_page_count=$(pdfinfo $DIR_PDF/Exam-$teacher-$lang.pdf | grep '^Pages:' | rev | cut -d ' ' -f 1 | rev) if [ $expected_page_count -ne $actual_page_count ]; then ((rc++)) echo "Unexpected number of pages generated." fi echo "$actual_page_count page(s) generated for $nb_of_students students. $expected_page_count pag(s) were expected." > $DIR_PDF/Exam-$teacher-$lang.log else ((rc++)) echo "Exam not generated for $teacher." fi done return $rc } function build_amc_project() { local teacher=$1 mkdir -p $DIR_EXAMS/$teacher/cr/corrections/jpg mkdir -p $DIR_EXAMS/$teacher/cr/corrections/pdf mkdir -p $DIR_EXAMS/$teacher/cr/diagnostic mkdir -p $DIR_EXAMS/$teacher/cr/zooms mkdir -p $DIR_EXAMS/$teacher/data mkdir -p $DIR_EXAMS/$teacher/exports mkdir -p $DIR_EXAMS/$teacher/scans mkdir -p $DIR_EXAMS/$teacher/copies mkdir -p $DIR_EXAMS/$teacher/media cp $DIR_CONFIG/$FILE_AMC_OPTIONS $DIR_EXAMS/$teacher/$FILE_AMC_OPTIONS } function add_media_files() { local teacher=$1 + echo "$DIR_MEDIA/ --> $DIR_EXAMS/$teacher/media/" cp $DIR_MEDIA/* $DIR_EXAMS/$teacher/media/ } function do_project() { mkdir -p $DIR_EXAMS local teacher for teacher in $(get_teachers); do tell_if_verbose " - $teacher" build_amc_project $teacher build_sections $teacher import_tex_files $teacher override_tex_files $teacher customize_tex_files $teacher add_media_files $teacher import_student_file $teacher done } function do_scans() { local teacher for teacher in $(get_teachers); do echo "Processing teacher $teacher" if [ ! -d $DIR_SCANS/$teacher ]; then echo "No scans found! (looked in $DIR_SCANS/$teacher)" break; fi rm -rf $DIR_EXAMS/$teacher/scans/ mkdir $DIR_EXAMS/$teacher/scans/ cp $DIR_SCANS/$teacher/* $DIR_EXAMS/$teacher/scans/ local file_count=$(find $DIR_EXAMS/$teacher/scans/ -type f | wc -l) echo "Number of files: $file_count" local page_count=0 for tif in $(find $DIR_EXAMS/$teacher/scans/ -type f); do if [ $(tiffinfo $tif 2> /dev/null | grep 'Page Number:' | cut -d '-' -f 2 ) -eq 0 ]; then ((page_count++)) else echo "Invalid page count for file: $tif"; fi done echo "Number of pages: $page_count" local students_count=$(cat $DIR_EXAMS/$teacher/$FILE_STUDENTS | grep -vc '^ID,') echo "Number of students: $students_count" local ppc=$(grep 'TOTAL_PAGES:' $DIR_TEACHERS/$teacher/$FILE_PROF | cut -d ':' -f 2) local expected=$((ppc*students_count)) echo "Expected number of pages: $expected" if [ ! $expected -eq $page_count ]; then echo "MISSING COPIES :" cat $DIR_EXAMS/$teacher/$FILE_STUDENTS | grep -v '^ID,' | cut -d ',' -f 1 >> /tmp/$$ find $DIR_EXAMS/$teacher/scans/ -type f | rev | cut -d '_' -f 1 | rev | cut -d '-' -f 1 | sed 's/^0*//g' | sort -u >> /tmp/$$ for missing in $(sort -n /tmp/$$ | uniq -u); do grep "^$missing," $DIR_EXAMS/$teacher/$FILE_STUDENTS done rm -f /tmp/$$ fi done } function do_analyse() { local teacher for teacher in $(get_teachers); do echo "Processing teacher $teacher" cd $DIR_EXAMS/$teacher/ auto-multiple-choice analyse --projet ./ ./scans/* # auto-multiple-choice note --data ./data --seuil 0.05 # ignored anyway... check "seuil" in options.xml cd - > /dev/null 2>&1 done } function do_associate() { local teacher for teacher in $(get_teachers); do echo "Processing teacher $teacher" cd $DIR_EXAMS/$teacher/ for csv in $(grep -v '^ID,' $FILE_STUDENTS | cut -d ',' -f 1,3); do local id=$(echo $csv | cut -d ',' -f 1) local sciper=$(echo $csv | cut -d ',' -f 2) auto-multiple-choice association --data ./data --set --student $id --id $sciper done cd - > /dev/null 2>&1 done } function do_annotate() { local teacher for teacher in $(get_teachers); do echo "Processing teacher $teacher" cd $DIR_EXAMS/$teacher/ auto-multiple-choice annote --projet ./ --data ./data --fich-noms $FILE_STUDENTS auto-multiple-choice regroupe --projet ./ --sujet DOC-subject.pdf --fich-noms $FILE_STUDENTS --tex-src $FILE_EXAM_BASENAME.tex --compose cd - > /dev/null 2>&1 done } function do_mailing() { local teacher for teacher in $(get_teachers); do echo "Processing teacher $teacher" local lang=$(get_lang $teacher) check_file_exists $DIR_CONFIG/$lang-$FILE_AMC_MAILING cp $DIR_CONFIG/$lang-$FILE_AMC_MAILING $DIR_EXAMS/$teacher/$FILE_AMC_MAILING sed "s?%FILE_STUDENTS%?./$FILE_STUDENTS?g" $DIR_EXAMS/$teacher/$FILE_AMC_MAILING > tmp.$$ mv tmp.$$ $DIR_EXAMS/$teacher/$FILE_AMC_MAILING echo "#!/bin/bash auto-multiple-choice mailing --xmlargs ./$FILE_AMC_MAILING exit 0" > $DIR_EXAMS/$teacher/$FILE_EMAILS_SCRIPT chmod +x $DIR_EXAMS/$teacher/$FILE_EMAILS_SCRIPT done } function do_export() { local teacher for teacher in $(get_teachers); do tell_if_verbose " - $teacher" cd $DIR_EXAMS/$teacher/ auto-multiple-choice export --data ./data --module CSV --fich-noms $FILE_STUDENTS --o $FILE_RESULTS.csv cd - > /dev/null 2>&1 done } function check_webdav_mounted() { if [ ! -d $DIR_WEBDAV_BASE ]; then echo "ERROR: webdav dir ($DIR_WEBDAV_BASE) is not accessible."; exit 1; fi } function do_webdav_catalog() { local teacher local rc=0 check_webdav_mounted for teacher in $(get_teachers); do tell_if_verbose " - $teacher" local lang=$(get_lang $teacher) mkdir -p $DIR_WEBDAV_CATALOGS for f in $(echo $DIR_BLANKS/Catalog-$teacher-$lang.pdf); do check_file_exists $f 1 if [ $? -eq 0 ]; then cp $f $DIR_WEBDAV_CATALOGS/ else echo "ERROR: [$teacher] "$f" not found. Did you run 'blank' action?" ((rc++)) break; fi done done return $rc } function do_webdav_sample() { local teacher local rc=0 check_webdav_mounted for teacher in $(get_teachers); do tell_if_verbose " - $teacher" local lang=$(get_lang $teacher) mkdir -p $DIR_WEBDAV_SAMPLES for f in $(echo $DIR_SAMPLES/Sample-$teacher-$lang.pdf); do check_file_exists $f 1 if [ $? -eq 0 ]; then cp $f $DIR_WEBDAV_SAMPLES/ else echo "ERROR: [$teacher] "$f" not found. Did you run 'sample' action?" ((rc++)) break; fi done done return $rc } function do_webdav_pdf() { local teacher local rc=0 check_webdav_mounted for teacher in $(get_teachers); do tell_if_verbose " - $teacher" local lang=$(get_lang $teacher) mkdir -p $DIR_WEBDAV_EXAMS for f in $(echo $DIR_PDF/Exam-$teacher-$lang.log $DIR_PDF/Exam-$teacher-$lang.pdf $DIR_PDF/Exam-$teacher-$lang-CORRECTION.pdf); do check_file_exists $f 1 if [ $? -eq 0 ]; then cp $f $DIR_WEBDAV_EXAMS/ else echo "ERROR: [$teacher] "$f" not found. Did you run 'list' action?" ((rc++)) break; fi done done return $rc } function do_webdav_list() { local teacher local rc=0 check_webdav_mounted for teacher in $(get_teachers); do tell_if_verbose " - $teacher" local lang=$(get_lang $teacher) mkdir -p $DIR_WEBDAV_LISTS for f in $(echo $DIR_LIST_OUT/List-$teacher.pdf $DIR_LIST_OUT/List-$teacher.csv); do check_file_exists $f 1 if [ $? -eq 0 ]; then cp $f $DIR_WEBDAV_LISTS/ else echo "ERROR: [$teacher] "$f" not found. Did you run 'list' action?" ((rc++)) break; fi done done return $rc } function do_clean() { local teacher local ask=$(get_param_value 'ask') for teacher in $(get_teachers); do tell_if_verbose " - $teacher" lang=$(get_lang $teacher) if [ "$ask" != "no" ]; then echo "Cleaning all generated data for teacher '$teacher' ? CTRL-C to abort." echo "(Use '--params ask=no' to force)" read a fi # Projects rm -rf $DIR_EXAMS/$teacher # Blanks rm -f $DIR_BLANKS/Blank-$teacher-$lang.pdf $DIR_BLANKS/Correction-Blank-$teacher-$lang.pdf $DIR_BLANKS/Catalog-$teacher-$lang.pdf # Samples rm -f $DIR_SAMPLES/Sample-$teacher-$lang.pdf # PDF rm -f $DIR_PDF/Exam-$teacher-$lang.log $DIR_PDF/Exam-$teacher-$lang.pdf $DIR_PDF/Exam-$teacher-$lang-CORRECTION.pdf # Lists rm -f $DIR_LIST_OUT/List-$teacher.pdf $DIR_LIST_OUT/List-$teacher.csv done for dir_to_clean in $(echo "$DIR_EXAMS $DIR_BLANKS $DIR_SAMPLES $DIR_PDF $DIR_LIST_OUT"); do if [ -d $dir_to_clean ]; then rmdir --ignore-fail-on-non-empty $dir_to_clean; fi; done }