add web PoC

This commit is contained in:
boyska 2014-10-26 20:13:32 +01:00
parent 441ac2683c
commit bd6ccaf0be
2 changed files with 40 additions and 0 deletions

4
mpc.py
View file

@ -10,10 +10,12 @@ from subprocess import check_output
import gevent
from gevent.queue import Queue
from gevent.wsgi import WSGIServer
from eventutils import ParentedLet, CeleryTask, Timer
from task import create as create_continous
import rpc
class MpcWatcher(ParentedLet):
@ -45,6 +47,8 @@ class Player(gevent.Greenlet):
def _run(self):
MpcWatcher(self.q).start()
Timer(6000, self.q).start()
http_server = WSGIServer(('', 5000), rpc.create_app(self.q))
http_server.start()
while True:
value = self.q.get()
# emitter = value['emitter']

36
rpc.py Normal file
View file

@ -0,0 +1,36 @@
import logging
from flask import current_app, Blueprint, Flask
rpc = Blueprint('rpc', __name__, url_prefix='/api')
def send_to_parent(kind, *args):
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