Mercurial > piecrust2
comparison piecrust/commands/builtin/serving.py @ 852:4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
* Everything is a `ContentSource`, including assets directories.
* Most content sources are subclasses of the base file-system source.
* A source is processed by a "pipeline", and there are 2 built-in pipelines,
one for assets and one for pages. The asset pipeline is vaguely functional,
but the page pipeline is completely broken right now.
* Rewrite the baking process as just running appropriate pipelines on each
content item. This should allow for better parallelization.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Wed, 17 May 2017 00:11:48 -0700 |
| parents | 81d9c3a3a0b5 |
| children | f77f9dcba072 |
comparison
equal
deleted
inserted
replaced
| 851:2c7e57d80bba | 852:4850f8c21b6e |
|---|---|
| 1 import logging | 1 import logging |
| 2 from piecrust.commands.base import ChefCommand | 2 from piecrust.commands.base import ChefCommand |
| 3 from piecrust.serving.wrappers import run_werkzeug_server, run_gunicorn_server | |
| 4 | 3 |
| 5 | 4 |
| 6 logger = logging.getLogger(__name__) | 5 logger = logging.getLogger(__name__) |
| 7 | 6 |
| 8 | 7 |
| 13 self.description = "Runs a local web server to serve your website." | 12 self.description = "Runs a local web server to serve your website." |
| 14 self.cache_name = 'server' | 13 self.cache_name = 'server' |
| 15 | 14 |
| 16 def setupParser(self, parser, app): | 15 def setupParser(self, parser, app): |
| 17 parser.add_argument( | 16 parser.add_argument( |
| 18 '-p', '--port', | 17 '-p', '--port', |
| 19 help="The port for the web server", | 18 help="The port for the web server", |
| 20 default=8080) | 19 default=8080) |
| 21 parser.add_argument( | 20 parser.add_argument( |
| 22 '-a', '--address', | 21 '-a', '--address', |
| 23 help="The host for the web server", | 22 help="The host for the web server", |
| 24 default='localhost') | 23 default='localhost') |
| 25 parser.add_argument( | 24 parser.add_argument( |
| 26 '--use-reloader', | 25 '--use-reloader', |
| 27 help="Restart the server when PieCrust code changes", | 26 help="Restart the server when PieCrust code changes", |
| 28 action='store_true') | 27 action='store_true') |
| 29 parser.add_argument( | 28 parser.add_argument( |
| 30 '--use-debugger', | 29 '--use-debugger', |
| 31 help="Show the debugger when an error occurs", | 30 help="Show the debugger when an error occurs", |
| 32 action='store_true') | 31 action='store_true') |
| 33 parser.add_argument( | 32 parser.add_argument( |
| 34 '--wsgi', | 33 '--wsgi', |
| 35 help="The WSGI server implementation to use", | 34 help="The WSGI server implementation to use", |
| 36 choices=['werkzeug', 'gunicorn'], | 35 choices=['werkzeug', 'gunicorn'], |
| 37 default='werkzeug') | 36 default='werkzeug') |
| 38 | 37 |
| 39 def run(self, ctx): | 38 def run(self, ctx): |
| 40 root_dir = ctx.app.root_dir | |
| 41 host = ctx.args.address | 39 host = ctx.args.address |
| 42 port = int(ctx.args.port) | 40 port = int(ctx.args.port) |
| 43 debug = ctx.args.debug or ctx.args.use_debugger | 41 debug = ctx.args.debug or ctx.args.use_debugger |
| 44 | 42 appfactory = ctx.appfactory |
| 45 from piecrust.app import PieCrustFactory | |
| 46 appfactory = PieCrustFactory( | |
| 47 ctx.app.root_dir, | |
| 48 cache=ctx.app.cache.enabled, | |
| 49 cache_key=ctx.app.cache_key, | |
| 50 config_variant=ctx.config_variant, | |
| 51 config_values=ctx.config_values, | |
| 52 debug=ctx.app.debug, | |
| 53 theme_site=ctx.app.theme_site) | |
| 54 | 43 |
| 55 if ctx.args.wsgi == 'werkzeug': | 44 if ctx.args.wsgi == 'werkzeug': |
| 45 from piecrust.serving.wrappers import run_werkzeug_server | |
| 56 run_werkzeug_server( | 46 run_werkzeug_server( |
| 57 appfactory, host, port, | 47 appfactory, host, port, |
| 58 use_debugger=debug, | 48 use_debugger=debug, |
| 59 use_reloader=ctx.args.use_reloader) | 49 use_reloader=ctx.args.use_reloader) |
| 60 | 50 |
| 61 elif ctx.args.wsgi == 'gunicorn': | 51 elif ctx.args.wsgi == 'gunicorn': |
| 52 from piecrust.serving.wrappers import run_gunicorn_server | |
| 62 options = { | 53 options = { |
| 63 'bind': '%s:%s' % (host, port), | 54 'bind': '%s:%s' % (host, port), |
| 64 'accesslog': '-', # print access log to stderr | 55 'accesslog': '-', # print access log to stderr |
| 65 } | 56 } |
| 66 if debug: | 57 if debug: |
| 67 options['loglevel'] = 'debug' | 58 options['loglevel'] = 'debug' |
| 68 if ctx.args.use_reloader: | 59 if ctx.args.use_reloader: |
| 69 options['reload'] = True | 60 options['reload'] = True |
| 70 run_gunicorn_server(appfactory, gunicorn_options=options) | 61 run_gunicorn_server(appfactory, gunicorn_options=options) |
