Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61918839
bamc_projects.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
Thu, May 9, 19:49
Size
5 KB
Mime Type
text/x-shellscript
Expires
Sat, May 11, 19:49 (2 d)
Engine
blob
Format
Raw Data
Handle
17536285
Attached To
R1066 amc-cape
bamc_projects.sh
View Options
#!/bin/bash
function
action_clean
()
{
local
exams
=
$@
local
exam
for
exam in
$(
echo
$exams
)
;
do
assert_exam
$exam
if
[
$?
-eq 1
]
;
then return
1;
fi
verbose
"Cleaning '$exam' in workspace '$DIR_WORKSPACE'..."
confirm
"Clean project and outputs for exam '$exam' ?"
if
[
$?
-eq 0
]
;
then return
0;
fi
for
dir in
$(
echo
$DIR_PROJECTS
$DIR_SAMPLES
$DIR_BLANKS
$DIR_PDFS
$DIR_LISTS
)
;
do
if
[
-d
"$DIR_WORKSPACE/$dir/$exam"
]
;
then
verbose
"Removing directory: '$dir/$exam'"
rm -rf
"$DIR_WORKSPACE/$dir/$exam/"
else
verbose
"Removing files: '$dir/$exam*'"
rm -rf
$DIR_WORKSPACE
/
$dir
/
$exam
*
fi
if
[
-d
"$DIR_WORKSPACE/$dir"
]
;
then
if
[
$(
ls -1A
$DIR_WORKSPACE
/
$dir
/ | wc -l
)
-eq 0
]
;
then
verbose
"Removing now empty directory: '$dir'"
rmdir
$DIR_WORKSPACE
/
$dir
/
fi
fi
done
done
return
0
}
function
action_project
()
{
# Get exam template to use
assert_template
if
[
$?
-ne 0
]
;
then return
1;
fi
local
exams
=
$@
local
exam lang
for
exam in
$(
echo
$exams
)
;
do
assert_exam
$exam
lang
=
$(
get_lang
$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
import_tex_files
$exam
$lang
if
[
$?
-ne 0
]
;
then
error
"Could not import LaTeX files :("
;
return
1;
fi
override_tex_files
$exam
if
[
$?
-ne 0
]
;
then
error
"Could not override LaTeX files :("
;
return
1;
fi
customize_tex_files
$exam
$lang
if
[
$?
-ne 0
]
;
then
error
"Could not customize LaTeX files :("
;
return
1;
fi
add_media_files
$exam
if
[
$?
-ne 0
]
;
then
error
"Could import media files :("
;
return
1;
fi
#import_student_file $exam
done
return
0
}
function
add_media_files
()
{
verbose
"Importing media files"
local
project
=
$DIR_PROJECTS
/
$1
cp
$DIR_EXAM_TEMPLATE
/media/*
$project
/media/
}
function
replace_in_file
()
{
local
pattern
=
$1
string
=
$2
filename
=
$3
sed
"s/$pattern/$string/g"
$filename
> /tmp/sed.tmp.
$$
mv /tmp/sed.tmp.
$$
$filename
return
0
}
function
customize_tex_files
()
{
verbose
"Customizing LaTeX files"
local
project
=
$DIR_PROJECTS
/
$1
local
exam
=
$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_section.tex file
if
[
-r
$exam
/extra_section.tex
]
;
then
sed -i
's?% #EXTRA_SECTION#?\\input{./extra_section.tex}?g'
$project
/exam.tex
fi
# Add extra_packages.tex file
if
[
-r
$exam
/extra_packages.tex
]
;
then
sed -i
's?% #EXTRA_PACKAGES#?\\input{./extra_packages.tex}?g'
$project
/exam.tex
fi
return
0
}
function
override_tex_files
()
{
verbose
"Overriding LaTeX files (if needed)"
local
exam
=
$DIR_EXAMS
/
$1
local
project
=
$DIR_PROJECTS
/
$1
local
f
for
f in
$(
find
$exam
/ -type f -name
'*.tex'
)
;
do
verbose
"- LaTeX override file found: $f"
done
find
$exam
/ -type f -name
'*.tex'
-exec cp
{}
$project
/
\;
}
function
import_tex_files
()
{
verbose
"Importing LaTeX files"
local
project
=
$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_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
get_exam_parameter
()
{
cat
$DIR_EXAMS
/
$1
/
$FILE_EXAM
| grep
"^$2:"
| cut -d
':'
-f 2-
}
function
get_lang
()
{
get_exam_parameter
$1
'LANG'
}
function
build_sections
()
{
local
project
=
$DIR_PROJECTS
/
$1
local
exam
=
$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
((
section_num++
))
section_file
=
$project
/section_
${
section_num
}
.tex
rm -f
$section_file
for
question in
$(
echo
$section
| tr
','
'\n'
)
;
do
verbose
"Adding $question to section $section_file..."
;
question_file
=
$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}
\melangegroupe{section${section_num}}
\restituegroupe{section${section_num}}
"
>>
$project
/random-sections.tex
done
return
0
}
# EOF
Event Timeline
Log In to Comment