-
Notifications
You must be signed in to change notification settings - Fork 1
/
py-httpd.sh
executable file
·55 lines (50 loc) · 980 Bytes
/
py-httpd.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
#!/bin/sh
rootdir=''
host=''
port=''
while [ $# -gt 0 ]; do
case "$1" in
(-d) rootdir="$2"; shift ;;
(-s) host="$2"; shift ;;
(-p) port="$2"; shift ;;
(--) shift; break ;;
(-*) echo ERROR; exit 123 ;;
(*) break
esac
shift
done
if [ $# -gt 0 ]; then
if [ $# -eq 1 ] && [ -z "$rootdir" ]; then
rootdir="$1"; shift;
else
echo ERROR
exit 123
fi
fi
[ -n "$rootdir" ] || rootdir="$(pwd)"
[ -n "$host" ] || host='localhost'
[ -n "$port" ] || port=8080
rootdir="$(readlink -f "$rootdir")"
echo "# rootdir=$rootdir"
echo "# at http://$host:$port/"
(
cd -- "$rootdir" || exit 1
{
cat<<EOF
import sys
import SimpleHTTPServer
import SocketServer
port = $port
host = "$host"
#if sys.argv[1:]:
# port = int(sys.argv[1])
#else:
# port = 8080
#host = "localhost"
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer((host, port), Handler)
#print "Serving HTTP on" , host, "port", port, "..."
httpd.serve_forever()
EOF
} | python
)