Subversion Repositories SmartDukaan

Rev

Rev 472 | Rev 759 | 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 '  void sendMail(Mail mail)'
25
  print '  void sendText(TextMessage message)'
26
  print '  void addMessage(Message message)'
27
  print '  void updateMessage(i64 id, string message)'
353 ashish 28
  print '  Message getMessage(i64 id)'
29
  print '  Message getSubstitutedMessage(i64 id,  params)'
494 rajveer 30
  print '  bool addUser(string username, string password, i64 warehouseId)'
31
  print '  bool deleteUser(string username)'
32
  print '  i64 authenticateUser(string username, string password)'
33
  print '  bool updatePassword(string username, string oldPassword, string newPassword)'
349 ashish 34
  print ''
35
  sys.exit(0)
36
 
37
pp = pprint.PrettyPrinter(indent = 2)
38
host = 'localhost'
39
port = 9090
40
uri = ''
41
framed = False
42
http = False
43
argi = 1
44
 
45
if sys.argv[argi] == '-h':
46
  parts = sys.argv[argi+1].split(':') 
47
  host = parts[0]
48
  port = int(parts[1])
49
  argi += 2
50
 
51
if sys.argv[argi] == '-u':
52
  url = urlparse(sys.argv[argi+1])
53
  parts = url[1].split(':') 
54
  host = parts[0]
55
  if len(parts) > 1:
56
    port = int(parts[1])
57
  else:
58
    port = 80
59
  uri = url[2]
60
  http = True
61
  argi += 2
62
 
63
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
64
  framed = True
65
  argi += 1
66
 
67
cmd = sys.argv[argi]
68
args = sys.argv[argi+1:]
69
 
70
if http:
71
  transport = THttpClient.THttpClient(host, port, uri)
72
else:
73
  socket = TSocket.TSocket(host, port)
74
  if framed:
75
    transport = TTransport.TFramedTransport(socket)
76
  else:
77
    transport = TTransport.TBufferedTransport(socket)
78
protocol = TBinaryProtocol.TBinaryProtocol(transport)
79
client = HelperService.Client(protocol)
80
transport.open()
81
 
472 rajveer 82
if cmd == 'sendMail':
349 ashish 83
  if len(args) != 1:
84
    print 'sendMail requires 1 args'
85
    sys.exit(1)
86
  pp.pprint(client.sendMail(eval(args[0]),))
87
 
88
elif cmd == 'sendText':
89
  if len(args) != 1:
90
    print 'sendText requires 1 args'
91
    sys.exit(1)
92
  pp.pprint(client.sendText(eval(args[0]),))
93
 
94
elif cmd == 'addMessage':
95
  if len(args) != 1:
96
    print 'addMessage requires 1 args'
97
    sys.exit(1)
98
  pp.pprint(client.addMessage(eval(args[0]),))
99
 
100
elif cmd == 'updateMessage':
101
  if len(args) != 2:
102
    print 'updateMessage requires 2 args'
103
    sys.exit(1)
104
  pp.pprint(client.updateMessage(eval(args[0]),args[1],))
105
 
106
elif cmd == 'getMessage':
107
  if len(args) != 1:
108
    print 'getMessage requires 1 args'
109
    sys.exit(1)
110
  pp.pprint(client.getMessage(eval(args[0]),))
111
 
112
elif cmd == 'getSubstitutedMessage':
113
  if len(args) != 2:
114
    print 'getSubstitutedMessage requires 2 args'
115
    sys.exit(1)
116
  pp.pprint(client.getSubstitutedMessage(eval(args[0]),eval(args[1]),))
117
 
494 rajveer 118
elif cmd == 'addUser':
119
  if len(args) != 3:
120
    print 'addUser requires 3 args'
121
    sys.exit(1)
122
  pp.pprint(client.addUser(args[0],args[1],eval(args[2]),))
123
 
124
elif cmd == 'deleteUser':
125
  if len(args) != 1:
126
    print 'deleteUser requires 1 args'
127
    sys.exit(1)
128
  pp.pprint(client.deleteUser(args[0],))
129
 
130
elif cmd == 'authenticateUser':
131
  if len(args) != 2:
132
    print 'authenticateUser requires 2 args'
133
    sys.exit(1)
134
  pp.pprint(client.authenticateUser(args[0],args[1],))
135
 
136
elif cmd == 'updatePassword':
137
  if len(args) != 3:
138
    print 'updatePassword requires 3 args'
139
    sys.exit(1)
140
  pp.pprint(client.updatePassword(args[0],args[1],args[2],))
141
 
349 ashish 142
transport.close()