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

import sys
import pprint
from urlparse import urlparse
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol

from ResultQuery import MySqlQueryService
from ResultQuery.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]] function [arg1 [arg2...]]'
  print ''
  print 'Functions:'
  print '  Result Query(QueryCommand command)'
  print '  Result MultQuery(MultQueryCommand command)'
  print '  i32 GetPartitionCount(string dbname)'
  print '  i64 GetGlobalID(string dbname, string tablename)'
  print '  i32 GetPartitionID(string dbname, string keyname, DataValue value)'
  print '  PartitionIDSets GetPartitionIDSet(string dbname, string keyname,  value_list)'
  print '  DDAStatus GetDDAStatus()'
  print '  bool BeginTransaction(string dbname, string transaction_id)'
  print '  bool EndTransaction(string dbname, string transaction_id, byte action)'
  print ''
  sys.exit(0)

pp = pprint.PrettyPrinter(indent = 2)
host = 'localhost'
port = 9090
uri = ''
framed = False
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

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

if http:
  transport = THttpClient.THttpClient(host, port, uri)
else:
  socket = TSocket.TSocket(host, port)
  if framed:
    transport = TTransport.TFramedTransport(socket)
  else:
    transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = MySqlQueryService.Client(protocol)
transport.open()

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

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

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

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

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

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

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

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

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

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

transport.close()

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

import sys
import pprint
from urlparse import urlparse
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol

from ResultQuery import MySqlQueryService
from ResultQuery.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]] function [arg1 [arg2...]]'
  print ''
  print 'Functions:'
  print '  Result Query(QueryCommand command)'
  print '  Result MultQuery(MultQueryCommand command)'
  print '  i32 GetPartitionCount(string dbname)'
  print '  i64 GetGlobalID(string dbname, string tablename)'
  print '  i32 GetPartitionID(string dbname, string keyname, DataValue value)'
  print '  PartitionIDSets GetPartitionIDSet(string dbname, string keyname,  value_list)'
  print '  DDAStatus GetDDAStatus()'
  print '  bool BeginTransaction(string dbname, string transaction_id)'
  print '  bool EndTransaction(string dbname, string transaction_id, byte action)'
  print ''
  sys.exit(0)

pp = pprint.PrettyPrinter(indent = 2)
host = 'localhost'
port = 9090
uri = ''
framed = False
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

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

if http:
  transport = THttpClient.THttpClient(host, port, uri)
else:
  socket = TSocket.TSocket(host, port)
  if framed:
    transport = TTransport.TFramedTransport(socket)
  else:
    transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = MySqlQueryService.Client(protocol)
transport.open()

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

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

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

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

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

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

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

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

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

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

transport.close()
