Mercurial > piecrust2
annotate piecrust/pipelines/page.py @ 895:accfe8fc8440
admin: Add a Micropub endpoint.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 02 Jul 2017 22:23:12 -0700 |
parents | b4e10471e970 |
children | 812ca80863d4 |
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 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
20 def initialize(self): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
21 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
|
22 stats.registerCounter('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
|
23 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
24 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
|
25 self.ctx.out_dir, |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
26 force=self.ctx.force) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
27 self._pagebaker.startWriterQueue() |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 |
881
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
29 def createJobs(self, ctx): |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
30 used_paths = {} |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
31 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
|
32 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
|
33 for e in rec.getEntries(): |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
34 paths = e.getAllOutputPaths() |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
35 if paths is not None: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
36 for p in paths: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
37 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
|
38 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
39 jobs = [] |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
40 route = self.source.route |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
41 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
|
42 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
|
43 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
44 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
|
45 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
|
46 uri = route.getUri(route_params) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
47 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
|
48 override = used_paths.get(path) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
49 if override is not None: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
50 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
|
51 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
|
52 if override_source.config['realm'] == \ |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
53 self.source.config['realm']: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
54 logger.error( |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
55 "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
|
56 "but is overriden by '%s'." % |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
57 (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
|
58 else: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
59 logger.debug( |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
60 "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
|
61 "but is overriden by '%s'." % |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
62 (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
|
63 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
64 entry = PagePipelineRecordEntry() |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
65 entry.item_spec = item.spec |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
66 entry.flags |= PagePipelineRecordEntry.FLAG_OVERRIDEN |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
67 record.addEntry(entry) |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
68 |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
69 continue |
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 jobs.append(self.createJob(item)) |
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 if len(jobs) > 0: |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
74 return jobs |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
75 return None |
b4e10471e970
bake: Don't create bake jobs for overriden pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
877
diff
changeset
|
76 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
92 def getDeletions(self, ctx): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
93 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
|
94 if prev and not cur: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
95 for sub in prev.subs: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 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
|
97 elif prev and cur: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 for p in diff: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
102 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
|
103 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
104 def collapseRecords(self, ctx): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
105 pass |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
106 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
107 def shutdown(self): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
108 self._pagebaker.stopWriterQueue() |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
109 |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 record_entry.timestamp = page.datetime.timestamp() |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
116 result.next_step_job = self.createJob(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
|
117 |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
118 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
|
119 # 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
|
120 # 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
|
121 # 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
|
122 # 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 except AbortedSourceUseError: |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
131 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
|
132 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
|
133 self.app.env.stats.stepCounter("SourceUseAbortions") |
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
134 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
|
135 finally: |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
136 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
|
137 |
877
d6d35b2efd04
bake: Rename "pass" to "step" and make the page pipeline use different steps.
Ludovic Chabant <ludovic@chabant.com>
parents:
871
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 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
|
142 cur_entry = result.record_entry |
871
504ddb370df8
refactor: Fixing some issues with baking assets.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
143 self._pagebaker.bake(page, prev_entry, cur_entry) |