forked from boru-roylu/simple_ta_helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade.sh
executable file
·128 lines (97 loc) · 3.15 KB
/
grade.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#! /bin/bash
if [ "$#" -eq 4 ]; then
stu_id=$(echo $1 | cut -d' ' -f1)
repo_name=$(echo $1 | cut -d' ' -f2)
git_pull=$2
github_username=$3
github_password=$4
else
stu_id=$1
repo_name=$2
git_pull=$3
delay_time=$4
github_username=$5
github_password=$6
fi
echo $#
. config
#. github_account
. program_config
if [ "$use_classroom" == "true" ]; then
repo_name="github.com/$classroom_domain/$prefix-$repo_name.git"
fi
echo ""
echo "Github repo: $repo_name"
echo "Git pull: $git_pull"
if [ "$delay_time" != "" ]; then
deadline="$delay_time"
fi
# Export environment parameters
# It will be also used in child process, "run.sh" and "eval.sh"
export MAIN_DIR=$save_dir/$course/$hw
export STU_ID=$stu_id
### git ###
if [ "$git_pull" == "true" ]; then
[ -d $MAIN_DIR/code/$STU_ID ] && rm -rf $MAIN_DIR/code/$STU_ID
mkdir -p $MAIN_DIR/code/$STU_ID
cd $MAIN_DIR/code/$STU_ID
git init
git remote add origin -f https://$github_username:$github_password@$repo_name
git config core.sparseCheckout true
if [ "$only_report" = true ]; then
echo "/*.pdf" >> .git/info/sparse-checkout
# echo "/${hw,,}/*.pdf" >> .git/info/sparse-checkout
else
echo "/*" >> .git/info/sparse-checkout
# echo "/${hw,,}/*" >> .git/info/sparse-checkout
fi
#git pull origin $branch
# TO save the disk usage, only clone the latest commit record
git pull origin $branch
if [ "$branch" != "master" ]; then
git checkout $branch
fi
# checkout to latest HEAD before deadline
git checkout `git rev-list -n 1 --before="$deadline" $branch`
if [ `date -d "${deadline}UTC+8" +%s` -lt `date -d $(git show --format=%cI -s) +%s` ]; then
echo "This commit is ahead the due date."
rm ./* -rf
fi
else
cd $MAIN_DIR/code/$STU_ID
fi
if [ "$only_clone" = true ]; then
exit
fi
if [ "$only_report" != true ]; then
# Create a tmp directory to copy student's homeword and TA grading files to this directory.
tmp_grade_dir=$(mktemp -d)
export DATA_DIR=$tmp_grade_dir/data
export OUTPUT_DIR=$tmp_grade_dir/output
export SCORE=$tmp_grade_dir/score
export PROGRAM_DIR=$tmp_grade_dir/program
export STU_DIR=$tmp_grade_dir/$stu_id
trap "rm -rf $tmp_grade_dir" EXIT
# Create a soft link to link data in tmp student's directory
ln -s $MAIN_DIR/data $tmp_grade_dir
# Copy all student's files and run.sh to tmp directory
cp -R $MAIN_DIR/code/$STU_ID $tmp_grade_dir
cp -R $MAIN_DIR/program $PROGRAM_DIR
# Change working directory to student's tmp directory
cd $STU_DIR
mkdir -p $OUTPUT_DIR
touch $SCORE
# student script DOS to unix
for fn in `ls $STU_DIR/*.sh`
do
dos2unix $fn
done
# run.sh
timeout -k 9 $limit_time bash -c "bash $PROGRAM_DIR/run.sh $args1 2> $MAIN_DIR/err/$stu_id 1> $MAIN_DIR/log/$stu_id" \
|| echo "timeout" >> $MAIN_DIR/err/$stu_id
# eval.sh
bash $PROGRAM_DIR/eval.sh $args2 2> $MAIN_DIR/err2/$stu_id 1> $MAIN_DIR/log2/$stu_id
mkdir -p $MAIN_DIR/output/$stu_id/
cp -f $OUTPUT_DIR/* $MAIN_DIR/output/$stu_id/
cp -f $SCORE $MAIN_DIR/score/$stu_id
fi