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