Mercurial > piecrust2
comparison piecrust/pipelines/_pagebaker.py @ 1132:3bcb2d446397
fix: Correctly invalidate pages that use dirtied sources.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 16 Apr 2018 22:22:54 -0700 |
parents | 298b07a899b5 |
children | 5f97b5b59dfe |
comparison
equal
deleted
inserted
replaced
1131:32f71dbf5cb1 | 1132:3bcb2d446397 |
---|---|
67 | 67 |
68 def _writeDirect(self, out_path, content): | 68 def _writeDirect(self, out_path, content): |
69 with open(out_path, 'w', encoding='utf8') as fp: | 69 with open(out_path, 'w', encoding='utf8') as fp: |
70 fp.write(content) | 70 fp.write(content) |
71 | 71 |
72 def bake(self, page, prev_entry, force=False): | 72 def bake(self, page, prev_entry, |
73 force_segments=False, force_layout=False): | |
73 cur_sub = 1 | 74 cur_sub = 1 |
74 has_more_subs = True | 75 has_more_subs = True |
75 app = self.app | 76 app = self.app |
76 out_dir = self.out_dir | 77 out_dir = self.out_dir |
77 force_bake = self.force or force | 78 force_segments = self.force or force_segments |
79 force_layout = self.force or force_layout | |
78 pretty_urls = page.config.get('pretty_urls', self.pretty_urls) | 80 pretty_urls = page.config.get('pretty_urls', self.pretty_urls) |
79 | 81 |
80 rendered_subs = [] | 82 rendered_subs = [] |
81 | 83 |
82 # Start baking the sub-pages. | 84 # Start baking the sub-pages. |
97 prev_sub_entry = prev_entry.getSub(cur_sub) | 99 prev_sub_entry = prev_entry.getSub(cur_sub) |
98 except IndexError: | 100 except IndexError: |
99 pass | 101 pass |
100 | 102 |
101 # Figure out if we need to bake this page. | 103 # Figure out if we need to bake this page. |
102 bake_status = _get_bake_status(page, out_path, force_bake, | 104 bake_status = _get_bake_status(page, out_path, |
105 force_segments, force_layout, | |
103 prev_sub_entry, cur_sub_entry) | 106 prev_sub_entry, cur_sub_entry) |
104 | 107 |
105 # If this page didn't bake because it's already up-to-date. | 108 # If this page didn't bake because it's already up-to-date. |
106 # Keep trying for as many subs as we know this page has. | 109 # Keep trying for as many subs as we know this page has. |
107 if bake_status == STATUS_CLEAN: | 110 if bake_status == STATUS_CLEAN: |
205 STATUS_CLEAN = 0 | 208 STATUS_CLEAN = 0 |
206 STATUS_BAKE = 1 | 209 STATUS_BAKE = 1 |
207 STATUS_INVALIDATE_AND_BAKE = 2 | 210 STATUS_INVALIDATE_AND_BAKE = 2 |
208 | 211 |
209 | 212 |
210 def _get_bake_status(page, out_path, force, prev_sub_entry, cur_sub_entry): | 213 def _get_bake_status(page, out_path, force_segments, force_layout, |
214 prev_sub_entry, cur_sub_entry): | |
215 # Easy tests. | |
216 if force_segments: | |
217 return STATUS_INVALIDATE_AND_BAKE | |
218 if force_layout: | |
219 return STATUS_BAKE | |
220 | |
211 # Figure out if we need to invalidate or force anything. | 221 # Figure out if we need to invalidate or force anything. |
212 status = _compute_force_flags(prev_sub_entry, cur_sub_entry) | 222 status = _compute_force_flags(prev_sub_entry, cur_sub_entry) |
213 if status != STATUS_CLEAN: | 223 if status != STATUS_CLEAN: |
214 return status | 224 return status |
215 | |
216 # Easy test. | |
217 if force: | |
218 cur_sub_entry['flags'] |= \ | |
219 SubPageFlags.FLAG_FORCED_BY_GENERAL_FORCE | |
220 # We need to invalidate any cache we have on this page because | |
221 # it's being forced, so something important has changed somehow. | |
222 return STATUS_INVALIDATE_AND_BAKE | |
223 | 225 |
224 # Check for up-to-date outputs. | 226 # Check for up-to-date outputs. |
225 in_path_time = page.content_mtime | 227 in_path_time = page.content_mtime |
226 try: | 228 try: |
227 out_path_time = os.path.getmtime(out_path) | 229 out_path_time = os.path.getmtime(out_path) |