Mercurial > piecrust2
comparison piecrust/commands/builtin/baking.py @ 854:08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
- Make a few APIs simpler.
- Content pipelines create their own jobs, so that generator sources can
keep aborting in `getContents`, but rely on their pipeline to generate
pages for baking.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 04 Jun 2017 23:34:28 -0700 |
parents | f070a4fc033c |
children | 8d25f76fce98 |
comparison
equal
deleted
inserted
replaced
853:f070a4fc033c | 854:08e02c2a2a1a |
---|---|
1 import os.path | |
1 import time | 2 import time |
2 import os.path | 3 import pprint |
3 import logging | 4 import logging |
4 import fnmatch | 5 import fnmatch |
6 import textwrap | |
5 import datetime | 7 import datetime |
6 from colorama import Fore | 8 from colorama import Fore |
7 from piecrust.commands.base import ChefCommand | 9 from piecrust.commands.base import ChefCommand |
8 | 10 |
9 | 11 |
26 help="Force re-baking the entire website.", | 28 help="Force re-baking the entire website.", |
27 action='store_true') | 29 action='store_true') |
28 parser.add_argument( | 30 parser.add_argument( |
29 '-p', '--pipelines', | 31 '-p', '--pipelines', |
30 help="The pipelines to run.", | 32 help="The pipelines to run.", |
31 nargs='*') | 33 action='append') |
32 parser.add_argument( | 34 parser.add_argument( |
33 '-w', '--workers', | 35 '-w', '--workers', |
34 help="The number of worker processes to spawn.", | 36 help="The number of worker processes to spawn.", |
35 type=int, default=-1) | 37 type=int, default=-1) |
36 parser.add_argument( | 38 parser.add_argument( |
89 if ctx.args.html_only: | 91 if ctx.args.html_only: |
90 allowed_pipelines = ['page'] | 92 allowed_pipelines = ['page'] |
91 elif ctx.args.assets_only: | 93 elif ctx.args.assets_only: |
92 allowed_pipelines = ['asset'] | 94 allowed_pipelines = ['asset'] |
93 elif ctx.args.pipelines: | 95 elif ctx.args.pipelines: |
96 if allowed_pipelines: | |
97 raise Exception( | |
98 "Can't specify `--html-only` or `--assets-only` with " | |
99 "`--pipelines`.") | |
94 allowed_pipelines = ctx.args.pipelines | 100 allowed_pipelines = ctx.args.pipelines |
95 | 101 |
96 baker = Baker( | 102 baker = Baker( |
97 ctx.appfactory, ctx.app, out_dir, | 103 ctx.appfactory, ctx.app, out_dir, |
98 force=ctx.args.force, | 104 force=ctx.args.force, |
198 continue | 204 continue |
199 | 205 |
200 logger.info("Record: %s" % rec.name) | 206 logger.info("Record: %s" % rec.name) |
201 logger.info("Status: %s" % ('SUCCESS' if rec.success | 207 logger.info("Status: %s" % ('SUCCESS' if rec.success |
202 else 'FAILURE')) | 208 else 'FAILURE')) |
203 for e in rec.entries: | 209 for e in rec.getEntries(): |
204 if ctx.args.fails and e.success: | 210 if ctx.args.fails and e.success: |
205 continue | 211 continue |
206 if in_pattern and not fnmatch.fnmatch(e.item_spec, in_pattern): | 212 if in_pattern and not fnmatch.fnmatch(e.item_spec, in_pattern): |
207 continue | 213 continue |
208 if out_pattern and not any( | 214 if out_pattern and not any( |
209 [fnmatch.fnmatch(op, out_pattern) | 215 [fnmatch.fnmatch(op, out_pattern) |
210 for op in e.out_paths]): | 216 for op in e.getAllOutputPaths()]): |
211 continue | 217 continue |
212 _print_record_entry(e) | 218 _print_record_entry(e) |
213 | 219 |
214 logger.info("") | 220 logger.info("") |
215 | 221 |
258 | 264 |
259 | 265 |
260 def _print_record_entry(e): | 266 def _print_record_entry(e): |
261 logger.info(" - %s" % e.item_spec) | 267 logger.info(" - %s" % e.item_spec) |
262 logger.info(" Outputs:") | 268 logger.info(" Outputs:") |
263 if e.out_paths: | 269 out_paths = list(e.getAllOutputPaths()) |
264 for op in e.out_paths: | 270 if out_paths: |
271 for op in out_paths: | |
265 logger.info(" - %s" % op) | 272 logger.info(" - %s" % op) |
266 else: | 273 else: |
267 logger.info(" <none>") | 274 logger.info(" <none>") |
268 | 275 |
269 e_desc = e.describe() | 276 e_desc = e.describe() |
270 for k in sorted(e_desc.keys()): | 277 for k, v in e_desc.items(): |
271 logger.info(" %s: %s" % (k, e_desc[k])) | 278 if isinstance(v, dict): |
272 | 279 text = pprint.pformat(v, indent=2) |
273 if e.errors: | 280 logger.info(" %s:" % k) |
281 logger.info(textwrap.indent(text, ' ')) | |
282 else: | |
283 logger.info(" %s: %s" % (k, v)) | |
284 | |
285 errors = list(e.getAllErrors()) | |
286 if errors: | |
274 logger.error(" Errors:") | 287 logger.error(" Errors:") |
275 for err in e.errors: | 288 for err in errors: |
276 logger.error(" - %s" % err) | 289 logger.error(" - %s" % err) |