-
Notifications
You must be signed in to change notification settings - Fork 29
/
start.sh
executable file
·155 lines (140 loc) · 3.15 KB
/
start.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
#!/usr/bin/env bash
# @author Joschi <[email protected]>
# created 2015-02-16 14:00
JSON_DIR="json"
base_dir=`pwd`
dictionary="${JSON_DIR}/dictionary.json"
file_list="patients.txt"
server_pid_file="${base_dir}/server_pid.txt"
server_log="${base_dir}/server_log.txt"
server_err="${base_dir}/server_err.txt"
USAGE="Usage: $0 -hq -p <patient file> [-d <dictionary file>] [--url] [--start|--stop] [--list|--list-update] [--refresh] [--shelve]"
usage() {
echo $USAGE
echo "-h: print help"
echo "-q: be quiet"
echo "-p <patient file>: the patient file to load"
echo "-d <dictionary file>: the dictionary file to load"
echo "--list: lists all available patient files"
echo "--list-update: updates this list"
echo "--url: only prints the URL (does not open a browser)"
echo "--start: starts the server"
echo "--stop: stops the server"
echo "--refresh: refreshes all already converted patient files"
echo "--shelve: uses shelve input"
exit 1
}
pfile=
dfile="${JSON_DIR}/dictionary.json"
only_url=
do_start=
do_stop=
show_list=
update_list=
quiet=
refresh=
shelve=
if [ $# -eq 0 ]; then
usage
fi
while [ $# -gt 0 ]; do
case "$1" in
"")
;;
-h)
usage
;;
-q)
quiet="-q"
;;
-p)
shift
pfile="$1"
;;
-d)
shift
dfile="$1"
;;
--url)
only_url="--no-open"
;;
--start)
do_start=1
;;
--stop)
do_stop=1
;;
--list)
show_list=1
;;
--list-update)
update_list=1
;;
--refresh)
refresh=1
;;
--shelve)
shelve="--shelve"
;;
*)
echo "illegal option -- $1"
usage ;;
esac
shift
done
if [[ $# -gt 1 ]]; then
echo "illegal option -- $1"
usage
fi
if [[ -z $pfile && -z $do_start && -z $do_stop && -z $show_list && -z $update_list && -z $refresh ]]; then
echo "require patient file"
usage
fi
cd_back() {
cd "${base_dir}"
}
print() {
if [ -z "${quiet}" ]; then
echo "$@"
fi
}
if [ ! -z $refresh ]; then
./setup.sh -s --convert "$(sed -E 's/json\/([^.]+)\.json/\1/' ${file_list})" --do-convert "${shelve}"
fi
if [ ! -z $do_start ]; then
if [[ -s "${server_pid_file}" || -f "${server_pid_file}" ]]; then
print "Server already running..."
else
print "Starting server..."
cd ..
python -m SimpleHTTPServer > "${server_log}" 2> "${server_err}" &
server_pid=$!
echo "${server_pid}" > "${server_pid_file}"
cd_back
fi
fi
if [ ! -z $do_stop ]; then
if [[ -s "${server_pid_file}" || -f "${server_pid_file}" ]]; then
server_pid=`cat "${server_pid_file}"`
print "Server pid: ${server_pid}"
chk_pid=`ps -p ${server_pid} | grep "python" | grep -v grep`
if [ -z "${chk_pid}" ]; then
echo "${server_pid} is not a python server!"
else
kill "${server_pid}"
rm -- "${server_pid_file}" 2> /dev/null
fi
else
print "No server running..."
fi
fi
if [ ! -z $update_list ]; then
find "${JSON_DIR}" -name "*.json" -and -not -path "${dictionary}" > "${file_list}"
fi
if [ ! -z $show_list ]; then
cat "${file_list}"
fi
if [ -z "${pfile}" ]; then
exit 0
fi
./open_url.sh -c "${quiet}" "${only_url}" -- "http://localhost:8000/patient-viz/index.html?p=${pfile}&d=${dfile}"