Mercurial > hg > MakeItSo
changeset 217:745c785b6986
spruce this up a bit
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 14 Dec 2015 12:51:34 -0800 |
parents | 04aad19e17c6 |
children | d61783ce9fd5 |
files | makeitso/python_package/{{package}}/web.py |
diffstat | 1 files changed, 28 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/makeitso/python_package/{{package}}/web.py Mon Dec 14 12:44:39 2015 -0800 +++ b/makeitso/python_package/{{package}}/web.py Mon Dec 14 12:51:34 2015 -0800 @@ -4,9 +4,14 @@ web handler for {{project}} """ +# imports +import argparse +import sys from webob import Request, Response, exc +from wsgiref import simple_server class Handler(object): + """WSGI HTTP Handler""" def __init__(self, **kw): pass @@ -17,9 +22,27 @@ body="{{project}}") return response(environ, start_response) -if __name__ == '__main__': - from wsgiref import simple_server +def main(args=sys.argv[1:]): + """CLI""" + + # parse command line + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('-p', '--port', dest='port', + type=int, default=8080, + help="port to serve on") + options = parser.parse_arguments(args) + + # instantiate WSGI handler app = Handler() - server = simple_server.make_server(host='0.0.0.0', port=8080, app=app) - server.serve_forever() - + + # serve it (Warning! Single threaded!) + server = simple_server.make_server(host='0.0.0.0', + port=options.port + app=app) + try: + server.serve_forever() + except KeyboardInterrupt: + pass + +if __name__ == '__main__': + main()