Mercurial > piecrust2
comparison piecrust/serving/util.py @ 666:81d9c3a3a0b5
internal: Get rid of the whole "sub cache" business.
* Compute cache keys up front, so the cache directory is only chosen once.
* Buffer up config variants to apply before loading the config. Makes it
possible to cache variant-resulting configs, too.
* Make a factory class to reuse the logic that creates the `PieCrust` object
correctly for multi-process workers and such.
* Add a test.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 03 Mar 2016 08:22:41 -0800 |
parents | 3ceeca7bb71c |
children | ab5c6a8ae90a |
comparison
equal
deleted
inserted
replaced
665:5dc13c816045 | 666:81d9c3a3a0b5 |
---|---|
3 import hashlib | 3 import hashlib |
4 import logging | 4 import logging |
5 import datetime | 5 import datetime |
6 from werkzeug.wrappers import Response | 6 from werkzeug.wrappers import Response |
7 from werkzeug.wsgi import wrap_file | 7 from werkzeug.wsgi import wrap_file |
8 from piecrust.app import PieCrust | 8 from piecrust.app import PieCrust, apply_variant_and_values |
9 from piecrust.rendering import QualifiedPage | 9 from piecrust.rendering import QualifiedPage |
10 from piecrust.routing import RouteNotFoundError | 10 from piecrust.routing import RouteNotFoundError |
11 from piecrust.sources.base import MODE_PARSING | 11 from piecrust.sources.base import MODE_PARSING |
12 from piecrust.sources.pageref import PageNotFoundError | 12 from piecrust.sources.pageref import PageNotFoundError |
13 from piecrust.uriutil import split_sub_uri | 13 from piecrust.uriutil import split_sub_uri |
14 | 14 |
15 | 15 |
16 logger = logging.getLogger(__name__) | 16 logger = logging.getLogger(__name__) |
17 | 17 |
18 | 18 |
19 def get_app_for_server(root_dir, debug=False, theme_site=False, | 19 def get_app_for_server(appfactory, root_url='/'): |
20 sub_cache_dir=None, root_url='/'): | 20 app = appfactory.create() |
21 app = PieCrust(root_dir=root_dir, debug=debug, theme_site=theme_site) | |
22 if sub_cache_dir: | |
23 app._useSubCacheDir(sub_cache_dir) | |
24 app.config.set('site/root', root_url) | 21 app.config.set('site/root', root_url) |
25 app.config.set('server/is_serving', True) | 22 app.config.set('server/is_serving', True) |
26 return app | 23 return app |
27 | 24 |
28 | 25 |