Mercurial > piecrust2
comparison piecrust/commands/builtin/baking.py @ 215:a47580a0955b
bake: Better error handling for the processing pipeline.
Pipeline jobs now keep track of whether they've seen any errors. This is
aggregated into an overall "success" flag for the processing record. Also, jobs
keep going as long as there's no critical (i.e. internal) failure happening.
Errors raised by processors are also better tracked: the actual processor that
failed, along with the input file, are tracks in the processing record.
The `bake` command returns a failure exit code if processing saw any error.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 31 Jan 2015 17:08:02 -0800 |
parents | e725af1d48fb |
children | 1f4c3dae1fe8 |
comparison
equal
deleted
inserted
replaced
214:09e350db7f8f | 215:a47580a0955b |
---|---|
38 | 38 |
39 def run(self, ctx): | 39 def run(self, ctx): |
40 out_dir = (ctx.args.output or | 40 out_dir = (ctx.args.output or |
41 os.path.join(ctx.app.root_dir, '_counter')) | 41 os.path.join(ctx.app.root_dir, '_counter')) |
42 | 42 |
43 success = True | |
43 start_time = time.clock() | 44 start_time = time.clock() |
44 try: | 45 try: |
45 # Bake the site sources. | 46 # Bake the site sources. |
46 self._bakeSources(ctx, out_dir) | 47 success = success & self._bakeSources(ctx, out_dir) |
47 | 48 |
48 # Bake the assets. | 49 # Bake the assets. |
49 if not ctx.args.no_assets: | 50 if not ctx.args.no_assets: |
50 self._bakeAssets(ctx, out_dir) | 51 success = success & self._bakeAssets(ctx, out_dir) |
51 | 52 |
52 # All done. | 53 # All done. |
53 logger.info('-------------------------') | 54 logger.info('-------------------------') |
54 logger.info(format_timed(start_time, 'done baking')) | 55 logger.info(format_timed(start_time, 'done baking')) |
55 return 0 | 56 return 0 if success else 1 |
56 except Exception as ex: | 57 except Exception as ex: |
57 if ctx.app.debug: | 58 if ctx.app.debug: |
58 logger.exception(ex) | 59 logger.exception(ex) |
59 else: | 60 else: |
60 logger.error(str(ex)) | 61 logger.error(str(ex)) |
63 def _bakeSources(self, ctx, out_dir): | 64 def _bakeSources(self, ctx, out_dir): |
64 baker = Baker( | 65 baker = Baker( |
65 ctx.app, out_dir, | 66 ctx.app, out_dir, |
66 force=ctx.args.force) | 67 force=ctx.args.force) |
67 baker.bake() | 68 baker.bake() |
69 return True | |
68 | 70 |
69 def _bakeAssets(self, ctx, out_dir): | 71 def _bakeAssets(self, ctx, out_dir): |
70 proc = ProcessorPipeline( | 72 proc = ProcessorPipeline( |
71 ctx.app, out_dir, | 73 ctx.app, out_dir, |
72 force=ctx.args.force) | 74 force=ctx.args.force) |
73 proc.run() | 75 record = proc.run() |
76 return record.success | |
74 | 77 |
75 | 78 |
76 class ShowRecordCommand(ChefCommand): | 79 class ShowRecordCommand(ChefCommand): |
77 def __init__(self): | 80 def __init__(self): |
78 super(ShowRecordCommand, self).__init__() | 81 super(ShowRecordCommand, self).__init__() |