Mercurial > piecrust2
comparison piecrust/serving/wrappers.py @ 663:3ceeca7bb71c
themes: Add support for a `--theme` argument to `chef`.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 01 Mar 2016 22:27:28 -0800 |
parents | 9ab005db2592 |
children | 81d9c3a3a0b5 |
comparison
equal
deleted
inserted
replaced
662:cbd5cdec0695 | 663:3ceeca7bb71c |
---|---|
7 | 7 |
8 logger = logging.getLogger(__name__) | 8 logger = logging.getLogger(__name__) |
9 | 9 |
10 | 10 |
11 def run_werkzeug_server(root_dir, host, port, | 11 def run_werkzeug_server(root_dir, host, port, |
12 debug_piecrust=False, sub_cache_dir=None, | 12 debug_piecrust=False, theme_site=False, |
13 sub_cache_dir=None, | |
13 use_debugger=False, use_reloader=False): | 14 use_debugger=False, use_reloader=False): |
14 from werkzeug.serving import run_simple | 15 from werkzeug.serving import run_simple |
15 | 16 |
16 def _run_sse_check(): | 17 def _run_sse_check(): |
17 # We don't want to run the processing loop here if this isn't | 18 # We don't want to run the processing loop here if this isn't |
23 return (not use_reloader or | 24 return (not use_reloader or |
24 os.environ.get('WERKZEUG_RUN_MAIN') == 'true') | 25 os.environ.get('WERKZEUG_RUN_MAIN') == 'true') |
25 | 26 |
26 app = _get_piecrust_server(root_dir, | 27 app = _get_piecrust_server(root_dir, |
27 debug=debug_piecrust, | 28 debug=debug_piecrust, |
29 theme_site=theme_site, | |
28 sub_cache_dir=sub_cache_dir, | 30 sub_cache_dir=sub_cache_dir, |
29 run_sse_check=_run_sse_check) | 31 run_sse_check=_run_sse_check) |
30 | 32 |
31 # We need to do a few things to get Werkzeug to properly shutdown or | 33 # We need to do a few things to get Werkzeug to properly shutdown or |
32 # restart while SSE responses are running. This is because Werkzeug runs | 34 # restart while SSE responses are running. This is because Werkzeug runs |
76 _shutdown_server() | 78 _shutdown_server() |
77 raise | 79 raise |
78 | 80 |
79 | 81 |
80 def run_gunicorn_server(root_dir, | 82 def run_gunicorn_server(root_dir, |
81 debug_piecrust=False, sub_cache_dir=None, | 83 debug_piecrust=False, theme_site=False, |
84 sub_cache_dir=None, | |
82 gunicorn_options=None): | 85 gunicorn_options=None): |
83 from gunicorn.app.base import BaseApplication | 86 from gunicorn.app.base import BaseApplication |
84 | 87 |
85 class PieCrustGunicornApplication(BaseApplication): | 88 class PieCrustGunicornApplication(BaseApplication): |
86 def __init__(self, app, options): | 89 def __init__(self, app, options): |
96 def load(self): | 99 def load(self): |
97 return self.app | 100 return self.app |
98 | 101 |
99 app = _get_piecrust_server(root_dir, | 102 app = _get_piecrust_server(root_dir, |
100 debug=debug_piecrust, | 103 debug=debug_piecrust, |
104 theme_site=theme_site, | |
101 sub_cache_dir=sub_cache_dir) | 105 sub_cache_dir=sub_cache_dir) |
102 | 106 |
103 gunicorn_options = gunicorn_options or {} | 107 gunicorn_options = gunicorn_options or {} |
104 app_wrapper = PieCrustGunicornApplication(app, gunicorn_options) | 108 app_wrapper = PieCrustGunicornApplication(app, gunicorn_options) |
105 app_wrapper.run() | 109 app_wrapper.run() |
106 | 110 |
107 | 111 |
108 def _get_piecrust_server(root_dir, debug=False, sub_cache_dir=None, | 112 def _get_piecrust_server( |
109 run_sse_check=None): | 113 root_dir, debug=False, theme_site=False, |
114 sub_cache_dir=None, run_sse_check=None): | |
110 from piecrust.serving.middlewares import ( | 115 from piecrust.serving.middlewares import ( |
111 StaticResourcesMiddleware, PieCrustDebugMiddleware) | 116 StaticResourcesMiddleware, PieCrustDebugMiddleware) |
112 from piecrust.serving.server import WsgiServer | 117 from piecrust.serving.server import WsgiServer |
113 app = WsgiServer(root_dir, debug=debug, sub_cache_dir=sub_cache_dir) | 118 app = WsgiServer(root_dir, debug=debug, theme_site=theme_site, |
119 sub_cache_dir=sub_cache_dir) | |
114 app = StaticResourcesMiddleware(app) | 120 app = StaticResourcesMiddleware(app) |
115 app = PieCrustDebugMiddleware(app, root_dir, | 121 app = PieCrustDebugMiddleware(app, root_dir, |
122 theme_site=theme_site, | |
116 sub_cache_dir=sub_cache_dir, | 123 sub_cache_dir=sub_cache_dir, |
117 run_sse_check=run_sse_check) | 124 run_sse_check=run_sse_check) |
118 return app | 125 return app |
119 | 126 |