Subversion Repositories SmartDukaan

Rev

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