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

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 pangramia.yt.tokens_ops import YTTokenOpService
from pangramia.yt.tokens_ops.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('  JobTokenData getOrRefreshTokenWithReport(string accountId, string oldUrl, JobState status, string details, string jobId, TokenUpdateMode updateType, string url, string clients)')
    print('  JobTokenData getOrRefreshToken(string accountId, TokenUpdateMode updateType, string url, string clients, string machineId)')
    print('  JobTokenData getLatestToken(string accountId)')
    print('  JobTokenData refreshToken(string accountId, TokenUpdateMode updateType, string url)')
    print('  bool reportState(string url, JobState status, string details, string jobId)')
    print('   getProxyStatus(string serverIdentity)')
    print('  bool banProxy(string proxyUrl, string serverIdentity)')
    print('  bool unbanProxy(string proxyUrl, string serverIdentity)')
    print('  bool resetAllProxyStatuses(string serverIdentity)')
    print('   getAccountStatus(string accountId, string accountPrefix)')
    print('  bool banAccount(string accountId, string reason)')
    print('  bool unbanAccount(string accountId, string reason)')
    print('  bool ping()')
    print('  bool reportError(string message,  details)')
    print('  void shutdown()')
    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 = YTTokenOpService.Client(protocol)
transport.open()

if cmd == 'getOrRefreshTokenWithReport':
    if len(args) != 8:
        print('getOrRefreshTokenWithReport requires 8 args')
        sys.exit(1)
    pp.pprint(client.getOrRefreshTokenWithReport(args[0], args[1], eval(args[2]), args[3], args[4], eval(args[5]), args[6], args[7],))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

transport.close()
