FacebookService-remote 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 fb303 import FacebookService
  18. from fb303.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(' string getName()')
  25. print(' string getVersion()')
  26. print(' fb_status getStatus()')
  27. print(' string getStatusDetails()')
  28. print(' getCounters()')
  29. print(' i64 getCounter(string key)')
  30. print(' void setOption(string key, string value)')
  31. print(' string getOption(string key)')
  32. print(' getOptions()')
  33. print(' string getCpuProfile(i32 profileDurationInSec)')
  34. print(' i64 aliveSince()')
  35. print(' void reinitialize()')
  36. print(' void shutdown()')
  37. print('')
  38. sys.exit(0)
  39. pp = pprint.PrettyPrinter(indent=2)
  40. host = 'localhost'
  41. port = 9090
  42. uri = ''
  43. framed = False
  44. ssl = False
  45. validate = True
  46. ca_certs = None
  47. keyfile = None
  48. certfile = None
  49. http = False
  50. argi = 1
  51. if sys.argv[argi] == '-h':
  52. parts = sys.argv[argi + 1].split(':')
  53. host = parts[0]
  54. if len(parts) > 1:
  55. port = int(parts[1])
  56. argi += 2
  57. if sys.argv[argi] == '-u':
  58. url = urlparse(sys.argv[argi + 1])
  59. parts = url[1].split(':')
  60. host = parts[0]
  61. if len(parts) > 1:
  62. port = int(parts[1])
  63. else:
  64. port = 80
  65. uri = url[2]
  66. if url[4]:
  67. uri += '?%s' % url[4]
  68. http = True
  69. argi += 2
  70. if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  71. framed = True
  72. argi += 1
  73. if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
  74. ssl = True
  75. argi += 1
  76. if sys.argv[argi] == '-novalidate':
  77. validate = False
  78. argi += 1
  79. if sys.argv[argi] == '-ca_certs':
  80. ca_certs = sys.argv[argi+1]
  81. argi += 2
  82. if sys.argv[argi] == '-keyfile':
  83. keyfile = sys.argv[argi+1]
  84. argi += 2
  85. if sys.argv[argi] == '-certfile':
  86. certfile = sys.argv[argi+1]
  87. argi += 2
  88. cmd = sys.argv[argi]
  89. args = sys.argv[argi + 1:]
  90. if http:
  91. transport = THttpClient.THttpClient(host, port, uri)
  92. else:
  93. if ssl:
  94. socket = TSSLSocket.TSSLSocket(host, port, validate=validate, ca_certs=ca_certs, keyfile=keyfile, certfile=certfile)
  95. else:
  96. socket = TSocket.TSocket(host, port)
  97. if framed:
  98. transport = TTransport.TFramedTransport(socket)
  99. else:
  100. transport = TTransport.TBufferedTransport(socket)
  101. protocol = TBinaryProtocol(transport)
  102. client = FacebookService.Client(protocol)
  103. transport.open()
  104. if cmd == 'getName':
  105. if len(args) != 0:
  106. print('getName requires 0 args')
  107. sys.exit(1)
  108. pp.pprint(client.getName())
  109. elif cmd == 'getVersion':
  110. if len(args) != 0:
  111. print('getVersion requires 0 args')
  112. sys.exit(1)
  113. pp.pprint(client.getVersion())
  114. elif cmd == 'getStatus':
  115. if len(args) != 0:
  116. print('getStatus requires 0 args')
  117. sys.exit(1)
  118. pp.pprint(client.getStatus())
  119. elif cmd == 'getStatusDetails':
  120. if len(args) != 0:
  121. print('getStatusDetails requires 0 args')
  122. sys.exit(1)
  123. pp.pprint(client.getStatusDetails())
  124. elif cmd == 'getCounters':
  125. if len(args) != 0:
  126. print('getCounters requires 0 args')
  127. sys.exit(1)
  128. pp.pprint(client.getCounters())
  129. elif cmd == 'getCounter':
  130. if len(args) != 1:
  131. print('getCounter requires 1 args')
  132. sys.exit(1)
  133. pp.pprint(client.getCounter(args[0],))
  134. elif cmd == 'setOption':
  135. if len(args) != 2:
  136. print('setOption requires 2 args')
  137. sys.exit(1)
  138. pp.pprint(client.setOption(args[0], args[1],))
  139. elif cmd == 'getOption':
  140. if len(args) != 1:
  141. print('getOption requires 1 args')
  142. sys.exit(1)
  143. pp.pprint(client.getOption(args[0],))
  144. elif cmd == 'getOptions':
  145. if len(args) != 0:
  146. print('getOptions requires 0 args')
  147. sys.exit(1)
  148. pp.pprint(client.getOptions())
  149. elif cmd == 'getCpuProfile':
  150. if len(args) != 1:
  151. print('getCpuProfile requires 1 args')
  152. sys.exit(1)
  153. pp.pprint(client.getCpuProfile(eval(args[0]),))
  154. elif cmd == 'aliveSince':
  155. if len(args) != 0:
  156. print('aliveSince requires 0 args')
  157. sys.exit(1)
  158. pp.pprint(client.aliveSince())
  159. elif cmd == 'reinitialize':
  160. if len(args) != 0:
  161. print('reinitialize requires 0 args')
  162. sys.exit(1)
  163. pp.pprint(client.reinitialize())
  164. elif cmd == 'shutdown':
  165. if len(args) != 0:
  166. print('shutdown requires 0 args')
  167. sys.exit(1)
  168. pp.pprint(client.shutdown())
  169. else:
  170. print('Unrecognized method %s' % cmd)
  171. sys.exit(1)
  172. transport.close()