Tools/ChangeLog

 12011-03-04 Tony Chang <tony@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 [Chromium] .checksum files without .pngs and vice-versa
 6 https://bugs.webkit.org/show_bug.cgi?id=55236
 7
 8 * Scripts/find-mismatched-results: Added. A script for finding
 9 mismatched results.
 10
1112011-03-04 Evan Martin <evan@chromium.org>
212
313 Reviewed by Tony Chang.

Tools/Scripts/find-mismatched-results

 1#!/usr/bin/env python
 2# Copyright (c) 2011 Google Inc. All rights reserved.
 3#
 4# Redistribution and use in source and binary forms, with or without
 5# modification, are permitted provided that the following conditions are
 6# met:
 7#
 8# * Redistributions of source code must retain the above copyright
 9# notice, this list of conditions and the following disclaimer.
 10# * Redistributions in binary form must reproduce the above
 11# copyright notice, this list of conditions and the following disclaimer
 12# in the documentation and/or other materials provided with the
 13# distribution.
 14# * Neither the name of Google Inc. nor the names of its
 15# contributors may be used to endorse or promote products derived from
 16# this software without specific prior written permission.
 17#
 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 29
 30"""Finds .png expectations without .checksums or .checksum expectations
 31without .pngs."""
 32
 33import optparse
 34import os
 35
 36def parse_args():
 37 """Returns a 2-tuple (options, paths) where options contains the
 38 parsed arguments and paths is a list of directories to search."""
 39 option_list = [
 40 optparse.make_option("-p", "--missing-pngs", dest="missing_pngs",
 41 action="store_true", default=False, help="Only list missing pngs."),
 42 optparse.make_option("-c", "--missing-checksums",
 43 dest="missing_checksums", action="store_true", default=False,
 44 help="Only list missing checksums."),
 45 ]
 46
 47 option_parser = optparse.OptionParser(option_list=option_list,
 48 description=__doc__)
 49 options, paths = option_parser.parse_args()
 50 if not options.missing_pngs and not options.missing_checksums:
 51 option_parser.error("Please --missing-pngs or --missing-checksums.")
 52
 53 if not paths:
 54 paths = [os.path.join(os.path.dirname(os.path.abspath(__file__)),
 55 '..', '..', 'LayoutTests')]
 56 return options, paths
 57
 58def find_mismatched_results(dirpath, filenames, options):
 59 """Prints mismatched results to stdout.
 60 dirpath is the directory we are searching
 61 filenames is a list of the filenames in dirpath.
 62 options is the parsed arguments."""
 63 checksum_files = set()
 64 png_files = set()
 65
 66 for filename in filenames:
 67 name, extension = os.path.splitext(filename)
 68 if not name.endswith("-expected"):
 69 continue
 70 if extension == ".checksum":
 71 checksum_files.add(name)
 72 elif extension == ".png":
 73 png_files.add(name)
 74
 75 if options.missing_pngs:
 76 missing_pngs = checksum_files.difference(png_files)
 77 for missing_png in missing_pngs:
 78 print os.path.normpath(os.path.join(dirpath, missing_png)
 79 ) + '.checksum'
 80
 81 if options.missing_checksums:
 82 missing_checksums = png_files.difference(checksum_files)
 83 for missing_checksum in missing_checksums:
 84 print os.path.normpath(os.path.join(dirpath, missing_checksum)
 85 ) + '.png'
 86
 87def main():
 88 options, paths = parse_args()
 89
 90 for path in paths:
 91 for dirpath, dirnames, filenames in os.walk(path):
 92 find_mismatched_results(dirpath, filenames, options)
 93if __name__ == "__main__":
 94 main()