From d5028cef2160dcc41fd1ebe9e7aeefb53a04b313 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Fri, 27 Dec 2019 13:34:54 +1300 Subject: [PATCH] Instance created within mem; Now semi-operational --- Dockerfile | 2 +- mopidy_iris/core.py | 15 +++++++++------ mopidy_iris/frontend.py | 8 +++----- mopidy_iris/handlers.py | 4 ---- mopidy_iris/mem.py | 4 +++- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 73cb6dc9..4cae8d20 100755 --- a/Dockerfile +++ b/Dockerfile @@ -55,7 +55,7 @@ COPY docker/pulse-client.conf /etc/pulse/client.conf ADD VERSION / # Allows any user to run mopidy, but runs by default as a randomly generated UID/GID. -ENV HOME=/var/lib/mopidy +#ENV HOME=/var/lib/mopidy EXPOSE 6600 6680 diff --git a/mopidy_iris/core.py b/mopidy_iris/core.py index 9f5b33ae..e0235bd4 100755 --- a/mopidy_iris/core.py +++ b/mopidy_iris/core.py @@ -37,7 +37,7 @@ class IrisCore(pykka.ThreadingActor): } - def __init__(self, config, core): + def setup(self, config, core): self.config = config self.core = core @@ -261,7 +261,7 @@ class IrisCore(pykka.ThreadingActor): callback = kwargs.get('callback', None) connections = [] - for connection in self.connections.itervalues(): + for connection in self.connections.values(): connections.append(connection['client']) response = { @@ -276,6 +276,9 @@ class IrisCore(pykka.ThreadingActor): connection = kwargs.get('connection', None) client = kwargs.get('client', None) + logger.debug("Connection added") + logger.debug(connection) + self.connections[client['connection_id']] = { 'client': client, 'connection_id': client['connection_id'], @@ -409,20 +412,20 @@ class IrisCore(pykka.ThreadingActor): def get_version(self, *args, **kwargs): + callback = kwargs.get('callback', False) url = 'https://pypi.python.org/pypi/Mopidy-Iris/json' - req = urllib.request(url) try: - response = urllib.urlopen(req, timeout=30).read() + response = urllib.request.urlopen(url, timeout=30).read() response = json.loads(response) latest_version = response['info']['version'] # compare our versions, and convert result to boolean - upgrade_available = cmp( parse_version( latest_version ), parse_version( self.version ) ) + upgrade_available = parse_version( latest_version ) > parse_version( self.version ) upgrade_available = ( upgrade_available == 1 ) - except (urllib.HTTPError, urllib.URLError) as e: + except (urllib.request.HTTPError, urllib.request.URLError) as e: latest_version = '0.0.0' upgrade_available = False diff --git a/mopidy_iris/frontend.py b/mopidy_iris/frontend.py index c09b64d7..831a4183 100755 --- a/mopidy_iris/frontend.py +++ b/mopidy_iris/frontend.py @@ -15,13 +15,11 @@ class IrisFrontend(pykka.ThreadingActor, CoreListener): def __init__(self, config, core): super(IrisFrontend, self).__init__() - - # create our core instance - iris = IrisCore(config, core) - print(iris) + # Pass our Mopidy config and core to the IrisCore instance + iris.config = config + iris.core = core def on_start(self): - print(iris) iris.start() def on_stop(self): diff --git a/mopidy_iris/handlers.py b/mopidy_iris/handlers.py index 3e5edc14..67514bf2 100755 --- a/mopidy_iris/handlers.py +++ b/mopidy_iris/handlers.py @@ -26,10 +26,6 @@ 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': iris.generateGuid(), diff --git a/mopidy_iris/mem.py b/mopidy_iris/mem.py index 5537a7b2..eada4948 100755 --- a/mopidy_iris/mem.py +++ b/mopidy_iris/mem.py @@ -1 +1,3 @@ -iris = None \ No newline at end of file +from .core import IrisCore + +iris = IrisCore() \ No newline at end of file