Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
4502 mandeep.dh 1
#!/usr/bin/env python
2
#
3
# Autogenerated by Thrift Compiler (0.7.0)
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 PurchaseService
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 '  i64 createPurchaseOrder(PurchaseOrder purchaseOrder)'
25
  print '  PurchaseOrder getPurchaseOrder(i64 id)'
26
  print '   getAllPurchaseOrders(POStatus status)'
27
  print '  Supplier getSupplier(i64 id)'
28
  print '  i64 startPurchase(i64 purchaseOrderId, string invoiceNumber, double freightCharges)'
29
  print '  i64 closePurchase(i64 purchaseId)'
30
  print '   getAllPurchases(i64 purchaseOrderId, bool open)'
4555 mandeep.dh 31
  print '  PurchaseOrder getPurchaseOrderForPurchase(i64 purchaseId)'
4502 mandeep.dh 32
  print ''
33
  sys.exit(0)
34
 
35
pp = pprint.PrettyPrinter(indent = 2)
36
host = 'localhost'
37
port = 9090
38
uri = ''
39
framed = False
40
http = False
41
argi = 1
42
 
43
if sys.argv[argi] == '-h':
44
  parts = sys.argv[argi+1].split(':')
45
  host = parts[0]
46
  port = int(parts[1])
47
  argi += 2
48
 
49
if sys.argv[argi] == '-u':
50
  url = urlparse(sys.argv[argi+1])
51
  parts = url[1].split(':')
52
  host = parts[0]
53
  if len(parts) > 1:
54
    port = int(parts[1])
55
  else:
56
    port = 80
57
  uri = url[2]
58
  if url[4]:
59
    uri += '?%s' % url[4]
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 = PurchaseService.Client(protocol)
80
transport.open()
81
 
82
if cmd == 'createPurchaseOrder':
83
  if len(args) != 1:
84
    print 'createPurchaseOrder requires 1 args'
85
    sys.exit(1)
86
  pp.pprint(client.createPurchaseOrder(eval(args[0]),))
87
 
88
elif cmd == 'getPurchaseOrder':
89
  if len(args) != 1:
90
    print 'getPurchaseOrder requires 1 args'
91
    sys.exit(1)
92
  pp.pprint(client.getPurchaseOrder(eval(args[0]),))
93
 
94
elif cmd == 'getAllPurchaseOrders':
95
  if len(args) != 1:
96
    print 'getAllPurchaseOrders requires 1 args'
97
    sys.exit(1)
98
  pp.pprint(client.getAllPurchaseOrders(eval(args[0]),))
99
 
100
elif cmd == 'getSupplier':
101
  if len(args) != 1:
102
    print 'getSupplier requires 1 args'
103
    sys.exit(1)
104
  pp.pprint(client.getSupplier(eval(args[0]),))
105
 
106
elif cmd == 'startPurchase':
107
  if len(args) != 3:
108
    print 'startPurchase requires 3 args'
109
    sys.exit(1)
110
  pp.pprint(client.startPurchase(eval(args[0]),args[1],eval(args[2]),))
111
 
112
elif cmd == 'closePurchase':
113
  if len(args) != 1:
114
    print 'closePurchase requires 1 args'
115
    sys.exit(1)
116
  pp.pprint(client.closePurchase(eval(args[0]),))
117
 
118
elif cmd == 'getAllPurchases':
119
  if len(args) != 2:
120
    print 'getAllPurchases requires 2 args'
121
    sys.exit(1)
122
  pp.pprint(client.getAllPurchases(eval(args[0]),eval(args[1]),))
123
 
4555 mandeep.dh 124
elif cmd == 'getPurchaseOrderForPurchase':
125
  if len(args) != 1:
126
    print 'getPurchaseOrderForPurchase requires 1 args'
4502 mandeep.dh 127
    sys.exit(1)
4555 mandeep.dh 128
  pp.pprint(client.getPurchaseOrderForPurchase(eval(args[0]),))
4502 mandeep.dh 129
 
130
else:
131
  print 'Unrecognized method %s' % cmd
132
  sys.exit(1)
133
 
134
transport.close()