comparison piecrust/commands/builtin/baking.py @ 979:45ad976712ec

tests: Big push to get the tests to pass again. - Lots of fixes everywhere in the code. - Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now. - Replace all `.md` test files with `.html` since now a auto-format extension always sets the format. - Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 29 Oct 2017 22:51:57 -0700
parents 98becbc75ccc
children f83ae0a5d793
comparison
equal deleted inserted replaced
978:7e51d14097cb 979:45ad976712ec
93 elif ctx.args.pipelines: 93 elif ctx.args.pipelines:
94 if allowed_pipelines or forbidden_pipelines: 94 if allowed_pipelines or forbidden_pipelines:
95 raise Exception( 95 raise Exception(
96 "Can't specify `--html-only` or `--assets-only` with " 96 "Can't specify `--html-only` or `--assets-only` with "
97 "`--pipelines`.") 97 "`--pipelines`.")
98 allowed_pipelines = []
99 forbidden_pipelines = []
98 for p in ctx.args.pipelines: 100 for p in ctx.args.pipelines:
99 if p[0] == '-': 101 if p[0] == '-':
100 forbidden_pipelines.append(p) 102 forbidden_pipelines.append(p)
101 else: 103 else:
102 allowed_pipelines.append(p) 104 allowed_pipelines.append(p)
105 if not allowed_pipelines:
106 allowed_pipelines = None
107 if not forbidden_pipelines:
108 forbidden_pipelines = None
103 109
104 baker = Baker( 110 baker = Baker(
105 ctx.appfactory, ctx.app, out_dir, 111 ctx.appfactory, ctx.app, out_dir,
106 force=ctx.args.force, 112 force=ctx.args.force,
107 allowed_pipelines=allowed_pipelines, 113 allowed_pipelines=allowed_pipelines,
112 118
113 119
114 class ShowRecordCommand(ChefCommand): 120 class ShowRecordCommand(ChefCommand):
115 def __init__(self): 121 def __init__(self):
116 super(ShowRecordCommand, self).__init__() 122 super(ShowRecordCommand, self).__init__()
117 self.name = 'showrecord' 123 self.name = 'showrecords'
118 self.description = ("Shows the bake record for a given output " 124 self.description = ("Shows the bake records for a given output "
119 "directory.") 125 "directory.")
120 126
121 def setupParser(self, parser, app): 127 def setupParser(self, parser, app):
122 parser.add_argument( 128 parser.add_argument(
123 '-o', '--output', 129 '-o', '--output',
124 help="The output directory for which to show the bake record " 130 help="The output directory for which to show the bake records "
125 "(defaults to `_counter`)", 131 "(defaults to `_counter`)",
126 nargs='?') 132 nargs='?')
127 parser.add_argument( 133 parser.add_argument(
128 '-i', '--in-path', 134 '-i', '--in-path',
129 help="A pattern that will be used to filter the relative path " 135 help="A pattern that will be used to filter the relative path "
138 help="Only show record entries for failures.") 144 help="Only show record entries for failures.")
139 parser.add_argument( 145 parser.add_argument(
140 '--last', 146 '--last',
141 type=int, 147 type=int,
142 default=0, 148 default=0,
143 help="Show the last Nth bake record.") 149 help="Show the last Nth bake records.")
150 parser.add_argument(
151 '--records',
152 help="Load the specified records file.")
144 parser.add_argument( 153 parser.add_argument(
145 '--html-only', 154 '--html-only',
146 action='store_true', 155 action='store_true',
147 help="Only show records for pages (not from the asset " 156 help="Only show records for pages (not from the asset "
148 "pipeline).") 157 "pipeline).")
155 nargs='*', 164 nargs='*',
156 help="Only show records for the given pipeline(s).") 165 help="Only show records for the given pipeline(s).")
157 parser.add_argument( 166 parser.add_argument(
158 '--show-stats', 167 '--show-stats',
159 action='store_true', 168 action='store_true',
160 help="Show stats from the record.") 169 help="Show stats from the records.")
161 parser.add_argument( 170 parser.add_argument(
162 '--show-manifest', 171 '--show-manifest',
163 help="Show manifest entries from the record.") 172 help="Show manifest entries from the records.")
164 173
165 def run(self, ctx): 174 def run(self, ctx):
166 import fnmatch 175 import fnmatch
167 from piecrust.baking.baker import get_bake_records_path 176 from piecrust.baking.baker import get_bake_records_path
168 from piecrust.pipelines.records import load_records 177 from piecrust.pipelines.records import load_records
169 178
170 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') 179 records_path = ctx.args.records
171 suffix = '' if ctx.args.last == 0 else '.%d' % ctx.args.last 180 if records_path is None:
172 records_path = get_bake_records_path(ctx.app, out_dir, suffix=suffix) 181 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir,
173 records = load_records(records_path) 182 '_counter')
183 suffix = '' if ctx.args.last == 0 else '.%d' % ctx.args.last
184 records_path = get_bake_records_path(ctx.app, out_dir,
185 suffix=suffix)
186 logger.info("Bake records for output: %s" % out_dir)
187 else:
188 logger.info("Bake records from: %s" % records_path)
189
190 records = load_records(records_path, True)
174 if records.invalidated: 191 if records.invalidated:
175 raise Exception( 192 raise Exception(
176 "The bake record was saved by a previous version of " 193 "The bake records were saved by a previous version of "
177 "PieCrust and can't be shown.") 194 "PieCrust and can't be shown.")
178 195
179 in_pattern = None 196 in_pattern = None
180 if ctx.args.in_path: 197 if ctx.args.in_path:
181 in_pattern = '*%s*' % ctx.args.in_path.strip('*') 198 in_pattern = '*%s*' % ctx.args.in_path.strip('*')
183 out_pattern = None 200 out_pattern = None
184 if ctx.args.out_path: 201 if ctx.args.out_path:
185 out_pattern = '*%s*' % ctx.args.out_path.strip('*') 202 out_pattern = '*%s*' % ctx.args.out_path.strip('*')
186 203
187 pipelines = ctx.args.pipelines 204 pipelines = ctx.args.pipelines
188 if not pipelines: 205 if pipelines is None:
189 pipelines = [p.PIPELINE_NAME 206 if ctx.args.assets_only:
190 for p in ctx.app.plugin_loader.getPipelines()] 207 pipelines = ['asset']
191 if ctx.args.assets_only: 208 if ctx.args.html_only:
192 pipelines = ['asset'] 209 pipelines = ['page']
193 if ctx.args.html_only: 210
194 pipelines = ['page']
195
196 logger.info("Bake record for: %s" % out_dir)
197 logger.info("Status: %s" % ('SUCCESS' if records.success 211 logger.info("Status: %s" % ('SUCCESS' if records.success
198 else 'FAILURE')) 212 else 'FAILURE'))
199 logger.info("Date/time: %s" % 213 logger.info("Date/time: %s" %
200 datetime.datetime.fromtimestamp(records.bake_time)) 214 datetime.datetime.fromtimestamp(records.bake_time))
201 logger.info("Incremental count: %d" % records.incremental_count) 215 logger.info("Incremental count: %d" % records.incremental_count)
204 logger.info("") 218 logger.info("")
205 219
206 if not ctx.args.show_stats and not ctx.args.show_manifest: 220 if not ctx.args.show_stats and not ctx.args.show_manifest:
207 for rec in records.records: 221 for rec in records.records:
208 if ctx.args.fails and rec.success: 222 if ctx.args.fails and rec.success:
223 logger.debug(
224 "Ignoring record '%s' because it was successful, "
225 "and `--fail` was passed." % rec.name)
209 continue 226 continue
210 227
211 ppname = rec.name[rec.name.index('@') + 1:] 228 ppname = rec.name[rec.name.index('@') + 1:]
212 if ppname not in pipelines: 229 if pipelines is not None and ppname not in pipelines:
230 logging.debug(
231 "Ignoring record '%s' because it was created by "
232 "pipeline '%s', which isn't listed in "
233 "`--pipelines`." % (rec.name, ppname))
213 continue 234 continue
214 235
215 entries_to_show = [] 236 entries_to_show = []
216 237
217 for e in rec.getEntries(): 238 for e in rec.getEntries():