# HG changeset patch # User Jeff Hammel # Date 1450126294 28800 # Node ID 745c785b69869132dfd067bc4b3d6a486441204b # Parent 04aad19e17c635b9e80e3ee329361b2871000682 spruce this up a bit diff -r 04aad19e17c6 -r 745c785b6986 makeitso/python_package/{{package}}/web.py --- 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()