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

Unified Diff: gm/rebaseline_server/download.py

Issue 143653006: new tool: download all GM images for a given builder, ready for skdiff (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: bsalomon comment Created 6 years, 11 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 | « gm/gm_json.py ('k') | gm/rebaseline_server/download_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/rebaseline_server/download.py
diff --git a/gm/rebaseline_server/download.py b/gm/rebaseline_server/download.py
new file mode 100755
index 0000000000000000000000000000000000000000..daa6503e69fe653aea5e7d7d95e54b978782fe44
--- /dev/null
+++ b/gm/rebaseline_server/download.py
@@ -0,0 +1,136 @@
+#!/usr/bin/python
+
+"""
+Copyright 2014 Google Inc.
+
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+
+Download actual GM results for a particular builder.
+"""
+
+# System-level imports
+import optparse
+import os
+import re
+import sys
+
+# Imports from within Skia
+#
+# We need to add the 'gm' directory, so that we can import gm_json.py within
+# that directory. That script allows us to parse the actual-results.json file
+# written out by the GM tool.
+# Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end*
+# so any dirs that are already in the PYTHONPATH will be preferred.
+PARENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
+GM_DIRECTORY = os.path.dirname(PARENT_DIRECTORY)
+if GM_DIRECTORY not in sys.path:
+ sys.path.append(GM_DIRECTORY)
+import gm_json
+import url_or_path
+
+DEFAULT_ACTUALS_BASE_URL = 'http://skia-autogen.googlecode.com/svn/gm-actual'
+DEFAULT_JSON_FILENAME = 'actual-results.json'
+
+
+class Download(object):
+
+ def __init__(self, actuals_base_url=DEFAULT_ACTUALS_BASE_URL,
+ json_filename=DEFAULT_JSON_FILENAME,
+ gm_actuals_root_url=gm_json.GM_ACTUALS_ROOT_HTTP_URL):
+ """
+ Args:
+ actuals_base_url: URL or local filepath pointing at the root directory
+ containing all actual-results.json files, e.g.,
+ http://domain.name/path/to/dir OR
+ /absolute/path/to/localdir (on Linux) OR
+ relative\path\to\localdir (on Windows)
+ json_filename: The JSON filename to read from within each directory.
+ gm_actuals_root_url: Base URL under which the actually-generated-by-bots
+ GM images are stored.
+ """
+ self._actuals_base_url = actuals_base_url
+ self._json_filename = json_filename
+ self._gm_actuals_root_url = gm_actuals_root_url
+ self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN)
+
+ def fetch(self, builder_name, dest_dir):
+ """ Downloads actual GM results for a particular builder.
+
+ Args:
+ builder_name: which builder to download results of
+ dest_dir: path to directory where the image files will be written;
+ if the directory does not exist yet, it will be created
+
+ TODO(epoger): Display progress info. Right now, it can take a long time
+ to download all of the results, and there is no indication of progress.
+
+ TODO(epoger): Download multiple images in parallel to speed things up.
+ """
+ json_url = url_or_path.join(self._actuals_base_url, builder_name,
+ self._json_filename)
+ json_contents = url_or_path.read_as_string(json_url)
+ results_dict = gm_json.LoadFromString(json_contents)
+
+ actual_results_dict = results_dict[gm_json.JSONKEY_ACTUALRESULTS]
+ for result_type in sorted(actual_results_dict.keys()):
+ results_of_this_type = actual_results_dict[result_type]
+ if not results_of_this_type:
+ continue
+ for image_name in sorted(results_of_this_type.keys()):
+ (test, config) = self._image_filename_re.match(image_name).groups()
+ (hash_type, hash_digest) = results_of_this_type[image_name]
+ source_url = gm_json.CreateGmActualUrl(
+ test_name=test, hash_type=hash_type, hash_digest=hash_digest,
+ gm_actuals_root_url=self._gm_actuals_root_url)
+ dest_path = os.path.join(dest_dir, config, test + '.png')
+ url_or_path.copy_contents(source_path=source_url, dest_path=dest_path,
+ create_subdirs_if_needed=True)
+
+
+def main():
+ parser = optparse.OptionParser()
+ parser.add_option('--actuals-base-url',
+ action='store', type='string',
+ default=DEFAULT_ACTUALS_BASE_URL,
+ help=('Base URL from which to read files containing JSON '
+ 'summaries of actual GM results; defaults to '
+ '"%default". To get a specific revision (useful for '
+ 'trybots) replace "svn" with "svn-history/r123".'))
+ parser.add_option('--builder',
+ action='store', type='string',
+ default=None,
+ help=('REQUIRED: Which builder to download results for. '
+ 'To see a list of builders, run "svn ls %s".' %
epoger 2014/01/23 04:15:32 At a cost, yes. If you look at https://code.googl
rmistry 2014/01/23 12:48:23 IMO having a --list-builders step would make it th
bsalomon 2014/01/23 14:20:33 This seems totally sufficient. Thanks!
epoger 2014/01/23 15:34:19 Discussed live: I will add this as a TODO, but "sv
epoger 2014/01/24 02:00:46 Done.
+ DEFAULT_ACTUALS_BASE_URL))
+ parser.add_option('--dest-dir',
+ action='store', type='string',
+ default=None,
+ help=('REQUIRED: Directory where all images should be '
+ 'written. If this directory does not exist yet, it '
+ 'will be created.'))
+ parser.add_option('--json-filename',
+ action='store', type='string',
+ default=DEFAULT_JSON_FILENAME,
+ help=('JSON summary filename to read for each builder; '
+ 'defaults to "%default".'))
+ (params, remaining_args) = parser.parse_args()
+
+ # Make sure all required options were set (no params should have value None),
+ # and that there were no items left over in the command line.
+ param_dict = vars(params)
+ for param_name, param_value in param_dict.items():
+ if param_value is None:
+ raise Exception('required option \'%s\' was not set' % param_name)
+ if len(remaining_args) is not 0:
+ raise Exception('extra items specified in the command line: %s' %
+ remaining_args)
+
+ downloader = Download(actuals_base_url=params.actuals_base_url)
+ downloader.fetch(builder_name=params.builder,
+ dest_dir=params.dest_dir)
+
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « gm/gm_json.py ('k') | gm/rebaseline_server/download_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698