Subversion Repositories SmartDukaan

Rev

Rev 716 | Rev 765 | 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:'
669 chandransh 24
  print '  Provider getProvider(i64 providerId)'
675 chandransh 25
  print '   getAllProviders()'
647 chandransh 26
  print '  LogisticsInfo getLogisticsEstimation(i64 itemId, string destination_pin)'
716 rajveer 27
  print '  LogisticsInfo getLogisticsInfo(string destination_pincode, i64 item_id)'
647 chandransh 28
  print '  string getEmptyAWB(i64 providerId)'
29
  print '   getShipmentInfo(string awb, i64 providerId)'
732 chandransh 30
  print '  string getDestinationCode(i64 providerId, string pinCode)'
412 ashish 31
  print ''
32
  sys.exit(0)
33
 
34
pp = pprint.PrettyPrinter(indent = 2)
35
host = 'localhost'
36
port = 9090
37
uri = ''
38
framed = False
39
http = False
40
argi = 1
41
 
42
if sys.argv[argi] == '-h':
43
  parts = sys.argv[argi+1].split(':') 
44
  host = parts[0]
45
  port = int(parts[1])
46
  argi += 2
47
 
48
if sys.argv[argi] == '-u':
49
  url = urlparse(sys.argv[argi+1])
50
  parts = url[1].split(':') 
51
  host = parts[0]
52
  if len(parts) > 1:
53
    port = int(parts[1])
54
  else:
55
    port = 80
56
  uri = url[2]
57
  http = True
58
  argi += 2
59
 
60
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
61
  framed = True
62
  argi += 1
63
 
64
cmd = sys.argv[argi]
65
args = sys.argv[argi+1:]
66
 
67
if http:
68
  transport = THttpClient.THttpClient(host, port, uri)
69
else:
70
  socket = TSocket.TSocket(host, port)
71
  if framed:
72
    transport = TTransport.TFramedTransport(socket)
73
  else:
74
    transport = TTransport.TBufferedTransport(socket)
75
protocol = TBinaryProtocol.TBinaryProtocol(transport)
76
client = LogisticsService.Client(protocol)
77
transport.open()
78
 
669 chandransh 79
if cmd == 'getProvider':
80
  if len(args) != 1:
81
    print 'getProvider requires 1 args'
82
    sys.exit(1)
83
  pp.pprint(client.getProvider(eval(args[0]),))
84
 
675 chandransh 85
elif cmd == 'getAllProviders':
86
  if len(args) != 0:
87
    print 'getAllProviders requires 0 args'
88
    sys.exit(1)
89
  pp.pprint(client.getAllProviders())
90
 
669 chandransh 91
elif cmd == 'getLogisticsEstimation':
483 rajveer 92
  if len(args) != 2:
647 chandransh 93
    print 'getLogisticsEstimation requires 2 args'
483 rajveer 94
    sys.exit(1)
647 chandransh 95
  pp.pprint(client.getLogisticsEstimation(eval(args[0]),args[1],))
483 rajveer 96
 
647 chandransh 97
elif cmd == 'getLogisticsInfo':
412 ashish 98
  if len(args) != 2:
647 chandransh 99
    print 'getLogisticsInfo requires 2 args'
412 ashish 100
    sys.exit(1)
716 rajveer 101
  pp.pprint(client.getLogisticsInfo(args[0],eval(args[1]),))
412 ashish 102
 
103
elif cmd == 'getEmptyAWB':
104
  if len(args) != 1:
105
    print 'getEmptyAWB requires 1 args'
106
    sys.exit(1)
107
  pp.pprint(client.getEmptyAWB(eval(args[0]),))
108
 
109
elif cmd == 'getShipmentInfo':
647 chandransh 110
  if len(args) != 2:
111
    print 'getShipmentInfo requires 2 args'
412 ashish 112
    sys.exit(1)
647 chandransh 113
  pp.pprint(client.getShipmentInfo(args[0],eval(args[1]),))
412 ashish 114
 
732 chandransh 115
elif cmd == 'getDestinationCode':
116
  if len(args) != 2:
117
    print 'getDestinationCode requires 2 args'
118
    sys.exit(1)
119
  pp.pprint(client.getDestinationCode(eval(args[0]),args[1],))
120
 
412 ashish 121
transport.close()