comparison piecrust/pipelines/_pagebaker.py @ 877:d6d35b2efd04

bake: Rename "pass" to "step" and make the page pipeline use different steps. That pipeline is now first loading all pages, and then rendering full pages unless they trigger a sub-render.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 15 Jun 2017 22:16:23 -0700
parents 504ddb370df8
children 8419daaa7a0e
comparison
equal deleted inserted replaced
876:d1095774bfcf 877:d6d35b2efd04
4 import logging 4 import logging
5 import threading 5 import threading
6 import urllib.parse 6 import urllib.parse
7 from piecrust.pipelines._pagerecords import SubPagePipelineRecordEntry 7 from piecrust.pipelines._pagerecords import SubPagePipelineRecordEntry
8 from piecrust.rendering import RenderingContext, render_page 8 from piecrust.rendering import RenderingContext, render_page
9 from piecrust.sources.base import AbortedSourceUseError
9 from piecrust.uriutil import split_uri 10 from piecrust.uriutil import split_uri
10 11
11 12
12 logger = logging.getLogger(__name__) 13 logger = logging.getLogger(__name__)
13 14
76 77
77 out_path = self.getOutputPath(sub_uri, pretty_urls) 78 out_path = self.getOutputPath(sub_uri, pretty_urls)
78 79
79 # Create the sub-entry for the bake record. 80 # Create the sub-entry for the bake record.
80 cur_sub_entry = SubPagePipelineRecordEntry(sub_uri, out_path) 81 cur_sub_entry = SubPagePipelineRecordEntry(sub_uri, out_path)
81 cur_entry.subs.append(cur_sub_entry)
82 82
83 # Find a corresponding sub-entry in the previous bake record. 83 # Find a corresponding sub-entry in the previous bake record.
84 prev_sub_entry = None 84 prev_sub_entry = None
85 if prev_entry is not None: 85 if prev_entry is not None:
86 try: 86 try:
95 # If this page didn't bake because it's already up-to-date. 95 # If this page didn't bake because it's already up-to-date.
96 # Keep trying for as many subs as we know this page has. 96 # Keep trying for as many subs as we know this page has.
97 if bake_status == STATUS_CLEAN: 97 if bake_status == STATUS_CLEAN:
98 cur_sub_entry.render_info = prev_sub_entry.copyRenderInfo() 98 cur_sub_entry.render_info = prev_sub_entry.copyRenderInfo()
99 cur_sub_entry.flags = SubPagePipelineRecordEntry.FLAG_NONE 99 cur_sub_entry.flags = SubPagePipelineRecordEntry.FLAG_NONE
100 cur_entry.subs.append(cur_sub_entry)
100 101
101 if prev_entry.num_subs >= cur_sub + 1: 102 if prev_entry.num_subs >= cur_sub + 1:
102 cur_sub += 1 103 cur_sub += 1
103 has_more_subs = True 104 has_more_subs = True
104 logger.debug(" %s is up to date, skipping to next " 105 logger.debug(" %s is up to date, skipping to next "
116 cur_sub_entry.flags |= \ 117 cur_sub_entry.flags |= \
117 SubPagePipelineRecordEntry.FLAG_FORMATTING_INVALIDATED 118 SubPagePipelineRecordEntry.FLAG_FORMATTING_INVALIDATED
118 119
119 logger.debug(" p%d -> %s" % (cur_sub, out_path)) 120 logger.debug(" p%d -> %s" % (cur_sub, out_path))
120 rp = self._bakeSingle(page, cur_sub, out_path) 121 rp = self._bakeSingle(page, cur_sub, out_path)
122 except AbortedSourceUseError:
123 raise
121 except Exception as ex: 124 except Exception as ex:
122 logger.exception(ex) 125 logger.exception(ex)
123 raise BakingError("%s: error baking '%s'." % 126 raise BakingError("%s: error baking '%s'." %
124 (page.content_spec, sub_uri)) from ex 127 (page.content_spec, sub_uri)) from ex
125 128
126 # Record what we did. 129 # Record what we did.
127 cur_sub_entry.flags |= SubPagePipelineRecordEntry.FLAG_BAKED 130 cur_sub_entry.flags |= SubPagePipelineRecordEntry.FLAG_BAKED
128 cur_sub_entry.render_info = rp.copyRenderInfo() 131 cur_sub_entry.render_info = rp.copyRenderInfo()
132 cur_entry.subs.append(cur_sub_entry)
129 133
130 # Copy page assets. 134 # Copy page assets.
131 if (cur_sub == 1 and 135 if (cur_sub == 1 and
132 cur_sub_entry.anyPass(lambda p: p.used_assets)): 136 cur_sub_entry.anyPass(lambda p: p.used_assets)):
133 if pretty_urls: 137 if pretty_urls: