Mercurial > piecrust2
comparison piecrust/serving.py @ 110:7f00176a3b4d
Prepare the server to support background asset pipelines.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 16 Oct 2014 08:19:02 -0700 |
parents | 73956224eb67 |
children | 208c652551a3 |
comparison
equal
deleted
inserted
replaced
109:438509f12332 | 110:7f00176a3b4d |
---|---|
24 logger = logging.getLogger(__name__) | 24 logger = logging.getLogger(__name__) |
25 | 25 |
26 | 26 |
27 class Server(object): | 27 class Server(object): |
28 def __init__(self, root_dir, host='localhost', port='8080', | 28 def __init__(self, root_dir, host='localhost', port='8080', |
29 debug=False, static_preview=True): | 29 debug=False, static_preview=True, |
30 synchronous_asset_pipeline=True): | |
30 self.root_dir = root_dir | 31 self.root_dir = root_dir |
31 self.host = host | 32 self.host = host |
32 self.port = port | 33 self.port = port |
33 self.debug = debug | 34 self.debug = debug |
34 self.static_preview = static_preview | 35 self.static_preview = static_preview |
36 self.synchronous_asset_pipeline = synchronous_asset_pipeline | |
35 self._out_dir = None | 37 self._out_dir = None |
36 self._skip_patterns = None | 38 self._skip_patterns = None |
37 self._force_patterns = None | 39 self._force_patterns = None |
38 self._record = None | 40 self._record = None |
39 self._mimetype_map = load_mimetype_map() | 41 self._mimetype_map = load_mimetype_map() |
117 # maps to it... make sure it's up to date by re-processing it | 119 # maps to it... make sure it's up to date by re-processing it |
118 # before serving. | 120 # before serving. |
119 mounts = app.assets_dirs | 121 mounts = app.assets_dirs |
120 asset_in_path = entry.path | 122 asset_in_path = entry.path |
121 asset_out_path = os.path.join(self._out_dir, rel_req_path) | 123 asset_out_path = os.path.join(self._out_dir, rel_req_path) |
122 pipeline = ProcessorPipeline( | 124 |
123 app, mounts, self._out_dir, | 125 if self.synchronous_asset_pipeline: |
124 skip_patterns=self._skip_patterns, | 126 pipeline = ProcessorPipeline( |
125 force_patterns=self._force_patterns) | 127 app, mounts, self._out_dir, |
126 pipeline.run(asset_in_path) | 128 skip_patterns=self._skip_patterns, |
129 force_patterns=self._force_patterns) | |
130 pipeline.run(asset_in_path) | |
127 | 131 |
128 logger.debug("Serving %s" % asset_out_path) | 132 logger.debug("Serving %s" % asset_out_path) |
129 wrapper = wrap_file(environ, open(asset_out_path, 'rb')) | 133 wrapper = wrap_file(environ, open(asset_out_path, 'rb')) |
130 response = Response(wrapper) | 134 response = Response(wrapper) |
131 _, ext = os.path.splitext(rel_req_path) | 135 _, ext = os.path.splitext(rel_req_path) |