slight cleaning for webserver
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys,os
|
||||
import sys, os
|
||||
import BaseHTTPServer
|
||||
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
||||
|
||||
def setup_options():
|
||||
''' Create command line options '''
|
||||
''' Create command line options '''
|
||||
from argparse import ArgumentParser
|
||||
|
||||
parser=ArgumentParser()
|
||||
@@ -16,7 +16,9 @@ def setup_options():
|
||||
parser.add_argument("rootpath",type=str,action="store",default=os.path.abspath('.'),nargs='?',
|
||||
help="Root path of the server")
|
||||
options=parser.parse_args()
|
||||
|
||||
if not os.path.exists(options.rootpath):
|
||||
parser.error("Path does not exist")
|
||||
options.rootpath = os.path.abspath(options.rootpath)
|
||||
return options
|
||||
|
||||
|
||||
@@ -27,6 +29,7 @@ def serve(options):
|
||||
Protocol = "HTTP/1.0"
|
||||
|
||||
server_address = (options.address, options.port)
|
||||
|
||||
os.chdir(options.rootpath)
|
||||
|
||||
HandlerClass.protocol_version = Protocol
|
||||
@@ -37,11 +40,13 @@ def serve(options):
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
httpd.server_close()
|
||||
httpd.server_close()
|
||||
except OSError:
|
||||
httpd.server_close()
|
||||
|
||||
options=setup_options()
|
||||
serve(options)
|
||||
if __name__ == "__main__":
|
||||
options=setup_options()
|
||||
serve(options)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user