github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/cli/sawtooth_cli/status.py (about) 1 # Copyright 2018 Intel Corporation 2 # 3 # Licensed under the Apache License, Version 2.0 (the 'License'); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # ------------------------------------------------------------------------------ 15 16 from sawtooth_cli import format_utils as fmt 17 from sawtooth_cli.rest_client import RestClient 18 from sawtooth_cli.exceptions import CliException 19 from sawtooth_cli.parent_parsers import base_http_parser 20 from sawtooth_cli.parent_parsers import base_list_parser 21 22 23 def add_status_parser(subparsers, parent_parser): 24 """Adds argument parser for the status command 25 26 Args: 27 subparsers: Add parsers to this subparser object 28 parent_parser: The parent argparse.ArgumentParser object 29 """ 30 parser = subparsers.add_parser( 31 'status', 32 help='Displays information about validator status', 33 description="Provides a subcommand to show a validator\'s status") 34 35 grand_parsers = parser.add_subparsers(title='subcommands', 36 dest='subcommand') 37 grand_parsers.required = True 38 add_status_show_parser(grand_parsers, parent_parser) 39 40 41 def add_status_show_parser(subparsers, parent_parser): 42 description = ('Displays information about the status of a validator.') 43 44 subparsers.add_parser( 45 'show', 46 description=description, 47 parents=[base_http_parser(), base_list_parser()]) 48 49 50 def do_status(args): 51 if args.subcommand == 'show': 52 do_status_show(args) 53 else: 54 raise CliException('Invalid command: {}'.format(args.subcommand)) 55 56 57 def do_status_show(args): 58 rest_client = RestClient(base_url=args.url) 59 status = rest_client.get_status() 60 61 if args.format == 'csv' or args.format == 'default': 62 print(status) 63 64 elif args.format == 'json': 65 fmt.print_json(status) 66 67 elif args.format == 'yaml': 68 fmt.print_yaml(status)