Add empty handler methods for enough MPD commands to get Sonata to 'connected' mode

This commit is contained in:
Stein Magnus Jodal 2009-12-23 20:58:05 +01:00
parent ecd5e686f6
commit 15b5968d5c
2 changed files with 64 additions and 2 deletions

56
mopidy/handler.py Normal file
View File

@ -0,0 +1,56 @@
import logging
import re
from mopidy import settings
logger = logging.getLogger('handler')
class MpdHandler(object):
def __init__(self):
self.request_handlers = [
(r'^currentsong$', self._currentsong),
(r'^listplaylists$', self._listplaylists),
(r'^lsinfo( "(?P<uri>[^"]*)")*$', self._lsinfo),
(r'^ping$', self._ping),
(r'^plchanges "(?P<version>\d+)"$', self._plchanges),
(r'^status$', self._status),
]
def handle_request(self, request):
for request_pattern, request_handling_method in self.request_handlers:
matches = re.match(request_pattern, request)
if matches is not None:
groups = matches.groupdict()
return request_handling_method(**groups)
logger.warning(u'Unhandled request: %s', request)
def _currentsong(self):
return None # TODO
def _listplaylists(self):
return None # TODO
def _lsinfo(self, uri):
if uri == u'/':
return self._listplaylists()
return None # TODO
def _ping(self):
return None
def _plchanges(self, version):
return None # TODO
def _status(self):
# TODO
return [
'volume: 0',
'repeat: 0',
'random: 0',
'single: 0',
'consume: 0',
'playlist: 0',
'playlistlength: 0',
'xfade: 0',
'state: stop',
]

View File

@ -2,14 +2,16 @@ import asynchat
import logging
from mopidy import get_version, settings
from mopidy.handler import MpdHandler
logger = logging.getLogger(u'session')
class MpdSession(asynchat.async_chat):
def __init__(self, client_socket, client_address):
def __init__(self, client_socket, client_address, handler=MpdHandler):
asynchat.async_chat.__init__(self, sock=client_socket)
self.input_buffer = []
self.set_terminator(settings.MPD_LINE_TERMINATOR)
self.handler = handler()
self.send_response(u'OK MPD (mopidy %s)' % get_version())
def collect_incoming_data(self, data):
@ -23,7 +25,11 @@ class MpdSession(asynchat.async_chat):
self.handle_request(input)
def handle_request(self, input):
pass # TODO
response = self.handler.handle_request(input)
if response is not None:
for line in response:
self.send_response(line)
self.send_response(u'OK')
def send_response(self, output):
logger.debug(u'Output: %s', output)