예제 #1
0
def setupServer():
    """ Setup the connection to the MVI Server."""
    global server
    try:
        server = vapi.connect_to_server(args.baseurl, args.token)
    except Exception as e:
        print("Error: Failed to setup server.", file=sys.stderr)
        print(e)
        exit(2)
def main(params):
    """Example python script to illustrate minimal use of the vapi library.

    This script will generate a summary list of datasets if no parameters are provided.
    If 1 parameter is given, it is assumed to be a dataset ID and details for that ID will be show.
    More than 2 parameters results in an error.

    :param params:
    """
    try:
        # No parameters to `connect_to_server()` will used VAPI_* env variables
        # This setups the server class, it does not actually maintain a connection
        server = vapi.connect_to_server()
    except Exception as e:
        print("Error: Failed to setup server.", file=sys.stderr)
        logger.debug(dict(e))
        return 2

    if len(params) == 1:
        # Show details about the dataset passed in.
        server.datasets.show(params[0])
        if server.rsp_ok():
            # Pretty print the details
            print(json.dumps(server.json(), indent=2))
        else:
            # Something went wrong. Show the status code.
            # All of visual-inspections failure messages should be in json, so pretty print that
            print(f"Request failed with code {server.status_code()}",
                  file=sys.stderr)
            print(json.dumps(server.json(), indent=2), file=sys.stderr)
            return 2

    elif len(params) == 0:
        # Get a list of all datasets visible to the current user
        server.datasets.report()
        if server.rsp_ok():
            printSummaryInfo(server.json())
        else:
            # Something went wrong. Show the status code.
            # All of visual-inspections failure messages should be in json, so pretty print that
            print(f"Request failed with code {server.status_code()}",
                  file=sys.stderr)
            print(json.dumps(server.json(), indent=2), file=sys.stderr)
            return 2

    else:
        print(f"""ERROR: too many parameters
        USAGE: either
            {sys.argv[0]}              -- to show list of datasets
        or
            {sys.argv[0]} <DatasetId>  -- to show details of one dataset.""",
              file=sys.stderr)
        return 1
    return 0
예제 #3
0
def main(params, cmd_flags=None):
    global server

    args = cli_utils.get_valid_input(usage_stmt, operation_map, id="--modelid", argv=params, cmd_flags=cmd_flags)
    if args is not None:
        try:
            server = vapi.connect_to_server(cli_utils.host_name, cli_utils.token)
        except Exception as e:
            print("Error: Failed to setup server.", file=sys.stderr)
            logger.debug(e)
            return 1

        args.operation(args.op_params)
예제 #4
0
def main(params, cmd_flags=None):
    global server

    args = cli_utils.get_valid_input(usage_stmt,
                                     operation_map,
                                     argv=params,
                                     cmd_flags=cmd_flags)
    if args is not None:
        # When requesting a token, we need to ignore any existing token info
        if args.cmd_params["<operation>"] == "token":
            cli_utils.token = ""
        try:
            server = vapi.connect_to_server(cli_utils.host_name,
                                            cli_utils.token)
        except Exception as e:
            print("Error: Failed to setup server.", file=sys.stderr)
            logger.debug(e)
            return 1

        args.operation(args.op_params)