Mercurial > piecrust2
comparison piecrust/serving/server.py @ 409:2bb5327c4c1f
debug: Fix serving of resources now that the module moved to a sub-folder.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 25 May 2015 18:38:05 -0700 |
parents | 3e4bb57d8506 |
children | e7b865f8f335 |
comparison
equal
deleted
inserted
replaced
408:fd8e39254da0 | 409:2bb5327c4c1f |
---|---|
10 from werkzeug.exceptions import ( | 10 from werkzeug.exceptions import ( |
11 NotFound, MethodNotAllowed, InternalServerError, HTTPException) | 11 NotFound, MethodNotAllowed, InternalServerError, HTTPException) |
12 from werkzeug.wrappers import Request, Response | 12 from werkzeug.wrappers import Request, Response |
13 from werkzeug.wsgi import ClosingIterator, wrap_file | 13 from werkzeug.wsgi import ClosingIterator, wrap_file |
14 from jinja2 import FileSystemLoader, Environment | 14 from jinja2 import FileSystemLoader, Environment |
15 from piecrust import CACHE_DIR | 15 from piecrust import CACHE_DIR, RESOURCES_DIR |
16 from piecrust.app import PieCrust | 16 from piecrust.app import PieCrust |
17 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page | 17 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page |
18 from piecrust.sources.base import MODE_PARSING | 18 from piecrust.sources.base import MODE_PARSING |
19 from piecrust.uriutil import split_sub_uri | 19 from piecrust.uriutil import split_sub_uri |
20 | 20 |
156 | 156 |
157 def _try_special_request(self, environ, request): | 157 def _try_special_request(self, environ, request): |
158 static_mount = '/__piecrust_static/' | 158 static_mount = '/__piecrust_static/' |
159 if request.path.startswith(static_mount): | 159 if request.path.startswith(static_mount): |
160 rel_req_path = request.path[len(static_mount):] | 160 rel_req_path = request.path[len(static_mount):] |
161 mount = os.path.join( | 161 mount = os.path.join(RESOURCES_DIR, 'server') |
162 os.path.dirname(__file__), | |
163 'resources', 'server') | |
164 full_path = os.path.join(mount, rel_req_path) | 162 full_path = os.path.join(mount, rel_req_path) |
165 try: | 163 try: |
166 response = self._make_wrapped_file_response( | 164 response = self._make_wrapped_file_response( |
167 environ, request, full_path) | 165 environ, request, full_path) |
168 return response | 166 return response |
171 | 169 |
172 debug_mount = '/__piecrust_debug/' | 170 debug_mount = '/__piecrust_debug/' |
173 if request.path.startswith(debug_mount): | 171 if request.path.startswith(debug_mount): |
174 rel_req_path = request.path[len(debug_mount):] | 172 rel_req_path = request.path[len(debug_mount):] |
175 if rel_req_path == 'pipeline_status': | 173 if rel_req_path == 'pipeline_status': |
176 from piecrust.server.procloop import ( | 174 from piecrust.serving.procloop import ( |
177 PipelineStatusServerSideEventProducer) | 175 PipelineStatusServerSideEventProducer) |
178 provider = PipelineStatusServerSideEventProducer( | 176 provider = PipelineStatusServerSideEventProducer( |
179 self._proc_loop.status_queue) | 177 self._proc_loop.status_queue) |
180 it = ClosingIterator(provider.run(), [provider.close]) | 178 it = ClosingIterator(provider.run(), [provider.close]) |
181 response = Response(it) | 179 response = Response(it) |
457 return res | 455 return res |
458 | 456 |
459 | 457 |
460 class ErrorMessageLoader(FileSystemLoader): | 458 class ErrorMessageLoader(FileSystemLoader): |
461 def __init__(self): | 459 def __init__(self): |
462 base_dir = os.path.join(os.path.dirname(__file__), 'resources', | 460 base_dir = os.path.join(RESOURCES_DIR, 'messages') |
463 'messages') | |
464 super(ErrorMessageLoader, self).__init__(base_dir) | 461 super(ErrorMessageLoader, self).__init__(base_dir) |
465 | 462 |
466 def get_source(self, env, template): | 463 def get_source(self, env, template): |
467 template += '.html' | 464 template += '.html' |
468 return super(ErrorMessageLoader, self).get_source(env, template) | 465 return super(ErrorMessageLoader, self).get_source(env, template) |