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 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' | |
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 '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.
| |
105 DEFAULT_ACTUALS_BASE_URL)) | |
106 parser.add_option('--dest-dir', | |
107 action='store', type='string', | |
108 default=None, | |
109 help=('REQUIRED: Directory where all images should be ' | |
110 'written. If this directory does not exist yet, it ' | |
111 'will be created.')) | |
112 parser.add_option('--json-filename', | |
113 action='store', type='string', | |
114 default=DEFAULT_JSON_FILENAME, | |
115 help=('JSON summary filename to read for each builder; ' | |
116 'defaults to "%default".')) | |
117 (params, remaining_args) = parser.parse_args() | |
118 | |
119 # Make sure all required options were set (no params should have value None), | |
120 # and that there were no items left over in the command line. | |
121 param_dict = vars(params) | |
122 for param_name, param_value in param_dict.items(): | |
123 if param_value is None: | |
124 raise Exception('required option \'%s\' was not set' % param_name) | |
125 if len(remaining_args) is not 0: | |
126 raise Exception('extra items specified in the command line: %s' % | |
127 remaining_args) | |
128 | |
129 downloader = Download(actuals_base_url=params.actuals_base_url) | |
130 downloader.fetch(builder_name=params.builder, | |
131 dest_dir=params.dest_dir) | |
132 | |
133 | |
134 | |
135 if __name__ == '__main__': | |
136 main() | |
OLD | NEW |