blob: 9bad367c613f5fe086b08816002b00646c6d4437 [file] [log] [blame]
Dan Jacques2bcefd22015-05-18 14:57:00 -07001# Copyright 2015 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Show the builder layout for CrOS waterfalls."""
6
7from __future__ import print_function
8
9import json
10import sys
11
Don Garrettb44956b2015-06-05 17:28:06 -070012from chromite.cbuildbot import config_lib
Dan Jacques2bcefd22015-05-18 14:57:00 -070013from chromite.lib import commandline
14
15
16def _FormatText(data, out):
17 """Formatter function for text output."""
18 output = lambda *a: print(*a, file=out)
19
20 for waterfall in sorted(data.iterkeys()):
21 layout = data[waterfall]
22 if not layout:
23 continue
24
25 output('== %s ==' % (waterfall,))
26 for board in sorted(layout.iterkeys()):
27 board_layout = layout[board]
28 children = board_layout.get('children', ())
29 if not children:
30 output('%(name)s' % board_layout)
31 else:
32 output('[%(name)s]' % board_layout)
33 for child in sorted(board_layout.get('children', ())):
34 output(' %s' % (child,))
35 output()
36
37
38def _FormatJson(data, out):
39 """Formatter function for JSON output."""
40 json.dump(data, out, sort_keys=True)
41
42
43_FORMATTERS = {
44 'text': _FormatText,
45 'json': _FormatJson,
46}
47
48
49def _ParseArguments(argv):
50 parser = commandline.ArgumentParser(description=__doc__)
51
52 parser.add_argument('--format', default='text',
53 choices=sorted(_FORMATTERS.iterkeys()),
54 help='Choose output format.')
55 opts = parser.parse_args(argv)
56 opts.format = _FORMATTERS[opts.format]
57 opts.Freeze()
58 return opts
59
60
61def main(argv):
62 opts = _ParseArguments(argv)
63
Don Garrett737cadd2015-10-22 17:43:47 -070064 site_config = config_lib.GetConfig()
Don Garrettb44956b2015-06-05 17:28:06 -070065
Dan Jacques2bcefd22015-05-18 14:57:00 -070066 layout = {}
Don Garrettb44956b2015-06-05 17:28:06 -070067 for config_name, config in site_config.iteritems():
Dan Jacques2bcefd22015-05-18 14:57:00 -070068 active_waterfall = config['active_waterfall']
69 if not active_waterfall:
70 continue
71
72 waterfall_layout = layout.setdefault(active_waterfall, {})
73 board_layout = waterfall_layout[config_name] = {
74 'name': config_name,
75 }
76
77 children = config['child_configs']
78 if children:
79 board_layout['children'] = [c['name'] for c in children]
80 opts.format(layout, sys.stdout)