fixed grade.sh
This commit is contained in:
45
Lab 1 - Group Work/grade.sh
Normal file → Executable file
45
Lab 1 - Group Work/grade.sh
Normal file → Executable file
@@ -1,34 +1,44 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -e
|
||||||
|
|
||||||
AUTOGRADE_DIR="${1:-lab1_files/autograde}"
|
AUTOGRADE_DIR="lab1_files/autograde"
|
||||||
STUDENTS_FILE="$AUTOGRADE_DIR/students.txt"
|
STUDENTS_FILE="$AUTOGRADE_DIR/students.txt"
|
||||||
APPEND_FILE="$AUTOGRADE_DIR/GRADING/APPEND.py"
|
APPEND_FILE="$AUTOGRADE_DIR/GRADING/APPEND.py"
|
||||||
|
|
||||||
[[ -f "$STUDENTS_FILE" ]] || { echo "students.txt missing"; exit 1; }
|
if [ ! -f "$STUDENTS_FILE" ]; then
|
||||||
[[ -f "$APPEND_FILE" ]] || { echo "APPEND.py missing"; exit 1; }
|
echo "students.txt not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
mapfile -t IDS < <(
|
if [ ! -f "$APPEND_FILE" ]; then
|
||||||
find "$AUTOGRADE_DIR" -mindepth 1 -maxdepth 1 -type d \
|
echo "APPEND.py not found"
|
||||||
! -name GRADING ! -name "__MACOSX" -printf '%f\n' | sort
|
exit 1
|
||||||
)
|
fi
|
||||||
|
|
||||||
lookup_name() {
|
lookup_name() {
|
||||||
local id="$1"
|
id="$1"
|
||||||
awk -v id="$id" '
|
awk -v id="$id" '
|
||||||
$1==id {
|
$1==id {
|
||||||
last=$NF
|
last=$NF
|
||||||
first=""
|
first=""
|
||||||
for(i=2;i<NF;i++) first=(first ? first" " : "")$i
|
for(i=2;i<NF;i++) {
|
||||||
print last", "first
|
first = (first ? first" " : "") $i
|
||||||
|
}
|
||||||
|
print last ", " first
|
||||||
|
exit
|
||||||
}
|
}
|
||||||
' "$STUDENTS_FILE"
|
' "$STUDENTS_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in "${IDS[@]}"; do
|
for student_dir in "$AUTOGRADE_DIR"/*; do
|
||||||
student_dir="$AUTOGRADE_DIR/$id"
|
[ -d "$student_dir" ] || continue
|
||||||
pyfile="$(find "$student_dir" -maxdepth 1 -name '*.py' | head -n 1 || true)"
|
|
||||||
[[ -n "$pyfile" ]] || continue
|
id="$(basename "$student_dir")"
|
||||||
|
[ "$id" = "GRADING" ] && continue
|
||||||
|
[ "$id" = "__MACOSX" ] && continue
|
||||||
|
|
||||||
|
pyfile="$(ls "$student_dir"/*.py 2>/dev/null | head -n 1)"
|
||||||
|
[ -n "$pyfile" ] || continue
|
||||||
|
|
||||||
outfile="$AUTOGRADE_DIR/dcs211_lab1_${id}.txt"
|
outfile="$AUTOGRADE_DIR/dcs211_lab1_${id}.txt"
|
||||||
|
|
||||||
@@ -41,7 +51,8 @@ Score: STUDENT_SCORE
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
name="$(lookup_name "$id")"
|
name="$(lookup_name "$id")"
|
||||||
sed -i.bak "s/STUDENT_NAME/${name:-UNKNOWN}/" "$outfile" && rm "$outfile.bak"
|
[ -n "$name" ] || name="UNKNOWN"
|
||||||
|
sed -i.bak "s/STUDENT_NAME/$name/" "$outfile" && rm "$outfile.bak"
|
||||||
|
|
||||||
graded="$student_dir/__graded_${id}.py"
|
graded="$student_dir/__graded_${id}.py"
|
||||||
cp "$pyfile" "$graded"
|
cp "$pyfile" "$graded"
|
||||||
@@ -52,9 +63,7 @@ EOF
|
|||||||
|
|
||||||
cat "$APPEND_FILE" >> "$graded"
|
cat "$APPEND_FILE" >> "$graded"
|
||||||
|
|
||||||
set +e
|
|
||||||
output="$(python3 "$graded" 2>&1)"
|
output="$(python3 "$graded" 2>&1)"
|
||||||
set -e
|
|
||||||
|
|
||||||
{
|
{
|
||||||
echo
|
echo
|
||||||
|
|||||||
Reference in New Issue
Block a user