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 2188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2199 | 2199 |
2200 def GetTreeStatusReason(): | 2200 def GetTreeStatusReason(): |
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 |
M-A Ruel
2014/08/14 18:42:02
2 lines
sheyang
2014/08/14 19:50:22
Done.
| |
2210 def GetBuilderMaster(bot_list): | |
2211 """For a given builder, fetch the master from AE if available.""" | |
2212 err_msg = '' | |
2213 master_map = None | |
2214 result_master = '' | |
2215 map_url = 'https://builders-map.appspot.com/' | |
2216 try: | |
2217 res = urllib2.urlopen(map_url) | |
2218 master_map = json.load(res) | |
M-A Ruel
2014/08/14 18:42:02
master_map = json.load(urllib2.urlopen(map_url))
sheyang
2014/08/14 19:50:24
Done.
| |
2219 except urllib2.URLError as url_e: | |
M-A Ruel
2014/08/14 18:42:02
s/url_e/e/
sheyang
2014/08/14 19:50:22
Done.
| |
2220 err_msg = ('Failed to fetch builder-to-master map from %s. Error: %s.' % | |
M-A Ruel
2014/08/14 18:42:02
Why not return right away?
sheyang
2014/08/14 19:50:22
Done.
| |
2221 (map_url, url_e)) | |
2222 except ValueError as val_e: | |
M-A Ruel
2014/08/14 18:42:02
s/val_e/e/
sheyang
2014/08/14 19:50:22
Done.
sheyang
2014/08/14 19:50:24
Done.
| |
2223 err_msg = 'Invalid json string from %s. Error: %s.' % (map_url, val_e) | |
2224 | |
2225 if master_map: | |
M-A Ruel
2014/08/14 18:42:02
if not master_map:
return None, err_msg
sheyang
2014/08/14 19:50:24
Done.
| |
2226 for bot in bot_list: | |
2227 if ':' in bot: | |
2228 builder, _ = bot.split(':', 1) | |
M-A Ruel
2014/08/14 18:42:02
builder = bot.split(':', 1)[0]
Remove line 2227,
sheyang
2014/08/14 19:50:22
Removed.
| |
2229 else: | |
2230 builder = bot | |
2231 master_list = master_map.get(builder, []) | |
2232 if not master_list: | |
2233 err_msg = 'Cannot find a master for builder %s.' % builder | |
M-A Ruel
2014/08/14 18:42:02
It'd likely be simpler to return right away.
sheyang
2014/08/14 19:50:22
Done.
| |
2234 break | |
2235 elif len(master_list) > 1: | |
2236 err_msg = ('The builder name %s exists in multiple masters %s.' % | |
M-A Ruel
2014/08/14 18:42:02
Same
sheyang
2014/08/14 19:50:22
Done.
| |
2237 (builder, master_list)) | |
2238 break | |
2239 else: | |
2240 cur_master = master_list[0] | |
2241 if not result_master: | |
2242 result_master = cur_master | |
2243 elif result_master != cur_master: | |
2244 err_msg = 'The builders do not belong to the same master.' | |
2245 result_master = '' | |
M-A Ruel
2014/08/14 18:42:02
Return
sheyang
2014/08/14 19:50:24
Done.
| |
2246 break | |
2247 return result_master, err_msg | |
2210 | 2248 |
M-A Ruel
2014/08/14 18:42:02
2 lines
sheyang
2014/08/14 19:50:24
Done.
| |
2211 def CMDtree(parser, args): | 2249 def CMDtree(parser, args): |
2212 """Shows the status of the tree.""" | 2250 """Shows the status of the tree.""" |
2213 _, args = parser.parse_args(args) | 2251 _, args = parser.parse_args(args) |
2214 status = GetTreeStatus() | 2252 status = GetTreeStatus() |
2215 if 'unset' == status: | 2253 if 'unset' == status: |
2216 print 'You must configure your tree status URL by running "git cl config".' | 2254 print 'You must configure your tree status URL by running "git cl config".' |
2217 return 2 | 2255 return 2 |
2218 | 2256 |
2219 print "The tree is %s" % status | 2257 print "The tree is %s" % status |
2220 print | 2258 print |
2221 print GetTreeStatusReason() | 2259 print GetTreeStatusReason() |
2222 if status != 'open': | 2260 if status != 'open': |
2223 return 1 | 2261 return 1 |
2224 return 0 | 2262 return 0 |
2225 | 2263 |
2226 | 2264 |
2227 def CMDtry(parser, args): | 2265 def CMDtry(parser, args): |
2228 """Triggers a try job through Rietveld.""" | 2266 """Triggers a try job through Rietveld.""" |
2229 group = optparse.OptionGroup(parser, "Try job options") | 2267 group = optparse.OptionGroup(parser, "Try job options") |
2230 group.add_option( | 2268 group.add_option( |
2231 "-b", "--bot", action="append", | 2269 "-b", "--bot", action="append", |
2232 help=("IMPORTANT: specify ONE builder per --bot flag. Use it multiple " | 2270 help=("IMPORTANT: specify ONE builder per --bot flag. Use it multiple " |
2233 "times to specify multiple builders. ex: " | 2271 "times to specify multiple builders. ex: " |
2234 "'-bwin_rel:ui_tests,webkit_unit_tests -bwin_layout'. See " | 2272 "'-b win_rel:ui_tests,webkit_unit_tests -b win_layout'. See " |
2235 "the try server waterfall for the builders name and the tests " | 2273 "the try server waterfall for the builders name and the tests " |
2236 "available. Can also be used to specify gtest_filter, e.g. " | 2274 "available. Can also be used to specify gtest_filter, e.g. " |
2237 "-bwin_rel:base_unittests:ValuesTest.*Value")) | 2275 "-b win_rel:base_unittests:ValuesTest.*Value")) |
2238 group.add_option( | 2276 group.add_option( |
2239 "-m", "--master", default='', | 2277 "-m", "--master", default='', |
2240 help=("Specify a try master where to run the tries.")) | 2278 help=("Specify a try master where to run the tries.")) |
2241 group.add_option( | 2279 group.add_option( |
2242 "-r", "--revision", | 2280 "-r", "--revision", |
2243 help="Revision to use for the try job; default: the " | 2281 help="Revision to use for the try job; default: the " |
2244 "revision will be determined by the try server; see " | 2282 "revision will be determined by the try server; see " |
2245 "its waterfall for more info") | 2283 "its waterfall for more info") |
2246 group.add_option( | 2284 group.add_option( |
2247 "-c", "--clobber", action="store_true", default=False, | 2285 "-c", "--clobber", action="store_true", default=False, |
(...skipping 21 matching lines...) Expand all Loading... | |
2269 parser.error('Need to upload first') | 2307 parser.error('Need to upload first') |
2270 | 2308 |
2271 props = cl.GetIssueProperties() | 2309 props = cl.GetIssueProperties() |
2272 if props.get('private'): | 2310 if props.get('private'): |
2273 parser.error('Cannot use trybots with private issue') | 2311 parser.error('Cannot use trybots with private issue') |
2274 | 2312 |
2275 if not options.name: | 2313 if not options.name: |
2276 options.name = cl.GetBranch() | 2314 options.name = cl.GetBranch() |
2277 | 2315 |
2278 if options.bot and not options.master: | 2316 if options.bot and not options.master: |
2279 parser.error('For manually specified bots please also specify the ' | 2317 options.master, err_msg = GetBuilderMaster(options.bot) |
2280 'tryserver master, e.g. "-m tryserver.chromium.linux".') | 2318 if err_msg: |
2319 parser.error('Tryserver master cannot be found because: %s\n' | |
2320 'Please manually specify the tryserver master' | |
2321 ', e.g. "-m tryserver.chromium.linux".' % err_msg) | |
2281 | 2322 |
2282 def GetMasterMap(): | 2323 def GetMasterMap(): |
2283 # Process --bot and --testfilter. | 2324 # Process --bot and --testfilter. |
2284 if not options.bot: | 2325 if not options.bot: |
2285 change = cl.GetChange(cl.GetCommonAncestorWithUpstream(), None) | 2326 change = cl.GetChange(cl.GetCommonAncestorWithUpstream(), None) |
2286 | 2327 |
2287 # Get try masters from PRESUBMIT.py files. | 2328 # Get try masters from PRESUBMIT.py files. |
2288 masters = presubmit_support.DoGetTryMasters( | 2329 masters = presubmit_support.DoGetTryMasters( |
2289 change, | 2330 change, |
2290 change.LocalPaths(), | 2331 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 ' | 2674 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
2634 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2675 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
2635 | 2676 |
2636 | 2677 |
2637 if __name__ == '__main__': | 2678 if __name__ == '__main__': |
2638 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2679 # These affect sys.stdout so do it outside of main() to simplify mocks in |
2639 # unit testing. | 2680 # unit testing. |
2640 fix_encoding.fix_encoding() | 2681 fix_encoding.fix_encoding() |
2641 colorama.init() | 2682 colorama.init() |
2642 sys.exit(main(sys.argv[1:])) | 2683 sys.exit(main(sys.argv[1:])) |
OLD | NEW |