Repository navigation
Expand file tree
/
Copy pathcorrect.bash
More file actions
107 lines (66 loc) · 2.09 KB
/
Copy pathcorrect.bash
File metadata and controls
107 lines (66 loc) · 2.09 KB
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
# Correct.bash script used for autocorrecting programming exams.
# Verbose check
VERBOSE=true
# Text file use by students
COPY_FILE="myths.txt"
# If available use python3 else python
python3 --version >/dev/null 2>&1 && py=python3 || py=python
# get path to .dbwebb folder
DBWEBB_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
PROJ_PATH="$DBWEBB_PATH/.."
LOG_PATH="$DBWEBB_PATH/log"
# Copy value-of-time file to .dbwebb for correction
cp "$PROJ_PATH/$COPY_FILE" "$DBWEBB_PATH"
test_status="$(cd "$DBWEBB_PATH" && ${py} test_dbwebb.py &> "$LOG_PATH")"
# Picks subparts of log file
ALL_LINES="$(cat "$LOG_PATH" | head -6)"
FIRST_LINE="$(cat "$LOG_PATH" | head -1)"
SECOND_LINE="$(cat "$LOG_PATH" | head -2 | tail -1)"
REST="$(cat "$LOG_PATH" | head -6 | tail -4)"
# Resets points
POINTS=0
# Output log file
output_log () {
echo
echo "====================================="
echo "TEST SCRIPT OUTPUT"
echo "====================================="
cat "$LOG_PATH"
}
# Clean, removes files
clean_up () {
rm "$DBWEBB_PATH/$COPY_FILE"
rm "$LOG_PATH"
}
# Checks if all files and modules are there
if [[ $FIRST_LINE = *"... ok"* ]]; then
echo "Alla moduler och filer finns."
fi
# Checks for completion of first assignment
if [[ $SECOND_LINE = *"... ok"* ]]; then
echo "Du har löst uppgift 1."
POINTS=$((POINTS+10))
else
echo "Du har inte löst uppgift 1."
fi
# Outputs whether an assignment is solved or not.
for i in `seq 3 3`; do
ASSIGNMENT=$(($i-1))
if [[ $(cat "$LOG_PATH" | head -$i | tail -1) = *"... ok"* ]]; then
echo "Du har löst uppgift $ASSIGNMENT."
POINTS=$((POINTS+10))
else
echo "Du har inte löst uppgift $ASSIGNMENT."
fi
done
# Sets grade message based on POINTS
if [[ $POINTS -gt 19 ]]; then
echo "Du har $POINTS poäng och är godkänd på den individuella examinationen."
else
echo "Du har $POINTS poäng. Detta är mindre än 20 och du är inte godkänd på den individuella examinationen."
fi
# Outputs log file from Python test script
output_log
# Clean up
clean_up
exit 0