/
gatorgrader.sh
executable file
·171 lines (154 loc) · 5.6 KB
/
gatorgrader.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
# assume that gatorgrader.py exits correctly
GATORGRADER_EXIT=0
# assume that the human-readable answer is "No"
GATORGRADER_EXIT_HUMAN_PASS="No"
# determine if the exit code is always failing
determine_exit_code() {
if [ "$1" -eq 1 ]; then
GATORGRADER_EXIT=1
else
if [ "$2" ]; then
echo "$2 was successful"
fi
fi
}
# determine a human-readable answer for status
determine_human_exit_code() {
if [ "$1" -eq 1 ]; then
GATORGRADER_EXIT_HUMAN_PASS="Yes"
fi
}
# define colors that can improve terminal output
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
end=$'\e[0m'
# define the viable command-line arguments for gatorgrader.sh
OPTS=`getopt -o vsc: --long verbose,start,check,update,download -- "$@"`
# parsing did not work correctly, give an error
if [ $? != 0 ] ; then echo "gatorgrader.sh could not parse the options!" >&2 ; exit 1 ; fi
# set the command-line arguments for further analysis
eval set -- "$OPTS"
# set the default values for the variables that mirror arguments
VERBOSE=false
START=false
CHECK=false
DOWNLOAD=false
UPDATE=""
# set the variables based on the command-line arguments
# the --update parameter accepts an additional argument
while true; do
case "$1" in
-v | --verbose ) VERBOSE=true; shift ;;
-s | --start ) START=true; shift ;;
-c | --check ) CHECK=true; shift ;;
-d | --download ) DOWNLOAD=true; shift ;;
-u | --update ) UPDATE="$3"; shift; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
# VERBOSE: Display the values of the variables
if [ "$VERBOSE" = true ]; then
echo VERBOSE=$VERBOSE
echo START=$START
echo CHECK=$CHECK
fi
# DOWNLOAD: Download the new code from a Git remote
if [ "$DOWNLOAD" = true ]; then
printf "%s\n" "${red}Updating the provided source code...${end}"
echo ""
git pull download master
echo ""
printf "%s\n" "${red}...Finished updating the provided source code${end}"
echo ""
fi
# UPDATE: Get ready for the download from a Git remote
if [ "$UPDATE" ]; then
printf "%s\n" "${red}Getting ready to update the provided source code...${end}"
echo ""
git remote add download "$UPDATE"
echo "Making a connection to $UPDATE"
echo ""
printf "%s\n" "${red}...Finished getting ready to update the provided source code${end}"
echo ""
fi
# START: Initialize the git submodule and the check it out
if [ "$START" = true ]; then
echo ""
printf "%s\n" "${red}Getting ready to check the assignment with GatorGrader...${end}"
echo ""
echo "Starting to initialize the submodule..."
git submodule update --init
cd gatorgrader||exit
git checkout master
cd ..
echo "... Finished Initializing the submodule"
echo ""
printf "%s\n" "${red}...Finished getting ready to check the assignment with GatorGrader${end}"
echo ""
fi
# CHECK: Setup the python3 venv and then run the GatorGrader checks
if [ "$CHECK" = true ]; then
# run all of the writing checks with mdl and proselint
echo ""
printf "%s\n" "${red}Checking the correctness of your technical writing!${end}"
echo ""
printf "%s\n" "${blu}Starting to run the mdl and proselint checks...${end}"
echo ""
mdl README.md
determine_exit_code $? "mdl README.md"
proselint README.md
determine_exit_code $? "proselint README.md"
echo ""
printf "%s\n" "${blu}...Finished checking the correctness of your technical writing${end}"
# run all of the checks with GatorGrader
echo ""
printf "%s\n" "${red}Checking the assignment with GatorGrader!${end}"
echo ""
printf "%s\n" "${blu}Starting to configure the GatorGrader environment ...${end}"
# create the venv for local python3 package management
python3 -m venv gatorgrader
source "$PWD/gatorgrader/bin/activate"
cd gatorgrader||exit
echo ""
# update pip and then install the requirements
# NOTE: run with python3 -m due to long directory names and Linux kernel limitation
python3 -m pip install -U pip
python3 -m pip install -r requirements.txt
python3 -m nltk.downloader punkt
cd ../||exit
echo ""
printf "%s\n" "${blu}... Finished configuring the GatorGrader environment${end}"
echo ""
# run the gatorgrader.py program to run the checks
printf "%s\n" "${blu}Starting to check with GatorGrader...${end}"
# ADD ADDITIONAL CALLS TO BOTH gatorgrader.py and determine_exit_code HERE
# --> GatorGrader CHECK: at least 1 header fragment exists in the code
python3 gatorgrader/gatorgrader.py --nowelcome --directories src/www/ \
--checkfiles answers.md --fragments "# A Web Site Created" --fragmentcounts 1
determine_exit_code $?
# --> GatorGrader CHECK: at least 4 subheader fragment exists in the code
python3 gatorgrader/gatorgrader.py --nowelcome --directories src/www/ \
--checkfiles answers.md --fragments "##" --fragmentcounts 2
determine_exit_code $?
# --> GatorGrader CHECK: at least 4 subheader fragment exists in the code
python3 gatorgrader/gatorgrader.py --nowelcome --directories src/www/ \
--checkfiles answers.md --fragments "jpg" --fragmentcounts 1
determine_exit_code $?
# --> GatorGrader CHECK: the repository contains at least three commits (update to current + 3)
python3 gatorgrader/gatorgrader.py --nowelcome --commits 8
determine_exit_code $?
echo ""
printf "%s\n" "${blu}... Finished checking with GatorGrader${end}"
# return the exit value from running the commands
determine_human_exit_code $GATORGRADER_EXIT
echo ""
printf "%s\n" "${red}Overall, are there any mistakes in the assignment? $GATORGRADER_EXIT_HUMAN_PASS ${end}"
echo ""
exit $GATORGRADER_EXIT
fi