Figuring out how to create global instance of IrisCore in Python3...
This commit is contained in:
@ -39,6 +39,9 @@ RUN wget -q -O - https://apt.mopidy.com/mopidy.gpg \
|
||||
# Install additional Python dependencies
|
||||
RUN python3.7 -m pip install --no-cache tox
|
||||
|
||||
# TEMPORARY: Install mopidy pre-release
|
||||
RUN python3 -m pip install --user Mopidy==3.0.0b1
|
||||
|
||||
# Start helper script.
|
||||
COPY docker/entrypoint.sh /entrypoint.sh
|
||||
|
||||
@ -56,7 +59,4 @@ ENV HOME=/var/lib/mopidy
|
||||
|
||||
EXPOSE 6600 6680
|
||||
|
||||
# Switch back to the circleci user
|
||||
USER circleci
|
||||
|
||||
CMD ["/bin/sh"]
|
||||
@ -9,7 +9,7 @@ from mopidy import config, ext
|
||||
from .frontend import IrisFrontend
|
||||
from .handlers import WebsocketHandler, HttpHandler
|
||||
from .core import IrisCore
|
||||
from .mem import setIris, getIris
|
||||
from .mem import iris
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
__version__ = '3.42.2'
|
||||
@ -48,10 +48,6 @@ class Extension( ext.Extension ):
|
||||
'factory': iris_factory
|
||||
})
|
||||
|
||||
# create our core instance
|
||||
setIris(IrisCore())
|
||||
getIris().version = self.version
|
||||
|
||||
# Add our frontend
|
||||
registry.add('frontend', IrisFrontend)
|
||||
|
||||
@ -110,8 +106,8 @@ def iris_factory(config, core):
|
||||
),
|
||||
(
|
||||
r'/(.*)',
|
||||
ReactRouterHandler, {
|
||||
'path': str(path)+'/index.html'
|
||||
tornado.web.StaticFileHandler, {
|
||||
'path': str(path)
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
@ -22,7 +22,7 @@ if sys.platform == 'win32':
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class IrisCore(pykka.ThreadingActor):
|
||||
version = 0
|
||||
version = "Unknown"
|
||||
spotify_token = False
|
||||
queue_metadata = {}
|
||||
connections = {}
|
||||
@ -37,6 +37,11 @@ class IrisCore(pykka.ThreadingActor):
|
||||
}
|
||||
|
||||
|
||||
def __init__(self, config, core):
|
||||
self.config = config
|
||||
self.core = core
|
||||
|
||||
|
||||
##
|
||||
# Mopidy server is starting
|
||||
##
|
||||
@ -99,8 +104,7 @@ class IrisCore(pykka.ThreadingActor):
|
||||
# @return string
|
||||
##
|
||||
def generateGuid(self):
|
||||
length = 12
|
||||
return ''.join(random.choice(string.lowercase) for i in range(length))
|
||||
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=12))
|
||||
|
||||
|
||||
##
|
||||
@ -224,7 +228,7 @@ class IrisCore(pykka.ThreadingActor):
|
||||
'params': data['params'] if 'params' in data else None
|
||||
}
|
||||
|
||||
for connection in self.connections.itervalues():
|
||||
for connection in self.connections.values():
|
||||
|
||||
send_to_this_connection = True
|
||||
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from mopidy.core import CoreListener
|
||||
from .core import IrisCore
|
||||
|
||||
import pykka
|
||||
import logging
|
||||
from .mem import getIris
|
||||
from .mem import iris
|
||||
|
||||
# import logger
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -13,17 +14,21 @@ class IrisFrontend(pykka.ThreadingActor, CoreListener):
|
||||
|
||||
def __init__(self, config, core):
|
||||
super(IrisFrontend, self).__init__()
|
||||
getIris().core = core
|
||||
getIris().config = config
|
||||
|
||||
|
||||
# create our core instance
|
||||
iris = IrisCore(config, core)
|
||||
print(iris)
|
||||
|
||||
def on_start(self):
|
||||
getIris().start()
|
||||
print(iris)
|
||||
iris.start()
|
||||
|
||||
def on_stop(self):
|
||||
getIris().stop()
|
||||
iris.stop()
|
||||
|
||||
def track_playback_ended(self, tl_track, time_position):
|
||||
getIris().check_for_radio_update()
|
||||
iris.check_for_radio_update()
|
||||
|
||||
def tracklist_changed(self):
|
||||
getIris().clean_queue_metadata()
|
||||
iris.clean_queue_metadata()
|
||||
|
||||
@ -5,7 +5,7 @@ from tornado.escape import json_encode, json_decode
|
||||
import tornado.ioloop, tornado.web, tornado.websocket, tornado.template
|
||||
import random, string, logging, uuid, subprocess, pykka, ast, logging, json, urllib, requests, time
|
||||
|
||||
from .mem import getIris
|
||||
from .mem import iris
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -26,16 +26,20 @@ class WebsocketHandler(tornado.websocket.WebSocketHandler):
|
||||
if (ip == '127.0.0.1' and hasattr(self.request.headers,'X-Forwarded-For')):
|
||||
ip = self.request.headers['X-Forwarded-For']
|
||||
|
||||
print("---------------------")
|
||||
print("WebsocketHandler.open")
|
||||
print(iris)
|
||||
|
||||
# Construct our initial client object, and add to our list of connections
|
||||
client = {
|
||||
'connection_id': getIris().generateGuid(),
|
||||
'connection_id': iris.generateGuid(),
|
||||
'ip': ip,
|
||||
'created': datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
|
||||
}
|
||||
|
||||
self.connection_id = client['connection_id']
|
||||
|
||||
getIris().add_connection(connection=self, client=client)
|
||||
iris.add_connection(connection=self, client=client)
|
||||
|
||||
|
||||
def on_message(self, message):
|
||||
@ -80,7 +84,7 @@ class WebsocketHandler(tornado.websocket.WebSocketHandler):
|
||||
|
||||
|
||||
def on_close(self):
|
||||
getIris().remove_connection(connection_id=self.connection_id)
|
||||
iris.remove_connection(connection_id=self.connection_id)
|
||||
|
||||
##
|
||||
# Handle a response from our core
|
||||
@ -114,7 +118,7 @@ class WebsocketHandler(tornado.websocket.WebSocketHandler):
|
||||
# Respond to the original request
|
||||
data = request_response
|
||||
data['recipient'] = self.connection_id
|
||||
getIris().send_message(data=data)
|
||||
iris.send_message(data=data)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,9 +1 @@
|
||||
|
||||
iris = None
|
||||
|
||||
def setIris(irisCore):
|
||||
global iris
|
||||
iris = irisCore
|
||||
|
||||
def getIris():
|
||||
return iris
|
||||
Reference in New Issue
Block a user