From 8e6b7c3c989d923af80dc4d473ac8d87d2ef3491 Mon Sep 17 00:00:00 2001 From: "epoger@google.com" Date: Wed, 14 Aug 2013 18:14:31 +0000 Subject: [PATCH] Delete compare_baselines.py and download_baselines.py ; we use rebaseline.py now Review URL: https://codereview.chromium.org/23082002 git-svn-id: http://skia.googlecode.com/svn/trunk@10714 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tools/compare_baselines.py | 209 --------------------------------------- tools/download_baselines.py | 235 -------------------------------------------- 2 files changed, 444 deletions(-) delete mode 100644 tools/compare_baselines.py delete mode 100644 tools/download_baselines.py diff --git a/tools/compare_baselines.py b/tools/compare_baselines.py deleted file mode 100644 index 7268eb7..0000000 --- a/tools/compare_baselines.py +++ /dev/null @@ -1,209 +0,0 @@ -''' -Compares the gm results within the local checkout against those already -committed to the Skia repository. - -Launch with --help to see more information. - - -Copyright 2012 Google Inc. - -Use of this source code is governed by a BSD-style license that can be -found in the LICENSE file. -''' - -# common Python modules -import fnmatch -import optparse -import os -import shutil -import tempfile - -# modules declared within this same directory -import svn - -USAGE_STRING = 'Usage: %s [options]' -HOWTO_STRING = ''' -To update the checked-in baselines across all platforms, follow these steps: - -cd .../trunk -svn update -svn stat # and make sure there are no files awaiting svn commit -make tools BUILDTYPE=Release -python tools/download_baselines.py -python tools/compare_baselines.py -# view compare_baselines output in a browser and make sure it's reasonable -# upload CL for review -# validate that the diffs look right in the review tool -# commit CL - -Note that the above instructions will only *update* already-checked-in -baseline images; if you want to check in new baseline images (ones that the -bots have been generating but we don't have a golden master for yet), you need -to use download_baselines.py's --add-new-files option. -''' -HELP_STRING = ''' - -Compares the gm results within the local checkout against those already -committed to the Skia repository. Relies on skdiff to do the low-level -comparison. - -''' + HOWTO_STRING - -TRUNK_PATH = os.path.join(os.path.dirname(__file__), os.pardir) - -OPTION_GM_BASEDIR = '--gm-basedir' -DEFAULT_GM_BASEDIR = os.path.join(TRUNK_PATH, os.pardir, 'gm-expected') -OPTION_PATH_TO_SKDIFF = '--path-to-skdiff' -# default PATH_TO_SKDIFF is determined at runtime -OPTION_SVN_GM_URL = '--svn-gm-url' -DEFAULT_SVN_GM_URL = 'http://skia.googlecode.com/svn/gm-expected' - -def CopyAllFilesAddingPrefix(source_dir, dest_dir, prefix): - """Copy all files from source_dir into dest_dir, adding prefix to the name - of each one as we copy it. - prefixes. - - @param source_dir - @param dest_dir where to save the copied files - @param prefix prefix to add to each filename when we make the copy - """ - all_filenames = os.listdir(source_dir) - for filename in all_filenames: - source_path = os.path.join(source_dir, filename) - if os.path.isdir(source_path): - print 'skipping %s because it is a directory, not a file' % filename - continue - dest_path = os.path.join(dest_dir, '%s%s' % (prefix, filename)) - shutil.copyfile(source_path, dest_path) - -def Flatten(source_dir, dest_dir, subdirectory_pattern): - """Copy all files from matching subdirectories under source_dir into - dest_dir, flattened into a single directory using subdirectory names as - prefixes. - - @param source_dir - @param dest_dir where to save the copied files - @param subdirectory_pattern only copy files from subdirectories that match - this Unix-style filename pattern (e.g., 'base-*') - """ - all_filenames = os.listdir(source_dir) - matching_filenames = fnmatch.filter(all_filenames, subdirectory_pattern) - for filename in matching_filenames: - source_path = os.path.join(source_dir, filename) - if not os.path.isdir(source_path): - print 'skipping %s because it is a file, not a directory' % filename - continue - print 'flattening directory %s' % source_path - CopyAllFilesAddingPrefix(source_dir=source_path, dest_dir=dest_dir, - prefix='%s_' % filename) - -def RunCommand(command): - """Run a command, raising an exception if it fails. - - @param command the command as a single string - """ - print 'running command [%s]...' % command - retval = os.system(command) - #if retval is not 0: - # raise Exception('command [%s] failed' % command) - -def FindPathToSkDiff(user_set_path=None): - """Return path to an existing skdiff binary, or raise an exception if we - cannot find one. - - @param user_set_path if None, the user did not specify a path, so look in - some likely places; otherwise, only check at this path - """ - if user_set_path is not None: - if os.path.isfile(user_set_path): - return user_set_path - raise Exception('unable to find skdiff at user-set path %s' % - user_set_path) - trunk_path = os.path.join(os.path.dirname(__file__), os.pardir) - possible_paths = [os.path.join(trunk_path, 'out', 'Release', 'skdiff'), - os.path.join(trunk_path, 'out', 'Debug', 'skdiff')] - for try_path in possible_paths: - if os.path.isfile(try_path): - return try_path - raise Exception('cannot find skdiff in paths %s; maybe you need to ' - 'specify the %s option or build skdiff?' % ( - possible_paths, OPTION_PATH_TO_SKDIFF)) - -def CompareBaselines(gm_basedir, path_to_skdiff, svn_gm_url): - """Compare the gm results within gm_basedir against those already - committed to the Skia repository. - - @param gm_basedir - @param path_to_skdiff - @param svn_gm_url base URL of Subversion repository where we store the - expected GM results - """ - # Validate parameters, filling in default values if necessary and possible. - if not os.path.isdir(gm_basedir): - raise Exception('cannot find gm_basedir at %s; maybe you need to ' - 'specify the %s option?' % ( - gm_basedir, OPTION_GM_BASEDIR)) - path_to_skdiff = FindPathToSkDiff(path_to_skdiff) - - tempdir_base = tempfile.mkdtemp() - - # Download all checked-in baseline images to a temp directory - checkedin_dir = os.path.join(tempdir_base, 'checkedin') - os.mkdir(checkedin_dir) - svn.Svn(checkedin_dir).Checkout(svn_gm_url, '.') - - # Flatten those checked-in baseline images into checkedin_flattened_dir - checkedin_flattened_dir = os.path.join(tempdir_base, 'checkedin_flattened') - os.mkdir(checkedin_flattened_dir) - Flatten(source_dir=checkedin_dir, dest_dir=checkedin_flattened_dir, - subdirectory_pattern='base-*') - - # Flatten the local baseline images into local_flattened_dir - local_flattened_dir = os.path.join(tempdir_base, 'local_flattened') - os.mkdir(local_flattened_dir) - Flatten(source_dir=gm_basedir, dest_dir=local_flattened_dir, - subdirectory_pattern='base-*') - - # Run skdiff to compare checkedin_flattened_dir against local_flattened_dir - diff_dir = os.path.join(tempdir_base, 'diffs') - os.mkdir(diff_dir) - RunCommand('%s %s %s %s' % (path_to_skdiff, checkedin_flattened_dir, - local_flattened_dir, diff_dir)) - print '\nskdiff results are ready in file://%s/index.html' % diff_dir - # TODO(epoger): delete tempdir_base tree to clean up after ourselves (but - # not before the user gets a chance to examine the results), and/or - # allow user to specify a different directory to write into? - -def RaiseUsageException(): - raise Exception('%s\nRun with --help for more detail.' % ( - USAGE_STRING % __file__)) - -def Main(options, args): - """Allow other scripts to call this script with fake command-line args. - """ - num_args = len(args) - if num_args != 0: - RaiseUsageException() - CompareBaselines(gm_basedir=options.gm_basedir, - path_to_skdiff=options.path_to_skdiff, - svn_gm_url=options.svn_gm_url) - -if __name__ == '__main__': - parser = optparse.OptionParser(USAGE_STRING % '%prog' + HELP_STRING) - parser.add_option(OPTION_GM_BASEDIR, - action='store', type='string', default=DEFAULT_GM_BASEDIR, - help='path to root of locally stored baseline images ' - 'to compare against those checked into the svn repo; ' - 'defaults to "%s"' % DEFAULT_GM_BASEDIR) - parser.add_option(OPTION_PATH_TO_SKDIFF, - action='store', type='string', default=None, - help='path to already-built skdiff tool; if not set, ' - 'will search for it in typical directories near this ' - 'script') - parser.add_option(OPTION_SVN_GM_URL, - action='store', type='string', default=DEFAULT_SVN_GM_URL, - help='URL of SVN repository within which we store the ' - 'expected GM baseline images; defaults to "%s"' % - DEFAULT_SVN_GM_URL) - (options, args) = parser.parse_args() - Main(options, args) diff --git a/tools/download_baselines.py b/tools/download_baselines.py deleted file mode 100644 index 3615b5d..0000000 --- a/tools/download_baselines.py +++ /dev/null @@ -1,235 +0,0 @@ -''' -Downloads the actual gm results most recently generated by the Skia buildbots, -and adds any new ones to SVN control. - -Launch with --help to see more information. - - -Copyright 2011 Google Inc. - -Use of this source code is governed by a BSD-style license that can be -found in the LICENSE file. -''' - -# common Python modules -import fnmatch -import optparse -import os -import re -import shutil -import sys -import tempfile - -# modules declared within this same directory -import compare_baselines -import svn - -USAGE_STRING = 'Usage: %s [options] [baseline_subdir]...' -HELP_STRING = ''' - -Downloads the actual gm results most recently generated by the Skia buildbots, -and adds any new ones to SVN control. - -If no baseline_subdir is given, then this tool will download the most-recently -generated actual gm results for ALL platforms. - -''' + compare_baselines.HOWTO_STRING - -# Base URL of SVN repository where buildbots store actual gm image results. -GM_ACTUAL_URL = 'http://skia-autogen.googlecode.com/svn/gm-actual' - -# GM baseline image URL in regular Skia SVN repository -GM_BASELINE_URL = 'https://skia.googlecode.com/svn/gm-expected' - -GM_EXPECTED_DIR = 'gm-expected' - -OPTION_ADD_NEW_FILES = '--add-new-files' -OPTION_BUILDER_SUFFIX = '--builder-suffix' -DEFAULT_BUILDER_SUFFIX = '32' -OPTION_IGNORE_LOCAL_MODS = '--ignore-local-mods' - -def GetLatestResultsSvnUrl(svn, baseline_subdir, builder_suffix): - """Return SVN URL from which we can check out the MOST RECENTLY generated images for this - baseline type. - - @param svn an Svn object we can use to call ListSubdirs() - @param baseline_subdir indicates which platform we want images for - @param builder_suffix if multiple builders uploaded actual GM images for this baseline type, - choose the one whose builder_name matches this suffix - """ - root_url = '%s/%s' % (GM_ACTUAL_URL, baseline_subdir) - subdirs = sorted(svn.ListSubdirs(root_url)) - num_subdirs = len(subdirs) - print('Within actual-results root URL %s, found these %d subdirs (presumably builder_names): %s' - % (root_url, num_subdirs, subdirs)) - - selected_subdir = None - if num_subdirs == 0: - print 'Found no builder_name subdirs, so reading actual images from the root_url itself.' - return root_url - elif num_subdirs == 1: - selected_subdir = subdirs[0] - print 'Found exactly one subdir in actual-results root_url: %s' % selected_subdir - else: - for possible_subdir in subdirs: - if possible_subdir.endswith(builder_suffix): - selected_subdir = possible_subdir - print 'Selected the first subdir ending in "%s": %s' % ( - builder_suffix, selected_subdir) - break - - if selected_subdir: - return '%s/%s/%s' % (root_url, selected_subdir, baseline_subdir) - else: - raise Exception('none of these subdirs of %s ended in "%s": %s' % ( - root_url, builder_suffix, subdirs)) - -def GetBaselineSvnUrl(baseline_subdir): - """Return SVN URL from which we can check out the baseline images for this - baseline type. - - @param baseline_subdir indicates which platform we want baselines for - """ - return '%s/%s' % (GM_BASELINE_URL, baseline_subdir) - -def CopyMatchingFiles(source_dir, dest_dir, filename_pattern, only_copy_updates=False): - """Copy all files from source_dir that match filename_pattern, and save them (with their - original filenames) in dest_dir. - - @param source_dir - @param dest_dir where to save the copied files - @param filename_pattern only copy files that match this Unix-style filename - pattern (e.g., '*.jpg') - @param only_copy_updates if True, only copy files that are already present in dest_dir - """ - all_filenames = os.listdir(source_dir) - matching_filenames = fnmatch.filter(all_filenames, filename_pattern) - for filename in matching_filenames: - source_path = os.path.join(source_dir, filename) - dest_path = os.path.join(dest_dir, filename) - if only_copy_updates and not os.path.isfile(dest_path): - continue - shutil.copyfile(source_path, dest_path) - -def DownloadBaselinesForOnePlatform(baseline_subdir): - """Download most recently generated baseline images for a single platform, - and add any new ones to SVN control. - - @param baseline_subdir - """ - # Create repo_to_modify to handle the SVN repository we will add files to. - gm_dir = os.path.join(os.pardir, GM_EXPECTED_DIR) # Shouldn't assume we're in trunk... - try: - os.makedirs(gm_dir) - except: - pass - repo_to_modify = svn.Svn(gm_dir) - repo_to_modify.Checkout(GetBaselineSvnUrl(baseline_subdir), baseline_subdir) - - # If there are any locally modified files in that directory, exit - # (so that we don't risk overwriting the user's previous work). - new_and_modified_files = repo_to_modify.GetNewAndModifiedFiles() - if not options.ignore_local_mods: - if new_and_modified_files: - raise Exception('Exiting because there are already new and/or ' - 'modified files in %s. To continue in spite of ' - 'that, run with %s option.' % ( - baseline_subdir, OPTION_IGNORE_LOCAL_MODS)) - - # Download actual gm images into a separate repo in a temporary directory. - actual_dir = tempfile.mkdtemp() - actual_repo = svn.Svn(actual_dir) - print 'Using %s as a temp dir' % actual_dir - actual_url = GetLatestResultsSvnUrl(svn=actual_repo, baseline_subdir=baseline_subdir, - builder_suffix=options.builder_suffix) - print 'Reading actual buildbot GM results from %s' % actual_url - actual_repo.Checkout(actual_url, '.') - - # Copy any of those files we are interested in into repo_to_modify, - # and then delete the temporary directory. - CopyMatchingFiles(source_dir=actual_dir, - dest_dir=os.path.join(gm_dir, baseline_subdir), - filename_pattern='*.png', - only_copy_updates=(not options.add_new_files)) - shutil.rmtree(actual_dir) - actual_repo = None - - # Add any new files to SVN control (if we are running with add_new_files). - if options.add_new_files: - new_files = repo_to_modify.GetNewFiles() - if new_files: - repo_to_modify.AddFiles(sorted(new_files)) - - # Set the mimetype property on any new/modified image files in - # baseline_subdir. (We used to set the mimetype property on *all* image - # files in the directory, even those whose content wasn't changing, - # but that caused confusion. See - # http://code.google.com/p/skia/issues/detail?id=618 .) - modified_files = repo_to_modify.GetNewAndModifiedFiles() - repo_to_modify.SetProperty(sorted(fnmatch.filter(modified_files, '*.png')), - svn.PROPERTY_MIMETYPE, 'image/png') - repo_to_modify.SetProperty(sorted(fnmatch.filter(modified_files, '*.pdf')), - svn.PROPERTY_MIMETYPE, 'application/pdf') - -def RaiseUsageException(): - raise Exception('%s\nRun with --help for more detail.' % ( - USAGE_STRING % __file__)) - -def Main(options, args): - """Allow other scripts to call this script with fake command-line args. - """ - # If no platforms are specified, do 'em all. - num_args = len(args) - if num_args == 0: - # TODO(epoger): automate the default set of platforms. We want to ensure - # that the user gets all of the platforms that the bots are running, - # not just whatever subdirectories he happens to have checked out... - # See http://code.google.com/p/skia/issues/detail?id=678 - # Now that we have added Svn.ListSubdirs(), we should be able to do this - # pretty easily... - # - # For now, I generate this list using these Unix commands: - # svn ls http://skia.googlecode.com/svn/gm-expected | grep ^base | sort >/tmp/baselines - # svn ls http://skia-autogen.googlecode.com/svn/gm-actual | grep ^base | sort >/tmp/actual - # comm -1 -2 /tmp/baselines /tmp/actual - args = [ - 'base-android-galaxy-nexus', - 'base-android-nexus-7', - 'base-android-nexus-s', - 'base-android-xoom', - 'base-macmini', - 'base-macmini-lion-float', - 'base-shuttle-win7-intel-float', - 'base-shuttle_ubuntu12_ati5770', - 'base-shuttle-win7-intel-angle', - 'base-shuttle-win7-intel-directwrite', - ] - - # Trim all subdir names. - baseline_subdirs = [] - for arg in args: - baseline_subdirs.append(arg.rstrip(os.sep)) - - # Process the subdirs, one at a time. - for baseline_subdir in baseline_subdirs: - DownloadBaselinesForOnePlatform(baseline_subdir=baseline_subdir) - -if __name__ == '__main__': - parser = optparse.OptionParser(USAGE_STRING % '%prog' + HELP_STRING) - parser.add_option(OPTION_ADD_NEW_FILES, - action='store_true', default=False, - help='in addition to downloading new versions of ' - 'existing baselines, also download baselines that are ' - 'not under SVN control yet') - parser.add_option(OPTION_BUILDER_SUFFIX, - action='store', type='string', default=DEFAULT_BUILDER_SUFFIX, - help='if multiple builders have uploaded actual GM images ' - 'for this platform, download the images uploaded by the ' - 'builder whose name ends in this suffix; defaults to ' - '"%s".' % DEFAULT_BUILDER_SUFFIX) - parser.add_option(OPTION_IGNORE_LOCAL_MODS, - action='store_true', default=False, - help='allow tool to run even if there are already ' - 'local modifications in the baseline_subdir') - (options, args) = parser.parse_args() - Main(options, args) -- 2.7.4