Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
349 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 HelperService
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:'
24
  print '   getLogisticsEstimation(i64 itemId,  location)'
25
  print '  void sendMail(Mail mail)'
26
  print '  void sendText(TextMessage message)'
27
  print '  void addMessage(Message message)'
28
  print '  void updateMessage(i64 id, string message)'
353 ashish 29
  print '  Message getMessage(i64 id)'
30
  print '  Message getSubstitutedMessage(i64 id,  params)'
349 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 = HelperService.Client(protocol)
77
transport.open()
78
 
79
if cmd == 'getLogisticsEstimation':
80
  if len(args) != 2:
81
    print 'getLogisticsEstimation requires 2 args'
82
    sys.exit(1)
83
  pp.pprint(client.getLogisticsEstimation(eval(args[0]),eval(args[1]),))
84
 
85
elif cmd == 'sendMail':
86
  if len(args) != 1:
87
    print 'sendMail requires 1 args'
88
    sys.exit(1)
89
  pp.pprint(client.sendMail(eval(args[0]),))
90
 
91
elif cmd == 'sendText':
92
  if len(args) != 1:
93
    print 'sendText requires 1 args'
94
    sys.exit(1)
95
  pp.pprint(client.sendText(eval(args[0]),))
96
 
97
elif cmd == 'addMessage':
98
  if len(args) != 1:
99
    print 'addMessage requires 1 args'
100
    sys.exit(1)
101
  pp.pprint(client.addMessage(eval(args[0]),))
102
 
103
elif cmd == 'updateMessage':
104
  if len(args) != 2:
105
    print 'updateMessage requires 2 args'
106
    sys.exit(1)
107
  pp.pprint(client.updateMessage(eval(args[0]),args[1],))
108
 
109
elif cmd == 'getMessage':
110
  if len(args) != 1:
111
    print 'getMessage requires 1 args'
112
    sys.exit(1)
113
  pp.pprint(client.getMessage(eval(args[0]),))
114
 
115
elif cmd == 'getSubstitutedMessage':
116
  if len(args) != 2:
117
    print 'getSubstitutedMessage requires 2 args'
118
    sys.exit(1)
119
  pp.pprint(client.getSubstitutedMessage(eval(args[0]),eval(args[1]),))
120
 
121
transport.close()