diff --git a/data/templates/chemistry/csv/extra.csv b/data/templates/chemistry/csv/extra.csv index f94ab0b..6cbc3f5 100644 --- a/data/templates/chemistry/csv/extra.csv +++ b/data/templates/chemistry/csv/extra.csv @@ -1 +1 @@ -#ID#,#SCIPER#,XXX-#NB#,XXX,#EMAIL#,EXTRA,N\A +#ID#,#SCIPER#,XXX-#NB#,XXX,#EMAIL#,EXTRA,#ROOM# diff --git a/data/templates/chemistry/project_build_script.sh b/data/templates/chemistry/project_build_script.sh index a2a0e3a..ed60216 100644 --- a/data/templates/chemistry/project_build_script.sh +++ b/data/templates/chemistry/project_build_script.sh @@ -1,336 +1,345 @@ #!/bin/bash # This part is specific to the template. # Entry point from bamc: build_project $exam # $exam: name of the exam to build # # Useful variable # --------------- # DIR_WORKSPACE [current workspace dir (absolute)] # DIR_PROJECTS [projects target directory] # DIR_EXAMS [exams'directory in workspace] e.g. $DIR_WORKSPACE/$DIR_EXAMS/$exam # DIR_PROJECTS [projects's directory in workspace] # DIR_EXAM_TEMPLATE [directory of the exam template in use] # FILE_STUDENTS # ... # see 'conf/bamc.conf' for full reference # # Useful functions # ---------------- # verbose "text" # debug "text" # get_lang $exam # ... # see 'lib/bash/*.sh' files for full reference function build_project() { local exam=$1 lang=$(get_lang $exam) assert_exam $exam verbose "Project '$exam' uses '$lang' language" if [ $? -eq 1 ]; then return 1; fi verbose "Building AMC project for '$exam' in workspace '$DIR_WORKSPACE'..." # Project structure build_amc_project $exam if [ $? -ne 0 ]; then error "Could not build AMC project :("; return 1; fi # Build LaTeX sections build_sections $exam $lang if [ $? -ne 0 ]; then error "Could not build project sections :("; return 1; fi # Add media files import_media_files $exam $lang if [ $? -ne 0 ]; then error "Could not import media files :("; return 1; fi # Import LaTeX files import_tex_files $exam $lang if [ $? -ne 0 ]; then error "Could not import LaTeX files :("; return 1; fi # Import local LaTeX files override_tex_files $exam $lang if [ $? -ne 0 ]; then error "Could not override LaTeX files :("; return 1; fi # Customize LaTeX file customize_tex_files $exam $lang if [ $? -ne 0 ]; then error "Could not customize LaTeX files :("; return 1; fi # Import media files add_media_files $exam if [ $? -ne 0 ]; then error "Could not import media files :("; return 1; fi # Build student list file import_student_file $exam if [ $? -ne 0 ]; then error "Could not create student list :("; return 1; fi return 0 } function import_student_file() { verbose "Customizing student files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 - local lang=$2 - + local lang=$2 + + + local params=$(cat $exam/exam.conf) + local ROOM="" + if [[ "$params" == *"ROOM"* ]] && [[ "$params" != *"#ROOM"* ]]; then + ROOM=",NA" + fi + local FILE=$exam/$FILE_STUDENTS check_file_exists $FILE if [ $? -ne 0 ]; then return 1; fi cp $FILE $project/$FILE_STUDENTS # Add extra students local nb IFS=$'\n' local id=$(tail -n 1 $project/$FILE_STUDENTS | cut -d ',' -f 1) local sample=$(head -n 1 $DIR_EXAM_TEMPLATE/csv/extra.csv) nb=0 local extra_students=$(read_variable_from_project EXTRA_STUDENTS $exam) + while [ $nb -lt $extra_students ]; 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" >> $project/$FILE_STUDENTS + sed "s/#SEMESTER#/$SEMESTER/g" |\ + sed "s/,#ROOM#/$ROOM/g" >> $project/FILE_STUDENTS done return 0 } function add_media_files() { verbose "Importing media files" verbose "$DIR_EXAM_TEMPLATE/media/* $project/media/" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 cp $DIR_EXAM_TEMPLATE/media/* $project/media/ } function customize_tex_files() { verbose "Customizing LaTeX files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local lang=$2 local replace IFS=$'\n' local FILE=$exam/$FILE_EXAM check_file_exists $FILE if [ $? -ne 0 ]; then return 1; fi # professor.tex local prof_file=$project/professor.tex check_file_exists $prof_file if [ $? -ne 0 ]; then return 1; fi for replace in $(cat $FILE); do replace_in_file "#$(echo $replace | cut -d ':' -f 1)#" "$(echo $replace | cut -d ':' -f 2-)" $prof_file done # exam.tex replace_in_file "#LANG#" $(echo $lang | tr '[a-z]' '[A-Z]') $project/exam.tex # Add extra_packages.tex file if [ -r $project/common_packages.tex ]; then replace_in_file '% #COMMON_PACKAGES#' '\\input{./common_packages.tex}' $project/exam.tex fi # Add extra_packages.tex file if [ -r $project/common_commands.tex ]; then replace_in_file '% #COMMON_COMMANDS#' '\\input{./common_commands.tex}' $project/exam.tex fi # Add extra_section.tex file if [ -r $project/extra_section.tex ]; then replace_in_file '% #EXTRA_SECTION#' '\\input{./extra_section.tex}' $project/exam.tex fi # Add extra_packages.tex file if [ -r $project/extra_packages.tex ]; then replace_in_file '% #EXTRA_PACKAGES#' '\\input{./extra_packages.tex}' $project/exam.tex fi # Add extra_packages.tex file if [ -r $project/extra_commands.tex ]; then replace_in_file '% #EXTRA_COMMANDS#' '\\input{./extra_commands.tex}' $project/exam.tex fi return 0 } function override_tex_files() { verbose "Importing supplementary LaTeX files" local common=$DIR_WORKSPACE/$DIR_COMMON local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local lang=$2 local f # Common (without lang) if [ -d $common ]; then for f in $(find $common -maxdepth 1 -type f -name '*.tex'); do verbose "- Common LaTeX file found: $f" cp $f $project/ done fi # Common (with lang) if [ -d $common/$lang ]; then for f in $(find $common/$lang -type f -name '*.tex'); do verbose "- Common LaTeX file found ($lang): $f" cp $f $project/ done fi # Extra for f in $(find $exam/ -type f -name '*.tex'); do verbose "- Extra LaTeX file found: $f" done find $exam/ -type f -name '*.tex' -exec cp {} $project/ \; return 0 } function import_tex_files() { verbose "Importing LaTeX files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local lang=$2 cp $DIR_EXAM_TEMPLATE/base/* $project/ cp $DIR_EXAM_TEMPLATE/$lang/* $project/ return 0 } function build_amc_project() { local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 verbose "Creating AMC project structure" mkdir -p $project/cr/corrections/jpg mkdir -p $project/cr/corrections/pdf mkdir -p $project/cr/diagnostic mkdir -p $project/cr/zooms mkdir -p $project/data mkdir -p $project/exports mkdir -p $project/scans mkdir -p $project/copies mkdir -p $project/media cp $DIR_EXAM_TEMPLATE/config/$FILE_AMC_OPTIONS $project/$FILE_AMC_OPTIONS return $? } function import_media_files() { local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local lang=$2 local questions_dir=$DIR_WORKSPACE/$DIR_QUESTIONS/$lang local media_file verbose "Importing media files" for media_file in $(find $questions_dir/ -type f -not -name '*\.tex'); do verbose "Importing file '$media_file'" cp $media_file $DIR_WORKSPACE/$DIR_PROJECTS/$1/ done if [ -d "$DIR_WORKSPACE/$DIR_EXAMS/$1/media/" ]; then for media_file in $(find $DIR_WORKSPACE/$DIR_EXAMS/$1/media/ -type f -not -name '*\.tex'); do verbose "Importing file '$media_file'" cp $media_file $DIR_WORKSPACE/$DIR_PROJECTS/$1/media/ done fi return 0 } function build_pool() { local pool_name=$1 local from=$2 local to=$3 debug "Pour $pool_name, je prends les questions de $from, je les mets dans '$to'." local pool_question for pool_question in $(find $from -name '*\.tex' | sort); do debug "adding $pool_question to $to" echo "%% From '$pool_name' $pool_question =======================================" >> $to echo '\element{'$pool_name'}{' >> $to cat $pool_question >> $to echo '}' >> $to done } function build_sections() { local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local lang=$2 local question_file question section_file section local IFS=$'\n' FILE=$exam/$FILE_SECTIONS verbose "Importing questions" check_file_exists $FILE if [ $? -ne 0 ]; then return 1; fi local section_num=0 local options pool_latex_copygroup pool_latex_input pool_base pool_name pool_count rm -f $project/sections.tex $project/random-sections.tex for section in $(cat $FILE); do ((section_num++)) options="" pool_latex_input="" pool_latex_copygroup="" section_file=$project/section_${section_num}.tex rm -f $section_file for question in $(echo $section | tr ',' '\n'); do debug "$question" if [ $(echo $question | cut -c 1) == "!" ]; then options=$(echo $question | cut -c 2-) debug "Options for this section: $options" continue fi if [[ $question =~ ^pools/ ]]; then pool_base=$(echo $question | cut -d '|' -f 1) pool_name='pool-'$(echo $pool_base | cut -d '/' -f 2) pool_count=$(echo $question | cut -d '|' -f 2) debug "Pool detected: $pool_name ($pool_base) - for $pool_count questions" build_pool $pool_name $DIR_WORKSPACE/$DIR_QUESTIONS/$lang/$pool_base $project/${pool_name}.tex pool_latex_input=$pool_latex_input' \input{./'${pool_name}'.tex}' pool_latex_copygroup=$pool_latex_copygroup' \copygroup['$pool_count']{'$pool_name'}{section'$section_num'-tmp}' else verbose "Adding $question to section $section_file..."; question_file=$DIR_WORKSPACE/$DIR_QUESTIONS/$lang/$question check_file_exists $question_file if [ $? -ne 0 ]; then return 1; fi echo "%% From $lang/$question =======================================" >> $section_file echo '\element{section'$section_num'}{' >> $section_file cat $question_file >> $section_file echo '}' >> $section_file fi done if [ ! -r $section_file ]; then echo '\element{section'$section_num'}{' >> $section_file echo '}' >> $section_file fi # Check section_file was initialized... echo "\input{./section_${section_num}.tex} $pool_latex_input" >> $project/sections.tex if [ $(echo $options | tr '|' '\n' | grep -c 'NORAND') -eq 1 ]; then debug "NOT mixing section #${section_num}" # Do not mix echo "\input{./header_${section_num}.tex} \cleargroup{section${section_num}-tmp} \setgroupmode{${pool_name}}{withoutreplacement} \copygroup{section${section_num}}{section${section_num}-tmp} $pool_latex_copygroup \restituegroupe{section${section_num}-tmp} " >> $project/random-sections.tex else echo "\input{./header_${section_num}.tex} \cleargroup{section${section_num}-tmp} \setgroupmode{${pool_name}}{withoutreplacement} \copygroup{section${section_num}}{section${section_num}-tmp} $pool_latex_copygroup \melangegroupe{section${section_num}-tmp} \restituegroupe{section${section_num}-tmp} " >> $project/random-sections.tex fi done return 0 } # EOF diff --git a/data/templates/linear-algebra/csv/extra.csv b/data/templates/linear-algebra/csv/extra.csv index f94ab0b..50bc304 100644 --- a/data/templates/linear-algebra/csv/extra.csv +++ b/data/templates/linear-algebra/csv/extra.csv @@ -1 +1 @@ -#ID#,#SCIPER#,XXX-#NB#,XXX,#EMAIL#,EXTRA,N\A +#ID#,#SCIPER#,XXX-#NB#,XXX,#EMAIL#,EXTRA,NA diff --git a/data/templates/linear-algebra/project_build_script.sh b/data/templates/linear-algebra/project_build_script.sh index 46d0174..96596d9 100644 --- a/data/templates/linear-algebra/project_build_script.sh +++ b/data/templates/linear-algebra/project_build_script.sh @@ -1,305 +1,314 @@ #!/bin/bash # This part is specific to the template. # Entry point from bamc: build_project $exam # $exam: name of the exam to build # # Useful variable # --------------- # DIR_WORKSPACE [current workspace dir (absolute)] # DIR_PROJECTS [projects target directory] # DIR_EXAMS [exams'directory in workspace] e.g. $DIR_WORKSPACE/$DIR_EXAMS/$exam # DIR_PROJECTS [projects's directory in workspace] # DIR_EXAM_TEMPLATE [directory of the exam template in use] # FILE_STUDENTS # ... # see 'conf/bamc.conf' for full reference # # Useful functions # ---------------- # verbose "text" # debug "text" # get_lang $exam # ... # see 'lib/bash/*.sh' files for full reference function build_project() { local exam=$1 lang=$(get_lang $exam) assert_exam $exam verbose "Project '$exam' uses '$lang' language" if [ $? -eq 1 ]; then return 1; fi verbose "Building AMC project for '$exam' in workspace '$DIR_WORKSPACE'..." # Project structure build_amc_project $exam if [ $? -ne 0 ]; then error "Could not build AMC project :("; return 1; fi # Build LaTeX sections build_sections $exam $lang if [ $? -ne 0 ]; then error "Could not build project sections :("; return 1; fi # Add media files import_media_files $exam $lang if [ $? -ne 0 ]; then error "Could not import media files :("; return 1; fi # Import LaTeX files import_tex_files $exam $lang if [ $? -ne 0 ]; then error "Could not import LaTeX files :("; return 1; fi # Import local LaTeX files override_tex_files $exam $lang if [ $? -ne 0 ]; then error "Could not override LaTeX files :("; return 1; fi # Customize LaTeX file customize_tex_files $exam $lang if [ $? -ne 0 ]; then error "Could not customize LaTeX files :("; return 1; fi # Import media files add_media_files $exam if [ $? -ne 0 ]; then error "Could not import media files :("; return 1; fi # Build student list file import_student_file $exam if [ $? -ne 0 ]; then error "Could not create student list :("; return 1; fi return 0 } function import_student_file() { verbose "Customizing student files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 - local lang=$2 - + local lang=$2 + + + local params=$(cat $exam/exam.conf) + local ROOM="" + if [[ "$params" == *"ROOM"* ]] && [[ "$params" != *"#ROOM"* ]]; then + ROOM=",NA" + fi + local FILE=$exam/$FILE_STUDENTS check_file_exists $FILE if [ $? -ne 0 ]; then return 1; fi cp $FILE $project/$FILE_STUDENTS # Add extra students local nb IFS=$'\n' local id=$(tail -n 1 $project/$FILE_STUDENTS | cut -d ',' -f 1) local sample=$(head -n 1 $DIR_EXAM_TEMPLATE/csv/extra.csv) nb=0 local extra_students=$(read_variable_from_project EXTRA_STUDENTS $exam) + while [ $nb -lt $extra_students ]; 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" >> $project/$FILE_STUDENTS + sed "s/#SEMESTER#/$SEMESTER/g" |\ + sed "s/,#ROOM#/$ROOM/g" >> $project/FILE_STUDENTS done return 0 } function add_media_files() { verbose "Importing media files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 cp $DIR_EXAM_TEMPLATE/media/* $project/media/ } function customize_tex_files() { verbose "Customizing LaTeX files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local lang=$2 local replace IFS=$'\n' local CONFIG_EXAM=$exam/$FILE_EXAM check_file_exists $CONFIG_EXAM if [ $? -ne 0 ]; then return 1; fi # professor.tex local prof_file=$project/professor.tex check_file_exists $prof_file if [ $? -ne 0 ]; then return 1; fi for replace in $(cat $CONFIG_EXAM | grep -v '^#' | grep ':' ); do replace_in_file "#$(echo $replace | cut -d ':' -f 1)#" "$(echo $replace | cut -d ':' -f 2-)" $prof_file done # first_page.tex (SIGNATURE) & (ROOM) & (QRCODE) local first_page_file=$project/first_page.tex if [ $(grep -c '^SIGNATURE$' $CONFIG_EXAM) -gt 0 ]; then replace_in_file "%SIGNATURE" "" $first_page_file; fi if [ $(grep -c '^ROOM$' $CONFIG_EXAM) -gt 0 ]; then replace_in_file "%ROOM" "" $first_page_file; fi if [ $(grep -c '^QRCODE$' $CONFIG_EXAM) -gt 0 ]; then replace_in_file "%QRCODE" "" $first_page_file; fi # exam.tex (FONT_SIZE) local exam_file=$project/exam.tex replace_in_file "#LANG#" $(echo $lang | tr '[a-z]' '[A-Z]') $exam_file if [ $(grep -c '^FONT_SIZE:' $CONFIG_EXAM) -gt 0 ]; then replace_in_file "\[a4paper\]" "\[a4paper,$(grep '^FONT_SIZE:' $CONFIG_EXAM | tail -n 1 | cut -d ':' -f 2-)\]" $exam_file fi # Add extra_packages.tex file if [ -r $project/common_packages.tex ]; then replace_in_file '% #COMMON_PACKAGES#' '\\input{./common_packages.tex}' $exam_file fi # Add extra_packages.tex file if [ -r $project/common_commands.tex ]; then replace_in_file '% #COMMON_COMMANDS#' '\\input{./common_commands.tex}' $exam_file fi # Add extra_section.tex file if [ -r $project/extra_section.tex ]; then replace_in_file '% #EXTRA_SECTION#' '\\input{./extra_section.tex}' $exam_file fi # Add extra_packages.tex file if [ -r $project/extra_packages.tex ]; then replace_in_file '% #EXTRA_PACKAGES#' '\\input{./extra_packages.tex}' $exam_file fi # Add extra_packages.tex file if [ -r $project/extra_commands.tex ]; then replace_in_file '% #EXTRA_COMMANDS#' '\\input{./extra_commands.tex}' $exam_file fi return 0 } function override_tex_files() { verbose "Importing supplementary LaTeX files" local common=$DIR_WORKSPACE/$DIR_COMMON local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local lang=$2 local f # Common (without lang) if [ -d $common ]; then for f in $(find $common -maxdepth 1 -type f -name '*.tex'); do verbose "- Common LaTeX file found: $f" cp $f $project/ done fi # Common (with lang) if [ -d $common/$lang ]; then for f in $(find $common/$lang -type f -name '*.tex'); do verbose "- Common LaTeX file found ($lang): $f" cp $f $project/ done fi # Extra for f in $(find $exam/ -type f -name '*.tex'); do verbose "- Extra LaTeX file found: $f" done find $exam/ -type f -name '*.tex' -exec cp {} $project/ \; return 0 } function import_tex_files() { verbose "Importing LaTeX files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local lang=$2 cp $DIR_EXAM_TEMPLATE/base/* $project/ cp $DIR_EXAM_TEMPLATE/$lang/* $project/ return 0 } function build_amc_project() { local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 verbose "Creating AMC project structure" mkdir -p $project/cr/corrections/jpg mkdir -p $project/cr/corrections/pdf mkdir -p $project/cr/diagnostic mkdir -p $project/cr/zooms mkdir -p $project/data mkdir -p $project/exports mkdir -p $project/scans mkdir -p $project/copies mkdir -p $project/media cp $DIR_EXAM_TEMPLATE/config/$FILE_AMC_OPTIONS $project/$FILE_AMC_OPTIONS return $? } function import_media_files() { local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local lang=$2 local questions_dir=$DIR_WORKSPACE/$DIR_QUESTIONS/$lang local media_file verbose "Importing media files" for media_file in $(find $questions_dir/ -type f -not -name '*\.tex'); do verbose "Importing file '$media_file'" cp $media_file $DIR_WORKSPACE/$DIR_PROJECTS/$1/ done if [ -d "$DIR_WORKSPACE/$DIR_EXAMS/$1/media/" ]; then for media_file in $(find $DIR_WORKSPACE/$DIR_EXAMS/$1/media/ -type f -not -name '*\.tex'); do verbose "Importing file '$media_file'" cp $media_file $DIR_WORKSPACE/$DIR_PROJECTS/$1/media/ done fi return 0 } function is_option_active() { local section_line=$1 local option=$2 if [ $(echo $section_line | grep -c "!$2,") -gt 0 ]; then return 1 else return 0 fi } function build_sections() { local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local lang=$2 local question_file question section_file section local IFS=$'\n' FILE=$exam/$FILE_SECTIONS verbose "Importing questions" check_file_exists $FILE if [ $? -ne 0 ]; then return 1; fi local section_num=0 rm -f $project/sections.tex $project/random-sections.tex for section in $(cat $FILE); do # Sample format of a section line: # !OPTION1,!OPTION2,tex_file1.tex,tex_file2.tex,... ((section_num++)) section_file=$project/section_${section_num}.tex rm -f $section_file for question in $(echo $section | tr ',' '\n'); do # Skip options (options start with "!") if [[ $question =~ ^! ]]; then verbose "This is an option, and not a question: $question (skipping)" continue; fi verbose "Adding $question to section $section_file..."; question_file=$DIR_WORKSPACE/$DIR_QUESTIONS/$lang/$question check_file_exists $question_file if [ $? -ne 0 ]; then return 1; fi echo "%% From $lang/$question =======================================" >> $section_file echo '\element{section'$section_num'}{' >> $section_file cat $question_file >> $section_file echo '}' >> $section_file done echo "\input{./section_${section_num}.tex}" >> $project/sections.tex echo "\input{./header_${section_num}.tex}" >> $project/random-sections.tex is_option_active $section 'NORAND' if [ $? -eq 0 ]; then # RANDOM order echo "\melangegroupe{section${section_num}}" >> $project/random-sections.tex fi echo "\restituegroupe{section${section_num}}" >> $project/random-sections.tex done return 0 } # EOF diff --git a/data/templates/maths/csv/extra.csv b/data/templates/maths/csv/extra.csv index f94ab0b..6cbc3f5 100644 --- a/data/templates/maths/csv/extra.csv +++ b/data/templates/maths/csv/extra.csv @@ -1 +1 @@ -#ID#,#SCIPER#,XXX-#NB#,XXX,#EMAIL#,EXTRA,N\A +#ID#,#SCIPER#,XXX-#NB#,XXX,#EMAIL#,EXTRA,#ROOM# diff --git a/data/templates/maths/project_build_script.sh b/data/templates/maths/project_build_script.sh index 46d0174..96596d9 100644 --- a/data/templates/maths/project_build_script.sh +++ b/data/templates/maths/project_build_script.sh @@ -1,305 +1,314 @@ #!/bin/bash # This part is specific to the template. # Entry point from bamc: build_project $exam # $exam: name of the exam to build # # Useful variable # --------------- # DIR_WORKSPACE [current workspace dir (absolute)] # DIR_PROJECTS [projects target directory] # DIR_EXAMS [exams'directory in workspace] e.g. $DIR_WORKSPACE/$DIR_EXAMS/$exam # DIR_PROJECTS [projects's directory in workspace] # DIR_EXAM_TEMPLATE [directory of the exam template in use] # FILE_STUDENTS # ... # see 'conf/bamc.conf' for full reference # # Useful functions # ---------------- # verbose "text" # debug "text" # get_lang $exam # ... # see 'lib/bash/*.sh' files for full reference function build_project() { local exam=$1 lang=$(get_lang $exam) assert_exam $exam verbose "Project '$exam' uses '$lang' language" if [ $? -eq 1 ]; then return 1; fi verbose "Building AMC project for '$exam' in workspace '$DIR_WORKSPACE'..." # Project structure build_amc_project $exam if [ $? -ne 0 ]; then error "Could not build AMC project :("; return 1; fi # Build LaTeX sections build_sections $exam $lang if [ $? -ne 0 ]; then error "Could not build project sections :("; return 1; fi # Add media files import_media_files $exam $lang if [ $? -ne 0 ]; then error "Could not import media files :("; return 1; fi # Import LaTeX files import_tex_files $exam $lang if [ $? -ne 0 ]; then error "Could not import LaTeX files :("; return 1; fi # Import local LaTeX files override_tex_files $exam $lang if [ $? -ne 0 ]; then error "Could not override LaTeX files :("; return 1; fi # Customize LaTeX file customize_tex_files $exam $lang if [ $? -ne 0 ]; then error "Could not customize LaTeX files :("; return 1; fi # Import media files add_media_files $exam if [ $? -ne 0 ]; then error "Could not import media files :("; return 1; fi # Build student list file import_student_file $exam if [ $? -ne 0 ]; then error "Could not create student list :("; return 1; fi return 0 } function import_student_file() { verbose "Customizing student files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 - local lang=$2 - + local lang=$2 + + + local params=$(cat $exam/exam.conf) + local ROOM="" + if [[ "$params" == *"ROOM"* ]] && [[ "$params" != *"#ROOM"* ]]; then + ROOM=",NA" + fi + local FILE=$exam/$FILE_STUDENTS check_file_exists $FILE if [ $? -ne 0 ]; then return 1; fi cp $FILE $project/$FILE_STUDENTS # Add extra students local nb IFS=$'\n' local id=$(tail -n 1 $project/$FILE_STUDENTS | cut -d ',' -f 1) local sample=$(head -n 1 $DIR_EXAM_TEMPLATE/csv/extra.csv) nb=0 local extra_students=$(read_variable_from_project EXTRA_STUDENTS $exam) + while [ $nb -lt $extra_students ]; 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" >> $project/$FILE_STUDENTS + sed "s/#SEMESTER#/$SEMESTER/g" |\ + sed "s/,#ROOM#/$ROOM/g" >> $project/FILE_STUDENTS done return 0 } function add_media_files() { verbose "Importing media files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 cp $DIR_EXAM_TEMPLATE/media/* $project/media/ } function customize_tex_files() { verbose "Customizing LaTeX files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local lang=$2 local replace IFS=$'\n' local CONFIG_EXAM=$exam/$FILE_EXAM check_file_exists $CONFIG_EXAM if [ $? -ne 0 ]; then return 1; fi # professor.tex local prof_file=$project/professor.tex check_file_exists $prof_file if [ $? -ne 0 ]; then return 1; fi for replace in $(cat $CONFIG_EXAM | grep -v '^#' | grep ':' ); do replace_in_file "#$(echo $replace | cut -d ':' -f 1)#" "$(echo $replace | cut -d ':' -f 2-)" $prof_file done # first_page.tex (SIGNATURE) & (ROOM) & (QRCODE) local first_page_file=$project/first_page.tex if [ $(grep -c '^SIGNATURE$' $CONFIG_EXAM) -gt 0 ]; then replace_in_file "%SIGNATURE" "" $first_page_file; fi if [ $(grep -c '^ROOM$' $CONFIG_EXAM) -gt 0 ]; then replace_in_file "%ROOM" "" $first_page_file; fi if [ $(grep -c '^QRCODE$' $CONFIG_EXAM) -gt 0 ]; then replace_in_file "%QRCODE" "" $first_page_file; fi # exam.tex (FONT_SIZE) local exam_file=$project/exam.tex replace_in_file "#LANG#" $(echo $lang | tr '[a-z]' '[A-Z]') $exam_file if [ $(grep -c '^FONT_SIZE:' $CONFIG_EXAM) -gt 0 ]; then replace_in_file "\[a4paper\]" "\[a4paper,$(grep '^FONT_SIZE:' $CONFIG_EXAM | tail -n 1 | cut -d ':' -f 2-)\]" $exam_file fi # Add extra_packages.tex file if [ -r $project/common_packages.tex ]; then replace_in_file '% #COMMON_PACKAGES#' '\\input{./common_packages.tex}' $exam_file fi # Add extra_packages.tex file if [ -r $project/common_commands.tex ]; then replace_in_file '% #COMMON_COMMANDS#' '\\input{./common_commands.tex}' $exam_file fi # Add extra_section.tex file if [ -r $project/extra_section.tex ]; then replace_in_file '% #EXTRA_SECTION#' '\\input{./extra_section.tex}' $exam_file fi # Add extra_packages.tex file if [ -r $project/extra_packages.tex ]; then replace_in_file '% #EXTRA_PACKAGES#' '\\input{./extra_packages.tex}' $exam_file fi # Add extra_packages.tex file if [ -r $project/extra_commands.tex ]; then replace_in_file '% #EXTRA_COMMANDS#' '\\input{./extra_commands.tex}' $exam_file fi return 0 } function override_tex_files() { verbose "Importing supplementary LaTeX files" local common=$DIR_WORKSPACE/$DIR_COMMON local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local lang=$2 local f # Common (without lang) if [ -d $common ]; then for f in $(find $common -maxdepth 1 -type f -name '*.tex'); do verbose "- Common LaTeX file found: $f" cp $f $project/ done fi # Common (with lang) if [ -d $common/$lang ]; then for f in $(find $common/$lang -type f -name '*.tex'); do verbose "- Common LaTeX file found ($lang): $f" cp $f $project/ done fi # Extra for f in $(find $exam/ -type f -name '*.tex'); do verbose "- Extra LaTeX file found: $f" done find $exam/ -type f -name '*.tex' -exec cp {} $project/ \; return 0 } function import_tex_files() { verbose "Importing LaTeX files" local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local lang=$2 cp $DIR_EXAM_TEMPLATE/base/* $project/ cp $DIR_EXAM_TEMPLATE/$lang/* $project/ return 0 } function build_amc_project() { local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 verbose "Creating AMC project structure" mkdir -p $project/cr/corrections/jpg mkdir -p $project/cr/corrections/pdf mkdir -p $project/cr/diagnostic mkdir -p $project/cr/zooms mkdir -p $project/data mkdir -p $project/exports mkdir -p $project/scans mkdir -p $project/copies mkdir -p $project/media cp $DIR_EXAM_TEMPLATE/config/$FILE_AMC_OPTIONS $project/$FILE_AMC_OPTIONS return $? } function import_media_files() { local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local lang=$2 local questions_dir=$DIR_WORKSPACE/$DIR_QUESTIONS/$lang local media_file verbose "Importing media files" for media_file in $(find $questions_dir/ -type f -not -name '*\.tex'); do verbose "Importing file '$media_file'" cp $media_file $DIR_WORKSPACE/$DIR_PROJECTS/$1/ done if [ -d "$DIR_WORKSPACE/$DIR_EXAMS/$1/media/" ]; then for media_file in $(find $DIR_WORKSPACE/$DIR_EXAMS/$1/media/ -type f -not -name '*\.tex'); do verbose "Importing file '$media_file'" cp $media_file $DIR_WORKSPACE/$DIR_PROJECTS/$1/media/ done fi return 0 } function is_option_active() { local section_line=$1 local option=$2 if [ $(echo $section_line | grep -c "!$2,") -gt 0 ]; then return 1 else return 0 fi } function build_sections() { local project=$DIR_WORKSPACE/$DIR_PROJECTS/$1 local exam=$DIR_WORKSPACE/$DIR_EXAMS/$1 local lang=$2 local question_file question section_file section local IFS=$'\n' FILE=$exam/$FILE_SECTIONS verbose "Importing questions" check_file_exists $FILE if [ $? -ne 0 ]; then return 1; fi local section_num=0 rm -f $project/sections.tex $project/random-sections.tex for section in $(cat $FILE); do # Sample format of a section line: # !OPTION1,!OPTION2,tex_file1.tex,tex_file2.tex,... ((section_num++)) section_file=$project/section_${section_num}.tex rm -f $section_file for question in $(echo $section | tr ',' '\n'); do # Skip options (options start with "!") if [[ $question =~ ^! ]]; then verbose "This is an option, and not a question: $question (skipping)" continue; fi verbose "Adding $question to section $section_file..."; question_file=$DIR_WORKSPACE/$DIR_QUESTIONS/$lang/$question check_file_exists $question_file if [ $? -ne 0 ]; then return 1; fi echo "%% From $lang/$question =======================================" >> $section_file echo '\element{section'$section_num'}{' >> $section_file cat $question_file >> $section_file echo '}' >> $section_file done echo "\input{./section_${section_num}.tex}" >> $project/sections.tex echo "\input{./header_${section_num}.tex}" >> $project/random-sections.tex is_option_active $section 'NORAND' if [ $? -eq 0 ]; then # RANDOM order echo "\melangegroupe{section${section_num}}" >> $project/random-sections.tex fi echo "\restituegroupe{section${section_num}}" >> $project/random-sections.tex done return 0 } # EOF diff --git a/lib/bash/bamc_configuration.sh b/lib/bash/bamc_configuration.sh index 3b58af2..99dfb80 100644 --- a/lib/bash/bamc_configuration.sh +++ b/lib/bash/bamc_configuration.sh @@ -1,42 +1,41 @@ #!/bin/bash # Read global configuration DIR_CONF=$SPATH/../conf/ FILE_CONF=$DIR_CONF/$(basename $0).conf if [ ! -r $FILE_CONF ]; then echo "Could not read configuration file ($FILE_CONF)" exit 1; fi source $FILE_CONF # Source local configuration (on request) function source_local_configuration() { # Check workspace assert_workspace "quiet"; if [ $? -eq 1 ]; then return 1; fi local FILE_LOCAL_CONF=$DIR_WORKSPACE/$DIR_CONFIG/$(basename $FILE_CONF) if [ -r $FILE_LOCAL_CONF ]; then source $FILE_LOCAL_CONF fi } # For some variables, check the exam dir to see if it has been redefined locally function read_variable_from_project() { # Check workspace assert_workspace "quiet"; if [ $? -eq 1 ]; then return 1; fi - local varname=$1 local exam=$2 local value=$(eval "echo -n $""${varname}") local FILE_PROJECT_CONF=$exam/$(basename $FILE_CONF) if [ -r $FILE_PROJECT_CONF ]; then if [ $(grep -c "^$varname=" $FILE_PROJECT_CONF) -gt 0 ]; then value=$(grep "^$varname=" $FILE_PROJECT_CONF | tail -n 1 | cut -d '=' -f 2) fi fi echo $value } # EOF