Subversion Repositories SmartDukaan

Rev

Rev 732 | Rev 1137 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
412 ashish 1
#!/usr/bin/env python
2
#
3
# Autogenerated by Thrift
4
#
5
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
6
#
7
 
8
import sys
9
import pprint
10
from urlparse import urlparse
11
from thrift.transport import TTransport
12
from thrift.transport import TSocket
13
from thrift.transport import THttpClient
14
from thrift.protocol import TBinaryProtocol
15
 
16
import LogisticsService
17
from ttypes import *
18
 
19
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
20
  print ''
21
  print 'Usage: ' + sys.argv[0] + ' [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
22
  print ''
23
  print 'Functions:'
765 rajveer 24
  print '  void closeSession()'
669 chandransh 25
  print '  Provider getProvider(i64 providerId)'
675 chandransh 26
  print '   getAllProviders()'
647 chandransh 27
  print '  LogisticsInfo getLogisticsEstimation(i64 itemId, string destination_pin)'
716 rajveer 28
  print '  LogisticsInfo getLogisticsInfo(string destination_pincode, i64 item_id)'
647 chandransh 29
  print '  string getEmptyAWB(i64 providerId)'
30
  print '   getShipmentInfo(string awb, i64 providerId)'
732 chandransh 31
  print '  string getDestinationCode(i64 providerId, string pinCode)'
412 ashish 32
  print ''
33
  sys.exit(0)
34
 
35
pp = pprint.PrettyPrinter(indent = 2)
36
host = 'localhost'
37
port = 9090
38
uri = ''
39
framed = False
40
http = False
41
argi = 1
42
 
43
if sys.argv[argi] == '-h':
44
  parts = sys.argv[argi+1].split(':') 
45
  host = parts[0]
46
  port = int(parts[1])
47
  argi += 2
48
 
49
if sys.argv[argi] == '-u':
50
  url = urlparse(sys.argv[argi+1])
51
  parts = url[1].split(':') 
52
  host = parts[0]
53
  if len(parts) > 1:
54
    port = int(parts[1])
55
  else:
56
    port = 80
57
  uri = url[2]
58
  http = True
59
  argi += 2
60
 
61
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
62
  framed = True
63
  argi += 1
64
 
65
cmd = sys.argv[argi]
66
args = sys.argv[argi+1:]
67
 
68
if http:
69
  transport = THttpClient.THttpClient(host, port, uri)
70
else:
71
  socket = TSocket.TSocket(host, port)
72
  if framed:
73
    transport = TTransport.TFramedTransport(socket)
74
  else:
75
    transport = TTransport.TBufferedTransport(socket)
76
protocol = TBinaryProtocol.TBinaryProtocol(transport)
77
client = LogisticsService.Client(protocol)
78
transport.open()
79
 
765 rajveer 80
if cmd == 'closeSession':
81
  if len(args) != 0:
82
    print 'closeSession requires 0 args'
83
    sys.exit(1)
84
  pp.pprint(client.closeSession())
85
 
86
elif cmd == 'getProvider':
669 chandransh 87
  if len(args) != 1:
88
    print 'getProvider requires 1 args'
89
    sys.exit(1)
90
  pp.pprint(client.getProvider(eval(args[0]),))
91
 
675 chandransh 92
elif cmd == 'getAllProviders':
93
  if len(args) != 0:
94
    print 'getAllProviders requires 0 args'
95
    sys.exit(1)
96
  pp.pprint(client.getAllProviders())
97
 
669 chandransh 98
elif cmd == 'getLogisticsEstimation':
483 rajveer 99
  if len(args) != 2:
647 chandransh 100
    print 'getLogisticsEstimation requires 2 args'
483 rajveer 101
    sys.exit(1)
647 chandransh 102
  pp.pprint(client.getLogisticsEstimation(eval(args[0]),args[1],))
483 rajveer 103
 
647 chandransh 104
elif cmd == 'getLogisticsInfo':
412 ashish 105
  if len(args) != 2:
647 chandransh 106
    print 'getLogisticsInfo requires 2 args'
412 ashish 107
    sys.exit(1)
716 rajveer 108
  pp.pprint(client.getLogisticsInfo(args[0],eval(args[1]),))
412 ashish 109
 
110
elif cmd == 'getEmptyAWB':
111
  if len(args) != 1:
112
    print 'getEmptyAWB requires 1 args'
113
    sys.exit(1)
114
  pp.pprint(client.getEmptyAWB(eval(args[0]),))
115
 
116
elif cmd == 'getShipmentInfo':
647 chandransh 117
  if len(args) != 2:
118
    print 'getShipmentInfo requires 2 args'
412 ashish 119
    sys.exit(1)
647 chandransh 120
  pp.pprint(client.getShipmentInfo(args[0],eval(args[1]),))
412 ashish 121
 
732 chandransh 122
elif cmd == 'getDestinationCode':
123
  if len(args) != 2:
124
    print 'getDestinationCode requires 2 args'
125
    sys.exit(1)
126
  pp.pprint(client.getDestinationCode(eval(args[0]),args[1],))
127
 
412 ashish 128
transport.close()