#!/usr/bin/env python
#
# Autogenerated by Thrift Compiler (0.14.1)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
#  options string: py
#

import sys
import pprint
if sys.version_info[0] > 2:
    from urllib.parse import urlparse
else:
    from urlparse import urlparse
from thrift.transport import TTransport, TSocket, TSSLSocket, THttpClient
from thrift.protocol.TBinaryProtocol import TBinaryProtocol

from iotdb.thrift.confignode import IConfigNodeRPCService
from iotdb.thrift.confignode.ttypes import *

if len(sys.argv) <= 1 or sys.argv[1] == '--help':
    print('')
    print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] [-novalidate] [-ca_certs certs] [-keyfile keyfile] [-certfile certfile] function [arg1 [arg2...]]')
    print('')
    print('Functions:')
    print('  TDataNodeRegisterResp registerDataNode(TDataNodeRegisterReq req)')
    print('  TSStatus activeDataNode(TDataNodeActiveReq req)')
    print('  TDataNodeInfoResp getDataNodeInfo(i32 dataNodeId)')
    print('  TClusterNodeInfos getAllClusterNodeInfos()')
    print('  TSStatus setStorageGroup(TSetStorageGroupReq req)')
    print('  TSStatus deleteStorageGroup(TDeleteStorageGroupReq req)')
    print('  TSStatus deleteStorageGroups(TDeleteStorageGroupsReq req)')
    print('  TSStatus setTTL(TSetTTLReq req)')
    print('  TSStatus setSchemaReplicationFactor(TSetSchemaReplicationFactorReq req)')
    print('  TSStatus setDataReplicationFactor(TSetDataReplicationFactorReq req)')
    print('  TSStatus setTimePartitionInterval(TSetTimePartitionIntervalReq req)')
    print('  TCountStorageGroupResp countMatchedStorageGroups( storageGroupPathPattern)')
    print('  TStorageGroupSchemaResp getMatchedStorageGroupSchemas( storageGroupPathPattern)')
    print('  TSchemaPartitionResp getSchemaPartition(TSchemaPartitionReq req)')
    print('  TSchemaPartitionResp getOrCreateSchemaPartition(TSchemaPartitionReq req)')
    print('  TSchemaNodeManagementResp getSchemaNodeManagementPartition(TSchemaNodeManagementReq req)')
    print('  TDataPartitionResp getDataPartition(TDataPartitionReq req)')
    print('  TDataPartitionResp getOrCreateDataPartition(TDataPartitionReq req)')
    print('  TSStatus operatePermission(TAuthorizerReq req)')
    print('  TAuthorizerResp queryPermission(TAuthorizerReq req)')
    print('  TPermissionInfoResp login(TLoginReq req)')
    print('  TPermissionInfoResp checkUserPrivileges(TCheckUserPrivilegesReq req)')
    print('  TConfigNodeRegisterResp registerConfigNode(TConfigNodeRegisterReq req)')
    print('  TSStatus addConsensusGroup(TConfigNodeRegisterResp req)')
    print('  TSStatus removeConfigNode(TConfigNodeLocation configNodeLocation)')
    print('  TSStatus stopConfigNode(TConfigNodeLocation configNodeLocation)')
    print('  TSStatus createFunction(TCreateFunctionReq req)')
    print('  TSStatus dropFunction(TDropFunctionReq req)')
    print('  TSStatus flush(TFlushReq req)')
    print('  TShowRegionResp showRegion(TShowRegionReq req)')
    print('  i64 getConfigNodeHeartBeat(i64 timestamp)')
    print('')
    sys.exit(0)

pp = pprint.PrettyPrinter(indent=2)
host = 'localhost'
port = 9090
uri = ''
framed = False
ssl = False
validate = True
ca_certs = None
keyfile = None
certfile = None
http = False
argi = 1

if sys.argv[argi] == '-h':
    parts = sys.argv[argi + 1].split(':')
    host = parts[0]
    if len(parts) > 1:
        port = int(parts[1])
    argi += 2

if sys.argv[argi] == '-u':
    url = urlparse(sys.argv[argi + 1])
    parts = url[1].split(':')
    host = parts[0]
    if len(parts) > 1:
        port = int(parts[1])
    else:
        port = 80
    uri = url[2]
    if url[4]:
        uri += '?%s' % url[4]
    http = True
    argi += 2

if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
    framed = True
    argi += 1

if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
    ssl = True
    argi += 1

if sys.argv[argi] == '-novalidate':
    validate = False
    argi += 1

if sys.argv[argi] == '-ca_certs':
    ca_certs = sys.argv[argi+1]
    argi += 2

if sys.argv[argi] == '-keyfile':
    keyfile = sys.argv[argi+1]
    argi += 2

if sys.argv[argi] == '-certfile':
    certfile = sys.argv[argi+1]
    argi += 2

cmd = sys.argv[argi]
args = sys.argv[argi + 1:]

if http:
    transport = THttpClient.THttpClient(host, port, uri)
else:
    if ssl:
        socket = TSSLSocket.TSSLSocket(host, port, validate=validate, ca_certs=ca_certs, keyfile=keyfile, certfile=certfile)
    else:
        socket = TSocket.TSocket(host, port)
    if framed:
        transport = TTransport.TFramedTransport(socket)
    else:
        transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol(transport)
client = IConfigNodeRPCService.Client(protocol)
transport.open()

if cmd == 'registerDataNode':
    if len(args) != 1:
        print('registerDataNode requires 1 args')
        sys.exit(1)
    pp.pprint(client.registerDataNode(eval(args[0]),))

elif cmd == 'activeDataNode':
    if len(args) != 1:
        print('activeDataNode requires 1 args')
        sys.exit(1)
    pp.pprint(client.activeDataNode(eval(args[0]),))

elif cmd == 'getDataNodeInfo':
    if len(args) != 1:
        print('getDataNodeInfo requires 1 args')
        sys.exit(1)
    pp.pprint(client.getDataNodeInfo(eval(args[0]),))

elif cmd == 'getAllClusterNodeInfos':
    if len(args) != 0:
        print('getAllClusterNodeInfos requires 0 args')
        sys.exit(1)
    pp.pprint(client.getAllClusterNodeInfos())

elif cmd == 'setStorageGroup':
    if len(args) != 1:
        print('setStorageGroup requires 1 args')
        sys.exit(1)
    pp.pprint(client.setStorageGroup(eval(args[0]),))

elif cmd == 'deleteStorageGroup':
    if len(args) != 1:
        print('deleteStorageGroup requires 1 args')
        sys.exit(1)
    pp.pprint(client.deleteStorageGroup(eval(args[0]),))

elif cmd == 'deleteStorageGroups':
    if len(args) != 1:
        print('deleteStorageGroups requires 1 args')
        sys.exit(1)
    pp.pprint(client.deleteStorageGroups(eval(args[0]),))

elif cmd == 'setTTL':
    if len(args) != 1:
        print('setTTL requires 1 args')
        sys.exit(1)
    pp.pprint(client.setTTL(eval(args[0]),))

elif cmd == 'setSchemaReplicationFactor':
    if len(args) != 1:
        print('setSchemaReplicationFactor requires 1 args')
        sys.exit(1)
    pp.pprint(client.setSchemaReplicationFactor(eval(args[0]),))

elif cmd == 'setDataReplicationFactor':
    if len(args) != 1:
        print('setDataReplicationFactor requires 1 args')
        sys.exit(1)
    pp.pprint(client.setDataReplicationFactor(eval(args[0]),))

elif cmd == 'setTimePartitionInterval':
    if len(args) != 1:
        print('setTimePartitionInterval requires 1 args')
        sys.exit(1)
    pp.pprint(client.setTimePartitionInterval(eval(args[0]),))

elif cmd == 'countMatchedStorageGroups':
    if len(args) != 1:
        print('countMatchedStorageGroups requires 1 args')
        sys.exit(1)
    pp.pprint(client.countMatchedStorageGroups(eval(args[0]),))

elif cmd == 'getMatchedStorageGroupSchemas':
    if len(args) != 1:
        print('getMatchedStorageGroupSchemas requires 1 args')
        sys.exit(1)
    pp.pprint(client.getMatchedStorageGroupSchemas(eval(args[0]),))

elif cmd == 'getSchemaPartition':
    if len(args) != 1:
        print('getSchemaPartition requires 1 args')
        sys.exit(1)
    pp.pprint(client.getSchemaPartition(eval(args[0]),))

elif cmd == 'getOrCreateSchemaPartition':
    if len(args) != 1:
        print('getOrCreateSchemaPartition requires 1 args')
        sys.exit(1)
    pp.pprint(client.getOrCreateSchemaPartition(eval(args[0]),))

elif cmd == 'getSchemaNodeManagementPartition':
    if len(args) != 1:
        print('getSchemaNodeManagementPartition requires 1 args')
        sys.exit(1)
    pp.pprint(client.getSchemaNodeManagementPartition(eval(args[0]),))

elif cmd == 'getDataPartition':
    if len(args) != 1:
        print('getDataPartition requires 1 args')
        sys.exit(1)
    pp.pprint(client.getDataPartition(eval(args[0]),))

elif cmd == 'getOrCreateDataPartition':
    if len(args) != 1:
        print('getOrCreateDataPartition requires 1 args')
        sys.exit(1)
    pp.pprint(client.getOrCreateDataPartition(eval(args[0]),))

elif cmd == 'operatePermission':
    if len(args) != 1:
        print('operatePermission requires 1 args')
        sys.exit(1)
    pp.pprint(client.operatePermission(eval(args[0]),))

elif cmd == 'queryPermission':
    if len(args) != 1:
        print('queryPermission requires 1 args')
        sys.exit(1)
    pp.pprint(client.queryPermission(eval(args[0]),))

elif cmd == 'login':
    if len(args) != 1:
        print('login requires 1 args')
        sys.exit(1)
    pp.pprint(client.login(eval(args[0]),))

elif cmd == 'checkUserPrivileges':
    if len(args) != 1:
        print('checkUserPrivileges requires 1 args')
        sys.exit(1)
    pp.pprint(client.checkUserPrivileges(eval(args[0]),))

elif cmd == 'registerConfigNode':
    if len(args) != 1:
        print('registerConfigNode requires 1 args')
        sys.exit(1)
    pp.pprint(client.registerConfigNode(eval(args[0]),))

elif cmd == 'addConsensusGroup':
    if len(args) != 1:
        print('addConsensusGroup requires 1 args')
        sys.exit(1)
    pp.pprint(client.addConsensusGroup(eval(args[0]),))

elif cmd == 'removeConfigNode':
    if len(args) != 1:
        print('removeConfigNode requires 1 args')
        sys.exit(1)
    pp.pprint(client.removeConfigNode(eval(args[0]),))

elif cmd == 'stopConfigNode':
    if len(args) != 1:
        print('stopConfigNode requires 1 args')
        sys.exit(1)
    pp.pprint(client.stopConfigNode(eval(args[0]),))

elif cmd == 'createFunction':
    if len(args) != 1:
        print('createFunction requires 1 args')
        sys.exit(1)
    pp.pprint(client.createFunction(eval(args[0]),))

elif cmd == 'dropFunction':
    if len(args) != 1:
        print('dropFunction requires 1 args')
        sys.exit(1)
    pp.pprint(client.dropFunction(eval(args[0]),))

elif cmd == 'flush':
    if len(args) != 1:
        print('flush requires 1 args')
        sys.exit(1)
    pp.pprint(client.flush(eval(args[0]),))

elif cmd == 'showRegion':
    if len(args) != 1:
        print('showRegion requires 1 args')
        sys.exit(1)
    pp.pprint(client.showRegion(eval(args[0]),))

elif cmd == 'getConfigNodeHeartBeat':
    if len(args) != 1:
        print('getConfigNodeHeartBeat requires 1 args')
        sys.exit(1)
    pp.pprint(client.getConfigNodeHeartBeat(eval(args[0]),))

else:
    print('Unrecognized method %s' % cmd)
    sys.exit(1)

transport.close()
