Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. from twisted.internet import defer
  2.  
  3. import optparse
  4.  
  5. from api import get_jocks_api
  6. from factories import JocksClientFactory
  7. from protocols import JocksProtocol
  8. from twisted.python import log
  9.  
  10. def parse_args():
  11. usage = '''usage : %prog[options]
  12.  
  13. Jocks Client provide you a simple and free way to downloads jocks stream from Jocks Server running
  14. all over the internet! You just need to know on what server you want to log on.
  15. Run it like that :
  16.  
  17. python jocks_client --function=<the_function_you_want_to_use> --args=<the specifications you want to use with the function>
  18.  
  19. This command will try to connect on a server located to localhost:11444 as default, you can of course choose the location of the server yourself :
  20.  
  21. python jocks_client --host=<address of the server host> --port=<the port the server use to provide jocks> --function=<function> --arg=<args>
  22.  
  23. For more informations about the functions to use to manage your jocks stream, see the README file!
  24.  
  25. Enjoy!
  26. '''
  27.  
  28. parser = optparse.OptionParser(usage)
  29.  
  30. help = 'The host name or ipv4 address of the server'
  31. parser.add_option('--host', help=help, default='localhost')
  32.  
  33. help = 'The port use by the server to provide jocks'
  34. parser.add_option('--port', help=help, type=int, default=11444)
  35.  
  36. help = 'The function you want to use to manage the jocks stream of the server'
  37. parser.add_option('--function', help=help)
  38.  
  39. help = 'The arguments you want to use with the function'
  40. parser.add_option('--arg', help=help)
  41.  
  42. options, args = parser.parse_args()
  43.  
  44. if len(args) != 0:
  45. parser.error('Jocks client do not need any argument from the command line.')
  46.  
  47. return options
  48.  
  49. def main():
  50. options = parse_args()
  51.  
  52. from twisted.internet import reactor
  53.  
  54. #callbacks
  55. def get_jocks(jocks):
  56. print jocks
  57.  
  58. def get_jocks_failed(err):
  59. print 'Jocks stream download failed.'
  60.  
  61. def get_jocks_done(_):
  62. reactor.stop()
  63.  
  64. d = get_jocks_api(options.host, options.port, options.function, options.arg)
  65. d.addCallbacks(get_jocks, get_jocks_failed)
  66. d.addBoth(get_jocks_done)
  67.  
  68. print 'You can check the logs if something went wrong during the process.'
  69.  
  70. log.startLogging(open('/var/log/jocks_client/client.log', 'w'))
  71.  
  72. reactor.run()
  73.  
  74. if __name__ == '__main__':
  75. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement