FacebookService-remote 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 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]] 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. http = False
  46. argi = 1
  47. if sys.argv[argi] == '-h':
  48. parts = sys.argv[argi+1].split(':')
  49. host = parts[0]
  50. if len(parts) > 1:
  51. port = int(parts[1])
  52. argi += 2
  53. if sys.argv[argi] == '-u':
  54. url = urlparse(sys.argv[argi+1])
  55. parts = url[1].split(':')
  56. host = parts[0]
  57. if len(parts) > 1:
  58. port = int(parts[1])
  59. else:
  60. port = 80
  61. uri = url[2]
  62. if url[4]:
  63. uri += '?%s' % url[4]
  64. http = True
  65. argi += 2
  66. if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  67. framed = True
  68. argi += 1
  69. if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
  70. ssl = True
  71. argi += 1
  72. cmd = sys.argv[argi]
  73. args = sys.argv[argi+1:]
  74. if http:
  75. transport = THttpClient.THttpClient(host, port, uri)
  76. else:
  77. socket = TSSLSocket.TSSLSocket(host, port, validate=False) if ssl else TSocket.TSocket(host, port)
  78. if framed:
  79. transport = TTransport.TFramedTransport(socket)
  80. else:
  81. transport = TTransport.TBufferedTransport(socket)
  82. protocol = TBinaryProtocol.TBinaryProtocol(transport)
  83. client = FacebookService.Client(protocol)
  84. transport.open()
  85. if cmd == 'getName':
  86. if len(args) != 0:
  87. print('getName requires 0 args')
  88. sys.exit(1)
  89. pp.pprint(client.getName())
  90. elif cmd == 'getVersion':
  91. if len(args) != 0:
  92. print('getVersion requires 0 args')
  93. sys.exit(1)
  94. pp.pprint(client.getVersion())
  95. elif cmd == 'getStatus':
  96. if len(args) != 0:
  97. print('getStatus requires 0 args')
  98. sys.exit(1)
  99. pp.pprint(client.getStatus())
  100. elif cmd == 'getStatusDetails':
  101. if len(args) != 0:
  102. print('getStatusDetails requires 0 args')
  103. sys.exit(1)
  104. pp.pprint(client.getStatusDetails())
  105. elif cmd == 'getCounters':
  106. if len(args) != 0:
  107. print('getCounters requires 0 args')
  108. sys.exit(1)
  109. pp.pprint(client.getCounters())
  110. elif cmd == 'getCounter':
  111. if len(args) != 1:
  112. print('getCounter requires 1 args')
  113. sys.exit(1)
  114. pp.pprint(client.getCounter(args[0],))
  115. elif cmd == 'setOption':
  116. if len(args) != 2:
  117. print('setOption requires 2 args')
  118. sys.exit(1)
  119. pp.pprint(client.setOption(args[0],args[1],))
  120. elif cmd == 'getOption':
  121. if len(args) != 1:
  122. print('getOption requires 1 args')
  123. sys.exit(1)
  124. pp.pprint(client.getOption(args[0],))
  125. elif cmd == 'getOptions':
  126. if len(args) != 0:
  127. print('getOptions requires 0 args')
  128. sys.exit(1)
  129. pp.pprint(client.getOptions())
  130. elif cmd == 'getCpuProfile':
  131. if len(args) != 1:
  132. print('getCpuProfile requires 1 args')
  133. sys.exit(1)
  134. pp.pprint(client.getCpuProfile(eval(args[0]),))
  135. elif cmd == 'aliveSince':
  136. if len(args) != 0:
  137. print('aliveSince requires 0 args')
  138. sys.exit(1)
  139. pp.pprint(client.aliveSince())
  140. elif cmd == 'reinitialize':
  141. if len(args) != 0:
  142. print('reinitialize requires 0 args')
  143. sys.exit(1)
  144. pp.pprint(client.reinitialize())
  145. elif cmd == 'shutdown':
  146. if len(args) != 0:
  147. print('shutdown requires 0 args')
  148. sys.exit(1)
  149. pp.pprint(client.shutdown())
  150. else:
  151. print('Unrecognized method %s' % cmd)
  152. sys.exit(1)
  153. transport.close()