| 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 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 return 0 | 97 return 0 |
| 98 _apply_on_issue(_get_commit, obj, issue) | 98 _apply_on_issue(_get_commit, obj, issue) |
| 99 | 99 |
| 100 def set_commit(obj, issue, flag): | 100 def set_commit(obj, issue, flag): |
| 101 """Sets the commit bit flag on an issue.""" | 101 """Sets the commit bit flag on an issue.""" |
| 102 def _set_commit(properties): | 102 def _set_commit(properties): |
| 103 print obj.set_flag(issue, properties['patchsets'][-1], 'commit', flag) | 103 print obj.set_flag(issue, properties['patchsets'][-1], 'commit', flag) |
| 104 return 0 | 104 return 0 |
| 105 _apply_on_issue(_set_commit, obj, issue) | 105 _apply_on_issue(_set_commit, obj, issue) |
| 106 | 106 |
| 107 |
| 108 def get_master_builder_map(config_path): |
| 109 """Returns a map of master -> [builders] from cq config.""" |
| 110 with open(config_path) as config_file: |
| 111 cq_config = config_file.read() |
| 112 |
| 113 config = cq_pb2.Config() |
| 114 text_format.Merge(cq_config, config) |
| 115 masters = {} |
| 116 if config.HasField('verifiers') and config.verifiers.HasField('try_job'): |
| 117 for bucket in config.verifiers.try_job.buckets: |
| 118 masters.setdefault(bucket.name, []) |
| 119 for builder in bucket.builders: |
| 120 if not builder.HasField('experiment_percentage'): |
| 121 masters[bucket.name].append(builder.name) |
| 122 return masters |
| 123 |
| 124 |
| 107 @need_issue | 125 @need_issue |
| 108 def CMDset(parser, args): | 126 def CMDset(parser, args): |
| 109 """Sets the commit bit.""" | 127 """Sets the commit bit.""" |
| 110 options, args, obj = parser.parse_args(args) | 128 options, args, obj = parser.parse_args(args) |
| 111 if args: | 129 if args: |
| 112 parser.error('Unrecognized args: %s' % ' '.join(args)) | 130 parser.error('Unrecognized args: %s' % ' '.join(args)) |
| 113 return set_commit(obj, options.issue, '1') | 131 return set_commit(obj, options.issue, '1') |
| 114 | 132 |
| 115 @need_issue | 133 @need_issue |
| 116 def CMDget(parser, args): | 134 def CMDget(parser, args): |
| (...skipping 23 matching lines...) Expand all Loading... |
| 140 ], | 158 ], |
| 141 'another_master': [ | 159 'another_master': [ |
| 142 'third_builder' | 160 'third_builder' |
| 143 ] | 161 ] |
| 144 } | 162 } |
| 145 """ | 163 """ |
| 146 _, args = parser.parse_args(args) | 164 _, args = parser.parse_args(args) |
| 147 if len(args) != 1: | 165 if len(args) != 1: |
| 148 parser.error('Expected a single path to CQ config. Got: %s' % | 166 parser.error('Expected a single path to CQ config. Got: %s' % |
| 149 ' '.join(args)) | 167 ' '.join(args)) |
| 150 | 168 print json.dumps(get_master_builder_map(args[0])) |
| 151 with open(args[0]) as config_file: | |
| 152 cq_config = config_file.read() | |
| 153 | |
| 154 config = cq_pb2.Config() | |
| 155 text_format.Merge(cq_config, config) | |
| 156 masters = {} | |
| 157 if config.HasField('verifiers') and config.verifiers.HasField('try_job'): | |
| 158 for bucket in config.verifiers.try_job.buckets: | |
| 159 masters.setdefault(bucket.name, []) | |
| 160 for builder in bucket.builders: | |
| 161 if not builder.HasField('experiment_percentage'): | |
| 162 masters[bucket.name].append(builder.name) | |
| 163 print json.dumps(masters) | |
| 164 | 169 |
| 165 CMDbuilders.func_usage_more = '<path-to-cq-config>' | 170 CMDbuilders.func_usage_more = '<path-to-cq-config>' |
| 166 | 171 |
| 167 | 172 |
| 168 def CMDvalidate(parser, args): | 173 def CMDvalidate(parser, args): |
| 169 """Validates a CQ config. | 174 """Validates a CQ config. |
| 170 | 175 |
| 171 Takes a single argument - path to the CQ config to be validated. Returns 0 on | 176 Takes a single argument - path to the CQ config to be validated. Returns 0 on |
| 172 valid config, non-zero on invalid config. Errors and warnings are printed to | 177 valid config, non-zero on invalid config. Errors and warnings are printed to |
| 173 screen. | 178 screen. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 return CMDhelp(parser, args) | 268 return CMDhelp(parser, args) |
| 264 | 269 |
| 265 | 270 |
| 266 if __name__ == "__main__": | 271 if __name__ == "__main__": |
| 267 fix_encoding.fix_encoding() | 272 fix_encoding.fix_encoding() |
| 268 try: | 273 try: |
| 269 sys.exit(main()) | 274 sys.exit(main()) |
| 270 except KeyboardInterrupt: | 275 except KeyboardInterrupt: |
| 271 sys.stderr.write('interrupted\n') | 276 sys.stderr.write('interrupted\n') |
| 272 sys.exit(1) | 277 sys.exit(1) |
| OLD | NEW |