Subversion Repositories SmartDukaan

Rev

Rev 3383 | Rev 3431 | 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
#
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 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':
45
  parts = sys.argv[argi+1].split(':') 
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])
52
  parts = url[1].split(':') 
53
  host = parts[0]
54
  if len(parts) > 1:
55
    port = int(parts[1])
56
  else:
57
    port = 80
58
  uri = url[2]
59
  http = True
60
  argi += 2
61
 
62
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
63
  framed = True
64
  argi += 1
65
 
66
cmd = sys.argv[argi]
67
args = sys.argv[argi+1:]
68
 
69
if http:
70
  transport = THttpClient.THttpClient(host, port, uri)
71
else:
72
  socket = TSocket.TSocket(host, port)
73
  if framed:
74
    transport = TTransport.TFramedTransport(socket)
75
  else:
76
    transport = TTransport.TBufferedTransport(socket)
77
protocol = TBinaryProtocol.TBinaryProtocol(transport)
78
client = WarehouseService.Client(protocol)
79
transport.open()
80
 
81
if cmd == 'createPurchaseOrder':
82
  if len(args) != 1:
83
    print 'createPurchaseOrder requires 1 args'
84
    sys.exit(1)
85
  pp.pprint(client.createPurchaseOrder(eval(args[0]),))
86
 
87
elif cmd == 'getPurchaseOrder':
88
  if len(args) != 1:
89
    print 'getPurchaseOrder requires 1 args'
90
    sys.exit(1)
91
  pp.pprint(client.getPurchaseOrder(eval(args[0]),))
92
 
3383 chandransh 93
elif cmd == 'getAllPurchaseOrders':
94
  if len(args) != 1:
95
    print 'getAllPurchaseOrders requires 1 args'
96
    sys.exit(1)
97
  pp.pprint(client.getAllPurchaseOrders(eval(args[0]),))
98
 
2832 chandransh 99
elif cmd == 'getSupplier':
100
  if len(args) != 1:
101
    print 'getSupplier requires 1 args'
102
    sys.exit(1)
103
  pp.pprint(client.getSupplier(eval(args[0]),))
104
 
2821 chandransh 105
elif cmd == 'startPurchase':
106
  if len(args) != 3:
107
    print 'startPurchase requires 3 args'
108
    sys.exit(1)
109
  pp.pprint(client.startPurchase(eval(args[0]),args[1],eval(args[2]),))
110
 
111
elif cmd == 'closePurchase':
112
  if len(args) != 1:
113
    print 'closePurchase requires 1 args'
114
    sys.exit(1)
115
  pp.pprint(client.closePurchase(eval(args[0]),))
116
 
3383 chandransh 117
elif cmd == 'getAllPurchases':
118
  if len(args) != 2:
119
    print 'getAllPurchases requires 2 args'
120
    sys.exit(1)
121
  pp.pprint(client.getAllPurchases(eval(args[0]),eval(args[1]),))
122
 
2821 chandransh 123
elif cmd == 'scanIn':
3383 chandransh 124
  if len(args) != 4:
125
    print 'scanIn requires 4 args'
2821 chandransh 126
    sys.exit(1)
3383 chandransh 127
  pp.pprint(client.scanIn(eval(args[0]),args[1],args[2],eval(args[3]),))
2821 chandransh 128
 
129
elif cmd == 'scanOut':
130
  if len(args) != 3:
131
    print 'scanOut requires 3 args'
132
    sys.exit(1)
3424 chandransh 133
  pp.pprint(client.scanOut(args[0],args[1],eval(args[2]),))
2821 chandransh 134
 
135
transport.close()