OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 """Fetches the tree status from a json url and returns the message | 2201 """Fetches the tree status from a json url and returns the message |
2202 with the reason for the tree to be opened or closed.""" | 2202 with the reason for the tree to be opened or closed.""" |
2203 url = settings.GetTreeStatusUrl() | 2203 url = settings.GetTreeStatusUrl() |
2204 json_url = urlparse.urljoin(url, '/current?format=json') | 2204 json_url = urlparse.urljoin(url, '/current?format=json') |
2205 connection = urllib2.urlopen(json_url) | 2205 connection = urllib2.urlopen(json_url) |
2206 status = json.loads(connection.read()) | 2206 status = json.loads(connection.read()) |
2207 connection.close() | 2207 connection.close() |
2208 return status['message'] | 2208 return status['message'] |
2209 | 2209 |
2210 | 2210 |
| 2211 def GetBuilderMaster(bot_list): |
| 2212 """For a given builder, fetch the master from AE if available.""" |
| 2213 map_url = 'https://builders-map.appspot.com/' |
| 2214 try: |
| 2215 master_map = json.load(urllib2.urlopen(map_url)) |
| 2216 except urllib2.URLError as e: |
| 2217 return None, ('Failed to fetch builder-to-master map from %s. Error: %s.' % |
| 2218 (map_url, e)) |
| 2219 except ValueError as e: |
| 2220 return None, ('Invalid json string from %s. Error: %s.' % (map_url, e)) |
| 2221 if not master_map: |
| 2222 return None, 'Failed to build master map.' |
| 2223 |
| 2224 result_master = '' |
| 2225 for bot in bot_list: |
| 2226 builder = bot.split(':', 1)[0] |
| 2227 master_list = master_map.get(builder, []) |
| 2228 if not master_list: |
| 2229 return None, ('No matching master for builder %s.' % builder) |
| 2230 elif len(master_list) > 1: |
| 2231 return None, ('The builder name %s exists in multiple masters %s.' % |
| 2232 (builder, master_list)) |
| 2233 else: |
| 2234 cur_master = master_list[0] |
| 2235 if not result_master: |
| 2236 result_master = cur_master |
| 2237 elif result_master != cur_master: |
| 2238 return None, 'The builders do not belong to the same master.' |
| 2239 return result_master, None |
| 2240 |
| 2241 |
2211 def CMDtree(parser, args): | 2242 def CMDtree(parser, args): |
2212 """Shows the status of the tree.""" | 2243 """Shows the status of the tree.""" |
2213 _, args = parser.parse_args(args) | 2244 _, args = parser.parse_args(args) |
2214 status = GetTreeStatus() | 2245 status = GetTreeStatus() |
2215 if 'unset' == status: | 2246 if 'unset' == status: |
2216 print 'You must configure your tree status URL by running "git cl config".' | 2247 print 'You must configure your tree status URL by running "git cl config".' |
2217 return 2 | 2248 return 2 |
2218 | 2249 |
2219 print "The tree is %s" % status | 2250 print "The tree is %s" % status |
2220 print | 2251 print |
2221 print GetTreeStatusReason() | 2252 print GetTreeStatusReason() |
2222 if status != 'open': | 2253 if status != 'open': |
2223 return 1 | 2254 return 1 |
2224 return 0 | 2255 return 0 |
2225 | 2256 |
2226 | 2257 |
2227 def CMDtry(parser, args): | 2258 def CMDtry(parser, args): |
2228 """Triggers a try job through Rietveld.""" | 2259 """Triggers a try job through Rietveld.""" |
2229 group = optparse.OptionGroup(parser, "Try job options") | 2260 group = optparse.OptionGroup(parser, "Try job options") |
2230 group.add_option( | 2261 group.add_option( |
2231 "-b", "--bot", action="append", | 2262 "-b", "--bot", action="append", |
2232 help=("IMPORTANT: specify ONE builder per --bot flag. Use it multiple " | 2263 help=("IMPORTANT: specify ONE builder per --bot flag. Use it multiple " |
2233 "times to specify multiple builders. ex: " | 2264 "times to specify multiple builders. ex: " |
2234 "'-bwin_rel:ui_tests,webkit_unit_tests -bwin_layout'. See " | 2265 "'-b win_rel:ui_tests,webkit_unit_tests -b win_layout'. See " |
2235 "the try server waterfall for the builders name and the tests " | 2266 "the try server waterfall for the builders name and the tests " |
2236 "available. Can also be used to specify gtest_filter, e.g. " | 2267 "available. Can also be used to specify gtest_filter, e.g. " |
2237 "-bwin_rel:base_unittests:ValuesTest.*Value")) | 2268 "-b win_rel:base_unittests:ValuesTest.*Value")) |
2238 group.add_option( | 2269 group.add_option( |
2239 "-m", "--master", default='', | 2270 "-m", "--master", default='', |
2240 help=("Specify a try master where to run the tries.")) | 2271 help=("Specify a try master where to run the tries.")) |
2241 group.add_option( | 2272 group.add_option( |
2242 "-r", "--revision", | 2273 "-r", "--revision", |
2243 help="Revision to use for the try job; default: the " | 2274 help="Revision to use for the try job; default: the " |
2244 "revision will be determined by the try server; see " | 2275 "revision will be determined by the try server; see " |
2245 "its waterfall for more info") | 2276 "its waterfall for more info") |
2246 group.add_option( | 2277 group.add_option( |
2247 "-c", "--clobber", action="store_true", default=False, | 2278 "-c", "--clobber", action="store_true", default=False, |
(...skipping 21 matching lines...) Expand all Loading... |
2269 parser.error('Need to upload first') | 2300 parser.error('Need to upload first') |
2270 | 2301 |
2271 props = cl.GetIssueProperties() | 2302 props = cl.GetIssueProperties() |
2272 if props.get('private'): | 2303 if props.get('private'): |
2273 parser.error('Cannot use trybots with private issue') | 2304 parser.error('Cannot use trybots with private issue') |
2274 | 2305 |
2275 if not options.name: | 2306 if not options.name: |
2276 options.name = cl.GetBranch() | 2307 options.name = cl.GetBranch() |
2277 | 2308 |
2278 if options.bot and not options.master: | 2309 if options.bot and not options.master: |
2279 parser.error('For manually specified bots please also specify the ' | 2310 options.master, err_msg = GetBuilderMaster(options.bot) |
2280 'tryserver master, e.g. "-m tryserver.chromium.linux".') | 2311 if err_msg: |
| 2312 parser.error('Tryserver master cannot be found because: %s\n' |
| 2313 'Please manually specify the tryserver master' |
| 2314 ', e.g. "-m tryserver.chromium.linux".' % err_msg) |
2281 | 2315 |
2282 def GetMasterMap(): | 2316 def GetMasterMap(): |
2283 # Process --bot and --testfilter. | 2317 # Process --bot and --testfilter. |
2284 if not options.bot: | 2318 if not options.bot: |
2285 change = cl.GetChange(cl.GetCommonAncestorWithUpstream(), None) | 2319 change = cl.GetChange(cl.GetCommonAncestorWithUpstream(), None) |
2286 | 2320 |
2287 # Get try masters from PRESUBMIT.py files. | 2321 # Get try masters from PRESUBMIT.py files. |
2288 masters = presubmit_support.DoGetTryMasters( | 2322 masters = presubmit_support.DoGetTryMasters( |
2289 change, | 2323 change, |
2290 change.LocalPaths(), | 2324 change.LocalPaths(), |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2633 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2667 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
2634 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2668 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
2635 | 2669 |
2636 | 2670 |
2637 if __name__ == '__main__': | 2671 if __name__ == '__main__': |
2638 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2672 # These affect sys.stdout so do it outside of main() to simplify mocks in |
2639 # unit testing. | 2673 # unit testing. |
2640 fix_encoding.fix_encoding() | 2674 fix_encoding.fix_encoding() |
2641 colorama.init() | 2675 colorama.init() |
2642 sys.exit(main(sys.argv[1:])) | 2676 sys.exit(main(sys.argv[1:])) |
OLD | NEW |