Subversion Repositories SmartDukaan

Rev

Rev 2832 | Go to most recent revision | Details | 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)'
26
  print '  i64 startPurchase(i64 purchaseOrderId, string invoiceNumber, double freightCharges)'
27
  print '  i64 closePurchase(i64 purchaseId)'
28
  print '  void scanIn(i64 purchaseId, i64 itemId, string itemNumber, string imeiNumber, ScanType type)'
29
  print '  void scanOut(i64 itemNumber, i64 imeiNumber, ScanType type)'
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 = WarehouseService.Client(protocol)
76
transport.open()
77
 
78
if cmd == 'createPurchaseOrder':
79
  if len(args) != 1:
80
    print 'createPurchaseOrder requires 1 args'
81
    sys.exit(1)
82
  pp.pprint(client.createPurchaseOrder(eval(args[0]),))
83
 
84
elif cmd == 'getPurchaseOrder':
85
  if len(args) != 1:
86
    print 'getPurchaseOrder requires 1 args'
87
    sys.exit(1)
88
  pp.pprint(client.getPurchaseOrder(eval(args[0]),))
89
 
90
elif cmd == 'startPurchase':
91
  if len(args) != 3:
92
    print 'startPurchase requires 3 args'
93
    sys.exit(1)
94
  pp.pprint(client.startPurchase(eval(args[0]),args[1],eval(args[2]),))
95
 
96
elif cmd == 'closePurchase':
97
  if len(args) != 1:
98
    print 'closePurchase requires 1 args'
99
    sys.exit(1)
100
  pp.pprint(client.closePurchase(eval(args[0]),))
101
 
102
elif cmd == 'scanIn':
103
  if len(args) != 5:
104
    print 'scanIn requires 5 args'
105
    sys.exit(1)
106
  pp.pprint(client.scanIn(eval(args[0]),eval(args[1]),args[2],args[3],eval(args[4]),))
107
 
108
elif cmd == 'scanOut':
109
  if len(args) != 3:
110
    print 'scanOut requires 3 args'
111
    sys.exit(1)
112
  pp.pprint(client.scanOut(eval(args[0]),eval(args[1]),eval(args[2]),))
113
 
114
transport.close()