Mercurial > piecrust2
diff piecrust/commands/builtin/baking.py @ 120:133845647083
Better error management and removal support in baking/processing.
* Baker and processor pipeline now store errors in their records.
* They also support deleting output files that are no longer valid.
* The basic transitional record class implements more boilerplate code.
* The processor pipeline is run from the `bake` command directly.
* New unit tests.
* Unit test mocking now mocks `os.remove` too.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 09 Nov 2014 14:46:23 -0800 |
parents | 0dd43c5f5484 |
children | 300eb1c2cb14 |
line wrap: on
line diff
--- a/piecrust/commands/builtin/baking.py Wed Oct 29 08:19:58 2014 -0700 +++ b/piecrust/commands/builtin/baking.py Sun Nov 09 14:46:23 2014 -0800 @@ -5,7 +5,9 @@ import datetime from piecrust.baking.baker import Baker from piecrust.baking.records import BakeRecord +from piecrust.chefutil import format_timed from piecrust.commands.base import ChefCommand +from piecrust.processing.base import ProcessorPipeline logger = logging.getLogger(__name__) @@ -32,19 +34,22 @@ action='store_true') def run(self, ctx): - baker = Baker( - ctx.app, - out_dir=ctx.args.output, - force=ctx.args.force, - portable=ctx.args.portable, - no_assets=ctx.args.no_assets) if ctx.args.portable: # Disable pretty URLs because there's likely not going to be # a web server to handle serving default documents. ctx.app.config.set('site/pretty_urls', False) try: - baker.bake() + # Bake the site sources. + self._bakeSources(ctx) + + # Bake the assets. + if not ctx.args.no_assets: + self._bakeAssets(ctx) + + # All done. + logger.info('-------------------------'); + logger.info(format_timed(start_time, 'done baking')); return 0 except Exception as ex: if ctx.app.debug: @@ -53,6 +58,32 @@ logger.error(str(ex)) return 1 + def _bakeSources(self, ctx): + num_workers = ctx.app.config.get('baker/workers') or 4 + baker = Baker( + ctx.app, + out_dir=ctx.args.output, + force=ctx.args.force, + portable=ctx.args.portable, + no_assets=ctx.args.no_assets, + num_workers=num_workers) + baker.bake() + + def _bakeAssets(self, ctx): + mounts = ctx.app.assets_dirs + baker_params = ctx.app.config.get('baker') or {} + skip_patterns = baker_params.get('skip_patterns') + force_patterns = baker_params.get('force_patterns') + num_workers = ctx.app.config.get('baker/workers') or 4 + proc = ProcessorPipeline( + ctx.app, mounts, ctx.args.output, + force=ctx.args.force, + skip_patterns=skip_patterns, + force_patterns=force_patterns, + num_workers=num_workers) + proc.run() + + class ShowRecordCommand(ChefCommand): def __init__(self): @@ -99,4 +130,6 @@ logging.info(" out URLs: %s" % entry.out_uris) logging.info(" out paths: %s" % entry.out_paths) logging.info(" used srcs: %s" % entry.used_source_names) + if entry.errors: + logging.error(" errors: %s" % entry.errors)