| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The LUCI Authors. All rights reserved. | 2 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that 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.9' | 8 __version__ = '0.8.10' |
| 9 | 9 |
| 10 import collections | 10 import collections |
| 11 import datetime | 11 import datetime |
| 12 import json | 12 import json |
| 13 import logging | 13 import logging |
| 14 import optparse | 14 import optparse |
| 15 import os | 15 import os |
| 16 import subprocess | 16 import subprocess |
| 17 import sys | 17 import sys |
| 18 import textwrap |
| 18 import threading | 19 import threading |
| 19 import time | 20 import time |
| 20 import urllib | 21 import urllib |
| 21 | 22 |
| 22 from third_party import colorama | 23 from third_party import colorama |
| 23 from third_party.depot_tools import fix_encoding | 24 from third_party.depot_tools import fix_encoding |
| 24 from third_party.depot_tools import subcommand | 25 from third_party.depot_tools import subcommand |
| 25 | 26 |
| 26 from utils import file_path | 27 from utils import file_path |
| 27 from utils import fs | 28 from utils import fs |
| (...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 except APIError as e: | 1402 except APIError as e: |
| 1402 parser.error(str(e)) | 1403 parser.error(str(e)) |
| 1403 if options.json: | 1404 if options.json: |
| 1404 options.json = unicode(os.path.abspath(options.json)) | 1405 options.json = unicode(os.path.abspath(options.json)) |
| 1405 with fs.open(options.json, 'wb') as f: | 1406 with fs.open(options.json, 'wb') as f: |
| 1406 json.dump(apis, f) | 1407 json.dump(apis, f) |
| 1407 else: | 1408 else: |
| 1408 help_url = ( | 1409 help_url = ( |
| 1409 'https://apis-explorer.appspot.com/apis-explorer/?base=%s/_ah/api#p/' % | 1410 'https://apis-explorer.appspot.com/apis-explorer/?base=%s/_ah/api#p/' % |
| 1410 options.swarming) | 1411 options.swarming) |
| 1411 for api_id, api in sorted(apis.iteritems()): | 1412 for i, (api_id, api) in enumerate(sorted(apis.iteritems())): |
| 1413 if i: |
| 1414 print('') |
| 1412 print api_id | 1415 print api_id |
| 1413 print ' ' + api['description'] | 1416 print ' ' + api['description'].strip() |
| 1414 for resource_name, resource in sorted(api['resources'].iteritems()): | 1417 if 'resources' in api: |
| 1415 print '' | 1418 # Old. |
| 1416 for method_name, method in sorted(resource['methods'].iteritems()): | 1419 for j, (resource_name, resource) in enumerate( |
| 1420 sorted(api['resources'].iteritems())): |
| 1421 if j: |
| 1422 print('') |
| 1423 for method_name, method in sorted(resource['methods'].iteritems()): |
| 1424 # Only list the GET ones. |
| 1425 if method['httpMethod'] != 'GET': |
| 1426 continue |
| 1427 print '- %s.%s: %s' % ( |
| 1428 resource_name, method_name, method['path']) |
| 1429 print('\n'.join( |
| 1430 ' ' + l for l in textwrap.wrap(method['description'], 78))) |
| 1431 print ' %s%s%s' % (help_url, api['servicePath'], method['id']) |
| 1432 else: |
| 1433 # New. |
| 1434 for method_name, method in sorted(api['methods'].iteritems()): |
| 1417 # Only list the GET ones. | 1435 # Only list the GET ones. |
| 1418 if method['httpMethod'] != 'GET': | 1436 if method['httpMethod'] != 'GET': |
| 1419 continue | 1437 continue |
| 1420 print '- %s.%s: %s' % ( | 1438 print '- %s: %s' % (method['id'], method['path']) |
| 1421 resource_name, method_name, method['path']) | 1439 print('\n'.join( |
| 1422 print ' ' + method['description'] | 1440 ' ' + l for l in textwrap.wrap(method['description'], 78))) |
| 1423 print ' %s%s%s' % (help_url, api['servicePath'], method['id']) | 1441 print ' %s%s%s' % (help_url, api['servicePath'], method['id']) |
| 1424 return 0 | 1442 return 0 |
| 1425 | 1443 |
| 1426 | 1444 |
| 1427 @subcommand.usage('(hash|isolated) [-- extra_args]') | 1445 @subcommand.usage('(hash|isolated) [-- extra_args]') |
| 1428 def CMDrun(parser, args): | 1446 def CMDrun(parser, args): |
| 1429 """Triggers a task and wait for the results. | 1447 """Triggers a task and wait for the results. |
| 1430 | 1448 |
| 1431 Basically, does everything to run a command remotely. | 1449 Basically, does everything to run a command remotely. |
| 1432 """ | 1450 """ |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 dispatcher = subcommand.CommandDispatcher(__name__) | 1685 dispatcher = subcommand.CommandDispatcher(__name__) |
| 1668 return dispatcher.execute(OptionParserSwarming(version=__version__), args) | 1686 return dispatcher.execute(OptionParserSwarming(version=__version__), args) |
| 1669 | 1687 |
| 1670 | 1688 |
| 1671 if __name__ == '__main__': | 1689 if __name__ == '__main__': |
| 1672 subprocess42.inhibit_os_error_reporting() | 1690 subprocess42.inhibit_os_error_reporting() |
| 1673 fix_encoding.fix_encoding() | 1691 fix_encoding.fix_encoding() |
| 1674 tools.disable_buffering() | 1692 tools.disable_buffering() |
| 1675 colorama.init() | 1693 colorama.init() |
| 1676 sys.exit(main(sys.argv[1:])) | 1694 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |