Mercurial > piecrust2
annotate piecrust/pipelines/page.py @ 939:abc52a6262a1
bake: Support the `draft` setting.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 04 Oct 2017 20:40:43 -0700 |
parents | 812ca80863d4 |
children | 45ad976712ec |
rev | line source |
---|---|
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
1 import logging |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 from piecrust.pipelines.base import ContentPipeline |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
3 from piecrust.pipelines._pagebaker import PageBaker |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
4 from piecrust.pipelines._pagerecords import PagePipelineRecordEntry |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
5 from piecrust.sources.base import AbortedSourceUseError |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
6 |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
7 |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
8 logger = logging.getLogger(__name__) |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 class PagePipeline(ContentPipeline): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 PIPELINE_NAME = 'page' |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
13 RECORD_ENTRY_CLASS = PagePipelineRecordEntry |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
14 |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
15 def __init__(self, source, ppctx): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
16 super().__init__(source, ppctx) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
17 self._pagebaker = None |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
18 self._stats = source.app.env.stats |
939
abc52a6262a1
bake: Support the `draft` setting.
Ludovic Chabant <ludovic@chabant.com>
parents:
903
diff
changeset
|
19 self._draft_setting = self.app.config['baker/no_bake_setting'] |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
21 def initialize(self): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
22 stats = self.app.env.stats |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
23 stats.registerCounter('SourceUseAbortions', raise_if_registered=False) |
903
812ca80863d4
bake: Keep track of which pages were aborted for using other pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
881
diff
changeset
|
24 stats.registerManifest('SourceUseAbortions', raise_if_registered=False) |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
26 self._pagebaker = PageBaker(self.app, |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
27 self.ctx.out_dir, |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
28 force=self.ctx.force) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
29 self._pagebaker.startWriterQueue() |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 |
881
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
31 def createJobs(self, ctx): |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
32 used_paths = {} |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
33 for rec in ctx.record_histories.current.records: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
34 src_name = rec.name.split('@')[0] |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
35 for e in rec.getEntries(): |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
36 paths = e.getAllOutputPaths() |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
37 if paths is not None: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
38 for p in paths: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
39 used_paths[p] = (src_name, e) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
40 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
41 jobs = [] |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
42 route = self.source.route |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
43 pretty_urls = self.app.config.get('site/pretty_urls') |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
44 record = ctx.record_histories.current.getRecord(self.record_name) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
45 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
46 for item in self.source.getAllContents(): |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
47 route_params = item.metadata['route_params'] |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
48 uri = route.getUri(route_params) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
49 path = self._pagebaker.getOutputPath(uri, pretty_urls) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
50 override = used_paths.get(path) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
51 if override is not None: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
52 override_source_name, override_entry = override |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
53 override_source = self.app.getSource(override_source_name) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
54 if override_source.config['realm'] == \ |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
55 self.source.config['realm']: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
56 logger.error( |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
57 "Page '%s' would get baked to '%s' " |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
58 "but is overriden by '%s'." % |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
59 (item.spec, path, override_entry.item_spec)) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
60 else: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
61 logger.debug( |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
62 "Page '%s' would get baked to '%s' " |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
63 "but is overriden by '%s'." % |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
64 (item.spec, path, override_entry.item_spec)) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
65 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
66 entry = PagePipelineRecordEntry() |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
67 entry.item_spec = item.spec |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
68 entry.flags |= PagePipelineRecordEntry.FLAG_OVERRIDEN |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
69 record.addEntry(entry) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
70 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
71 continue |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
72 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
73 jobs.append(self.createJob(item)) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
74 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
75 if len(jobs) > 0: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
76 return jobs |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
77 return None |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
78 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
79 def mergeRecordEntry(self, record_entry, ctx): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
80 existing = ctx.record.getEntry(record_entry.item_spec) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
81 existing.errors += record_entry.errors |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
82 existing.flags |= record_entry.flags |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
83 existing.subs = record_entry.subs |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
84 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
85 def run(self, job, ctx, result): |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
86 step_num = job.step_num |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
87 if step_num == 0: |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
88 self._loadPage(job.content_item, ctx, result) |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
89 elif step_num == 1: |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
90 self._renderOrPostpone(job.content_item, ctx, result) |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
91 elif step_num == 2: |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
92 self._renderAlways(job.content_item, ctx, result) |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
93 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
94 def getDeletions(self, ctx): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
95 for prev, cur in ctx.record_history.diffs: |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 if prev and not cur: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
97 for sub in prev.subs: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 yield (sub.out_path, 'previous source file was removed') |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 elif prev and cur: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
100 prev_out_paths = [o.out_path for o in prev.subs] |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
101 cur_out_paths = [o.out_path for o in cur.subs] |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
102 diff = set(prev_out_paths) - set(cur_out_paths) |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
103 for p in diff: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
104 yield (p, 'source file changed outputs') |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
105 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
106 def collapseRecords(self, ctx): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
107 pass |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
108 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
109 def shutdown(self): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
110 self._pagebaker.stopWriterQueue() |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
111 |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
112 def _loadPage(self, content_item, ctx, result): |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
113 logger.debug("Loading page: %s" % content_item.spec) |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
114 page = self.app.getPage(self.source, content_item) |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
115 record_entry = result.record_entry |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
116 record_entry.config = page.config.getAll() |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
117 record_entry.timestamp = page.datetime.timestamp() |
939
abc52a6262a1
bake: Support the `draft` setting.
Ludovic Chabant <ludovic@chabant.com>
parents:
903
diff
changeset
|
118 |
abc52a6262a1
bake: Support the `draft` setting.
Ludovic Chabant <ludovic@chabant.com>
parents:
903
diff
changeset
|
119 if not page.config.get(self._draft_setting): |
abc52a6262a1
bake: Support the `draft` setting.
Ludovic Chabant <ludovic@chabant.com>
parents:
903
diff
changeset
|
120 result.next_step_job = self.createJob(content_item) |
abc52a6262a1
bake: Support the `draft` setting.
Ludovic Chabant <ludovic@chabant.com>
parents:
903
diff
changeset
|
121 else: |
abc52a6262a1
bake: Support the `draft` setting.
Ludovic Chabant <ludovic@chabant.com>
parents:
903
diff
changeset
|
122 record_entry.flags |= PagePipelineRecordEntry.FLAG_IS_DRAFT |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
123 |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
124 def _renderOrPostpone(self, content_item, ctx, result): |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
125 # Here our job is to render the page's segments so that they're |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
126 # cached in memory and on disk... unless we detect that the page |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
127 # is using some other sources, in which case we abort and we'll try |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
128 # again on the second pass. |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
129 logger.debug("Conditional render for: %s" % content_item.spec) |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
130 page = self.app.getPage(self.source, content_item) |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
131 prev_entry = ctx.previous_entry |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
132 cur_entry = result.record_entry |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
133 self.app.env.abort_source_use = True |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
134 try: |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
135 self._pagebaker.bake(page, prev_entry, cur_entry) |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
136 except AbortedSourceUseError: |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
137 logger.debug("Page was aborted for using source: %s" % |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
138 content_item.spec) |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
139 self.app.env.stats.stepCounter("SourceUseAbortions") |
903
812ca80863d4
bake: Keep track of which pages were aborted for using other pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
881
diff
changeset
|
140 self.app.env.stats.addManifestEntry("SourceUseAbortions", |
812ca80863d4
bake: Keep track of which pages were aborted for using other pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
881
diff
changeset
|
141 content_item.spec) |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
142 result.next_step_job = self.createJob(content_item) |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
143 finally: |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
144 self.app.env.abort_source_use = False |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
145 |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
146 def _renderAlways(self, content_item, ctx, result): |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
147 logger.debug("Full render for: %s" % content_item.spec) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
148 page = self.app.getPage(self.source, content_item) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
149 prev_entry = ctx.previous_entry |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
150 cur_entry = result.record_entry |
871
504ddb370df8
refactor: Fixing some issues with baking assets.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
151 self._pagebaker.bake(page, prev_entry, cur_entry) |