Subversion Repositories SmartDukaan

Rev

Rev 777 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/env python
#
# Autogenerated by Thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#

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

import TestService
from 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 '  void sayHello(string message)'
  print '  string getUser(i64 id)'
  print '  i64 getAddressId()'
  print '  Address getAddress()'
  print '  void createUser(string name)'
  print '  void closeSession()'
  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]
  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]
  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 = TestService.Client(protocol)
transport.open()

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

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

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

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

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

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

transport.close()