Subversion Repositories SmartDukaan

Rev

Rev 2821 | Rev 3383 | 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)'
2832 chandransh 26
  print '  Supplier getSupplier(i64 id)'
2821 chandransh 27
  print '  i64 startPurchase(i64 purchaseOrderId, string invoiceNumber, double freightCharges)'
28
  print '  i64 closePurchase(i64 purchaseId)'
29
  print '  void scanIn(i64 purchaseId, i64 itemId, string itemNumber, string imeiNumber, ScanType type)'
30
  print '  void scanOut(i64 itemNumber, i64 imeiNumber, ScanType type)'
31
  print ''
32
  sys.exit(0)
33
 
34
pp = pprint.PrettyPrinter(indent = 2)
35
host = 'localhost'
36
port = 9090
37
uri = ''
38
framed = False
39
http = False
40
argi = 1
41
 
42
if sys.argv[argi] == '-h':
43
  parts = sys.argv[argi+1].split(':') 
44
  host = parts[0]
45
  port = int(parts[1])
46
  argi += 2
47
 
48
if sys.argv[argi] == '-u':
49
  url = urlparse(sys.argv[argi+1])
50
  parts = url[1].split(':') 
51
  host = parts[0]
52
  if len(parts) > 1:
53
    port = int(parts[1])
54
  else:
55
    port = 80
56
  uri = url[2]
57
  http = True
58
  argi += 2
59
 
60
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
61
  framed = True
62
  argi += 1
63
 
64
cmd = sys.argv[argi]
65
args = sys.argv[argi+1:]
66
 
67
if http:
68
  transport = THttpClient.THttpClient(host, port, uri)
69
else:
70
  socket = TSocket.TSocket(host, port)
71
  if framed:
72
    transport = TTransport.TFramedTransport(socket)
73
  else:
74
    transport = TTransport.TBufferedTransport(socket)
75
protocol = TBinaryProtocol.TBinaryProtocol(transport)
76
client = WarehouseService.Client(protocol)
77
transport.open()
78
 
79
if cmd == 'createPurchaseOrder':
80
  if len(args) != 1:
81
    print 'createPurchaseOrder requires 1 args'
82
    sys.exit(1)
83
  pp.pprint(client.createPurchaseOrder(eval(args[0]),))
84
 
85
elif cmd == 'getPurchaseOrder':
86
  if len(args) != 1:
87
    print 'getPurchaseOrder requires 1 args'
88
    sys.exit(1)
89
  pp.pprint(client.getPurchaseOrder(eval(args[0]),))
90
 
2832 chandransh 91
elif cmd == 'getSupplier':
92
  if len(args) != 1:
93
    print 'getSupplier requires 1 args'
94
    sys.exit(1)
95
  pp.pprint(client.getSupplier(eval(args[0]),))
96
 
2821 chandransh 97
elif cmd == 'startPurchase':
98
  if len(args) != 3:
99
    print 'startPurchase requires 3 args'
100
    sys.exit(1)
101
  pp.pprint(client.startPurchase(eval(args[0]),args[1],eval(args[2]),))
102
 
103
elif cmd == 'closePurchase':
104
  if len(args) != 1:
105
    print 'closePurchase requires 1 args'
106
    sys.exit(1)
107
  pp.pprint(client.closePurchase(eval(args[0]),))
108
 
109
elif cmd == 'scanIn':
110
  if len(args) != 5:
111
    print 'scanIn requires 5 args'
112
    sys.exit(1)
113
  pp.pprint(client.scanIn(eval(args[0]),eval(args[1]),args[2],args[3],eval(args[4]),))
114
 
115
elif cmd == 'scanOut':
116
  if len(args) != 3:
117
    print 'scanOut requires 3 args'
118
    sys.exit(1)
119
  pp.pprint(client.scanOut(eval(args[0]),eval(args[1]),eval(args[2]),))
120
 
121
transport.close()