TCLIService-remote 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #!/usr/bin/env python
  2. #
  3. # Autogenerated by Thrift Compiler (0.9.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. from urlparse import urlparse
  12. from thrift.transport import TTransport
  13. from thrift.transport import TSocket
  14. from thrift.transport import THttpClient
  15. from thrift.protocol import TBinaryProtocol
  16. import TCLIService
  17. from ttypes import *
  18. if len(sys.argv) <= 1 or sys.argv[1] == '--help':
  19. print ''
  20. print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
  21. print ''
  22. print 'Functions:'
  23. print ' TOpenSessionResp OpenSession(TOpenSessionReq req)'
  24. print ' TCloseSessionResp CloseSession(TCloseSessionReq req)'
  25. print ' TGetInfoResp GetInfo(TGetInfoReq req)'
  26. print ' TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req)'
  27. print ' TGetTypeInfoResp GetTypeInfo(TGetTypeInfoReq req)'
  28. print ' TGetCatalogsResp GetCatalogs(TGetCatalogsReq req)'
  29. print ' TGetSchemasResp GetSchemas(TGetSchemasReq req)'
  30. print ' TGetTablesResp GetTables(TGetTablesReq req)'
  31. print ' TGetTableTypesResp GetTableTypes(TGetTableTypesReq req)'
  32. print ' TGetColumnsResp GetColumns(TGetColumnsReq req)'
  33. print ' TGetFunctionsResp GetFunctions(TGetFunctionsReq req)'
  34. print ' TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req)'
  35. print ' TCancelOperationResp CancelOperation(TCancelOperationReq req)'
  36. print ' TCloseOperationResp CloseOperation(TCloseOperationReq req)'
  37. print ' TGetResultSetMetadataResp GetResultSetMetadata(TGetResultSetMetadataReq req)'
  38. print ' TFetchResultsResp FetchResults(TFetchResultsReq req)'
  39. print ' TGetLogResp GetLog(TGetLogReq req)'
  40. print ''
  41. sys.exit(0)
  42. pp = pprint.PrettyPrinter(indent = 2)
  43. host = 'localhost'
  44. port = 9090
  45. uri = ''
  46. framed = False
  47. http = False
  48. argi = 1
  49. if sys.argv[argi] == '-h':
  50. parts = sys.argv[argi+1].split(':')
  51. host = parts[0]
  52. if len(parts) > 1:
  53. port = int(parts[1])
  54. argi += 2
  55. if sys.argv[argi] == '-u':
  56. url = urlparse(sys.argv[argi+1])
  57. parts = url[1].split(':')
  58. host = parts[0]
  59. if len(parts) > 1:
  60. port = int(parts[1])
  61. else:
  62. port = 80
  63. uri = url[2]
  64. if url[4]:
  65. uri += '?%s' % url[4]
  66. http = True
  67. argi += 2
  68. if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  69. framed = True
  70. argi += 1
  71. cmd = sys.argv[argi]
  72. args = sys.argv[argi+1:]
  73. if http:
  74. transport = THttpClient.THttpClient(host, port, uri)
  75. else:
  76. socket = TSocket.TSocket(host, port)
  77. if framed:
  78. transport = TTransport.TFramedTransport(socket)
  79. else:
  80. transport = TTransport.TBufferedTransport(socket)
  81. protocol = TBinaryProtocol.TBinaryProtocol(transport)
  82. client = TCLIService.Client(protocol)
  83. transport.open()
  84. if cmd == 'OpenSession':
  85. if len(args) != 1:
  86. print 'OpenSession requires 1 args'
  87. sys.exit(1)
  88. pp.pprint(client.OpenSession(eval(args[0]),))
  89. elif cmd == 'CloseSession':
  90. if len(args) != 1:
  91. print 'CloseSession requires 1 args'
  92. sys.exit(1)
  93. pp.pprint(client.CloseSession(eval(args[0]),))
  94. elif cmd == 'GetInfo':
  95. if len(args) != 1:
  96. print 'GetInfo requires 1 args'
  97. sys.exit(1)
  98. pp.pprint(client.GetInfo(eval(args[0]),))
  99. elif cmd == 'ExecuteStatement':
  100. if len(args) != 1:
  101. print 'ExecuteStatement requires 1 args'
  102. sys.exit(1)
  103. pp.pprint(client.ExecuteStatement(eval(args[0]),))
  104. elif cmd == 'GetTypeInfo':
  105. if len(args) != 1:
  106. print 'GetTypeInfo requires 1 args'
  107. sys.exit(1)
  108. pp.pprint(client.GetTypeInfo(eval(args[0]),))
  109. elif cmd == 'GetCatalogs':
  110. if len(args) != 1:
  111. print 'GetCatalogs requires 1 args'
  112. sys.exit(1)
  113. pp.pprint(client.GetCatalogs(eval(args[0]),))
  114. elif cmd == 'GetSchemas':
  115. if len(args) != 1:
  116. print 'GetSchemas requires 1 args'
  117. sys.exit(1)
  118. pp.pprint(client.GetSchemas(eval(args[0]),))
  119. elif cmd == 'GetTables':
  120. if len(args) != 1:
  121. print 'GetTables requires 1 args'
  122. sys.exit(1)
  123. pp.pprint(client.GetTables(eval(args[0]),))
  124. elif cmd == 'GetTableTypes':
  125. if len(args) != 1:
  126. print 'GetTableTypes requires 1 args'
  127. sys.exit(1)
  128. pp.pprint(client.GetTableTypes(eval(args[0]),))
  129. elif cmd == 'GetColumns':
  130. if len(args) != 1:
  131. print 'GetColumns requires 1 args'
  132. sys.exit(1)
  133. pp.pprint(client.GetColumns(eval(args[0]),))
  134. elif cmd == 'GetFunctions':
  135. if len(args) != 1:
  136. print 'GetFunctions requires 1 args'
  137. sys.exit(1)
  138. pp.pprint(client.GetFunctions(eval(args[0]),))
  139. elif cmd == 'GetOperationStatus':
  140. if len(args) != 1:
  141. print 'GetOperationStatus requires 1 args'
  142. sys.exit(1)
  143. pp.pprint(client.GetOperationStatus(eval(args[0]),))
  144. elif cmd == 'CancelOperation':
  145. if len(args) != 1:
  146. print 'CancelOperation requires 1 args'
  147. sys.exit(1)
  148. pp.pprint(client.CancelOperation(eval(args[0]),))
  149. elif cmd == 'CloseOperation':
  150. if len(args) != 1:
  151. print 'CloseOperation requires 1 args'
  152. sys.exit(1)
  153. pp.pprint(client.CloseOperation(eval(args[0]),))
  154. elif cmd == 'GetResultSetMetadata':
  155. if len(args) != 1:
  156. print 'GetResultSetMetadata requires 1 args'
  157. sys.exit(1)
  158. pp.pprint(client.GetResultSetMetadata(eval(args[0]),))
  159. elif cmd == 'FetchResults':
  160. if len(args) != 1:
  161. print 'FetchResults requires 1 args'
  162. sys.exit(1)
  163. pp.pprint(client.FetchResults(eval(args[0]),))
  164. elif cmd == 'GetLog':
  165. if len(args) != 1:
  166. print 'GetLog requires 1 args'
  167. sys.exit(1)
  168. pp.pprint(client.GetLog(eval(args[0]),))
  169. else:
  170. print 'Unrecognized method %s' % cmd
  171. sys.exit(1)
  172. transport.close()