| 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 logging | 13 import logging |
| 13 import optparse | 14 import optparse |
| 14 import os | 15 import os |
| 15 import sys | 16 import sys |
| 16 import urllib2 | 17 import urllib2 |
| 17 | 18 |
| 18 import breakpad # pylint: disable=W0611 | 19 import breakpad # pylint: disable=W0611 |
| 19 | 20 |
| 20 import auth | 21 import auth |
| 21 import fix_encoding | 22 import fix_encoding |
| 22 import rietveld | 23 import rietveld |
| 23 | 24 |
| 25 THIRD_PARTY_DIR = os.path.join(os.path.dirname(__file__), 'third_party') |
| 26 sys.path.append(THIRD_PARTY_DIR) |
| 27 |
| 28 from cq_client import cq_pb2 |
| 29 from google.protobuf import text_format |
| 24 | 30 |
| 25 def usage(more): | 31 def usage(more): |
| 26 def hook(fn): | 32 def hook(fn): |
| 27 fn.func_usage_more = more | 33 fn.func_usage_more = more |
| 28 return fn | 34 return fn |
| 29 return hook | 35 return hook |
| 30 | 36 |
| 31 | 37 |
| 32 def need_issue(fn): | 38 def need_issue(fn): |
| 33 """Post-parse args to create a Rietveld object.""" | 39 """Post-parse args to create a Rietveld object.""" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 101 |
| 96 @need_issue | 102 @need_issue |
| 97 def CMDclear(parser, args): | 103 def CMDclear(parser, args): |
| 98 """Clears the commit bit.""" | 104 """Clears the commit bit.""" |
| 99 options, args, obj = parser.parse_args(args) | 105 options, args, obj = parser.parse_args(args) |
| 100 if args: | 106 if args: |
| 101 parser.error('Unrecognized args: %s' % ' '.join(args)) | 107 parser.error('Unrecognized args: %s' % ' '.join(args)) |
| 102 return set_commit(obj, options.issue, '0') | 108 return set_commit(obj, options.issue, '0') |
| 103 | 109 |
| 104 | 110 |
| 111 def CMDbuilders(parser, args): |
| 112 """Prints json-formatted list of builders given a path to cq.cfg file. |
| 113 |
| 114 The output is a dictionary in the following format: |
| 115 { |
| 116 'master_name': { |
| 117 'builder_name': { |
| 118 'custom_property': 'value', |
| 119 'testfilter': 'compile' |
| 120 }, |
| 121 'another_builder': {} |
| 122 }, |
| 123 'another_master': { |
| 124 'third_builder': {} |
| 125 } |
| 126 } |
| 127 """ |
| 128 _, args = parser.parse_args(args) |
| 129 if len(args) != 1: |
| 130 parser.error('Expected a single path to CQ config. Got: %s' % |
| 131 ' '.join(args)) |
| 132 |
| 133 with open(args[0]) as config_file: |
| 134 cq_config = config_file.read() |
| 135 |
| 136 config = cq_pb2.Config() |
| 137 text_format.Merge(cq_config, config) |
| 138 masters = {} |
| 139 if config.HasField('verifiers') and config.verifiers.HasField('try_job'): |
| 140 for bucket in config.verifiers.try_job.buckets: |
| 141 masters.setdefault(bucket.name, {}) |
| 142 for builder in bucket.builders: |
| 143 if not builder.HasField('experiment_percentage'): |
| 144 masters[bucket.name].setdefault(builder.name, {}) |
| 145 for prop in builder.properties: |
| 146 masters[bucket.name][builder.name][prop.name] = prop.value |
| 147 print json.dumps(masters) |
| 148 |
| 149 CMDbuilders.func_usage_more = '<path-to-cq-config>' |
| 150 |
| 105 ############################################################################### | 151 ############################################################################### |
| 106 ## Boilerplate code | 152 ## Boilerplate code |
| 107 | 153 |
| 108 | 154 |
| 109 class OptionParser(optparse.OptionParser): | 155 class OptionParser(optparse.OptionParser): |
| 110 """An OptionParser instance with default options. | 156 """An OptionParser instance with default options. |
| 111 | 157 |
| 112 It should be then processed with gen_usage() before being used. | 158 It should be then processed with gen_usage() before being used. |
| 113 """ | 159 """ |
| 114 def __init__(self, *args, **kwargs): | 160 def __init__(self, *args, **kwargs): |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return CMDhelp(parser, args) | 228 return CMDhelp(parser, args) |
| 183 | 229 |
| 184 | 230 |
| 185 if __name__ == "__main__": | 231 if __name__ == "__main__": |
| 186 fix_encoding.fix_encoding() | 232 fix_encoding.fix_encoding() |
| 187 try: | 233 try: |
| 188 sys.exit(main()) | 234 sys.exit(main()) |
| 189 except KeyboardInterrupt: | 235 except KeyboardInterrupt: |
| 190 sys.stderr.write('interrupted\n') | 236 sys.stderr.write('interrupted\n') |
| 191 sys.exit(1) | 237 sys.exit(1) |
| OLD | NEW |