Subversion Repositories SmartDukaan

Rev

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