summaryrefslogtreecommitdiff
path: root/lang/python/src/wiredtiger/service/WiredTiger-remote
blob: 027792c9c55cdefceeb21fc0509061a8cd686928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env python
#
# Autogenerated by Thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#

import sys
import pprint
from urlparse import urlparse
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol

import WiredTiger
from ttypes import *

if len(sys.argv) <= 1 or sys.argv[1] == '--help':
  print ''
  print 'Usage: ' + sys.argv[0] + ' [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
  print ''
  print 'Functions:'
  print '  string strerror(i32 err)'
  print '  WT_VERSION version()'
  print '  WT_HANDLE open(string home, string config)'
  print '  WT_HANDLE open_session(WT_HANDLE connection, string config)'
  print '  void close_connection(WT_HANDLE connection, string config)'
  print '  bool is_new(WT_HANDLE connection)'
  print '  void close_session(WT_HANDLE session, string config)'
  print '  WT_CURSOR_HANDLE open_cursor(WT_HANDLE session, string uri, WT_HANDLE to_dup, string config)'
  print '  void create_table(WT_HANDLE session, string name, string config)'
  print '  void rename_table(WT_HANDLE session, string oldname, string newname, string config)'
  print '  void drop_table(WT_HANDLE session, string name, string config)'
  print '  void truncate_table(WT_HANDLE session, string name, WT_HANDLE cursor_start, WT_HANDLE cursor_end, string config)'
  print '  void verify_table(WT_HANDLE session, string name, string config)'
  print '  void begin_transaction(WT_HANDLE session, string config)'
  print '  void commit_transaction(WT_HANDLE session, string config)'
  print '  void rollback_transaction(WT_HANDLE session, string config)'
  print '  void checkpoint(WT_HANDLE session, string config)'
  print '  WT_MOVE_RESULT move_first(WT_HANDLE cursor)'
  print '  WT_MOVE_RESULT move_last(WT_HANDLE cursor)'
  print '  WT_MOVE_RESULT move_next(WT_HANDLE cursor)'
  print '  WT_MOVE_RESULT move_prev(WT_HANDLE cursor)'
  print '  WT_MOVE_RESULT search(WT_HANDLE cursor, WT_RECORD record)'
  print '  WT_MOVE_RESULT search_near(WT_HANDLE cursor, WT_RECORD record)'
  print '  string insert_record(WT_HANDLE cursor, WT_RECORD record)'
  print '  void update_record(WT_HANDLE cursor, string value)'
  print '  void delete_record(WT_HANDLE cursor)'
  print '  void close_cursor(WT_HANDLE cursor, string config)'
  print ''
  sys.exit(0)

pp = pprint.PrettyPrinter(indent = 2)
host = 'localhost'
port = 9090
uri = ''
framed = False
http = False
argi = 1

if sys.argv[argi] == '-h':
  parts = sys.argv[argi+1].split(':')
  host = parts[0]
  port = int(parts[1])
  argi += 2

if sys.argv[argi] == '-u':
  url = urlparse(sys.argv[argi+1])
  parts = url[1].split(':')
  host = parts[0]
  if len(parts) > 1:
    port = int(parts[1])
  else:
    port = 80
  uri = url[2]
  if url[4]:
    uri += '?%s' % url[4]
  http = True
  argi += 2

if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  framed = True
  argi += 1

cmd = sys.argv[argi]
args = sys.argv[argi+1:]

if http:
  transport = THttpClient.THttpClient(host, port, uri)
else:
  socket = TSocket.TSocket(host, port)
  if framed:
    transport = TTransport.TFramedTransport(socket)
  else:
    transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = WiredTiger.Client(protocol)
transport.open()

if cmd == 'strerror':
  if len(args) != 1:
    print 'strerror requires 1 args'
    sys.exit(1)
  pp.pprint(client.strerror(eval(args[0]),))

elif cmd == 'version':
  if len(args) != 0:
    print 'version requires 0 args'
    sys.exit(1)
  pp.pprint(client.version())

elif cmd == 'open':
  if len(args) != 2:
    print 'open requires 2 args'
    sys.exit(1)
  pp.pprint(client.open(args[0],args[1],))

elif cmd == 'open_session':
  if len(args) != 2:
    print 'open_session requires 2 args'
    sys.exit(1)
  pp.pprint(client.open_session(eval(args[0]),args[1],))

elif cmd == 'close_connection':
  if len(args) != 2:
    print 'close_connection requires 2 args'
    sys.exit(1)
  pp.pprint(client.close_connection(eval(args[0]),args[1],))

elif cmd == 'is_new':
  if len(args) != 1:
    print 'is_new requires 1 args'
    sys.exit(1)
  pp.pprint(client.is_new(eval(args[0]),))

elif cmd == 'close_session':
  if len(args) != 2:
    print 'close_session requires 2 args'
    sys.exit(1)
  pp.pprint(client.close_session(eval(args[0]),args[1],))

elif cmd == 'open_cursor':
  if len(args) != 4:
    print 'open_cursor requires 4 args'
    sys.exit(1)
  pp.pprint(client.open_cursor(eval(args[0]),args[1],eval(args[2]),args[3],))

elif cmd == 'create_table':
  if len(args) != 3:
    print 'create_table requires 3 args'
    sys.exit(1)
  pp.pprint(client.create_table(eval(args[0]),args[1],args[2],))

elif cmd == 'rename_table':
  if len(args) != 4:
    print 'rename_table requires 4 args'
    sys.exit(1)
  pp.pprint(client.rename_table(eval(args[0]),args[1],args[2],args[3],))

elif cmd == 'drop_table':
  if len(args) != 3:
    print 'drop_table requires 3 args'
    sys.exit(1)
  pp.pprint(client.drop_table(eval(args[0]),args[1],args[2],))

elif cmd == 'truncate_table':
  if len(args) != 5:
    print 'truncate_table requires 5 args'
    sys.exit(1)
  pp.pprint(client.truncate_table(eval(args[0]),args[1],eval(args[2]),eval(args[3]),args[4],))

elif cmd == 'verify_table':
  if len(args) != 3:
    print 'verify_table requires 3 args'
    sys.exit(1)
  pp.pprint(client.verify_table(eval(args[0]),args[1],args[2],))

elif cmd == 'begin_transaction':
  if len(args) != 2:
    print 'begin_transaction requires 2 args'
    sys.exit(1)
  pp.pprint(client.begin_transaction(eval(args[0]),args[1],))

elif cmd == 'commit_transaction':
  if len(args) != 2:
    print 'commit_transaction requires 2 args'
    sys.exit(1)
  pp.pprint(client.commit_transaction(eval(args[0]),args[1],))

elif cmd == 'rollback_transaction':
  if len(args) != 2:
    print 'rollback_transaction requires 2 args'
    sys.exit(1)
  pp.pprint(client.rollback_transaction(eval(args[0]),args[1],))

elif cmd == 'checkpoint':
  if len(args) != 2:
    print 'checkpoint requires 2 args'
    sys.exit(1)
  pp.pprint(client.checkpoint(eval(args[0]),args[1],))

elif cmd == 'move_first':
  if len(args) != 1:
    print 'move_first requires 1 args'
    sys.exit(1)
  pp.pprint(client.move_first(eval(args[0]),))

elif cmd == 'move_last':
  if len(args) != 1:
    print 'move_last requires 1 args'
    sys.exit(1)
  pp.pprint(client.move_last(eval(args[0]),))

elif cmd == 'move_next':
  if len(args) != 1:
    print 'move_next requires 1 args'
    sys.exit(1)
  pp.pprint(client.move_next(eval(args[0]),))

elif cmd == 'move_prev':
  if len(args) != 1:
    print 'move_prev requires 1 args'
    sys.exit(1)
  pp.pprint(client.move_prev(eval(args[0]),))

elif cmd == 'search':
  if len(args) != 2:
    print 'search requires 2 args'
    sys.exit(1)
  pp.pprint(client.search(eval(args[0]),eval(args[1]),))

elif cmd == 'search_near':
  if len(args) != 2:
    print 'search_near requires 2 args'
    sys.exit(1)
  pp.pprint(client.search_near(eval(args[0]),eval(args[1]),))

elif cmd == 'insert_record':
  if len(args) != 2:
    print 'insert_record requires 2 args'
    sys.exit(1)
  pp.pprint(client.insert_record(eval(args[0]),eval(args[1]),))

elif cmd == 'update_record':
  if len(args) != 2:
    print 'update_record requires 2 args'
    sys.exit(1)
  pp.pprint(client.update_record(eval(args[0]),args[1],))

elif cmd == 'delete_record':
  if len(args) != 1:
    print 'delete_record requires 1 args'
    sys.exit(1)
  pp.pprint(client.delete_record(eval(args[0]),))

elif cmd == 'close_cursor':
  if len(args) != 2:
    print 'close_cursor requires 2 args'
    sys.exit(1)
  pp.pprint(client.close_cursor(eval(args[0]),args[1],))

else:
  print 'Unrecognized method %s' % cmd
  sys.exit(1)

transport.close()