OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Access the commit queue from the command line. | 6 """Access the commit queue from the command line. |
7 """ | 7 """ |
8 | 8 |
9 __version__ = '0.1' | 9 __version__ = '0.1' |
10 | 10 |
11 import functools | 11 import functools |
12 import json | 12 import json |
13 import logging | 13 import logging |
14 import optparse | 14 import optparse |
15 import os | 15 import os |
16 import sys | 16 import sys |
17 import urllib2 | 17 import urllib2 |
18 | 18 |
19 import breakpad # pylint: disable=W0611 | 19 import breakpad # pylint: disable=W0611 |
20 | 20 |
21 import auth | 21 import auth |
22 import fix_encoding | 22 import fix_encoding |
23 import rietveld | 23 import rietveld |
24 | 24 |
25 THIRD_PARTY_DIR = os.path.join(os.path.dirname(__file__), 'third_party') | 25 THIRD_PARTY_DIR = os.path.join(os.path.dirname(__file__), 'third_party') |
26 sys.path.insert(0, THIRD_PARTY_DIR) | 26 sys.path.insert(0, THIRD_PARTY_DIR) |
27 | 27 |
28 from cq_client import cq_pb2 | 28 from cq_client import cq_pb2 |
| 29 from cq_client import validate_config |
29 from protobuf26 import text_format | 30 from protobuf26 import text_format |
30 | 31 |
31 def usage(more): | 32 def usage(more): |
32 def hook(fn): | 33 def hook(fn): |
33 fn.func_usage_more = more | 34 fn.func_usage_more = more |
34 return fn | 35 return fn |
35 return hook | 36 return hook |
36 | 37 |
37 | 38 |
38 def need_issue(fn): | 39 def need_issue(fn): |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 if config.HasField('verifiers') and config.verifiers.HasField('try_job'): | 137 if config.HasField('verifiers') and config.verifiers.HasField('try_job'): |
137 for bucket in config.verifiers.try_job.buckets: | 138 for bucket in config.verifiers.try_job.buckets: |
138 masters.setdefault(bucket.name, []) | 139 masters.setdefault(bucket.name, []) |
139 for builder in bucket.builders: | 140 for builder in bucket.builders: |
140 if not builder.HasField('experiment_percentage'): | 141 if not builder.HasField('experiment_percentage'): |
141 masters[bucket.name].append(builder.name) | 142 masters[bucket.name].append(builder.name) |
142 print json.dumps(masters) | 143 print json.dumps(masters) |
143 | 144 |
144 CMDbuilders.func_usage_more = '<path-to-cq-config>' | 145 CMDbuilders.func_usage_more = '<path-to-cq-config>' |
145 | 146 |
| 147 |
| 148 def CMDvalidate(parser, args): |
| 149 """Validates a CQ config. |
| 150 |
| 151 Takes a single argument - path to the CQ config to be validated. Returns 0 on |
| 152 valid config, non-zero on invalid config. Errors and warnings are printed to |
| 153 screen. |
| 154 """ |
| 155 _, args = parser.parse_args(args) |
| 156 if len(args) != 1: |
| 157 parser.error('Expected a single path to CQ config. Got: %s' % |
| 158 ' '.join(args)) |
| 159 |
| 160 with open(args[0]) as config_file: |
| 161 cq_config = config_file.read() |
| 162 return validate_config.validate(cq_config) |
| 163 |
| 164 CMDvalidate.func_usage_more = '<path-to-cq-config>' |
| 165 |
146 ############################################################################### | 166 ############################################################################### |
147 ## Boilerplate code | 167 ## Boilerplate code |
148 | 168 |
149 | 169 |
150 class OptionParser(optparse.OptionParser): | 170 class OptionParser(optparse.OptionParser): |
151 """An OptionParser instance with default options. | 171 """An OptionParser instance with default options. |
152 | 172 |
153 It should be then processed with gen_usage() before being used. | 173 It should be then processed with gen_usage() before being used. |
154 """ | 174 """ |
155 def __init__(self, *args, **kwargs): | 175 def __init__(self, *args, **kwargs): |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 return CMDhelp(parser, args) | 243 return CMDhelp(parser, args) |
224 | 244 |
225 | 245 |
226 if __name__ == "__main__": | 246 if __name__ == "__main__": |
227 fix_encoding.fix_encoding() | 247 fix_encoding.fix_encoding() |
228 try: | 248 try: |
229 sys.exit(main()) | 249 sys.exit(main()) |
230 except KeyboardInterrupt: | 250 except KeyboardInterrupt: |
231 sys.stderr.write('interrupted\n') | 251 sys.stderr.write('interrupted\n') |
232 sys.exit(1) | 252 sys.exit(1) |
OLD | NEW |