Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(818)

Side by Side Diff: client/swarming.py

Issue 1404063003: Fix regression in 49abac87faa60. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Swarming Authors. All rights reserved. 2 # Copyright 2013 The Swarming Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 that 3 # Use of this source code is governed under the Apache License, Version 2.0 that
4 # can be found in the LICENSE file. 4 # can be found in the LICENSE file.
5 5
6 """Client tool to trigger tasks or retrieve results from a Swarming server.""" 6 """Client tool to trigger tasks or retrieve results from a Swarming server."""
7 7
8 __version__ = '0.8.2' 8 __version__ = '0.8.2'
9 9
10 import collections 10 import collections
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 '-j', '--json', 1056 '-j', '--json',
1057 help='Load the task ids from .json as saved by trigger --dump-json') 1057 help='Load the task ids from .json as saved by trigger --dump-json')
1058 options, args = parser.parse_args(args) 1058 options, args = parser.parse_args(args)
1059 if not args and not options.json: 1059 if not args and not options.json:
1060 parser.error('Must specify at least one task id or --json.') 1060 parser.error('Must specify at least one task id or --json.')
1061 if args and options.json: 1061 if args and options.json:
1062 parser.error('Only use one of task id or --json.') 1062 parser.error('Only use one of task id or --json.')
1063 1063
1064 if options.json: 1064 if options.json:
1065 try: 1065 try:
1066 with fs.open(options.json, 'rb') as f: 1066 with fs.open(unicode(options.json), 'rb') as f:
1067 tasks = sorted( 1067 tasks = sorted(
1068 json.load(f)['tasks'].itervalues(), key=lambda x: x['shard_index']) 1068 json.load(f)['tasks'].itervalues(), key=lambda x: x['shard_index'])
1069 args = [t['task_id'] for t in tasks] 1069 args = [t['task_id'] for t in tasks]
1070 except (KeyError, IOError, TypeError, ValueError): 1070 except (KeyError, IOError, TypeError, ValueError):
1071 parser.error('Failed to parse %s' % options.json) 1071 parser.error('Failed to parse %s' % options.json)
1072 else: 1072 else:
1073 valid = frozenset('0123456789abcdef') 1073 valid = frozenset('0123456789abcdef')
1074 if any(not valid.issuperset(task_id) for task_id in args): 1074 if any(not valid.issuperset(task_id) for task_id in args):
1075 parser.error('Task ids are 0-9a-f.') 1075 parser.error('Task ids are 0-9a-f.')
1076 1076
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 data['items'].extend(new['items']) 1177 data['items'].extend(new['items'])
1178 data['cursor'] = new.get('cursor') 1178 data['cursor'] = new.get('cursor')
1179 1179
1180 if options.progress: 1180 if options.progress:
1181 print('') 1181 print('')
1182 if options.limit and len(data.get('items', [])) > options.limit: 1182 if options.limit and len(data.get('items', [])) > options.limit:
1183 data['items'] = data['items'][:options.limit] 1183 data['items'] = data['items'][:options.limit]
1184 data.pop('cursor', None) 1184 data.pop('cursor', None)
1185 1185
1186 if options.json: 1186 if options.json:
1187 tools.write_json(options.json, data, True) 1187 tools.write_json(unicode(options.json), data, True)
1188 else: 1188 else:
1189 try: 1189 try:
1190 tools.write_json(sys.stdout, data, False) 1190 tools.write_json(sys.stdout, data, False)
1191 sys.stdout.write('\n') 1191 sys.stdout.write('\n')
1192 except IOError: 1192 except IOError:
1193 pass 1193 pass
1194 return 0 1194 return 0
1195 1195
1196 1196
1197 def CMDquery_list(parser, args): 1197 def CMDquery_list(parser, args):
1198 """Returns list of all the Swarming APIs that can be used with command 1198 """Returns list of all the Swarming APIs that can be used with command
1199 'query'. 1199 'query'.
1200 """ 1200 """
1201 parser.add_option( 1201 parser.add_option(
1202 '--json', help='Path to JSON output file (otherwise prints to stdout)') 1202 '--json', help='Path to JSON output file (otherwise prints to stdout)')
1203 options, args = parser.parse_args(args) 1203 options, args = parser.parse_args(args)
1204 if args: 1204 if args:
1205 parser.error('No argument allowed.') 1205 parser.error('No argument allowed.')
1206 1206
1207 try: 1207 try:
1208 apis = endpoints_api_discovery_apis(options.swarming) 1208 apis = endpoints_api_discovery_apis(options.swarming)
1209 except APIError as e: 1209 except APIError as e:
1210 parser.error(str(e)) 1210 parser.error(str(e))
1211 if options.json: 1211 if options.json:
1212 with fs.open(options.json, 'wb') as f: 1212 with fs.open(unicode(options.json), 'wb') as f:
1213 json.dump(apis, f) 1213 json.dump(apis, f)
1214 else: 1214 else:
1215 help_url = ( 1215 help_url = (
1216 'https://apis-explorer.appspot.com/apis-explorer/?base=%s/_ah/api#p/' % 1216 'https://apis-explorer.appspot.com/apis-explorer/?base=%s/_ah/api#p/' %
1217 options.swarming) 1217 options.swarming)
1218 for api_id, api in sorted(apis.iteritems()): 1218 for api_id, api in sorted(apis.iteritems()):
1219 print api_id 1219 print api_id
1220 print ' ' + api['description'] 1220 print ' ' + api['description']
1221 for resource_name, resource in sorted(api['resources'].iteritems()): 1221 for resource_name, resource in sorted(api['resources'].iteritems()):
1222 print '' 1222 print ''
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 options.swarming, task_request, options.shards) 1359 options.swarming, task_request, options.shards)
1360 if tasks: 1360 if tasks:
1361 print('Triggered task: %s' % options.task_name) 1361 print('Triggered task: %s' % options.task_name)
1362 tasks_sorted = sorted( 1362 tasks_sorted = sorted(
1363 tasks.itervalues(), key=lambda x: x['shard_index']) 1363 tasks.itervalues(), key=lambda x: x['shard_index'])
1364 if options.dump_json: 1364 if options.dump_json:
1365 data = { 1365 data = {
1366 'base_task_name': options.task_name, 1366 'base_task_name': options.task_name,
1367 'tasks': tasks, 1367 'tasks': tasks,
1368 } 1368 }
1369 tools.write_json(options.dump_json, data, True) 1369 tools.write_json(unicode(options.dump_json), data, True)
1370 print('To collect results, use:') 1370 print('To collect results, use:')
1371 print(' swarming.py collect -S %s --json %s' % 1371 print(' swarming.py collect -S %s --json %s' %
1372 (options.swarming, options.dump_json)) 1372 (options.swarming, options.dump_json))
1373 else: 1373 else:
1374 print('To collect results, use:') 1374 print('To collect results, use:')
1375 print(' swarming.py collect -S %s %s' % 1375 print(' swarming.py collect -S %s %s' %
1376 (options.swarming, ' '.join(t['task_id'] for t in tasks_sorted))) 1376 (options.swarming, ' '.join(t['task_id'] for t in tasks_sorted)))
1377 print('Or visit:') 1377 print('Or visit:')
1378 for t in tasks_sorted: 1378 for t in tasks_sorted:
1379 print(' ' + t['view_url']) 1379 print(' ' + t['view_url'])
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 def main(args): 1426 def main(args):
1427 dispatcher = subcommand.CommandDispatcher(__name__) 1427 dispatcher = subcommand.CommandDispatcher(__name__)
1428 return dispatcher.execute(OptionParserSwarming(version=__version__), args) 1428 return dispatcher.execute(OptionParserSwarming(version=__version__), args)
1429 1429
1430 1430
1431 if __name__ == '__main__': 1431 if __name__ == '__main__':
1432 fix_encoding.fix_encoding() 1432 fix_encoding.fix_encoding()
1433 tools.disable_buffering() 1433 tools.disable_buffering()
1434 colorama.init() 1434 colorama.init()
1435 sys.exit(main(sys.argv[1:])) 1435 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698