| Index: tools/rebaseline.py
|
| ===================================================================
|
| --- tools/rebaseline.py (revision 9425)
|
| +++ tools/rebaseline.py (working copy)
|
| @@ -17,7 +17,6 @@
|
| import os
|
| import subprocess
|
| import sys
|
| -import tempfile
|
|
|
| # Mapping of gm-expectations subdir (under
|
| # https://skia.googlecode.com/svn/gm-expected/ )
|
| @@ -48,6 +47,9 @@
|
| }
|
|
|
|
|
| +class CommandFailedException(Exception):
|
| + pass
|
| +
|
| class Rebaseliner(object):
|
|
|
| # params:
|
| @@ -75,30 +77,56 @@
|
| 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 dry_run is False, execute subprocess.call(cmd).
|
| + # If dry_run is True, print the command we would have otherwise run.
|
| + # Raises a CommandFailedException if the command fails.
|
| + def _Call(self, cmd):
|
| if self._dry_run:
|
| print '%s' % ' '.join(cmd)
|
| - return 0
|
| - if stdout:
|
| - return subprocess.call(cmd, stdout=stdout)
|
| - else:
|
| - return subprocess.call(cmd)
|
| + return
|
| + if subprocess.call(cmd) != 0:
|
| + raise CommandFailedException('error running command: ' +
|
| + ' '.join(cmd))
|
|
|
| + # Download a single file, raising a CommandFailedException if it fails.
|
| + def _DownloadFile(self, source_url, dest_filename):
|
| + # Download into a temporary file and then rename it afterwards,
|
| + # so that we don't corrupt the existing file if it fails midway thru.
|
| + temp_filename = os.path.join(os.path.dirname(dest_filename),
|
| + '.temp-' + os.path.basename(dest_filename))
|
| +
|
| + # TODO(epoger): Replace calls to "curl"/"mv" (which will only work on
|
| + # Unix) with a Python HTTP library (which should work cross-platform)
|
| + self._Call([ 'curl', '--fail', '--silent', source_url,
|
| + '--output', temp_filename ])
|
| + self._Call([ 'mv', temp_filename, dest_filename ])
|
| +
|
| # 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:
|
| +
|
| + # Try to download this file, but if that fails, keep going...
|
| + #
|
| + # This not treated as a fatal failure because not all
|
| + # platforms generate all configs (e.g., Android does not
|
| + # generate PDF).
|
| + #
|
| + # We could tweak the list of configs within this tool to
|
| + # reflect which combinations the bots actually generate, and
|
| + # then fail if any of those expected combinations are
|
| + # missing... but then this tool would become useless every
|
| + # time someone tweaked the configs on the bots without
|
| + # updating this script.
|
| + try:
|
| + self._DownloadFile(source_url=url, dest_filename=outfilename)
|
| + except CommandFailedException:
|
| print '# Couldn\'t fetch ' + url
|
| return
|
| - cmd = [ 'cp', temp.name, outfilename ]
|
| - self._Call(cmd);
|
| +
|
| + # Add this file to version control (if it isn't already).
|
| if self._is_svn_checkout:
|
| cmd = [ 'svn', 'add', '--quiet', outfilename ]
|
| self._Call(cmd)
|
|
|