Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63514355
bamc_amc-commands.sh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, May 20, 16:22
Size
6 KB
Mime Type
text/x-shellscript
Expires
Wed, May 22, 16:22 (2 d)
Engine
blob
Format
Raw Data
Handle
17782267
Attached To
R1066 amc-cape
bamc_amc-commands.sh
View Options
#!/bin/bash
function
assert_environment
()
{
assert_workspace;
if
[
$?
-ne 0
]
;
then return
1;
fi
assert_exam
$1
;
if
[
$?
-ne 0
]
;
then return
1;
fi
assert_project
$1
;
if
[
$?
-ne 0
]
;
then return
1;
fi
assert_template;
if
[
$?
-ne 0
]
;
then return
1;
fi
return
0
}
function
get_page_count
()
{
local
item
=
$1
local
lang
=
$2
local
pdf
=
$DIR_WORKSPACE
/
$DIR_PDFS
/EXAM-
${
lang
}
-
${
item
}
.pdf
if
[
-r
$pdf
]
;
then
pdfinfo
$pdf
| grep
'Pages: '
| rev | cut -d
' '
-f 1 | rev
return
0
else
echo
0
return
1
fi
}
function
check_page_count
()
{
local
item
=
$1
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$item
local
exam
=
$DIR_WORKSPACE
/
$DIR_EXAMS
/
$1
local
lang
=
$2
local
page_count
=
0
expected_page_count
=
0
student_count
=
0
# Count pages...
page_count
=
$(
get_page_count
$item
$lang
)
student_count
=
$(($(
cat
$project
/
$FILE_STUDENTS
| wc -l
)
-
1
))
expected_page_count
=
$((
$student_count
*
$(
get_exam_parameter
$item
'TOTAL_PAGES'
)))
local
extra_students
=
$(
read_variable_from_project EXTRA_STUDENTS
$exam
)
perma
"[$item]: $page_count page(s) - $(($student_count-$extra_students))+$extra_students student(s) ($(get_exam_parameter $item 'TOTAL_PAGES') p/s)."
if
[
$page_count
-ne
$expected_page_count
]
;
then
if
[
$page_count
-eq 0
]
;
then
error
"Exam PDF not found. Did you run the 'exam' action ?"
else
error
"Unexpected number of pages in PDF: $expected_page_count page(s) were expected."
fi
return
1
fi
# All good
return
0
}
function
action_exam-summary
()
{
local
rc
=
0
total
=
0
ppe
=
0
while
[
$#
-gt 0
]
;
do
assert_environment
$1
;
if
[
$?
-ne 0
]
;
then
((
rc++
))
;
shift
;
continue
;
fi
local
item
=
$1
local
lang
=
$(
get_lang
$item
)
check_page_count
$item
$lang
if
[
$?
-ne 0
]
;
then
((
rc++
))
else
total
=
$((
total+
$(
get_page_count
$item
$lang
)))
fi
shift
done
if
[
$rc
-eq 0
]
;
then
perma
"Total: $total A4-paper sides"
fi
return
$rc
}
function
action_exam
()
{
local
rc
=
0
while
[
$#
-gt 0
]
;
do
assert_environment
$1
;
if
[
$?
-ne 0
]
;
then
((
rc++
))
;
shift
;
continue
;
fi
local
item
=
$1
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$item
local
lang
=
$(
get_lang
$item
)
amc_prepare
$item
"exam"
if
[
$?
-eq 0
]
;
then
mkdir -p
$DIR_WORKSPACE
/
$DIR_PDFS
mv
$project
/EXAM-exam.pdf
$DIR_WORKSPACE
/
$DIR_PDFS
/EXAM-
${
lang
}
-
${
item
}
.pdf
mv
$project
/EXAM-correction.pdf
$DIR_WORKSPACE
/
$DIR_PDFS
/EXAM-CORRECTION-
${
lang
}
-
${
item
}
.pdf
amc_clean
$item
check_page_count
$item
$lang
else
((
rc++
))
fi
shift
done
return
$rc
;
}
function
action_blank
()
{
local
rc
=
0
while
[
$#
-gt 0
]
;
do
assert_environment
$1
;
if
[
$?
-ne 0
]
;
then
((
rc++
))
;
shift
;
continue
;
fi
local
item
=
$1
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$item
local
lang
=
$(
get_lang
$item
)
amc_prepare
$item
"blank"
if
[
$?
-eq 0
]
;
then
mkdir -p
$DIR_WORKSPACE
/
$DIR_BLANKS
mv
$project
/BLANK-exam.pdf
$DIR_WORKSPACE
/
$DIR_BLANKS
/BLANK-
${
lang
}
-
${
item
}
.pdf
amc_clean
$item
else
((
rc++
))
fi
shift
done
return
$rc
;
}
function
action_catalog
()
{
local
rc
=
0
while
[
$#
-gt 0
]
;
do
assert_environment
$1
;
if
[
$?
-ne 0
]
;
then
((
rc++
))
;
shift
;
continue
;
fi
local
item
=
$1
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$item
local
lang
=
$(
get_lang
$item
)
amc_prepare
$item
"catalog"
if
[
$?
-eq 0
]
;
then
mkdir -p
$DIR_WORKSPACE
/
$DIR_CATALOGS
mv
$project
/catalog.pdf
$DIR_WORKSPACE
/
$DIR_CATALOGS
/CATALOG-
${
lang
}
-
${
item
}
.pdf
amc_clean
$item
else
((
rc++
))
fi
shift
done
return
$rc
;
}
function
action_sample
()
{
local
rc
=
0
while
[
$#
-gt 0
]
;
do
assert_environment
$1
;
if
[
$?
-ne 0
]
;
then
((
rc++
))
;
shift
;
continue
;
fi
local
item
=
$1
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$item
local
lang
=
$(
get_lang
$item
)
amc_prepare
$item
"sample"
if
[
$?
-eq 0
]
;
then
mkdir -p
$DIR_WORKSPACE
/
$DIR_SAMPLES
mv
$project
/SAMPLE-exam.pdf
$DIR_WORKSPACE
/
$DIR_SAMPLES
/SAMPLE-
${
lang
}
-
${
item
}
.pdf
mv
$project
/SAMPLE-correction.pdf
$DIR_WORKSPACE
/
$DIR_SAMPLES
/SAMPLE-CORRECTION-
${
lang
}
-
${
item
}
.pdf
amc_clean
$item
else
((
rc++
))
fi
shift
done
return
$rc
;
}
function
action_check
()
{
local
rc
=
0
while
[
$#
-gt 0
]
;
do
assert_environment
$1
;
if
[
$?
-ne 0
]
;
then
((
rc++
))
;
shift
;
continue
;
fi
local
item
=
$1
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$item
local
lang
=
$(
get_lang
$item
)
amc_prepare
$item
"check"
if
[
$?
-ne 0
]
;
then
((
rc++
))
;
else
amc_clean
$item
;
fi
shift
done
return
$rc
;
}
function
amc_clean
()
{
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
rm -f
$project
/*-exam.pdf
$project
/*-correction.pdf
$project
/amc-compiled.*
}
function
amc_prepare
()
{
local
project
=
$DIR_WORKSPACE
/
$DIR_PROJECTS
/
$1
local
runs
=
$PDFLATEX_RUNS
ok
=
0
local
mode
=
$2
prefix
perma
"Running AMC/$mode on project '$1'"
case
$mode
in
"blank"
|
"sample"
|
"catalog"
|
"exam"
)
if
[
-r
$project
/INVALID
]
;
then
error
"This AMC project is marked as invalid. Please correct project and run the 'check' action again."
return
1
fi
prefix
=
$(
echo
$mode
| tr
'[a-z]'
'[A-Z]'
)
;;
"check"
)
prefix
=
BLANK;;
esac
# Save real students.csv file
case
$mode
in
"blank"
|
"check"
|
"catalog"
)
mv
$project
/
$FILE_STUDENTS
$project
/
${
FILE_STUDENTS
}
.sav
cp
$DIR_EXAM_TEMPLATE
/csv/blank.csv
$project
/
$FILE_STUDENTS
;;
"sample"
)
mv
$project
/
$FILE_STUDENTS
$project
/
${
FILE_STUDENTS
}
.sav
cp
$DIR_EXAM_TEMPLATE
/csv/sample.csv
$project
/
$FILE_STUDENTS
;;
esac
# Clean before compiling project
amc_clean
$1
while
[
$runs
-gt 0
]
;
do
auto-multiple-choice prepare
\
--mode s
\
--with pdflatex
\
--filter latex
\
--prefix
$project
/
\
--out-sujet
${
prefix
}
-exam.pdf
\
--out-corrige
${
prefix
}
-correction.pdf
\
$project
/exam.tex > /dev/null 2>&1
if
[
! -r
$project
/
${
prefix
}
-exam.pdf
]
;
then
runs
=
0;
else
ok
=
1;
fi
;
if
[
! -r
$project
/
${
prefix
}
-correction.pdf
]
;
then
runs
=
0;
else
ok
=
1;
fi
;
((
runs--
))
done
# Restore students.csv
case
$mode
in
"blank"
|
"check"
|
"sample"
|
"catalog"
|
"sample"
)
mv
$project
/
${
FILE_STUDENTS
}
.sav
$project
/
$FILE_STUDENTS
;;
esac
if
[
$ok
-eq 0
]
;
then
error
"This AMC/LaTeX project does not compile with AMC."
touch
$project
/INVALID
return
1
else
rm -f
$project
/INVALID
fi
return
0
}
# EOF
Event Timeline
Log In to Comment