1
1
#!/usr/bin/env python
3
3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
# You can obtain one at http://mozilla.org/MPL/2.0/.
7
7
import BaseHTTPServer
8
8
import SimpleHTTPServer
226
227
def main(args=sys.argv[1:]):
228
229
# parse command line options
229
230
from optparse import OptionParser
230
231
parser = OptionParser()
231
parser.add_option('-p', '--port', dest='port',
232
parser.add_option('-p', '--port', dest='port',
232
233
type="int", default=8888,
233
234
help="port to run the server on [DEFAULT: %default]")
234
235
parser.add_option('-H', '--host', dest='host',
235
236
default='127.0.0.1',
236
237
help="host [DEFAULT: %default]")
238
parser.add_option('-i', '--external-ip', action="store_true",
239
dest='external_ip', default=False,
240
help="find and use external ip for host")
237
241
parser.add_option('-d', '--docroot', dest='docroot',
238
242
default=os.getcwd(),
239
243
help="directory to serve files from [DEFAULT: %default]")
240
244
options, args = parser.parse_args(args)
246
parser.error("mozhttpd does not take any arguments")
242
247
parser.print_help()
250
if options.external_ip:
251
host = iface.get_lan_ip()
245
255
# create the server
246
kwargs = options.__dict__.copy()
247
server = MozHttpd(**kwargs)
256
server = MozHttpd(host=host, port=options.port, docroot=options.docroot)
249
258
print "Serving '%s' at %s:%s" % (server.docroot, server.host, server.port)
250
259
server.start(block=True)