Mercurial > piecrust2
view piecrust/commands/builtin/serving.py @ 334:b034f6f15e22
bake: Several bug taxonomy-related fixes for incorrect incremental bakes.
* Improve how the baker processes taxonomy terms and figures out what needs
to be re-baked or not.
* Create bake entries for clean taxnomy terms so they're not deleted by an
incremental bake.
* Add more information to bake records.
* Slugify taxonomy terms is now done by the route in one place.
* Fix a bug where the cache key for invalidating rendered segments was not
computed the same way as when the caching was done.
* Fix how term combinations are passed around, rendered, printed, parsed, etc.
(TODO: more word needed in the routing functions)
* Expose to the template whether a taxonomy term is a combination or not.
* Display term combinations better in the built-in theme.
* Rename `route.taxonomy` to `route.taxonomy_name` to prevent confusion.
* Add options to show bake records for previous bakes.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 03 Apr 2015 10:59:50 -0700 |
parents | 4f00bb99400e |
children | c2ca72fb7f0b |
line wrap: on
line source
import logging from piecrust.serving import Server, _sse_abort 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." 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( '--wsgi', help="The WSGI server implementation to use", choices=['werkzeug', 'gunicorn'], default='werkzeug') def run(self, ctx): host = ctx.args.address port = int(ctx.args.port) debug = ctx.args.debug or ctx.args.use_debugger server = Server( ctx.app.root_dir, debug=debug, use_reloader=ctx.args.use_reloader) app = server.getWsgiApp() if ctx.args.wsgi == 'werkzeug': from werkzeug.serving import run_simple try: run_simple(host, port, app, threaded=True, use_debugger=debug, use_reloader=ctx.args.use_reloader) finally: _sse_abort.set() elif ctx.args.wsgi == 'gunicorn': from gunicorn.app.base import BaseApplication class PieCrustGunicornApplication(BaseApplication): def __init__(self, app, options): self.app = app self.options = options super(PieCrustGunicornApplication, self).__init__() def load_config(self): for k, v in self.options.items(): if k in self.cfg.settings and v is not None: self.cfg.set(k, v) def load(self): return self.app options = { 'bind': '%s:%s' % (host, port), 'accesslog': '-', 'worker_class': 'gaiohttp', 'workers': 2, 'timeout': 999999} if debug: options['loglevel'] = 'debug' if ctx.args.use_reloader: options['reload'] = True app_wrapper = PieCrustGunicornApplication(app, options) app_wrapper.run()