Subversion Repositories SmartDukaan

Rev

Rev 353 | Rev 494 | 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)'
349 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 = HelperService.Client(protocol)
76
transport.open()
77
 
472 rajveer 78
if cmd == 'sendMail':
349 ashish 79
  if len(args) != 1:
80
    print 'sendMail requires 1 args'
81
    sys.exit(1)
82
  pp.pprint(client.sendMail(eval(args[0]),))
83
 
84
elif cmd == 'sendText':
85
  if len(args) != 1:
86
    print 'sendText requires 1 args'
87
    sys.exit(1)
88
  pp.pprint(client.sendText(eval(args[0]),))
89
 
90
elif cmd == 'addMessage':
91
  if len(args) != 1:
92
    print 'addMessage requires 1 args'
93
    sys.exit(1)
94
  pp.pprint(client.addMessage(eval(args[0]),))
95
 
96
elif cmd == 'updateMessage':
97
  if len(args) != 2:
98
    print 'updateMessage requires 2 args'
99
    sys.exit(1)
100
  pp.pprint(client.updateMessage(eval(args[0]),args[1],))
101
 
102
elif cmd == 'getMessage':
103
  if len(args) != 1:
104
    print 'getMessage requires 1 args'
105
    sys.exit(1)
106
  pp.pprint(client.getMessage(eval(args[0]),))
107
 
108
elif cmd == 'getSubstitutedMessage':
109
  if len(args) != 2:
110
    print 'getSubstitutedMessage requires 2 args'
111
    sys.exit(1)
112
  pp.pprint(client.getSubstitutedMessage(eval(args[0]),eval(args[1]),))
113
 
114
transport.close()