Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
119:0811f92cbdc7 | 120:133845647083 |
---|---|
3 import hashlib | 3 import hashlib |
4 import fnmatch | 4 import fnmatch |
5 import datetime | 5 import datetime |
6 from piecrust.baking.baker import Baker | 6 from piecrust.baking.baker import Baker |
7 from piecrust.baking.records import BakeRecord | 7 from piecrust.baking.records import BakeRecord |
8 from piecrust.chefutil import format_timed | |
8 from piecrust.commands.base import ChefCommand | 9 from piecrust.commands.base import ChefCommand |
10 from piecrust.processing.base import ProcessorPipeline | |
9 | 11 |
10 | 12 |
11 logger = logging.getLogger(__name__) | 13 logger = logging.getLogger(__name__) |
12 | 14 |
13 | 15 |
30 parser.add_argument('--no-assets', | 32 parser.add_argument('--no-assets', |
31 help="Don't process assets (only pages).", | 33 help="Don't process assets (only pages).", |
32 action='store_true') | 34 action='store_true') |
33 | 35 |
34 def run(self, ctx): | 36 def run(self, ctx): |
35 baker = Baker( | |
36 ctx.app, | |
37 out_dir=ctx.args.output, | |
38 force=ctx.args.force, | |
39 portable=ctx.args.portable, | |
40 no_assets=ctx.args.no_assets) | |
41 if ctx.args.portable: | 37 if ctx.args.portable: |
42 # Disable pretty URLs because there's likely not going to be | 38 # Disable pretty URLs because there's likely not going to be |
43 # a web server to handle serving default documents. | 39 # a web server to handle serving default documents. |
44 ctx.app.config.set('site/pretty_urls', False) | 40 ctx.app.config.set('site/pretty_urls', False) |
45 | 41 |
46 try: | 42 try: |
47 baker.bake() | 43 # Bake the site sources. |
44 self._bakeSources(ctx) | |
45 | |
46 # Bake the assets. | |
47 if not ctx.args.no_assets: | |
48 self._bakeAssets(ctx) | |
49 | |
50 # All done. | |
51 logger.info('-------------------------'); | |
52 logger.info(format_timed(start_time, 'done baking')); | |
48 return 0 | 53 return 0 |
49 except Exception as ex: | 54 except Exception as ex: |
50 if ctx.app.debug: | 55 if ctx.app.debug: |
51 logger.exception(ex) | 56 logger.exception(ex) |
52 else: | 57 else: |
53 logger.error(str(ex)) | 58 logger.error(str(ex)) |
54 return 1 | 59 return 1 |
60 | |
61 def _bakeSources(self, ctx): | |
62 num_workers = ctx.app.config.get('baker/workers') or 4 | |
63 baker = Baker( | |
64 ctx.app, | |
65 out_dir=ctx.args.output, | |
66 force=ctx.args.force, | |
67 portable=ctx.args.portable, | |
68 no_assets=ctx.args.no_assets, | |
69 num_workers=num_workers) | |
70 baker.bake() | |
71 | |
72 def _bakeAssets(self, ctx): | |
73 mounts = ctx.app.assets_dirs | |
74 baker_params = ctx.app.config.get('baker') or {} | |
75 skip_patterns = baker_params.get('skip_patterns') | |
76 force_patterns = baker_params.get('force_patterns') | |
77 num_workers = ctx.app.config.get('baker/workers') or 4 | |
78 proc = ProcessorPipeline( | |
79 ctx.app, mounts, ctx.args.output, | |
80 force=ctx.args.force, | |
81 skip_patterns=skip_patterns, | |
82 force_patterns=force_patterns, | |
83 num_workers=num_workers) | |
84 proc.run() | |
85 | |
55 | 86 |
56 | 87 |
57 class ShowRecordCommand(ChefCommand): | 88 class ShowRecordCommand(ChefCommand): |
58 def __init__(self): | 89 def __init__(self): |
59 super(ShowRecordCommand, self).__init__() | 90 super(ShowRecordCommand, self).__init__() |
97 logging.info(" taxonomy: %s:%s" % (entry.taxonomy_name, entry.taxonomy_term)) | 128 logging.info(" taxonomy: %s:%s" % (entry.taxonomy_name, entry.taxonomy_term)) |
98 logging.info(" config: %s" % entry.config) | 129 logging.info(" config: %s" % entry.config) |
99 logging.info(" out URLs: %s" % entry.out_uris) | 130 logging.info(" out URLs: %s" % entry.out_uris) |
100 logging.info(" out paths: %s" % entry.out_paths) | 131 logging.info(" out paths: %s" % entry.out_paths) |
101 logging.info(" used srcs: %s" % entry.used_source_names) | 132 logging.info(" used srcs: %s" % entry.used_source_names) |
133 if entry.errors: | |
134 logging.error(" errors: %s" % entry.errors) | |
102 | 135 |