Mercurial > piecrust2
comparison piecrust/data/assetor.py @ 415:0e9a94b7fdfa
bake: Improve bake record information.
* Store things in the bake record that require less interaction between the
master process and the workers. For instance, don't store the paginator
object in the render pass info -- instead, just store whether pagination
was used, and whether it had more items.
* Simplify information passing between workers and bake passes by saving the
rendering info to the JSON cache. This means the "render first sub" job
doesn't have to return anything except errors now.
* Add more performance counter info.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 20 Jun 2015 19:23:16 -0700 |
parents | 422052d2e978 |
children | dc78ade3f320 |
comparison
equal
deleted
inserted
replaced
414:c4b3a7fd2f87 | 415:0e9a94b7fdfa |
---|---|
1 import os | 1 import os |
2 import os.path | 2 import os.path |
3 import logging | 3 import logging |
4 from piecrust import ASSET_DIR_SUFFIX | |
4 from piecrust.uriutil import multi_replace | 5 from piecrust.uriutil import multi_replace |
5 | 6 |
6 | 7 |
7 logger = logging.getLogger(__name__) | 8 logger = logging.getLogger(__name__) |
8 | 9 |
29 | 30 |
30 return base_url.rstrip('/') + '/' | 31 return base_url.rstrip('/') + '/' |
31 | 32 |
32 | 33 |
33 class Assetor(object): | 34 class Assetor(object): |
34 ASSET_DIR_SUFFIX = '-assets' | |
35 | |
36 debug_render_doc = """Helps render URLs to files in the current page's | 35 debug_render_doc = """Helps render URLs to files in the current page's |
37 asset folder.""" | 36 asset folder.""" |
38 debug_render = [] | 37 debug_render = [] |
39 debug_render_dynamic = ['_debugRenderAssetNames'] | 38 debug_render_dynamic = ['_debugRenderAssetNames'] |
40 | 39 |
56 | 55 |
57 def __iter__(self): | 56 def __iter__(self): |
58 self._cacheAssets() | 57 self._cacheAssets() |
59 return map(lambda i: i[0], self._cache.values()) | 58 return map(lambda i: i[0], self._cache.values()) |
60 | 59 |
60 def _getFilenames(self): | |
61 assert self._cache is not None | |
62 return map(lambda i: i[1], self._cache.values()) | |
63 | |
61 def _debugRenderAssetNames(self): | 64 def _debugRenderAssetNames(self): |
62 self._cacheAssets() | 65 self._cacheAssets() |
63 return list(self._cache.keys()) | 66 return list(self._cache.keys()) |
64 | 67 |
65 def _cacheAssets(self): | 68 def _cacheAssets(self): |
66 if self._cache is not None: | 69 if self._cache is not None: |
67 return | 70 return |
68 | 71 |
69 self._cache = {} | 72 self._cache = {} |
70 name, ext = os.path.splitext(self._page.path) | 73 name, ext = os.path.splitext(self._page.path) |
71 assets_dir = name + Assetor.ASSET_DIR_SUFFIX | 74 assets_dir = name + ASSET_DIR_SUFFIX |
72 if not os.path.isdir(assets_dir): | 75 if not os.path.isdir(assets_dir): |
73 return | 76 return |
74 | 77 |
75 rel_assets_dir = os.path.relpath(assets_dir, self._page.app.root_dir) | 78 rel_assets_dir = os.path.relpath(assets_dir, self._page.app.root_dir) |
76 base_url = build_base_url(self._page.app, self._uri, rel_assets_dir) | 79 base_url = build_base_url(self._page.app, self._uri, rel_assets_dir) |
86 "Multiple asset files are named '%s'." % name) | 89 "Multiple asset files are named '%s'." % name) |
87 self._cache[name] = (base_url + fn, full_fn) | 90 self._cache[name] = (base_url + fn, full_fn) |
88 | 91 |
89 cpi = self._page.app.env.exec_info_stack.current_page_info | 92 cpi = self._page.app.env.exec_info_stack.current_page_info |
90 if cpi is not None: | 93 if cpi is not None: |
91 used_assets = list(map(lambda i: i[1], self._cache.values())) | 94 cpi.render_ctx.used_assets = True |
92 cpi.render_ctx.used_assets = used_assets | |
93 | 95 |