rpc.py 809 B

123456789101112131415161718192021222324252627282930313233343536
  1. import logging
  2. from flask import current_app, Blueprint, Flask
  3. rpc = Blueprint('rpc', __name__, url_prefix='/api')
  4. def send_to_parent(kind, *args):
  5. if not hasattr(current_app, 'queue'):
  6. logging.debug('no parent queue; aborting send')
  7. return
  8. msg = {
  9. 'emitter': current_app._get_current_object(),
  10. 'class': current_app._get_current_object().__class__.__name__,
  11. 'kind': kind,
  12. 'args': args
  13. }
  14. current_app.queue.put(msg)
  15. @rpc.route('/')
  16. def rpc_index():
  17. return 'So, what command would you like to give?'
  18. @rpc.route('/refresh')
  19. def rpc_refresh():
  20. print current_app.queue
  21. send_to_parent('rpc')
  22. return 'ok, put'
  23. def create_app(queue):
  24. app = Flask(__name__)
  25. app.register_blueprint(rpc)
  26. app.queue = queue
  27. return app