Subversion Repositories SmartDukaan

Rev

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