TCLIService-remote 5.1 KB

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