Mercurial > piecrust2
comparison piecrust/commands/builtin/baking.py @ 338:938be93215cb
bake: Improve render context and bake record, fix incremental bake bugs.
* Used sources and taxonomies are now stored on a per-render-pass basis.
This fixes bugs where sources/taxonomies were used for one pass, but that
pass is skipped on a later bake because its result is cached.
* Bake records are now created for all pages even when they're not baked.
Record collapsing is gone except for taxonomy index pages.
* Bake records now also have sub-entries in order to store information about
each sub-page, since some sub-pages could use sources/taxonomies differently
than others, or be missing from the output. This lets PieCrust handle
clean/dirty states on a sub-page level.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 06 Apr 2015 19:59:54 -0700 |
parents | b034f6f15e22 |
children | 2cd2b5d07129 |
comparison
equal
deleted
inserted
replaced
337:49408002798e | 338:938be93215cb |
---|---|
4 import hashlib | 4 import hashlib |
5 import fnmatch | 5 import fnmatch |
6 import datetime | 6 import datetime |
7 from piecrust.baking.baker import Baker | 7 from piecrust.baking.baker import Baker |
8 from piecrust.baking.records import ( | 8 from piecrust.baking.records import ( |
9 BakeRecord, | 9 BakeRecord, BakeRecordPageEntry, BakeRecordSubPageEntry) |
10 FLAG_OVERRIDEN as BAKE_FLAG_OVERRIDEN, | |
11 FLAG_SOURCE_MODIFIED as BAKE_FLAG_SOURCE_MODIFIED, | |
12 FLAG_FORCED_BY_SOURCE as BAKE_FLAG_FORCED_BY_SOURCE) | |
13 from piecrust.chefutil import format_timed | 10 from piecrust.chefutil import format_timed |
14 from piecrust.commands.base import ChefCommand | 11 from piecrust.commands.base import ChefCommand |
15 from piecrust.processing.base import ProcessorPipeline | 12 from piecrust.processing.base import ProcessorPipeline |
16 from piecrust.processing.records import ( | 13 from piecrust.processing.records import ( |
17 ProcessorPipelineRecord, | 14 ProcessorPipelineRecord, |
152 any([o for o in entry.out_paths | 149 any([o for o in entry.out_paths |
153 if fnmatch.fnmatch(o, out_pattern)])): | 150 if fnmatch.fnmatch(o, out_pattern)])): |
154 continue | 151 continue |
155 | 152 |
156 flags = [] | 153 flags = [] |
157 if entry.flags & BAKE_FLAG_OVERRIDEN: | 154 if entry.flags & BakeRecordPageEntry.FLAG_OVERRIDEN: |
158 flags.append('overriden') | 155 flags.append('overriden') |
159 if entry.flags & BAKE_FLAG_SOURCE_MODIFIED: | |
160 flags.append('overriden') | |
161 if entry.flags & BAKE_FLAG_FORCED_BY_SOURCE: | |
162 flags.append('forced by source') | |
163 | 156 |
164 passes = {PASS_RENDERING: 'render', PASS_FORMATTING: 'format'} | 157 passes = {PASS_RENDERING: 'render', PASS_FORMATTING: 'format'} |
165 used_srcs = ['%s (%s)' % (s[0], passes[s[1]]) | |
166 for s in entry.used_source_names] | |
167 | 158 |
168 logging.info(" - ") | 159 logging.info(" - ") |
169 logging.info(" path: %s" % entry.rel_path) | 160 logging.info(" path: %s" % entry.rel_path) |
170 logging.info(" spec: %s:%s" % (entry.source_name, | 161 logging.info(" spec: %s:%s" % (entry.source_name, |
171 entry.rel_path)) | 162 entry.rel_path)) |
172 if entry.taxonomy_info: | 163 if entry.taxonomy_info: |
173 logging.info(" taxonomy: %s:%s for %s" % | 164 tn, t, sn = entry.taxonomy_info |
174 entry.taxonomy_info) | 165 logging.info(" taxonomy: %s (%s:%s)" % |
166 (t, sn, tn)) | |
175 else: | 167 else: |
176 logging.info(" taxonomy: <none>") | 168 logging.info(" taxonomy: <none>") |
177 logging.info(" flags: %s" % ', '.join(flags)) | 169 logging.info(" flags: %s" % ', '.join(flags)) |
178 logging.info(" config: %s" % entry.config) | 170 logging.info(" config: %s" % entry.config) |
179 logging.info(" out URLs: %s" % entry.out_uris) | 171 |
180 logging.info(" out paths: %s" % [os.path.relpath(p, out_dir) | 172 logging.info(" %d sub-pages:" % len(entry.subs)) |
181 for p in entry.out_paths]) | 173 for sub in entry.subs: |
182 logging.info(" clean URLs:%s" % entry.clean_uris) | 174 logging.info(" - ") |
183 logging.info(" used srcs: %s" % used_srcs) | 175 logging.info(" URL: %s" % sub.out_uri) |
184 logging.info(" used terms:%s" % entry.used_taxonomy_terms) | 176 logging.info(" path: %s" % os.path.relpath(sub.out_path, |
185 logging.info(" used pgn: %d" % entry.used_pagination_item_count) | 177 out_dir)) |
186 if entry.errors: | 178 logging.info(" baked?: %s" % sub.was_baked) |
187 logging.error(" errors: %s" % entry.errors) | 179 |
180 sub_flags = [] | |
181 if sub.flags & BakeRecordSubPageEntry.FLAG_FORCED_BY_SOURCE: | |
182 sub_flags.append('forced by source') | |
183 if sub.flags & BakeRecordSubPageEntry.FLAG_FORCED_BY_NO_PREVIOUS: | |
184 sub_flags.append('forced by missing previous record entry') | |
185 if sub.flags & BakeRecordSubPageEntry.FLAG_FORCED_BY_PREVIOUS_ERRORS: | |
186 sub_flags.append('forced by previous errors') | |
187 logging.info(" flags: %s" % ', '.join(sub_flags)) | |
188 | |
189 for p, pi in sub.render_passes.items(): | |
190 logging.info(" %s pass:" % passes[p]) | |
191 logging.info(" used srcs: %s" % | |
192 ', '.join(pi.used_source_names)) | |
193 logging.info(" used terms: %s" % | |
194 ', '.join( | |
195 ['%s (%s:%s)' % (t, sn, tn) | |
196 for sn, tn, t in pi.used_taxonomy_terms])) | |
197 | |
198 if sub.errors: | |
199 logging.error(" errors: %s" % sub.errors) | |
200 | |
201 logging.info(" assets: %s" % ', '.join(entry.assets)) | |
188 | 202 |
189 record_cache = ctx.app.cache.getCache('proc') | 203 record_cache = ctx.app.cache.getCache('proc') |
190 if not record_cache.has(record_name): | 204 if not record_cache.has(record_name): |
191 return | 205 return |
192 | 206 |