-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhttp_debugger.py
55 lines (43 loc) · 1.17 KB
/
http_debugger.py
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
#! /usr/bin/env python
#
# $Id: servehttp,v 1.3 2007/02/03 10:27:01 matthias Exp matthias $
#
# httpserve - Serve a directory using HTTP.
#
# by Matthias Friedrich <[email protected]>
#
# This program is distributed under the Artistic License.
#
import os
import sys
import SimpleHTTPServer
import BaseHTTPServer
from optparse import OptionParser
port = 8000
parser = OptionParser()
parser.set_usage('%prog [options] directory')
parser.add_option('-p', '--port', dest = 'port', help = 'the port to listen on')
(options, args) = parser.parse_args()
if len(args) != 1:
parser.print_help()
sys.exit(1)
try:
os.chdir(args[0])
except OSError:
parser.error("Can't change to directory `%s'" % args[0])
if options.port:
try:
port = int(options.port)
if not ( 0 < port < 65536 ):
raise ValueError()
except ValueError:
parser.error('port number has to be numeric (1-65535)')
sys.exit(1)
handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = BaseHTTPServer.HTTPServer(('', port), handler)
print "Serving directory '%s' on port %d" % (os.getcwd(), port)
try:
httpd.serve_forever()
except KeyboardInterrupt:
print 'Server killed on user request (keyboard interrupt).'
# EOF