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

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 CatalogService import CatalogService
from CatalogService.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('  TDdlExecResponse ExecDdl(TDdlExecRequest req)')
    print('  TGetCatalogObjectResponse GetCatalogObject(TGetCatalogObjectRequest req)')
    print('  TGetPartitionStatsResponse GetPartitionStats(TGetPartitionStatsRequest req)')
    print('  TResetMetadataResponse ResetMetadata(TResetMetadataRequest req)')
    print('  TUpdateCatalogResponse UpdateCatalog(TUpdateCatalogRequest req)')
    print('  TGetFunctionsResponse GetFunctions(TGetFunctionsRequest req)')
    print('  TPrioritizeLoadResponse PrioritizeLoad(TPrioritizeLoadRequest req)')
    print('  TGetPartialCatalogObjectResponse GetPartialCatalogObject(TGetPartialCatalogObjectRequest req)')
    print('  TUpdateTableUsageResponse UpdateTableUsage(TUpdateTableUsageRequest req)')
    print('  TGetNullPartitionNameResponse GetNullPartitionName(TGetNullPartitionNameRequest req)')
    print('  TGetLatestCompactionsResponse GetLatestCompactions(TGetLatestCompactionsRequest req)')
    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 = CatalogService.Client(protocol)
transport.open()

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

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

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

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

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

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

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

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

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

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

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

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

transport.close()
