Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
|
rmistry
2014/01/22 22:00:30
The name of this file is very generic (download.py
epoger
2014/01/23 05:00:53
A fair point. How about download_gm_actuals.py ?
rmistry
2014/01/23 12:48:23
download_gm_actuals.py SGTM
epoger
2014/01/23 15:34:19
Discussed live: will name it download_actuals.py
epoger
2014/01/24 02:00:46
Done.
| |
| 2 | |
| 3 """ | |
| 4 Copyright 2014 Google Inc. | |
| 5 | |
| 6 Use of this source code is governed by a BSD-style license that can be | |
| 7 found in the LICENSE file. | |
| 8 | |
| 9 Download actual GM results for a particular builder. | |
| 10 """ | |
| 11 | |
| 12 # System-level imports | |
| 13 import optparse | |
| 14 import os | |
| 15 import re | |
| 16 import sys | |
| 17 | |
| 18 # Imports from within Skia | |
| 19 # | |
| 20 # We need to add the 'gm' directory, so that we can import gm_json.py within | |
| 21 # that directory. That script allows us to parse the actual-results.json file | |
| 22 # written out by the GM tool. | |
| 23 # Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end* | |
| 24 # so any dirs that are already in the PYTHONPATH will be preferred. | |
| 25 PARENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) | |
| 26 GM_DIRECTORY = os.path.dirname(PARENT_DIRECTORY) | |
| 27 if GM_DIRECTORY not in sys.path: | |
| 28 sys.path.append(GM_DIRECTORY) | |
| 29 import gm_json | |
| 30 import url_or_path | |
| 31 | |
| 32 DEFAULT_ACTUALS_BASE_URL = 'http://skia-autogen.googlecode.com/svn/gm-actual' | |
|
rmistry
2014/01/22 22:00:30
'https://skia-autogen.googlecode.com/svn' exists i
epoger
2014/01/23 05:00:53
Done.
| |
| 33 DEFAULT_JSON_FILENAME = 'actual-results.json' | |
| 34 | |
| 35 | |
| 36 class Download(object): | |
| 37 | |
| 38 def __init__(self, actuals_base_url=DEFAULT_ACTUALS_BASE_URL, | |
| 39 json_filename=DEFAULT_JSON_FILENAME, | |
| 40 gm_actuals_root_url=gm_json.GM_ACTUALS_ROOT_HTTP_URL): | |
| 41 """ | |
| 42 Args: | |
| 43 actuals_base_url: URL or local filepath pointing at the root directory | |
| 44 containing all actual-results.json files, e.g., | |
| 45 http://domain.name/path/to/dir OR | |
| 46 /absolute/path/to/localdir (on Linux) OR | |
| 47 relative\path\to\localdir (on Windows) | |
| 48 json_filename: The JSON filename to read from within each directory. | |
| 49 gm_actuals_root_url: Base URL under which the actually-generated-by-bots | |
| 50 GM images are stored. | |
| 51 """ | |
| 52 self._actuals_base_url = actuals_base_url | |
| 53 self._json_filename = json_filename | |
| 54 self._gm_actuals_root_url = gm_actuals_root_url | |
| 55 self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN) | |
| 56 | |
| 57 def fetch(self, builder_name, dest_dir): | |
| 58 """ Downloads actual GM results for a particular builder. | |
| 59 | |
| 60 Args: | |
| 61 builder_name: which builder to download results of | |
| 62 dest_dir: path to directory where the image files will be written; | |
| 63 if the directory does not exist yet, it will be created | |
| 64 | |
| 65 TODO(epoger): Display progress info. Right now, it can take a long time | |
| 66 to download all of the results, and there is no indication of progress. | |
| 67 | |
| 68 TODO(epoger): Download multiple images in parallel to speed things up. | |
| 69 """ | |
| 70 json_url = url_or_path.join(self._actuals_base_url, builder_name, | |
| 71 self._json_filename) | |
| 72 json_contents = url_or_path.read_as_string(json_url) | |
| 73 results_dict = gm_json.LoadFromString(json_contents) | |
| 74 | |
| 75 actual_results_dict = results_dict[gm_json.JSONKEY_ACTUALRESULTS] | |
| 76 for result_type in sorted(actual_results_dict.keys()): | |
| 77 results_of_this_type = actual_results_dict[result_type] | |
| 78 if not results_of_this_type: | |
| 79 continue | |
| 80 for image_name in sorted(results_of_this_type.keys()): | |
| 81 (test, config) = self._image_filename_re.match(image_name).groups() | |
| 82 (hash_type, hash_digest) = results_of_this_type[image_name] | |
| 83 source_url = gm_json.CreateGmActualUrl( | |
| 84 test_name=test, hash_type=hash_type, hash_digest=hash_digest, | |
| 85 gm_actuals_root_url=self._gm_actuals_root_url) | |
| 86 dest_path = os.path.join(dest_dir, config, test + '.png') | |
| 87 url_or_path.copy_contents(source_path=source_url, dest_path=dest_path, | |
| 88 create_subdirs_if_needed=True) | |
| 89 | |
| 90 | |
| 91 def main(): | |
| 92 parser = optparse.OptionParser() | |
| 93 parser.add_option('--actuals-base-url', | |
| 94 action='store', type='string', | |
| 95 default=DEFAULT_ACTUALS_BASE_URL, | |
| 96 help=('Base URL from which to read files containing JSON ' | |
| 97 'summaries of actual GM results; defaults to ' | |
| 98 '"%default". To get a specific revision (useful for ' | |
| 99 'trybots) replace "svn" with "svn-history/r123".')) | |
| 100 parser.add_option('--builder', | |
| 101 action='store', type='string', | |
| 102 default=None, | |
| 103 help='REQUIRED: Which builder to download results for.') | |
| 104 parser.add_option('--dest-dir', | |
| 105 action='store', type='string', | |
| 106 default=None, | |
| 107 help=('REQUIRED: Directory where all images should be ' | |
| 108 'written. If this directory does not exist yet, it ' | |
| 109 'will be created.')) | |
| 110 parser.add_option('--json-filename', | |
| 111 action='store', type='string', | |
| 112 default=DEFAULT_JSON_FILENAME, | |
| 113 help=('JSON summary filename to read for each builder; ' | |
| 114 'defaults to "%default".')) | |
| 115 (params, remaining_args) = parser.parse_args() | |
| 116 | |
| 117 # Make sure all required options were set (no params should have value None), | |
| 118 # and that there were no items left over in the command line. | |
| 119 param_dict = vars(params) | |
| 120 for param_name, param_value in param_dict.items(): | |
| 121 if param_value is None: | |
| 122 raise Exception('required option \'%s\' was not set' % param_name) | |
| 123 if len(remaining_args) is not 0: | |
| 124 raise Exception('extra items specified in the command line: %s' % | |
| 125 remaining_args) | |
| 126 | |
| 127 downloader = Download(actuals_base_url=params.actuals_base_url) | |
| 128 downloader.fetch(builder_name=params.builder, | |
| 129 dest_dir=params.dest_dir) | |
| 130 | |
| 131 | |
| 132 | |
| 133 if __name__ == '__main__': | |
| 134 main() | |
| OLD | NEW |