Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
2821 chandransh 1
#!/usr/bin/env python
2
#
3431 rajveer 3
# Autogenerated by Thrift Compiler (0.7.0)
2821 chandransh 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 WarehouseService
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)'
3383 chandransh 26
  print '   getAllPurchaseOrders(POStatus status)'
2832 chandransh 27
  print '  Supplier getSupplier(i64 id)'
2821 chandransh 28
  print '  i64 startPurchase(i64 purchaseOrderId, string invoiceNumber, double freightCharges)'
29
  print '  i64 closePurchase(i64 purchaseId)'
3383 chandransh 30
  print '   getAllPurchases(i64 purchaseOrderId, bool open)'
31
  print '  void scanIn(i64 purchaseId, string itemNumber, string imeiNumber, ScanType type)'
3424 chandransh 32
  print '  void scanOut(string itemNumber, string imeiNumber, ScanType type)'
2821 chandransh 33
  print ''
34
  sys.exit(0)
35
 
36
pp = pprint.PrettyPrinter(indent = 2)
37
host = 'localhost'
38
port = 9090
39
uri = ''
40
framed = False
41
http = False
42
argi = 1
43
 
44
if sys.argv[argi] == '-h':
3431 rajveer 45
  parts = sys.argv[argi+1].split(':')
2821 chandransh 46
  host = parts[0]
47
  port = int(parts[1])
48
  argi += 2
49
 
50
if sys.argv[argi] == '-u':
51
  url = urlparse(sys.argv[argi+1])
3431 rajveer 52
  parts = url[1].split(':')
2821 chandransh 53
  host = parts[0]
54
  if len(parts) > 1:
55
    port = int(parts[1])
56
  else:
57
    port = 80
58
  uri = url[2]
3431 rajveer 59
  if url[4]:
60
    uri += '?%s' % url[4]
2821 chandransh 61
  http = True
62
  argi += 2
63
 
64
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
65
  framed = True
66
  argi += 1
67
 
68
cmd = sys.argv[argi]
69
args = sys.argv[argi+1:]
70
 
71
if http:
72
  transport = THttpClient.THttpClient(host, port, uri)
73
else:
74
  socket = TSocket.TSocket(host, port)
75
  if framed:
76
    transport = TTransport.TFramedTransport(socket)
77
  else:
78
    transport = TTransport.TBufferedTransport(socket)
79
protocol = TBinaryProtocol.TBinaryProtocol(transport)
80
client = WarehouseService.Client(protocol)
81
transport.open()
82
 
83
if cmd == 'createPurchaseOrder':
84
  if len(args) != 1:
85
    print 'createPurchaseOrder requires 1 args'
86
    sys.exit(1)
87
  pp.pprint(client.createPurchaseOrder(eval(args[0]),))
88
 
89
elif cmd == 'getPurchaseOrder':
90
  if len(args) != 1:
91
    print 'getPurchaseOrder requires 1 args'
92
    sys.exit(1)
93
  pp.pprint(client.getPurchaseOrder(eval(args[0]),))
94
 
3383 chandransh 95
elif cmd == 'getAllPurchaseOrders':
96
  if len(args) != 1:
97
    print 'getAllPurchaseOrders requires 1 args'
98
    sys.exit(1)
99
  pp.pprint(client.getAllPurchaseOrders(eval(args[0]),))
100
 
2832 chandransh 101
elif cmd == 'getSupplier':
102
  if len(args) != 1:
103
    print 'getSupplier requires 1 args'
104
    sys.exit(1)
105
  pp.pprint(client.getSupplier(eval(args[0]),))
106
 
2821 chandransh 107
elif cmd == 'startPurchase':
108
  if len(args) != 3:
109
    print 'startPurchase requires 3 args'
110
    sys.exit(1)
111
  pp.pprint(client.startPurchase(eval(args[0]),args[1],eval(args[2]),))
112
 
113
elif cmd == 'closePurchase':
114
  if len(args) != 1:
115
    print 'closePurchase requires 1 args'
116
    sys.exit(1)
117
  pp.pprint(client.closePurchase(eval(args[0]),))
118
 
3383 chandransh 119
elif cmd == 'getAllPurchases':
120
  if len(args) != 2:
121
    print 'getAllPurchases requires 2 args'
122
    sys.exit(1)
123
  pp.pprint(client.getAllPurchases(eval(args[0]),eval(args[1]),))
124
 
2821 chandransh 125
elif cmd == 'scanIn':
3383 chandransh 126
  if len(args) != 4:
127
    print 'scanIn requires 4 args'
2821 chandransh 128
    sys.exit(1)
3383 chandransh 129
  pp.pprint(client.scanIn(eval(args[0]),args[1],args[2],eval(args[3]),))
2821 chandransh 130
 
131
elif cmd == 'scanOut':
132
  if len(args) != 3:
133
    print 'scanOut requires 3 args'
134
    sys.exit(1)
3424 chandransh 135
  pp.pprint(client.scanOut(args[0],args[1],eval(args[2]),))
2821 chandransh 136
 
3431 rajveer 137
else:
138
  print 'Unrecognized method %s' % cmd
139
  sys.exit(1)
140
 
2821 chandransh 141
transport.close()