245def main(control_commitish):
246 assert os.pardir == '..' and '/' in [os.sep, os.altsep]
249 os.chdir(os.path.dirname(__file__) + '/../..')
251 tmpdir = tempfile.mkdtemp(prefix='skpdf_')
252 exp = tmpdir + '/experim'
253 con = tmpdir + '/control'
256 image_diff_metric =
build_skia(control_worktree,
'image_diff_metric')
257
258 out = sys.stdout
260 out.write(
'\nNumber of PDFs: %d\n\n' %
len(common_paths))
261 def compare_identical(path):
262 cpath, epath = (os.path.join(x, path) for x in (con, exp))
265 return True
266 return False
267 identical_count =
shardsum(compare_identical, common_paths)
268 out.write('Number of identical PDFs: %d\n\n' % identical_count)
269
271 if not differing_paths:
272 out.write('All PDFs are the same!\n')
273 sys.exit(0)
274 out.write(
'Number of differing PDFs: %d\n' %
len(differing_paths))
275 for p in differing_paths:
277 out.write('\n')
279 [os.path.join(x, p) for p in differing_paths for x in [con, exp]])
280
282 identical_count =
shardsum(compare_identical, common_pngs)
283 out.write('Number of PDFs that rasterize the same: %d\n\n'
284 % identical_count)
285
287 if not differing_pngs:
288 out.write('All PDFs rasterize the same!\n')
289 sys.exit(0)
290 out.write('Number of PDFs that rasterize differently: %d\n'
291 %
len(differing_pngs))
292 for p in differing_pngs:
294 out.write('\n')
295
296 scores = dict()
297 def compare_differing_pngs(path):
298 cpath, epath = (os.path.join(x, path) for x in (con, exp))
299 s =
float(subprocess.check_output([image_diff_metric, cpath, epath]))
300 indicator = '.' if s < 0.001 else ':' if s < 0.01 else '!'
301 sys.stdout.write(indicator)
302 sys.stdout.flush()
303 scores[path] = s
304 shard(compare_differing_pngs, differing_pngs)
305 paths = sorted(scores.iterkeys(), key=lambda p: -scores[p])
306 out.write('\n\n')
307 for p in paths:
308 pdfpath =
printable_path(tmpdir +
'/*/' + p.replace(
'.0.png',
''))
309 out.write(' %6.4f %s\n' % (scores[p], pdfpath))
310 out.write('\n')
311
312 errors = []
313 rc = re.compile('^' + PDF_CONFIG + r'/([^/]*)/([^/]*)\.pdf\.0\.png$')
314 for p in paths:
315 m = rc.match(p)
316 assert(m)
317 source, name = m.groups()
318 errors.append((source, name, scores[p]))
319
320 for source in SOURCES:
321 os.makedirs(os.path.join(con, REFERENCE_BACKEND, source))
322 dm_args = [dm, '--src'] + SOURCES + [
323 '--config', REFERENCE_BACKEND, '-w', con, '-m'] + [
324 '^%s$' % name for _, name, _ in errors]
326
327 report = tmpdir + '/report.html'
328 with open(report, 'w') as o:
329 o.write(HTML_HEAD)
330 o.write('c="%s/";\n' % os.path.relpath(con, tmpdir))
331 o.write('e="%s/";\n' % os.path.relpath(exp, tmpdir))
332 o.write('z=[\n')
333 for source, name, score in errors:
334 gt = REFERENCE_BACKEND + '/' + source + '/' + name + '.png'
335 p = '%s/%s/%s.pdf.0.png' % (PDF_CONFIG, source, name)
336 desc = '%s | %s | %g' % (source, name, score)
337 o.write('["%s","%s","%s"],\n' % (p, gt, desc))
338 o.write(HTML_TAIL)
341
def shardsum(fn, arglist)
def main(control_commitish)