Mercurial > piecrust2
view piecrust/commands/builtin/serving.py @ 1168:10520472cc73
routing: Fix breakages with routing on some versions of Python.
Finally figured what happened with change 6baa94da8b16 (this is a Mercurial
hash by the way if you're looking at the Git mirror). Between Python 3.6 and
3.7 there was a change where the percent sign ('%') went from being escaped by
`re.escape` to _not_ being escaped. So now we need to use different regex
patterns dependin on the Python version, yay.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 04 Oct 2019 11:13:33 -0700 |
parents | 33a89139c284 |
children |
line wrap: on
line source
import logging from piecrust.commands.base import ChefCommand logger = logging.getLogger(__name__) class ServeCommand(ChefCommand): def __init__(self): super(ServeCommand, self).__init__() self.name = 'serve' self.description = "Runs a local web server to serve your website." self.cache_name = 'server' def setupParser(self, parser, app): parser.add_argument( '-p', '--port', help="The port for the web server", default=8080) parser.add_argument( '-a', '--address', help="The host for the web server", default='localhost') parser.add_argument( '--use-reloader', help="Restart the server when PieCrust code changes", action='store_true') parser.add_argument( '--use-debugger', help="Show the debugger when an error occurs", action='store_true') parser.add_argument( '--admin', help="Also serve the administration panel.", action='store_true') parser.add_argument( '--wsgi', help="The WSGI server implementation to use", choices=['werkzeug', 'gunicorn'], default='werkzeug') def run(self, ctx): appfactory = ctx.appfactory host = ctx.args.address port = int(ctx.args.port) use_debugger = ctx.args.debug or ctx.args.use_debugger from piecrust.serving.wrappers import run_piecrust_server run_piecrust_server( ctx.args.wsgi, appfactory, host, port, is_cmdline_mode=True, serve_admin=ctx.args.admin, use_reloader=ctx.args.use_reloader, use_debugger=use_debugger)