From 5e10ad0e05c617f5b90ce64cc1cfe0677d30d119 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 20 Aug 2010 00:38:36 +0200 Subject: [PATCH] Replace SERVER and FRONTEND with a new FRONTENDS setting --- docs/api/mpd.rst | 19 +++++++++++++++--- docs/changes.rst | 3 +++ mopidy/__main__.py | 6 +++--- mopidy/frontends/mpd/__init__.py | 33 ++++++++++++++++++++++++++++++++ mopidy/frontends/mpd/session.py | 4 ++-- mopidy/process.py | 11 +++++------ mopidy/settings.py | 16 ++++++---------- mopidy/utils/settings.py | 4 +++- 8 files changed, 71 insertions(+), 25 deletions(-) diff --git a/docs/api/mpd.rst b/docs/api/mpd.rst index 7bf7fe7b..6361e909 100644 --- a/docs/api/mpd.rst +++ b/docs/api/mpd.rst @@ -4,6 +4,8 @@ .. automodule:: mopidy.frontends.mpd :synopsis: MPD frontend + :members: + :undoc-members: MPD server @@ -17,10 +19,21 @@ MPD server .. inheritance-diagram:: mopidy.frontends.mpd.server -MPD frontend -============ +MPD session +=========== -.. automodule:: mopidy.frontends.mpd.frontend +.. automodule:: mopidy.frontends.mpd.session + :synopsis: MPD client session + :members: + :undoc-members: + +.. inheritance-diagram:: mopidy.frontends.mpd.session + + +MPD dispatcher +============== + +.. automodule:: mopidy.frontends.mpd.dispatcher :synopsis: MPD request dispatcher :members: :undoc-members: diff --git a/docs/changes.rst b/docs/changes.rst index 341ef850..7c2ce19d 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -58,6 +58,9 @@ greatly improved MPD client support. - Support for single track repeat added. (Fixes: :issue:`4`) - Rename ``mopidy.frontends.mpd.{serializer => translator}`` to match naming in backends. + - Remove setting :attr:`mopidy.settings.SERVER` and + :attr:`mopidy.settings.FRONTEND` in favour of the new + :attr:`mopidy.settings.FRONTENDS`. - Backends: diff --git a/mopidy/__main__.py b/mopidy/__main__.py index a2230180..1c0318e7 100644 --- a/mopidy/__main__.py +++ b/mopidy/__main__.py @@ -24,11 +24,11 @@ def main(): logger.info('-- Starting Mopidy --') get_or_create_folder('~/.mopidy/') core_queue = multiprocessing.Queue() - get_class(settings.SERVER)(core_queue).start() output_class = get_class(settings.OUTPUT) backend_class = get_class(settings.BACKENDS[0]) - frontend_class = get_class(settings.FRONTEND) - core = CoreProcess(core_queue, output_class, backend_class, frontend_class) + frontend = get_class(settings.FRONTENDS[0])() + frontend.start_server(core_queue) + core = CoreProcess(core_queue, output_class, backend_class, frontend) core.start() asyncore.loop() diff --git a/mopidy/frontends/mpd/__init__.py b/mopidy/frontends/mpd/__init__.py index e69de29b..53f2003f 100644 --- a/mopidy/frontends/mpd/__init__.py +++ b/mopidy/frontends/mpd/__init__.py @@ -0,0 +1,33 @@ +from mopidy.frontends.mpd.dispatcher import MpdDispatcher +from mopidy.frontends.mpd.server import MpdServer + +class MpdFrontend(object): + """ + The MPD frontend. + """ + + def __init__(self): + self.server = None + self.dispatcher = None + + def start_server(self, core_queue): + """ + Starts the MPD server. + + :param core_queue: the core queue + :type core_queue: :class:`multiprocessing.Queue` + """ + self.server = MpdServer(core_queue) + self.server.start() + + def create_dispatcher(self, backend): + """ + Creates a dispatcher for MPD requests. + + :param backend: the backend + :type backend: :class:`mopidy.backends.base.BaseBackend` + :rtype: :class:`mopidy.frontends.mpd.dispatcher.MpdDispatcher` + """ + + self.dispatcher = MpdDispatcher(backend) + return self.dispatcher diff --git a/mopidy/frontends/mpd/session.py b/mopidy/frontends/mpd/session.py index 0a7533e7..305c8b84 100644 --- a/mopidy/frontends/mpd/session.py +++ b/mopidy/frontends/mpd/session.py @@ -11,8 +11,8 @@ logger = logging.getLogger('mopidy.frontends.mpd.session') class MpdSession(asynchat.async_chat): """ - The MPD client session. Keeps track of a single client and dispatches its - MPD requests to the frontend. + The MPD client session. Keeps track of a single client and passes its + MPD requests to the dispatcher. """ def __init__(self, server, client_socket, client_socket_address, diff --git a/mopidy/process.py b/mopidy/process.py index 01ac8ed4..5fac3d65 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -36,17 +36,16 @@ class BaseProcess(multiprocessing.Process): class CoreProcess(BaseProcess): - def __init__(self, core_queue, output_class, backend_class, - frontend_class): + def __init__(self, core_queue, output_class, backend_class, frontend): super(CoreProcess, self).__init__() self.core_queue = core_queue self.output_queue = None self.output_class = output_class self.backend_class = backend_class - self.frontend_class = frontend_class self.output = None self.backend = None - self.frontend = None + self.frontend = frontend + self.dispatcher = None def run_inside_try(self): self.setup() @@ -58,13 +57,13 @@ class CoreProcess(BaseProcess): self.output_queue = multiprocessing.Queue() self.output = self.output_class(self.core_queue, self.output_queue) self.backend = self.backend_class(self.core_queue, self.output_queue) - self.frontend = self.frontend_class(self.backend) + self.dispatcher = self.frontend.create_dispatcher(self.backend) def process_message(self, message): if message.get('to') == 'output': self.output_queue.put(message) elif message['command'] == 'mpd_request': - response = self.frontend.handle_request(message['request']) + response = self.dispatcher.handle_request(message['request']) connection = unpickle_connection(message['reply_to']) connection.send(response) elif message['command'] == 'end_of_track': diff --git a/mopidy/settings.py b/mopidy/settings.py index 895a1e24..8a0ae862 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -41,12 +41,15 @@ DUMP_LOG_FORMAT = CONSOLE_LOG_FORMAT #: DUMP_LOG_FILENAME = u'dump.log' DUMP_LOG_FILENAME = u'dump.log' -#: Protocol frontend to use. +#: List of server frontends to use. #: #: Default:: #: -#: FRONTEND = u'mopidy.frontends.mpd.dispatcher.MpdDispatcher' -FRONTEND = u'mopidy.frontends.mpd.dispatcher.MpdDispatcher' +#: FRONTENDS = (u'mopidy.frontends.mpd.MpdFrontend',) +#: +#: .. note:: +#: Currently only the first frontend in the list is used. +FRONTENDS = (u'mopidy.frontends.mpd.MpdFrontend',) #: Path to folder with local music. #: @@ -127,13 +130,6 @@ MIXER_MAX_VOLUME = 100 #: OUTPUT = u'mopidy.outputs.gstreamer.GStreamerOutput' OUTPUT = u'mopidy.outputs.gstreamer.GStreamerOutput' -#: Server to use. -#: -#: Default:: -#: -#: SERVER = u'mopidy.frontends.mpd.server.MpdServer' -SERVER = u'mopidy.frontends.mpd.server.MpdServer' - #: Which address Mopidy's MPD server should bind to. #: #:Examples: diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index 478a03e6..f1d213de 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -37,7 +37,7 @@ class SettingsProxy(object): def current(self): current = copy(self.default) current.update(self.local) - return current + return current def __getattr__(self, attr): if not self._is_setting(attr): @@ -81,6 +81,8 @@ def validate_settings(defaults, settings): errors = {} changed = { + 'FRONTEND': 'FRONTENDS', + 'SERVER': None, 'SERVER_HOSTNAME': 'MPD_SERVER_HOSTNAME', 'SERVER_PORT': 'MPD_SERVER_PORT', 'SPOTIFY_LIB_APPKEY': None,