-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.sh
executable file
·165 lines (150 loc) · 3.23 KB
/
result.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
#!/bin/bash
PARSE="../../../scripts/parse.awk"
PROCESS="../../../scripts/process.py"
TEST_NAME="last"
printHelp() {
echo "./result.sh [-n TEST_NAME] [process options]"
echo "./result.sh TEST_NAME"
}
PROCESS_ARGS=""
RESULT_ONLY=0
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-n | --name)
TEST_NAME="$2"
shift 2
;;
-C | --console)
PROCESS_ARGS="${PROCESS_ARGS}$1 "
shift 1
;;
-N | --no-color)
PROCESS_ARGS="${PROCESS_ARGS}$1 "
shift 1
;;
-R | --result)
RESULT_ONLY=1
shift 1
;;
-D | --discuz)
PROCESS_ARGS="${PROCESS_ARGS}$1 "
shift 1
;;
-H | --html)
PROCESS_ARGS="${PROCESS_ARGS}$1 "
shift 1
;;
-S | --simplify)
PROCESS_ARGS="${PROCESS_ARGS}$1 "
shift 1
;;
-A | --curve)
PROCESS_ARGS="${PROCESS_ARGS}$1 "
shift 1
;;
-M | --map)
PROCESS_ARGS="${PROCESS_ARGS}$1 "
shift 1
;;
-T | --temp)
PROCESS_ARGS="${PROCESS_ARGS}$1 "
shift 1
;;
-h)
printHelp
exit 0
;;
*) # unknown option
if [ $# = 1 ]; then
TEST_NAME="$1"
shift 1
else
echo "$1" is not valid
printHelp
exit 1
fi
;;
esac
done
DIR="out/${TEST_NAME}"
if [ -d "$DIR" ]; then
echo "Directory exists: $DIR"
# You can add commands here to execute if the directory exists
else
echo "Directory does not exist: $DIR"
matching_dirs=$(find "out" -maxdepth 1 -type d -name "${TEST_NAME}*")
if [ -z "$matching_dirs" ]; then
echo "No directories found starting with '$TEST_NAME' in out/."
exit 1
fi
dir_count=$(echo "$matching_dirs" | grep -c /)
if [ $dir_count -gt 1 ]; then
echo "Error: Multiple directories found starting with '$TEST_NAME':"
echo "$matching_dirs"
exit 1
fi
matching_dirs=$(find "out" -maxdepth 1 -type d -name "${TEST_NAME}*" -exec basename {} \;)
TEST_NAME=$(echo "$matching_dirs" | head -n 1)
echo "Using directory: $TEST_NAME"
DIR="out/${TEST_NAME}"
fi
RESULT_DIR="${DIR}/result.d"
cd $RESULT_DIR 2>/dev/null || exit
if [ $RESULT_ONLY -eq 0 ]; then
echo $(pwd)
fi
spinner() {
local DELAY=0.05
while [ 1 ]; do
echo -n '/'
sleep $DELAY
echo -n '-'
sleep $DELAY
echo -n '\'
sleep $DELAY
echo -n '|'
sleep $DELAY
done
}
SPINNER_PID=-1
if [ $# -le 0 ] && [ $RESULT_ONLY -eq 0 ]; then
spinner &
SPINNER_PID=$!
fi
RESULT=$(mktemp)
RESULT_LIST=$(ls -1 | grep '[0-9]\+' | sort -n)
echo >>"$RESULT"
parseall() {
local TITLE="N/A"
local CACHE_DIR="cache.d"
local CACHE_FILE="$CACHE_DIR/cache"
mkdir $CACHE_DIR 2>/dev/null
touch $CACHE_FILE
chmod 777 $CACHE_DIR $CACHE_FILE 2>/dev/null
for i in $RESULT_LIST; do
if [ "$TITLE" = "N/A" ]; then
TITLE=$(cat $i | grep '\<vs\>' | sed -e 's/\t//g')
if [ -z "$TITLE" ]; then
TITLE="N/A"
fi
fi
if [ ! -f $CACHE_DIR/"$i" ]; then
local OUTPUT
OUTPUT=$(awk -f $PARSE "$i")
if [ -n "$OUTPUT" ]; then
echo "$OUTPUT" >>$CACHE_FILE
touch $CACHE_DIR/"$i"
fi
fi
done
echo $TITLE
cat $CACHE_FILE
}
parseall | python2.7 $PROCESS $PROCESS_ARGS >>"$RESULT"
if [ $SPINNER_PID -gt 0 ]; then
exec 2>/dev/null
kill $SPINNER_PID
fi
cat "$RESULT"
rm -f "$RESULT"