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/.
16 # directory of this file
17 here
= os
.path
.dirname(os
.path
.realpath(__file__
))
20 class WebServers(object):
21 def __init__(self
, host
, port
, docroot
, count
):
24 self
.docroot
= docroot
33 while len(self
.servers
) < self
.count
:
35 mozhttpd
.MozHttpd(host
=self
.host
, port
=port
, docroot
=self
.docroot
)
38 self
.servers
[-1].start()
39 except socket
.error
as error
:
40 if isinstance(error
, socket
.error
):
42 print("port {} is in use.".format(port
))
44 print("port {} error {}".format(port
, error
))
45 elif isinstance(error
, str):
46 print("port {} error {}".format(port
, error
))
49 except Exception as error
:
50 print("port {} error {}".format(port
, error
))
55 raise Exception("Too many errors in webservers.py")
59 while len(self
.servers
) > 0:
60 server
= self
.servers
.pop()
65 parser
= argparse
.ArgumentParser(
66 description
="Start mozhttpd servers for use by areweslimyet."
73 help="Starting port. Defaults to 8001. Web servers will be "
74 "created for each port from the starting port to starting port "
81 help="Number of web servers to start. Defaults to 100.",
87 help="Name of webserver host. Defaults to localhost.",
90 args
= parser
.parse_args()
91 web_servers
= WebServers(args
.host
, args
.port
, "%s/html" % here
, args
.count
)
95 if __name__
== "__main__":