Mercurial > piecrust2
annotate piecrust/commands/builtin/baking.py @ 891:f13d618cfec6
themes: Allow keeping local overrides when copying a theme locally.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 02 Jul 2017 22:19:58 -0700 |
parents | 803c5c28a71f |
children | 98becbc75ccc |
rev | line source |
---|---|
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
1 import os.path |
121 | 2 import time |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 import logging |
92
0dd43c5f5484
More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
4 import datetime |
421
4a43d7015b75
bake: Improve performance timers reports.
Ludovic Chabant <ludovic@chabant.com>
parents:
415
diff
changeset
|
5 from colorama import Fore |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 from piecrust.commands.base import ChefCommand |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 logger = logging.getLogger(__name__) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 class BakeCommand(ChefCommand): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 def __init__(self): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 super(BakeCommand, self).__init__() |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 self.name = 'bake' |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 self.description = "Bakes your website into static HTML files." |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 def setupParser(self, parser, app): |
192
4c0ab0b044fe
cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents:
127
diff
changeset
|
19 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
20 '-o', '--output', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
21 help="The directory to put all the baked HTML files into " |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
22 "(defaults to `_counter`)") |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
23 parser.add_argument( |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
24 '-f', '--force', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
25 help="Force re-baking the entire website.", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
26 action='store_true') |
192
4c0ab0b044fe
cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents:
127
diff
changeset
|
27 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
28 '-p', '--pipelines', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
29 help="The pipelines to run.", |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
30 action='append') |
192
4c0ab0b044fe
cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents:
127
diff
changeset
|
31 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
32 '-w', '--workers', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
33 help="The number of worker processes to spawn.", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
34 type=int, default=-1) |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
359
diff
changeset
|
35 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
36 '--batch-size', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
37 help="The number of jobs per batch.", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
38 type=int, default=-1) |
462
04abc97dd3b6
bake: Add CLI argument to specify job batch size.
Ludovic Chabant <ludovic@chabant.com>
parents:
421
diff
changeset
|
39 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
40 '--assets-only', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
41 help="Only bake the assets (don't bake the web pages).", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
42 action='store_true') |
220
84e2bc2d16cb
bake: Change arguments to selectively bake to make them symmetrical.
Ludovic Chabant <ludovic@chabant.com>
parents:
218
diff
changeset
|
43 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
44 '--html-only', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
45 help="Only bake the pages (don't run the asset pipeline).", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
46 action='store_true') |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
359
diff
changeset
|
47 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
48 '--show-stats', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
49 help="Show detailed information about the bake.", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
50 action='store_true') |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 def run(self, ctx): |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
53 from piecrust.chefutil import format_timed |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
54 |
127
bc63dc20baa0
Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
55 out_dir = (ctx.args.output or |
bc63dc20baa0
Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
56 os.path.join(ctx.app.root_dir, '_counter')) |
bc63dc20baa0
Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
57 |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
359
diff
changeset
|
58 start_time = time.perf_counter() |
39
2f717f961996
Better error reporting and cache validation.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
59 try: |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
60 records = self._doBake(ctx, out_dir) |
120
133845647083
Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents:
92
diff
changeset
|
61 |
687
61d606fbc313
bake: Change `show-timers` to `show-stats`, add stats.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
62 # Show merged stats. |
61d606fbc313
bake: Change `show-timers` to `show-stats`, add stats.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
63 if ctx.args.show_stats: |
415
0e9a94b7fdfa
bake: Improve bake record information.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
64 logger.info("-------------------") |
0e9a94b7fdfa
bake: Improve bake record information.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
65 logger.info("Timing information:") |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
66 _show_stats(records.stats) |
415
0e9a94b7fdfa
bake: Improve bake record information.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
67 |
120
133845647083
Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents:
92
diff
changeset
|
68 # All done. |
192
4c0ab0b044fe
cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents:
127
diff
changeset
|
69 logger.info('-------------------------') |
4c0ab0b044fe
cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents:
127
diff
changeset
|
70 logger.info(format_timed(start_time, 'done baking')) |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
71 return 0 if records.success else 1 |
39
2f717f961996
Better error reporting and cache validation.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
72 except Exception as ex: |
43 | 73 if ctx.app.debug: |
74 logger.exception(ex) | |
75 else: | |
76 logger.error(str(ex)) | |
39
2f717f961996
Better error reporting and cache validation.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
77 return 1 |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
78 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
79 def _doBake(self, ctx, out_dir): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
80 from piecrust.baking.baker import Baker |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
81 |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
359
diff
changeset
|
82 if ctx.args.workers > 0: |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
359
diff
changeset
|
83 ctx.app.config.set('baker/workers', ctx.args.workers) |
462
04abc97dd3b6
bake: Add CLI argument to specify job batch size.
Ludovic Chabant <ludovic@chabant.com>
parents:
421
diff
changeset
|
84 if ctx.args.batch_size > 0: |
04abc97dd3b6
bake: Add CLI argument to specify job batch size.
Ludovic Chabant <ludovic@chabant.com>
parents:
421
diff
changeset
|
85 ctx.app.config.set('baker/batch_size', ctx.args.batch_size) |
120
133845647083
Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents:
92
diff
changeset
|
86 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
87 allowed_pipelines = None |
868
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
88 forbidden_pipelines = None |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
89 if ctx.args.html_only: |
868
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
90 forbidden_pipelines = ['asset'] |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
91 elif ctx.args.assets_only: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
92 allowed_pipelines = ['asset'] |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
93 elif ctx.args.pipelines: |
868
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
94 if allowed_pipelines or forbidden_pipelines: |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
95 raise Exception( |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
96 "Can't specify `--html-only` or `--assets-only` with " |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
97 "`--pipelines`.") |
868
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
98 for p in ctx.args.pipelines: |
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
99 if p[0] == '-': |
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
100 forbidden_pipelines.append(p) |
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
101 else: |
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
102 allowed_pipelines.append(p) |
120
133845647083
Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents:
92
diff
changeset
|
103 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
104 baker = Baker( |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
105 ctx.appfactory, ctx.app, out_dir, |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
106 force=ctx.args.force, |
868
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
107 allowed_pipelines=allowed_pipelines, |
8d25f76fce98
bake: Add ability to specify pipelines to exclude during the bake.
Ludovic Chabant <ludovic@chabant.com>
parents:
854
diff
changeset
|
108 forbidden_pipelines=forbidden_pipelines) |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
109 records = baker.bake() |
415
0e9a94b7fdfa
bake: Improve bake record information.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
110 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
111 return records |
421
4a43d7015b75
bake: Improve performance timers reports.
Ludovic Chabant <ludovic@chabant.com>
parents:
415
diff
changeset
|
112 |
4a43d7015b75
bake: Improve performance timers reports.
Ludovic Chabant <ludovic@chabant.com>
parents:
415
diff
changeset
|
113 |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
114 class ShowRecordCommand(ChefCommand): |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
115 def __init__(self): |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
116 super(ShowRecordCommand, self).__init__() |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
117 self.name = 'showrecord' |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
118 self.description = ("Shows the bake record for a given output " |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
119 "directory.") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
120 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
121 def setupParser(self, parser, app): |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
122 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
123 '-o', '--output', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
124 help="The output directory for which to show the bake record " |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
125 "(defaults to `_counter`)", |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
126 nargs='?') |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
127 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
128 '-i', '--in-path', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
129 help="A pattern that will be used to filter the relative path " |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
130 "of entries to show.") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
131 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
132 '-t', '--out-path', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
133 help="A pattern that will be used to filter the output path " |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
134 "of entries to show.") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
135 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
136 '--fails', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
137 action='store_true', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
138 help="Only show record entries for failures.") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
139 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
140 '--last', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
141 type=int, |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
142 default=0, |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
143 help="Show the last Nth bake record.") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
144 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
145 '--html-only', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
146 action='store_true', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
147 help="Only show records for pages (not from the asset " |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
148 "pipeline).") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
149 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
150 '--assets-only', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
151 action='store_true', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
152 help="Only show records for assets (not from pages).") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
153 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
154 '-p', '--pipelines', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
155 nargs='*', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
156 help="Only show records for the given pipeline(s).") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
157 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
158 '--show-stats', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
159 action='store_true', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
160 help="Show stats from the record.") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
161 parser.add_argument( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
162 '--show-manifest', |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
163 help="Show manifest entries from the record.") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
164 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
165 def run(self, ctx): |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
873
diff
changeset
|
166 import fnmatch |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
167 from piecrust.baking.baker import get_bake_records_path |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
168 from piecrust.pipelines.records import load_records |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
169 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
170 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
171 suffix = '' if ctx.args.last == 0 else '.%d' % ctx.args.last |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
172 records_path = get_bake_records_path(ctx.app, out_dir, suffix=suffix) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
173 records = load_records(records_path) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
174 if records.invalidated: |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
175 raise Exception( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
176 "The bake record was saved by a previous version of " |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
177 "PieCrust and can't be shown.") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
178 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
179 in_pattern = None |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
180 if ctx.args.in_path: |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
181 in_pattern = '*%s*' % ctx.args.in_path.strip('*') |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
182 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
183 out_pattern = None |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
184 if ctx.args.out_path: |
883
803c5c28a71f
showrecord: Fix bug when filtering output paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
185 out_pattern = '*%s*' % ctx.args.out_path.strip('*') |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
186 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
187 pipelines = ctx.args.pipelines |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
188 if not pipelines: |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
189 pipelines = [p.PIPELINE_NAME |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
190 for p in ctx.app.plugin_loader.getPipelines()] |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
191 if ctx.args.assets_only: |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
192 pipelines = ['asset'] |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
193 if ctx.args.html_only: |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
194 pipelines = ['page'] |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
195 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
196 logger.info("Bake record for: %s" % out_dir) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
197 logger.info("Status: %s" % ('SUCCESS' if records.success |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
198 else 'FAILURE')) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
199 logger.info("Date/time: %s" % |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
200 datetime.datetime.fromtimestamp(records.bake_time)) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
201 logger.info("Incremental count: %d" % records.incremental_count) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
202 logger.info("Versions: %s/%s" % (records._app_version, |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
203 records._record_version)) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
204 logger.info("") |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
205 |
873
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
206 if not ctx.args.show_stats: |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
207 for rec in records.records: |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
208 if ctx.args.fails and rec.success: |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
209 continue |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
210 |
873
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
211 ppname = rec.name[rec.name.index('@') + 1:] |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
212 if ppname not in pipelines: |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
213 continue |
873
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
214 |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
215 entries_to_show = [] |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
216 |
873
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
217 for e in rec.getEntries(): |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
218 if ctx.args.fails and e.success: |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
219 continue |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
220 if in_pattern and not fnmatch.fnmatch(e.item_spec, |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
221 in_pattern): |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
222 continue |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
223 if out_pattern and not any( |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
224 [fnmatch.fnmatch(op, out_pattern) |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
225 for op in e.getAllOutputPaths()]): |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
226 continue |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
227 entries_to_show.append(e) |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
228 |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
229 if entries_to_show: |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
230 logger.info("Record: %s" % rec.name) |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
231 logger.info("Status: %s" % ('SUCCESS' if rec.success |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
232 else 'FAILURE')) |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
233 for e in entries_to_show: |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
234 _print_record_entry(e) |
93ea115027fc
showrecord: Don't show empty records when filtering.
Ludovic Chabant <ludovic@chabant.com>
parents:
872
diff
changeset
|
235 logger.info("") |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
236 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
237 stats = records.stats |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
238 if ctx.args.show_stats: |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
239 _show_stats(stats) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
240 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
241 if ctx.args.show_manifest: |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
242 for name in sorted(stats.manifests.keys()): |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
243 if ctx.args.show_manifest.lower() in name.lower(): |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
244 val = stats.manifests[name] |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
245 logger.info( |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
246 " [%s%s%s] [%d entries]" % |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
247 (Fore.CYAN, name, Fore.RESET, len(val))) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
248 for v in val: |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
249 logger.info(" - %s" % v) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
250 |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
251 |
692
c11a4339fccb
bake: Show more stats.
Ludovic Chabant <ludovic@chabant.com>
parents:
687
diff
changeset
|
252 def _show_stats(stats, *, full=False): |
687
61d606fbc313
bake: Change `show-timers` to `show-stats`, add stats.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
253 indent = ' ' |
61d606fbc313
bake: Change `show-timers` to `show-stats`, add stats.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
254 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
255 logger.info(' Timers:') |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
256 for name, val in sorted(stats.timers.items(), key=lambda i: i[1], |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
257 reverse=True): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
258 val_str = '%8.1f s' % val |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
259 logger.info( |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
260 "%s[%s%s%s] %s" % |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
261 (indent, Fore.GREEN, val_str, Fore.RESET, name)) |
687
61d606fbc313
bake: Change `show-timers` to `show-stats`, add stats.
Ludovic Chabant <ludovic@chabant.com>
parents:
666
diff
changeset
|
262 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
263 logger.info(' Counters:') |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
264 for name in sorted(stats.counters.keys()): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
265 val_str = '%8d ' % stats.counters[name] |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
266 logger.info( |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
267 "%s[%s%s%s] %s" % |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
268 (indent, Fore.GREEN, val_str, Fore.RESET, name)) |
421
4a43d7015b75
bake: Improve performance timers reports.
Ludovic Chabant <ludovic@chabant.com>
parents:
415
diff
changeset
|
269 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
270 logger.info(' Manifests:') |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
271 for name in sorted(stats.manifests.keys()): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
272 val = stats.manifests[name] |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
273 logger.info( |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
274 "%s[%s%s%s] [%d entries]" % |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
275 (indent, Fore.CYAN, name, Fore.RESET, len(val))) |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
276 if full: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
277 for v in val: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
804
diff
changeset
|
278 logger.info("%s - %s" % (indent, v)) |
415
0e9a94b7fdfa
bake: Improve bake record information.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
279 |
0e9a94b7fdfa
bake: Improve bake record information.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
280 |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
281 def _print_record_entry(e): |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
873
diff
changeset
|
282 import pprint |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
873
diff
changeset
|
283 import textwrap |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
873
diff
changeset
|
284 |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
285 logger.info(" - %s" % e.item_spec) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
286 logger.info(" Outputs:") |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
287 out_paths = list(e.getAllOutputPaths()) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
288 if out_paths: |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
289 for op in out_paths: |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
290 logger.info(" - %s" % op) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
291 else: |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
292 logger.info(" <none>") |
334
b034f6f15e22
bake: Several bug taxonomy-related fixes for incorrect incremental bakes.
Ludovic Chabant <ludovic@chabant.com>
parents:
331
diff
changeset
|
293 |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
294 e_desc = e.describe() |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
295 for k, v in e_desc.items(): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
296 if isinstance(v, dict): |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
297 text = pprint.pformat(v, indent=2) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
298 logger.info(" %s:" % k) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
299 logger.info(textwrap.indent(text, ' ')) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
300 else: |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
301 logger.info(" %s: %s" % (k, v)) |
194
5d8351cb32d8
showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents:
193
diff
changeset
|
302 |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
303 errors = list(e.getAllErrors()) |
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
304 if errors: |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
305 logger.error(" Errors:") |
854
08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
853
diff
changeset
|
306 for err in errors: |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
307 logger.error(" - %s" % err) |