2016-09-15 10:06:37
Automatically Organize/Compile Blackboard C++ Files
If you're like me and you teach C++ courses that use Blackboard as the file submission method you've probably wanted to smash your computer as you've graded the students' code. When you download the code for a specific assignment, Blackboard gives you all students' files in a single ZIP file. Normally that's fine if the files included in the ZIP file are organized decently. With Blackboard, they are not. Instead of having folders for each student that contains their files, Blackboard just throws all files in a single folder. It's up to you to figure them out.I've redacted the student IDs, which are the only way to determine which files belong to whom, and any names. This file structure is a mess. I have to read each text file to find a student's name, see which ID is in the filename, match that to the corresponding CPP file, then compile their code and grade the work. That is a disaster.
So in order to make my life, and hopefully someone else's life, easier, I wrote a Bash script to expand the ZIP file, parse the IDs and determine student names, create directories of the student names, move the files in to the proper directories, and compile the code. The only work I have to do is run the programs to verify the results and check the code for any issues. Now it's extremely easy for me to grade the programs and enter grades in Blackboard now that I have folder names telling me what code belongs to what student. Hopefully someone else finds this useful too.
Usage:
> compilebb gradebook_FA16CS101_Week203_2016-09-14-07-57-06.zip
#!/bin/bash
# Try to make it distro-independent since I use both
# Ubuntu and CentOS
MKDIR=$(/usr/bin/which mkdir)
UNZIP=$(/usr/bin/which unzip)
LS=$(/usr/bin/which ls)
AWK=$(/usr/bin/which awk)
UNIQ=$(/usr/bin/which uniq)
GREP=$(/usr/bin/which grep)
MV=$(/usr/bin/which mv)
FIND=$(/usr/bin/which find)
GPP=$(/usr/bin/which g++)
# Parse the ZIP filename, create the dir, unzip the file
ZIP=$1
ZIPARR=(${ZIP//_/ })
DIRNAME=${ZIPARR[2]}
$MKDIR $DIRNAME
$UNZIP $ZIP -d $DIRNAME
# Get the list of UIDs
IDLIST=$($LS $DIRNAME | $AWK -F"_attempt_" '{print $1}' | $UNIQ | $AWK -F_ '{print $2}')
# Parse the txt file for each UID and make a name dir for each.
# Move appropriate files into each folder.
# Find the CPP file, then compile it and log the output
for x in $IDLIST
do
STUDIR=$($GREP ^Name: $DIRNAME/*$x*txt | $AWK -F"Name: " '{print $2}' | $AWK -F' \\(' '{print $1}')
$MKDIR "$DIRNAME/$STUDIR"
$MV $DIRNAME/*$x* "$DIRNAME/$STUDIR"
CPPFILE=$($FIND "$DIRNAME/$STUDIR" -regextype posix-extended -regex '.*(cpp|CPP)')
$GPP -o "$DIRNAME/$STUDIR/$x.out" "$CPPFILE" &> "$DIRNAME/$STUDIR/$x-log.txt"
done
Back