TCLIService-remote 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #!/usr/bin/env python
  2. #
  3. # Autogenerated by Thrift Compiler (0.13.0)
  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. if sys.version_info[0] > 2:
  12. from urllib.parse import urlparse
  13. else:
  14. from urlparse import urlparse
  15. from thrift.transport import TTransport, TSocket, TSSLSocket, THttpClient
  16. from thrift.protocol.TBinaryProtocol 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]] [-novalidate] [-ca_certs certs] [-keyfile keyfile] [-certfile certfile] 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(' TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req)')
  36. print(' TCancelOperationResp CancelOperation(TCancelOperationReq req)')
  37. print(' TCloseOperationResp CloseOperation(TCloseOperationReq req)')
  38. print(' TGetResultSetMetadataResp GetResultSetMetadata(TGetResultSetMetadataReq req)')
  39. print(' TFetchResultsResp FetchResults(TFetchResultsReq req)')
  40. print(' TGetDelegationTokenResp GetDelegationToken(TGetDelegationTokenReq req)')
  41. print(' TCancelDelegationTokenResp CancelDelegationToken(TCancelDelegationTokenReq req)')
  42. print(' TRenewDelegationTokenResp RenewDelegationToken(TRenewDelegationTokenReq req)')
  43. print(' TGetLogResp GetLog(TGetLogReq req)')
  44. print('')
  45. sys.exit(0)
  46. pp = pprint.PrettyPrinter(indent=2)
  47. host = 'localhost'
  48. port = 9090
  49. uri = ''
  50. framed = False
  51. ssl = False
  52. validate = True
  53. ca_certs = None
  54. keyfile = None
  55. certfile = None
  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. if sys.argv[argi] == '-novalidate':
  84. validate = False
  85. argi += 1
  86. if sys.argv[argi] == '-ca_certs':
  87. ca_certs = sys.argv[argi+1]
  88. argi += 2
  89. if sys.argv[argi] == '-keyfile':
  90. keyfile = sys.argv[argi+1]
  91. argi += 2
  92. if sys.argv[argi] == '-certfile':
  93. certfile = sys.argv[argi+1]
  94. argi += 2
  95. cmd = sys.argv[argi]
  96. args = sys.argv[argi + 1:]
  97. if http:
  98. transport = THttpClient.THttpClient(host, port, uri)
  99. else:
  100. if ssl:
  101. socket = TSSLSocket.TSSLSocket(host, port, validate=validate, ca_certs=ca_certs, keyfile=keyfile, certfile=certfile)
  102. else:
  103. socket = TSocket.TSocket(host, port)
  104. if framed:
  105. transport = TTransport.TFramedTransport(socket)
  106. else:
  107. transport = TTransport.TBufferedTransport(socket)
  108. protocol = TBinaryProtocol(transport)
  109. client = TCLIService.Client(protocol)
  110. transport.open()
  111. if cmd == 'OpenSession':
  112. if len(args) != 1:
  113. print('OpenSession requires 1 args')
  114. sys.exit(1)
  115. pp.pprint(client.OpenSession(eval(args[0]),))
  116. elif cmd == 'CloseSession':
  117. if len(args) != 1:
  118. print('CloseSession requires 1 args')
  119. sys.exit(1)
  120. pp.pprint(client.CloseSession(eval(args[0]),))
  121. elif cmd == 'GetInfo':
  122. if len(args) != 1:
  123. print('GetInfo requires 1 args')
  124. sys.exit(1)
  125. pp.pprint(client.GetInfo(eval(args[0]),))
  126. elif cmd == 'ExecuteStatement':
  127. if len(args) != 1:
  128. print('ExecuteStatement requires 1 args')
  129. sys.exit(1)
  130. pp.pprint(client.ExecuteStatement(eval(args[0]),))
  131. elif cmd == 'GetTypeInfo':
  132. if len(args) != 1:
  133. print('GetTypeInfo requires 1 args')
  134. sys.exit(1)
  135. pp.pprint(client.GetTypeInfo(eval(args[0]),))
  136. elif cmd == 'GetCatalogs':
  137. if len(args) != 1:
  138. print('GetCatalogs requires 1 args')
  139. sys.exit(1)
  140. pp.pprint(client.GetCatalogs(eval(args[0]),))
  141. elif cmd == 'GetSchemas':
  142. if len(args) != 1:
  143. print('GetSchemas requires 1 args')
  144. sys.exit(1)
  145. pp.pprint(client.GetSchemas(eval(args[0]),))
  146. elif cmd == 'GetTables':
  147. if len(args) != 1:
  148. print('GetTables requires 1 args')
  149. sys.exit(1)
  150. pp.pprint(client.GetTables(eval(args[0]),))
  151. elif cmd == 'GetTableTypes':
  152. if len(args) != 1:
  153. print('GetTableTypes requires 1 args')
  154. sys.exit(1)
  155. pp.pprint(client.GetTableTypes(eval(args[0]),))
  156. elif cmd == 'GetColumns':
  157. if len(args) != 1:
  158. print('GetColumns requires 1 args')
  159. sys.exit(1)
  160. pp.pprint(client.GetColumns(eval(args[0]),))
  161. elif cmd == 'GetFunctions':
  162. if len(args) != 1:
  163. print('GetFunctions requires 1 args')
  164. sys.exit(1)
  165. pp.pprint(client.GetFunctions(eval(args[0]),))
  166. elif cmd == 'GetOperationStatus':
  167. if len(args) != 1:
  168. print('GetOperationStatus requires 1 args')
  169. sys.exit(1)
  170. pp.pprint(client.GetOperationStatus(eval(args[0]),))
  171. elif cmd == 'CancelOperation':
  172. if len(args) != 1:
  173. print('CancelOperation requires 1 args')
  174. sys.exit(1)
  175. pp.pprint(client.CancelOperation(eval(args[0]),))
  176. elif cmd == 'CloseOperation':
  177. if len(args) != 1:
  178. print('CloseOperation requires 1 args')
  179. sys.exit(1)
  180. pp.pprint(client.CloseOperation(eval(args[0]),))
  181. elif cmd == 'GetResultSetMetadata':
  182. if len(args) != 1:
  183. print('GetResultSetMetadata requires 1 args')
  184. sys.exit(1)
  185. pp.pprint(client.GetResultSetMetadata(eval(args[0]),))
  186. elif cmd == 'FetchResults':
  187. if len(args) != 1:
  188. print('FetchResults requires 1 args')
  189. sys.exit(1)
  190. pp.pprint(client.FetchResults(eval(args[0]),))
  191. elif cmd == 'GetDelegationToken':
  192. if len(args) != 1:
  193. print('GetDelegationToken requires 1 args')
  194. sys.exit(1)
  195. pp.pprint(client.GetDelegationToken(eval(args[0]),))
  196. elif cmd == 'CancelDelegationToken':
  197. if len(args) != 1:
  198. print('CancelDelegationToken requires 1 args')
  199. sys.exit(1)
  200. pp.pprint(client.CancelDelegationToken(eval(args[0]),))
  201. elif cmd == 'RenewDelegationToken':
  202. if len(args) != 1:
  203. print('RenewDelegationToken requires 1 args')
  204. sys.exit(1)
  205. pp.pprint(client.RenewDelegationToken(eval(args[0]),))
  206. elif cmd == 'GetLog':
  207. if len(args) != 1:
  208. print('GetLog requires 1 args')
  209. sys.exit(1)
  210. pp.pprint(client.GetLog(eval(args[0]),))
  211. else:
  212. print('Unrecognized method %s' % cmd)
  213. sys.exit(1)
  214. transport.close()