Merge branch 'master' of git@github.com:jodal/mopidy
This commit is contained in:
commit
b434fe3551
@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
from mopidy import settings
|
from mopidy import settings
|
||||||
from mopidy.backends.spotify_backend import SpotifyBackend
|
from mopidy.backends.spotify_backend import SpotifyBackend
|
||||||
@ -55,7 +56,7 @@ class MpdHandler(object):
|
|||||||
|
|
||||||
@register(r'^close$')
|
@register(r'^close$')
|
||||||
def _close(self):
|
def _close(self):
|
||||||
self.session.close_when_done()
|
self.session.do_close()
|
||||||
|
|
||||||
@register(r'^consume (?P<state>[01])$')
|
@register(r'^consume (?P<state>[01])$')
|
||||||
def _consume(self, state):
|
def _consume(self, state):
|
||||||
@ -82,13 +83,17 @@ class MpdHandler(object):
|
|||||||
def _deleteid(self, songid):
|
def _deleteid(self, songid):
|
||||||
pass # TODO
|
pass # TODO
|
||||||
|
|
||||||
|
@register(r'^$')
|
||||||
|
def _empty(self):
|
||||||
|
pass
|
||||||
|
|
||||||
@register(r'^idle( (?P<subsystems>.+))*$')
|
@register(r'^idle( (?P<subsystems>.+))*$')
|
||||||
def _idle(self, subsystems=None):
|
def _idle(self, subsystems=None):
|
||||||
pass # TODO
|
pass # TODO
|
||||||
|
|
||||||
@register(r'^kill$')
|
@register(r'^kill$')
|
||||||
def _kill(self):
|
def _kill(self):
|
||||||
pass # TODO
|
self.session.do_kill()
|
||||||
|
|
||||||
@register(r'^listplaylist (?P<name>.+)$')
|
@register(r'^listplaylist (?P<name>.+)$')
|
||||||
def _listplaylist(self, name):
|
def _listplaylist(self, name):
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import asyncore
|
import asyncore
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
import sys
|
||||||
|
|
||||||
from mopidy import settings
|
from mopidy import settings
|
||||||
from mopidy.session import MpdSession
|
from mopidy.session import MpdSession
|
||||||
@ -19,7 +20,13 @@ class MpdServer(asyncore.dispatcher):
|
|||||||
def handle_accept(self):
|
def handle_accept(self):
|
||||||
(client_socket, client_address) = self.accept()
|
(client_socket, client_address) = self.accept()
|
||||||
logger.info(u'Connection from: [%s]:%s', *client_address)
|
logger.info(u'Connection from: [%s]:%s', *client_address)
|
||||||
self.handler_class(client_socket, client_address)
|
self.handler_class(self, client_socket, client_address)
|
||||||
|
|
||||||
def handle_close(self):
|
def handle_close(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
def do_kill(self):
|
||||||
|
logger.info('Received "kill". Shutting down.')
|
||||||
|
self.handle_close()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|||||||
@ -7,17 +7,22 @@ from mopidy.handler import MpdHandler
|
|||||||
logger = logging.getLogger(u'session')
|
logger = logging.getLogger(u'session')
|
||||||
|
|
||||||
class MpdSession(asynchat.async_chat):
|
class MpdSession(asynchat.async_chat):
|
||||||
def __init__(self, client_socket, client_address, handler=MpdHandler):
|
def __init__(self, server, client_socket, client_address,
|
||||||
|
handler=MpdHandler):
|
||||||
asynchat.async_chat.__init__(self, sock=client_socket)
|
asynchat.async_chat.__init__(self, sock=client_socket)
|
||||||
|
self.server = server
|
||||||
self.client_address = client_address
|
self.client_address = client_address
|
||||||
self.input_buffer = []
|
self.input_buffer = []
|
||||||
self.set_terminator(settings.MPD_LINE_TERMINATOR)
|
self.set_terminator(settings.MPD_LINE_TERMINATOR)
|
||||||
self.handler = handler(session=self)
|
self.handler = handler(session=self)
|
||||||
self.send_response(u'OK MPD %s' % get_mpd_version())
|
self.send_response(u'OK MPD %s' % get_mpd_version())
|
||||||
|
|
||||||
def close_when_done(self):
|
def do_close(self):
|
||||||
logger.info(u'Closing connection with [%s]:%s', *self.client_address)
|
logger.info(u'Closing connection with [%s]:%s', *self.client_address)
|
||||||
asynchat.async_chat.close_when_done(self)
|
self.close_when_done()
|
||||||
|
|
||||||
|
def do_kill(self):
|
||||||
|
self.server.do_kill()
|
||||||
|
|
||||||
def collect_incoming_data(self, data):
|
def collect_incoming_data(self, data):
|
||||||
self.input_buffer.append(data)
|
self.input_buffer.append(data)
|
||||||
|
|||||||
@ -419,7 +419,10 @@ class StickersHandlerTest(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class DummySession(object):
|
class DummySession(object):
|
||||||
def close_when_done(self):
|
def do_close(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def do_kill(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -431,6 +434,10 @@ class ConnectionHandlerTest(unittest.TestCase):
|
|||||||
result = self.h.handle_request(u'close')
|
result = self.h.handle_request(u'close')
|
||||||
self.assert_(result is None)
|
self.assert_(result is None)
|
||||||
|
|
||||||
|
def test_empty_request(self):
|
||||||
|
result = self.h.handle_request(u'')
|
||||||
|
self.assert_(result is None)
|
||||||
|
|
||||||
def test_kill(self):
|
def test_kill(self):
|
||||||
result = self.h.handle_request(u'kill')
|
result = self.h.handle_request(u'kill')
|
||||||
self.assert_(result is None)
|
self.assert_(result is None)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user