TCLIService-remote 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #!/usr/bin/env python
  2. #
  3. # Autogenerated by Thrift Compiler (0.9.3)
  4. #
  5. # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  6. #
  7. # options string: py:new_style
  8. #
  9. import sys
  10. import pprint
  11. from urlparse import urlparse
  12. from thrift.transport import TTransport
  13. from thrift.transport import TSocket
  14. from thrift.transport import TSSLSocket
  15. from thrift.transport import THttpClient
  16. from thrift.protocol import TBinaryProtocol
  17. from TCLIService import TCLIService
  18. from TCLIService.ttypes import *
  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]] [-s[sl]] function [arg1 [arg2...]]')
  22. print('')
  23. print('Functions:')
  24. print(' TOpenSessionResp OpenSession(TOpenSessionReq req)')
  25. print(' TCloseSessionResp CloseSession(TCloseSessionReq req)')
  26. print(' TGetInfoResp GetInfo(TGetInfoReq req)')
  27. print(' TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req)')
  28. print(' TGetTypeInfoResp GetTypeInfo(TGetTypeInfoReq req)')
  29. print(' TGetCatalogsResp GetCatalogs(TGetCatalogsReq req)')
  30. print(' TGetSchemasResp GetSchemas(TGetSchemasReq req)')
  31. print(' TGetTablesResp GetTables(TGetTablesReq req)')
  32. print(' TGetTableTypesResp GetTableTypes(TGetTableTypesReq req)')
  33. print(' TGetColumnsResp GetColumns(TGetColumnsReq req)')
  34. print(' TGetFunctionsResp GetFunctions(TGetFunctionsReq req)')
  35. print(' TGetPrimaryKeysResp GetPrimaryKeys(TGetPrimaryKeysReq req)')
  36. print(' TGetCrossReferenceResp GetCrossReference(TGetCrossReferenceReq req)')
  37. print(' TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req)')
  38. print(' TCancelOperationResp CancelOperation(TCancelOperationReq req)')
  39. print(' TCloseOperationResp CloseOperation(TCloseOperationReq req)')
  40. print(' TGetResultSetMetadataResp GetResultSetMetadata(TGetResultSetMetadataReq req)')
  41. print(' TFetchResultsResp FetchResults(TFetchResultsReq req)')
  42. print(' TGetDelegationTokenResp GetDelegationToken(TGetDelegationTokenReq req)')
  43. print(' TCancelDelegationTokenResp CancelDelegationToken(TCancelDelegationTokenReq req)')
  44. print(' TRenewDelegationTokenResp RenewDelegationToken(TRenewDelegationTokenReq req)')
  45. print(' TGetQueryIdResp GetQueryId(TGetQueryIdReq req)')
  46. print(' TSetClientInfoResp SetClientInfo(TSetClientInfoReq req)')
  47. print(' TGetLogResp GetLog(TGetLogReq req)')
  48. print('')
  49. sys.exit(0)
  50. pp = pprint.PrettyPrinter(indent = 2)
  51. host = 'localhost'
  52. port = 9090
  53. uri = ''
  54. framed = False
  55. ssl = False
  56. http = False
  57. argi = 1
  58. if sys.argv[argi] == '-h':
  59. parts = sys.argv[argi+1].split(':')
  60. host = parts[0]
  61. if len(parts) > 1:
  62. port = int(parts[1])
  63. argi += 2
  64. if sys.argv[argi] == '-u':
  65. url = urlparse(sys.argv[argi+1])
  66. parts = url[1].split(':')
  67. host = parts[0]
  68. if len(parts) > 1:
  69. port = int(parts[1])
  70. else:
  71. port = 80
  72. uri = url[2]
  73. if url[4]:
  74. uri += '?%s' % url[4]
  75. http = True
  76. argi += 2
  77. if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  78. framed = True
  79. argi += 1
  80. if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
  81. ssl = True
  82. argi += 1
  83. cmd = sys.argv[argi]
  84. args = sys.argv[argi+1:]
  85. if http:
  86. transport = THttpClient.THttpClient(host, port, uri)
  87. else:
  88. socket = TSSLSocket.TSSLSocket(host, port, validate=False) if ssl else TSocket.TSocket(host, port)
  89. if framed:
  90. transport = TTransport.TFramedTransport(socket)
  91. else:
  92. transport = TTransport.TBufferedTransport(socket)
  93. protocol = TBinaryProtocol.TBinaryProtocol(transport)
  94. client = TCLIService.Client(protocol)
  95. transport.open()
  96. if cmd == 'OpenSession':
  97. if len(args) != 1:
  98. print('OpenSession requires 1 args')
  99. sys.exit(1)
  100. pp.pprint(client.OpenSession(eval(args[0]),))
  101. elif cmd == 'CloseSession':
  102. if len(args) != 1:
  103. print('CloseSession requires 1 args')
  104. sys.exit(1)
  105. pp.pprint(client.CloseSession(eval(args[0]),))
  106. elif cmd == 'GetInfo':
  107. if len(args) != 1:
  108. print('GetInfo requires 1 args')
  109. sys.exit(1)
  110. pp.pprint(client.GetInfo(eval(args[0]),))
  111. elif cmd == 'ExecuteStatement':
  112. if len(args) != 1:
  113. print('ExecuteStatement requires 1 args')
  114. sys.exit(1)
  115. pp.pprint(client.ExecuteStatement(eval(args[0]),))
  116. elif cmd == 'GetTypeInfo':
  117. if len(args) != 1:
  118. print('GetTypeInfo requires 1 args')
  119. sys.exit(1)
  120. pp.pprint(client.GetTypeInfo(eval(args[0]),))
  121. elif cmd == 'GetCatalogs':
  122. if len(args) != 1:
  123. print('GetCatalogs requires 1 args')
  124. sys.exit(1)
  125. pp.pprint(client.GetCatalogs(eval(args[0]),))
  126. elif cmd == 'GetSchemas':
  127. if len(args) != 1:
  128. print('GetSchemas requires 1 args')
  129. sys.exit(1)
  130. pp.pprint(client.GetSchemas(eval(args[0]),))
  131. elif cmd == 'GetTables':
  132. if len(args) != 1:
  133. print('GetTables requires 1 args')
  134. sys.exit(1)
  135. pp.pprint(client.GetTables(eval(args[0]),))
  136. elif cmd == 'GetTableTypes':
  137. if len(args) != 1:
  138. print('GetTableTypes requires 1 args')
  139. sys.exit(1)
  140. pp.pprint(client.GetTableTypes(eval(args[0]),))
  141. elif cmd == 'GetColumns':
  142. if len(args) != 1:
  143. print('GetColumns requires 1 args')
  144. sys.exit(1)
  145. pp.pprint(client.GetColumns(eval(args[0]),))
  146. elif cmd == 'GetFunctions':
  147. if len(args) != 1:
  148. print('GetFunctions requires 1 args')
  149. sys.exit(1)
  150. pp.pprint(client.GetFunctions(eval(args[0]),))
  151. elif cmd == 'GetPrimaryKeys':
  152. if len(args) != 1:
  153. print('GetPrimaryKeys requires 1 args')
  154. sys.exit(1)
  155. pp.pprint(client.GetPrimaryKeys(eval(args[0]),))
  156. elif cmd == 'GetCrossReference':
  157. if len(args) != 1:
  158. print('GetCrossReference requires 1 args')
  159. sys.exit(1)
  160. pp.pprint(client.GetCrossReference(eval(args[0]),))
  161. elif cmd == 'GetOperationStatus':
  162. if len(args) != 1:
  163. print('GetOperationStatus requires 1 args')
  164. sys.exit(1)
  165. pp.pprint(client.GetOperationStatus(eval(args[0]),))
  166. elif cmd == 'CancelOperation':
  167. if len(args) != 1:
  168. print('CancelOperation requires 1 args')
  169. sys.exit(1)
  170. pp.pprint(client.CancelOperation(eval(args[0]),))
  171. elif cmd == 'CloseOperation':
  172. if len(args) != 1:
  173. print('CloseOperation requires 1 args')
  174. sys.exit(1)
  175. pp.pprint(client.CloseOperation(eval(args[0]),))
  176. elif cmd == 'GetResultSetMetadata':
  177. if len(args) != 1:
  178. print('GetResultSetMetadata requires 1 args')
  179. sys.exit(1)
  180. pp.pprint(client.GetResultSetMetadata(eval(args[0]),))
  181. elif cmd == 'FetchResults':
  182. if len(args) != 1:
  183. print('FetchResults requires 1 args')
  184. sys.exit(1)
  185. pp.pprint(client.FetchResults(eval(args[0]),))
  186. elif cmd == 'GetDelegationToken':
  187. if len(args) != 1:
  188. print('GetDelegationToken requires 1 args')
  189. sys.exit(1)
  190. pp.pprint(client.GetDelegationToken(eval(args[0]),))
  191. elif cmd == 'CancelDelegationToken':
  192. if len(args) != 1:
  193. print('CancelDelegationToken requires 1 args')
  194. sys.exit(1)
  195. pp.pprint(client.CancelDelegationToken(eval(args[0]),))
  196. elif cmd == 'RenewDelegationToken':
  197. if len(args) != 1:
  198. print('RenewDelegationToken requires 1 args')
  199. sys.exit(1)
  200. pp.pprint(client.RenewDelegationToken(eval(args[0]),))
  201. elif cmd == 'GetQueryId':
  202. if len(args) != 1:
  203. print('GetQueryId requires 1 args')
  204. sys.exit(1)
  205. pp.pprint(client.GetQueryId(eval(args[0]),))
  206. elif cmd == 'SetClientInfo':
  207. if len(args) != 1:
  208. print('SetClientInfo requires 1 args')
  209. sys.exit(1)
  210. pp.pprint(client.SetClientInfo(eval(args[0]),))
  211. elif cmd == 'GetLog':
  212. if len(args) != 1:
  213. print('GetLog requires 1 args')
  214. sys.exit(1)
  215. pp.pprint(client.GetLog(eval(args[0]),))
  216. else:
  217. print('Unrecognized method %s' % cmd)
  218. sys.exit(1)
  219. transport.close()