Mercurial > piecrust2
comparison piecrust/serving.py @ 130:7f81c84f7ddb
Handle the case where the debug server needs to serve an asset created after it was started.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Sat, 15 Nov 2014 16:03:50 +0100 |
| parents | 28444014ce7d |
| children | 9e4c2e68a129 |
comparison
equal
deleted
inserted
replaced
| 129:3080b6d02f40 | 130:7f81c84f7ddb |
|---|---|
| 144 | 144 |
| 145 def _try_serve_asset(self, app, environ, request): | 145 def _try_serve_asset(self, app, environ, request): |
| 146 logger.debug("Searching for asset with path: %s" % request.path) | 146 logger.debug("Searching for asset with path: %s" % request.path) |
| 147 rel_req_path = request.path.lstrip('/').replace('/', os.sep) | 147 rel_req_path = request.path.lstrip('/').replace('/', os.sep) |
| 148 entry = self._asset_record.previous.findEntry(rel_req_path) | 148 entry = self._asset_record.previous.findEntry(rel_req_path) |
| 149 do_synchronous_process = True | |
| 150 mounts = app.assets_dirs | |
| 149 if entry is None: | 151 if entry is None: |
| 150 return None | 152 # We don't know any asset that could have created this path, |
| 153 # but we'll see if there's a new asset that could fit. | |
| 154 pipeline = ProcessorPipeline( | |
| 155 app, mounts, self._out_dir, | |
| 156 skip_patterns=self._skip_patterns, | |
| 157 force_patterns=self._force_patterns) | |
| 158 record = pipeline.run(new_only=True) | |
| 159 entry = record.current.findEntry(rel_req_path) | |
| 160 if entry is None: | |
| 161 return None | |
| 162 | |
| 163 logger.debug("Found new asset: %s" % entry.path) | |
| 164 self._asset_record.addEntry(entry) | |
| 165 do_synchronous_process = False | |
| 151 | 166 |
| 152 # Yep, we know about this URL because we processed an asset that | 167 # Yep, we know about this URL because we processed an asset that |
| 153 # maps to it... make sure it's up to date by re-processing it | 168 # maps to it... make sure it's up to date by re-processing it |
| 154 # before serving. | 169 # before serving. |
| 155 mounts = app.assets_dirs | |
| 156 asset_in_path = entry.path | 170 asset_in_path = entry.path |
| 157 asset_out_path = os.path.join(self._out_dir, rel_req_path) | 171 asset_out_path = os.path.join(self._out_dir, rel_req_path) |
| 158 | 172 |
| 159 if self.synchronous_asset_pipeline: | 173 if self.synchronous_asset_pipeline and do_synchronous_process: |
| 160 pipeline = ProcessorPipeline( | 174 pipeline = ProcessorPipeline( |
| 161 app, mounts, self._out_dir, | 175 app, mounts, self._out_dir, |
| 162 skip_patterns=self._skip_patterns, | 176 skip_patterns=self._skip_patterns, |
| 163 force_patterns=self._force_patterns) | 177 force_patterns=self._force_patterns) |
| 164 pipeline.run(asset_in_path) | 178 pipeline.run(asset_in_path) |
