ojan@chromium.org | 7cb9d15 | 2012-11-20 19:58:45 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 | # |
| 4 | # Redistribution and use in source and binary forms, with or without |
| 5 | # modification, are permitted provided that the following conditions are |
| 6 | # met: |
| 7 | # |
| 8 | # * Redistributions of source code must retain the above copyright |
| 9 | # notice, this list of conditions and the following disclaimer. |
| 10 | # * Redistributions in binary form must reproduce the above |
| 11 | # copyright notice, this list of conditions and the following disclaimer |
| 12 | # in the documentation and/or other materials provided with the |
| 13 | # distribution. |
| 14 | # * Neither the name of Google Inc. nor the names of its |
| 15 | # contributors may be used to endorse or promote products derived from |
| 16 | # this software without specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | import json |
| 31 | import logging |
| 32 | import optparse |
| 33 | import os |
| 34 | import urllib2 |
| 35 | |
| 36 | # FIXME: See if Tools/Scripts/webkitpy/layout_tests/port/builders.py should also read |
| 37 | # the output json file here as its data source. |
| 38 | |
| 39 | |
| 40 | def master_json_url(master_url): |
| 41 | return master_url + '/json/builders' |
| 42 | |
| 43 | |
| 44 | def builder_json_url(master_url, builder): |
| 45 | return master_json_url(master_url) + '/' + urllib2.quote(builder) |
| 46 | |
| 47 | |
| 48 | def cached_build_json_url(master_url, builder, build_number): |
| 49 | return builder_json_url(master_url, builder) + '/builds/' + str(build_number) |
| 50 | |
| 51 | |
| 52 | def fetch_json(url): |
| 53 | logging.debug('Fetching %s' % url) |
| 54 | return json.load(urllib2.urlopen(url)) |
| 55 | |
| 56 | |
| 57 | def insert_builder_and_test_data(masters): |
| 58 | for master in masters: |
| 59 | master_url = master['url'] |
| 60 | tests_object = {} |
| 61 | master['tests'] = tests_object |
| 62 | |
| 63 | for builder in fetch_json(master_json_url(master_url)): |
| 64 | build_data = fetch_json(builder_json_url(master_url, builder)) |
| 65 | cached_builds = build_data['cachedBuilds'] |
| 66 | current_builds = build_data['currentBuilds'] |
| 67 | |
| 68 | latest_cached_build = cached_builds.pop() |
| 69 | while latest_cached_build in current_builds and len(cached_builds): |
| 70 | latest_cached_build = cached_builds.pop() |
| 71 | |
| 72 | for step in fetch_json(cached_build_json_url(master_url, builder, latest_cached_build))['steps']: |
| 73 | step_name = step['name'] |
zandobersek@gmail.com | 99123c5 | 2013-05-06 17:55:57 +0000 | [diff] [blame] | 74 | if step_name != 'layout-test': |
ojan@chromium.org | 7cb9d15 | 2012-11-20 19:58:45 +0000 | [diff] [blame] | 75 | continue |
| 76 | |
zandobersek@gmail.com | 99123c5 | 2013-05-06 17:55:57 +0000 | [diff] [blame] | 77 | # Adjust for backwards compatibility |
| 78 | step_name = 'layout-tests' |
| 79 | |
ojan@chromium.org | 7cb9d15 | 2012-11-20 19:58:45 +0000 | [diff] [blame] | 80 | if step_name not in tests_object: |
| 81 | tests_object[step_name] = {'builders': []} |
| 82 | tests_object[step_name]['builders'].append(builder) |
| 83 | |
| 84 | for step_name in tests_object: |
| 85 | tests_object[step_name]['builders'].sort() |
| 86 | |
| 87 | |
| 88 | def main(): |
| 89 | option_parser = optparse.OptionParser() |
| 90 | option_parser.add_option('-v', '--verbose', action='store_true', default=False, help='Print debug logging') |
| 91 | options, args = option_parser.parse_args() |
| 92 | |
| 93 | logging.getLogger().setLevel(logging.DEBUG if options.verbose else logging.INFO) |
| 94 | |
| 95 | masters = [ |
ojan@chromium.org | 7cb9d15 | 2012-11-20 19:58:45 +0000 | [diff] [blame] | 96 | {'name': 'webkit.org', 'url': 'http://build.webkit.org'}, |
| 97 | ] |
| 98 | |
| 99 | insert_builder_and_test_data(masters) |
| 100 | |
| 101 | json_file_prefix = ('// This file is auto-generated by Tools/TestResultServer/generate_builders_json.py. It should not be manually modified.\n' |
zandobersek@gmail.com | 99123c5 | 2013-05-06 17:55:57 +0000 | [diff] [blame] | 102 | '// It uses jsonp instead of proper json because we want to be able to load it from a file URL for local testing.\n' |
ojan@chromium.org | 7cb9d15 | 2012-11-20 19:58:45 +0000 | [diff] [blame] | 103 | 'LOAD_BUILDBOT_DATA(') |
| 104 | json_file_suffix = ');\n'; |
| 105 | |
| 106 | json_file = open(os.path.join('static-dashboards', 'builders.jsonp'), 'w') |
| 107 | json_file.write(json_file_prefix + json.dumps(masters, separators=(', ', ': '), indent=4, sort_keys=True) + json_file_suffix) |
| 108 | |
| 109 | |
| 110 | if __name__ == "__main__": |
| 111 | main() |