comparison piecrust/pipelines/_pagebaker.py @ 979:45ad976712ec

tests: Big push to get the tests to pass again. - Lots of fixes everywhere in the code. - Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now. - Replace all `.md` test files with `.html` since now a auto-format extension always sets the format. - Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 29 Oct 2017 22:51:57 -0700
parents 8419daaa7a0e
children 8adc27285d93
comparison
equal deleted inserted replaced
978:7e51d14097cb 979:45ad976712ec
9 from piecrust.sources.base import AbortedSourceUseError 9 from piecrust.sources.base import AbortedSourceUseError
10 from piecrust.uriutil import split_uri 10 from piecrust.uriutil import split_uri
11 11
12 12
13 logger = logging.getLogger(__name__) 13 logger = logging.getLogger(__name__)
14
15
16 def get_output_path(app, out_dir, uri, pretty_urls):
17 uri_root, uri_path = split_uri(app, uri)
18
19 bake_path = [out_dir]
20 decoded_uri = urllib.parse.unquote(uri_path)
21 if pretty_urls:
22 bake_path.append(decoded_uri)
23 bake_path.append('index.html')
24 elif decoded_uri == '':
25 bake_path.append('index.html')
26 else:
27 bake_path.append(decoded_uri)
28
29 return os.path.normpath(os.path.join(*bake_path))
14 30
15 31
16 class BakingError(Exception): 32 class BakingError(Exception):
17 pass 33 pass
18 34
49 65
50 def _writeDirect(self, out_path, content): 66 def _writeDirect(self, out_path, content):
51 with open(out_path, 'w', encoding='utf8') as fp: 67 with open(out_path, 'w', encoding='utf8') as fp:
52 fp.write(content) 68 fp.write(content)
53 69
54 def getOutputPath(self, uri, pretty_urls):
55 uri_root, uri_path = split_uri(self.app, uri)
56
57 bake_path = [self.out_dir]
58 decoded_uri = urllib.parse.unquote(uri_path)
59 if pretty_urls:
60 bake_path.append(decoded_uri)
61 bake_path.append('index.html')
62 elif decoded_uri == '':
63 bake_path.append('index.html')
64 else:
65 bake_path.append(decoded_uri)
66
67 return os.path.normpath(os.path.join(*bake_path))
68
69 def bake(self, page, prev_entry, cur_entry): 70 def bake(self, page, prev_entry, cur_entry):
70 cur_sub = 1 71 cur_sub = 1
71 has_more_subs = True 72 has_more_subs = True
73 app = self.app
74 out_dir = self.out_dir
72 pretty_urls = page.config.get('pretty_urls', self.pretty_urls) 75 pretty_urls = page.config.get('pretty_urls', self.pretty_urls)
73 76
74 # Start baking the sub-pages. 77 # Start baking the sub-pages.
75 while has_more_subs: 78 while has_more_subs:
76 sub_uri = page.getUri(sub_num=cur_sub) 79 sub_uri = page.getUri(sub_num=cur_sub)
77 logger.debug("Baking '%s' [%d]..." % (sub_uri, cur_sub)) 80 logger.debug("Baking '%s' [%d]..." % (sub_uri, cur_sub))
78 81
79 out_path = self.getOutputPath(sub_uri, pretty_urls) 82 out_path = get_output_path(app, out_dir, sub_uri, pretty_urls)
80 83
81 # Create the sub-entry for the bake record. 84 # Create the sub-entry for the bake record.
82 cur_sub_entry = SubPagePipelineRecordEntry(sub_uri, out_path) 85 cur_sub_entry = SubPagePipelineRecordEntry(sub_uri, out_path)
83 86
84 # Find a corresponding sub-entry in the previous bake record. 87 # Find a corresponding sub-entry in the previous bake record.
202 if status != STATUS_CLEAN: 205 if status != STATUS_CLEAN:
203 return status 206 return status
204 207
205 # Easy test. 208 # Easy test.
206 if force: 209 if force:
210 cur_sub_entry.flags |= \
211 SubPagePipelineRecordEntry.FLAG_FORCED_BY_GENERAL_FORCE
207 return STATUS_BAKE 212 return STATUS_BAKE
208 213
209 # Check for up-to-date outputs. 214 # Check for up-to-date outputs.
210 in_path_time = page.content_mtime 215 in_path_time = page.content_mtime
211 try: 216 try:
212 out_path_time = os.path.getmtime(out_path) 217 out_path_time = os.path.getmtime(out_path)
213 except OSError: 218 except OSError:
214 # File doesn't exist, we'll need to bake. 219 # File doesn't exist, we'll need to bake.
220 cur_sub_entry.flags |= \
221 SubPagePipelineRecordEntry.FLAG_FORCED_BY_NO_PREVIOUS
215 return STATUS_BAKE 222 return STATUS_BAKE
216 223
217 if out_path_time <= in_path_time: 224 if out_path_time <= in_path_time:
218 return STATUS_BAKE 225 return STATUS_BAKE
219 226