Clear wallet data when sync is disabled.
[chromium-blink-merge.git] / testing / buildbot / manage.py
blobf3d57a94321bc3b4de2137121e87e72d10a279ad
1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium 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.
6 """Toolbox to manage all the json files in this directory.
8 It can reformat them in their canonical format or ensures they are well
9 formatted.
10 """
12 import argparse
13 import collections
14 import glob
15 import json
16 import os
17 import sys
20 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
21 sys.path.insert(
22 0, os.path.join(THIS_DIR, '..', '..', 'third_party', 'colorama', 'src'))
24 import colorama
26 # These are not 'builders'.
27 SKIP = {
28 'compile_targets', 'gtest_tests', 'filter_compile_builders',
29 'non_filter_builders', 'non_filter_tests_builders',
33 def upgrade_test(test):
34 """Converts from old style string to new style dict."""
35 if isinstance(test, basestring):
36 return {'test': test}
37 assert isinstance(test, dict)
38 return test
41 def main():
42 colorama.init()
43 parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__)
44 group = parser.add_mutually_exclusive_group(required=True)
45 group.add_argument(
46 '-c', '--check', action='store_true', help='Only check the files')
47 group.add_argument(
48 '--convert', action='store_true',
49 help='Convert a test to run on Swarming everywhere')
50 group.add_argument(
51 '--remaining', action='store_true',
52 help='Count the number of tests not yet running on Swarming')
53 group.add_argument(
54 '-w', '--write', action='store_true', help='Rewrite the files')
55 parser.add_argument(
56 'test_name', nargs='?',
57 help='The test name to print which configs to update; only to be used '
58 'with --remaining')
59 args = parser.parse_args()
61 if args.convert and not args.test_name:
62 parser.error('A test name is required with --convert')
64 # Stats when running in --remaining mode;
65 tests_location = collections.defaultdict(
66 lambda: {
67 'count_run_local': 0, 'count_run_on_swarming': 0, 'local_configs': {}
70 result = 0
71 for filepath in glob.glob(os.path.join(THIS_DIR, '*.json')):
72 filename = os.path.basename(filepath)
73 with open(filepath) as f:
74 content = f.read()
75 config = json.loads(content)
76 for builder, data in sorted(config.iteritems()):
77 if builder in SKIP:
78 # Oddities.
79 continue
81 if not isinstance(data, dict):
82 print('%s: %s is broken: %s' % (filename, builder, data))
83 continue
85 if 'gtest_tests' in data:
86 config[builder]['gtest_tests'] = sorted(
87 (upgrade_test(l) for l in data['gtest_tests']),
88 key=lambda x: x['test'])
90 if args.remaining:
91 for test in data['gtest_tests']:
92 name = test['test']
93 if test.get('swarming', {}).get('can_use_on_swarming_builders'):
94 tests_location[name]['count_run_on_swarming'] += 1
95 else:
96 tests_location[name]['count_run_local'] += 1
97 tests_location[name]['local_configs'].setdefault(
98 filename, []).append(builder)
99 elif args.convert:
100 for test in data['gtest_tests']:
101 if test['test'] != args.test_name:
102 continue
103 test.setdefault('swarming', {})['can_use_on_swarming_builders'] = (
104 True)
106 expected = json.dumps(
107 config, sort_keys=True, indent=2, separators=(',', ': ')) + '\n'
108 if content != expected:
109 result = 1
110 if args.write or args.convert:
111 with open(filepath, 'wb') as f:
112 f.write(expected)
113 print('Updated %s' % filename)
114 else:
115 print('%s is not in canonical format' % filename)
117 if args.remaining:
118 if args.test_name:
119 if args.test_name not in tests_location:
120 print('Unknown test %s' % args.test_name)
121 return 1
122 for config, builders in sorted(
123 tests_location[args.test_name]['local_configs'].iteritems()):
124 print('%s:' % config)
125 for builder in sorted(builders):
126 print(' %s' % builder)
127 else:
128 l = max(map(len, tests_location))
129 print('%-*s%sLocal %sSwarming' %
130 (l, 'Test', colorama.Fore.RED, colorama.Fore.GREEN))
131 total_local = 0
132 total_swarming = 0
133 for name, location in sorted(tests_location.iteritems()):
134 if not location['count_run_on_swarming']:
135 c = colorama.Fore.RED
136 elif location['count_run_local']:
137 c = colorama.Fore.YELLOW
138 else:
139 c = colorama.Fore.GREEN
140 total_local += location['count_run_local']
141 total_swarming += location['count_run_on_swarming']
142 print('%s%-*s %4d %4d' %
143 (c, l, name, location['count_run_local'],
144 location['count_run_on_swarming']))
145 total = total_local + total_swarming
146 p_local = 100. * total_local / total
147 p_swarming = 100. * total_swarming / total
148 print('%s%-*s %4d (%4.1f%%) %4d (%4.1f%%)' %
149 (colorama.Fore.WHITE, l, 'Total:', total_local, p_local,
150 total_swarming, p_swarming))
151 print('%-*s %4d' % (l, 'Total executions:', total))
152 return result
155 if __name__ == "__main__":
156 sys.exit(main())