larigira/rpc.py
boyska 6f9e4b199b SIGHUP, use mpd connection without subcommand
beside being ugly, using "mpc idle" subprocess was making the whole
thing unable to terminate & release HTTP port when closing.
2014-10-27 00:25:19 +01:00

37 lines
861 B
Python

import logging
from flask import current_app, Blueprint, Flask
rpc = Blueprint('rpc', __name__, url_prefix='/api')
def send_to_parent(kind, *args):
'''similar to the behaviour of a ParentedLet'''
if not hasattr(current_app, 'queue'):
logging.debug('no parent queue; aborting send')
return
msg = {
'emitter': current_app._get_current_object(),
'class': current_app._get_current_object().__class__.__name__,
'kind': kind,
'args': args
}
current_app.queue.put(msg)
@rpc.route('/')
def rpc_index():
return 'So, what command would you like to give?'
@rpc.route('/refresh')
def rpc_refresh():
print current_app.queue
send_to_parent('rpc')
return 'ok, put'
def create_app(queue):
app = Flask(__name__)
app.register_blueprint(rpc)
app.queue = queue
return app