Files
Iris/mopidy_iris/__init__.py

84 lines
2.3 KiB
Python
Raw Normal View History

2016-10-30 07:51:39 +13:00
from __future__ import unicode_literals
import logging, os, json
import tornado.web
import tornado.websocket
2017-02-18 12:45:48 +13:00
import handlers
2016-10-30 07:51:39 +13:00
from mopidy import config, ext
2017-02-18 12:45:48 +13:00
from frontend import IrisFrontend
2017-02-18 22:04:05 +13:00
from handlers import WebsocketHandler, HttpHandler
2017-02-18 12:45:48 +13:00
from core import IrisCore
2017-09-22 16:15:50 +12:00
from raven import Client
2016-10-30 07:51:39 +13:00
logger = logging.getLogger(__name__)
2017-10-17 20:24:31 +13:00
__version__ = '3.5.4'
2016-10-30 07:51:39 +13:00
##
# Core extension class
#
# Loads config and gets the party started. Initiates any additional frontends, etc.
##
class Extension( ext.Extension ):
2016-10-30 07:51:39 +13:00
dist_name = 'Mopidy-Iris'
ext_name = 'iris'
version = __version__
def get_default_config(self):
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf')
return config.read(conf_file)
def get_config_schema(self):
schema = config.ConfigSchema(self.ext_name)
schema['enabled'] = config.Boolean()
schema['country'] = config.String()
schema['locale'] = config.String()
schema['authorization_url'] = config.String()
2016-10-30 07:51:39 +13:00
return schema
def setup(self, registry):
# Add web extension
registry.add('http:app', {
'name': self.ext_name,
2017-02-18 12:45:48 +13:00
'factory': iris_factory
2016-10-30 07:51:39 +13:00
})
2017-02-18 12:45:48 +13:00
# create our core instance
mem.iris = IrisCore()
mem.iris.version = self.version
2017-09-22 16:15:50 +12:00
# Connect to our Ravent Sentry error tracker
mem.iris.raven_client = Client(
dsn='https://023e3bf7721b48f29948545fc36a4621:ba30d29174ef4778ac4e141d445607a2@sentry.io/219026',
release=self.version
)
2017-02-18 12:45:48 +13:00
# Add our frontend
registry.add('frontend', IrisFrontend)
def iris_factory(config, core):
path = os.path.join( os.path.dirname(__file__), 'static')
return [
(r"/images/(.*)", tornado.web.StaticFileHandler, {
'path': config['local-images']['image_dir']
}),
(r'/http/([^/]*)', handlers.HttpHandler, {
'core': core,
'config': config
}),
(r'/ws/?', handlers.WebsocketHandler, {
'core': core,
'config': config
}),
(r'/(.*)', tornado.web.StaticFileHandler, {
'path': path,
'default_filename': 'index.html'
}),
2017-03-02 20:37:04 +13:00
]