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