Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Unified Diff: tools/rebaseline.py

Issue 15675010: rebaseline.py: use argparse command-line flags for more flexibility (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: tweaks Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/rebaseline.py
===================================================================
--- tools/rebaseline.py (revision 9318)
+++ tools/rebaseline.py (working copy)
@@ -13,6 +13,7 @@
checkout, the files will be added to the staging area for commit.
'''
+import argparse
import os
import subprocess
import sys
@@ -21,7 +22,7 @@
# Mapping of gm-expectations subdir (under
# https://skia.googlecode.com/svn/gm-expected/ )
# to builder name (see list at http://108.170.217.252:10117/builders )
-subdir_mapping = {
+SUBDIR_MAPPING = {
'base-shuttle-win7-intel-float':
'Test-Win7-ShuttleA-HD2000-x86-Release',
'base-shuttle-win7-intel-angle':
@@ -46,63 +47,126 @@
'Test-Android-Nexus10-MaliT604-Arm7-Release',
}
-IS_SVN_CHECKOUT = (os.path.exists('.svn') or
- os.path.exists(os.path.join('..', '.svn')))
-IS_GIT_CHECKOUT = (os.path.exists('.git') or
- os.path.exists(os.path.join('..', '.git')))
+class Rebaseliner(object):
-# Rebaseline a single file.
-def RebaselineOneFile(expectations_subdir, builder_name,
- infilename, outfilename):
- url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' +
- expectations_subdir + '/' + builder_name + '/' +
- expectations_subdir + '/' + infilename)
- cmd = [ 'curl', '--fail', '--silent', url ]
- temp = tempfile.NamedTemporaryFile()
- ret = subprocess.call(cmd, stdout=temp)
- if ret != 0:
- print 'Couldn\'t fetch ' + url
- return
- cmd = [ 'cp', temp.name, outfilename ]
- subprocess.call(cmd);
- if IS_SVN_CHECKOUT:
- cmd = [ 'svn', 'add', '--quiet', outfilename ]
- subprocess.call(cmd)
- cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', 'image/png',
- outfilename ];
- subprocess.call(cmd)
- elif IS_GIT_CHECKOUT:
- cmd = [ 'git', 'add', outfilename ]
- subprocess.call(cmd)
+ # params:
+ # tests: list of tests to rebaseline
+ # configs: which configs to run for each test
+ # subdirs: which platform subdirectories to rebaseline; if an empty list,
+ # rebaseline all platform subdirectories
+ # dry_run: if True, instead of actually downloading files or adding
+ # files to checkout, display a list of operations that
+ # we would normally perform
+ def __init__(self, tests, configs=[], subdirs=[], dry_run=False):
+ if not tests:
+ raise Exception('at least one test must be specified')
+ self._tests = tests
+ self._configs = configs
+ if not subdirs:
+ self._subdirs = sorted(SUBDIR_MAPPING.keys())
+ else:
+ self._subdirs = subdirs
+ self._dry_run = dry_run
+ self._is_svn_checkout = (
+ os.path.exists('.svn') or
+ os.path.exists(os.path.join(os.pardir, '.svn')))
+ self._is_git_checkout = (
+ os.path.exists('.git') or
+ os.path.exists(os.path.join(os.pardir, '.git')))
+ # Execute subprocess.call(), unless dry_run is True
+ def _Call(self, cmd, stdout=None):
+ if self._dry_run:
+ print '%s' % ' '.join(cmd)
+ return 0
+ if stdout:
+ return subprocess.call(cmd, stdout=stdout)
+ else:
+ return subprocess.call(cmd)
-# Rebaseline all testtypes for a single test.
-def RebaselineOneTest(expectations_subdir, builder_name, testname):
- if (expectations_subdir == 'base-shuttle-win7-intel-angle'):
- testtypes = [ 'angle', 'anglemsaa16' ]
- else:
- testtypes = [ '565', '8888', 'gpu', 'pdf', 'mesa', 'msaa16', 'msaa4' ]
- print expectations_subdir + ':'
- for testtype in testtypes:
- infilename = testname + '_' + testtype + '.png'
- print infilename
- outfilename = os.path.join(expectations_subdir, infilename);
- RebaselineOneFile(expectations_subdir=expectations_subdir,
- builder_name=builder_name,
- infilename=infilename,
- outfilename=outfilename)
+ # Rebaseline a single file.
+ def _RebaselineOneFile(self, expectations_subdir, builder_name,
+ infilename, outfilename):
+ url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' +
+ expectations_subdir + '/' + builder_name + '/' +
+ expectations_subdir + '/' + infilename)
+ cmd = [ 'curl', '--fail', '--silent', url ]
+ temp = tempfile.NamedTemporaryFile()
+ ret = self._Call(cmd, stdout=temp)
+ if ret != 0:
+ print '# Couldn\'t fetch ' + url
+ return
+ cmd = [ 'cp', temp.name, outfilename ]
+ self._Call(cmd);
+ if self._is_svn_checkout:
+ cmd = [ 'svn', 'add', '--quiet', outfilename ]
+ self._Call(cmd)
+ cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', 'image/png',
+ outfilename ];
+ self._Call(cmd)
+ elif self._is_git_checkout:
+ cmd = [ 'git', 'add', outfilename ]
+ self._Call(cmd)
+ # Rebaseline the given configs for a single test.
+ #
+ # params:
+ # expectations_subdir
+ # builder_name
+ # test: a single test to rebaseline
+ def _RebaselineOneTest(self, expectations_subdir, builder_name, test):
+ if self._configs:
+ configs = self._configs
+ else:
+ if (expectations_subdir == 'base-shuttle-win7-intel-angle'):
+ configs = [ 'angle', 'anglemsaa16' ]
+ else:
+ configs = [ '565', '8888', 'gpu', 'pdf', 'mesa', 'msaa16',
+ 'msaa4' ]
+ print '# ' + expectations_subdir + ':'
+ for config in configs:
+ infilename = test + '_' + config + '.png'
+ print '# ' + infilename
+ outfilename = os.path.join(expectations_subdir, infilename);
+ self._RebaselineOneFile(expectations_subdir=expectations_subdir,
+ builder_name=builder_name,
+ infilename=infilename,
+ outfilename=outfilename)
+ # Rebaseline all platforms/tests/types we specified in the constructor.
+ def RebaselineAll(self):
+ for test in self._tests:
+ for subdir in self._subdirs:
+ if not subdir in SUBDIR_MAPPING.keys():
+ raise Exception(('unrecognized platform subdir "%s"; ' +
+ 'should be one of %s') % (
+ subdir, SUBDIR_MAPPING.keys()))
+ builder_name = SUBDIR_MAPPING[subdir]
+ self._RebaselineOneTest(expectations_subdir=subdir,
+ builder_name=builder_name,
+ test=test)
-if len(sys.argv) < 2:
- print ('Usage: ' + os.path.basename(sys.argv[0]) +
- ' <testname> [ <testname> ... ]')
- exit(1)
-for testname in sys.argv[1:]:
- for expectations_subdir in sorted(subdir_mapping.keys()):
- builder_name = subdir_mapping[expectations_subdir]
- RebaselineOneTest(expectations_subdir=expectations_subdir,
- builder_name=builder_name,
- testname=testname)
+# main...
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--configs', metavar='CONFIG', nargs='+',
epoger 2013/05/30 15:39:28 This means: if "--configs" is given, it MUST be fo
+ help='which configurations to rebaseline, e.g. ' +
+ '"--configs 565 8888"; if unspecified, run a default ' +
+ 'set of configs')
+parser.add_argument('--dry_run', action='store_true',
+ help='instead of actually downloading files or adding ' +
+ 'files to checkout, display a list of operations that ' +
+ 'we would normally perform')
+parser.add_argument('--subdirs', metavar='SUBDIR', nargs='+',
+ help='which platform subdirectories to rebaseline; ' +
+ 'if unspecified, rebaseline all subdirs, same as ' +
+ '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys())))
+parser.add_argument('--tests', metavar='TEST', nargs='+', required=True,
+ help='which tests to rebaseline, e.g. ' +
+ '"--tests aaclip bigmatrix"')
+args = parser.parse_args()
+rebaseliner = Rebaseliner(tests=args.tests, configs=args.configs,
+ subdirs=args.subdirs, dry_run=args.dry_run)
+rebaseliner.RebaselineAll()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698