From 215dd777f6a2366bb90d2d1953e9e011e059f710 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 17 Jul 2014 00:58:10 +0200 Subject: [PATCH] http: Move Mopidy request handlers to helper method --- mopidy/http/actor.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/mopidy/http/actor.py b/mopidy/http/actor.py index 3324a277..f705c707 100644 --- a/mopidy/http/actor.py +++ b/mopidy/http/actor.py @@ -86,32 +86,15 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): def _get_request_handlers(self): request_handlers = [] - request_handlers.extend(self._get_app_request_handlers()) request_handlers.extend(self._get_static_request_handlers()) - - # Either default Mopidy or user defined path to files - static_dir = self.config['http']['static_dir'] - if static_dir and not os.path.exists(static_dir): - logger.warning( - 'Configured http/static_dir %s does not exist. ' - 'Falling back to default HTTP handler.', static_dir) - static_dir = None - if static_dir: - request_handlers.append((r'/(.*)', handlers.StaticFileHandler, { - 'path': self.config['http']['static_dir'], - 'default_filename': 'index.html', - })) - else: - request_handlers.append((r'/', tornado.web.RedirectHandler, { - 'url': '/mopidy/', - 'permanent': False, - })) + request_handlers.extend(self._get_mopidy_request_handlers()) logger.debug( 'HTTP routes from extensions: %s', formatting.indent('\n'.join( '%r: %r' % (r[0], r[1]) for r in request_handlers))) + return request_handlers def _get_app_request_handlers(self): @@ -146,3 +129,25 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): )) logger.debug('Loaded static HTTP extension: %s', static['name']) return result + + def _get_mopidy_request_handlers(self): + # Either default Mopidy or user defined path to files + + static_dir = self.config['http']['static_dir'] + + if static_dir and not os.path.exists(static_dir): + logger.warning( + 'Configured http/static_dir %s does not exist. ' + 'Falling back to default HTTP handler.', static_dir) + static_dir = None + + if static_dir: + return [(r'/(.*)', handlers.StaticFileHandler, { + 'path': self.config['http']['static_dir'], + 'default_filename': 'index.html', + })] + else: + return [(r'/', tornado.web.RedirectHandler, { + 'url': '/mopidy/', + 'permanent': False, + })]