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 | |
30 from protobuf26 import text_format | 29 from protobuf26 import text_format |
31 | 30 |
32 def usage(more): | 31 def usage(more): |
33 def hook(fn): | 32 def hook(fn): |
34 fn.func_usage_more = more | 33 fn.func_usage_more = more |
35 return fn | 34 return fn |
36 return hook | 35 return hook |
37 | 36 |
38 | 37 |
39 def need_issue(fn): | 38 def need_issue(fn): |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 ' '.join(args)) | 180 ' '.join(args)) |
182 print json.dumps(get_master_builder_map( | 181 print json.dumps(get_master_builder_map( |
183 args[0], | 182 args[0], |
184 include_experimental=options.include_experimental, | 183 include_experimental=options.include_experimental, |
185 include_triggered=options.include_triggered)) | 184 include_triggered=options.include_triggered)) |
186 | 185 |
187 CMDbuilders.func_usage_more = '<path-to-cq-config>' | 186 CMDbuilders.func_usage_more = '<path-to-cq-config>' |
188 | 187 |
189 | 188 |
190 def CMDvalidate(parser, args): | 189 def CMDvalidate(parser, args): |
191 """Validates a CQ config. | 190 """Validates a CQ config, returns 0 on valid config. |
192 | 191 |
193 Takes a single argument - path to the CQ config to be validated. Returns 0 on | 192 BUGS: this doesn't do semantic validation, only verifies validity of protobuf. |
194 valid config, non-zero on invalid config. Errors and warnings are printed to | 193 But don't worry - bad cq.cfg won't cause outages, luci-config service will |
195 screen. | 194 not accept them, will send warning email, and continue using previous |
| 195 version. |
196 """ | 196 """ |
197 _, args = parser.parse_args(args) | 197 _, args = parser.parse_args(args) |
198 if len(args) != 1: | 198 if len(args) != 1: |
199 parser.error('Expected a single path to CQ config. Got: %s' % | 199 parser.error('Expected a single path to CQ config. Got: %s' % |
200 ' '.join(args)) | 200 ' '.join(args)) |
201 | 201 |
202 with open(args[0]) as config_file: | 202 config = cq_pb2.Config() |
203 cq_config = config_file.read() | 203 try: |
204 return 0 if validate_config.IsValid(cq_config) else 1 | 204 with open(args[0]) as config_file: |
| 205 text_config = config_file.read() |
| 206 text_format.Merge(text_config, config) |
| 207 # TODO(tandrii): provide an option to actually validate semantics of CQ |
| 208 # config. |
| 209 return 0 |
| 210 except text_format.ParseError as e: |
| 211 print 'failed to parse cq.cfg: %s' % e |
| 212 return 1 |
| 213 |
205 | 214 |
206 CMDvalidate.func_usage_more = '<path-to-cq-config>' | 215 CMDvalidate.func_usage_more = '<path-to-cq-config>' |
207 | 216 |
208 ############################################################################### | 217 ############################################################################### |
209 ## Boilerplate code | 218 ## Boilerplate code |
210 | 219 |
211 | 220 |
212 class OptionParser(optparse.OptionParser): | 221 class OptionParser(optparse.OptionParser): |
213 """An OptionParser instance with default options. | 222 """An OptionParser instance with default options. |
214 | 223 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 return CMDhelp(parser, args) | 294 return CMDhelp(parser, args) |
286 | 295 |
287 | 296 |
288 if __name__ == "__main__": | 297 if __name__ == "__main__": |
289 fix_encoding.fix_encoding() | 298 fix_encoding.fix_encoding() |
290 try: | 299 try: |
291 sys.exit(main()) | 300 sys.exit(main()) |
292 except KeyboardInterrupt: | 301 except KeyboardInterrupt: |
293 sys.stderr.write('interrupted\n') | 302 sys.stderr.write('interrupted\n') |
294 sys.exit(1) | 303 sys.exit(1) |
OLD | NEW |