diff --git a/openlp/core/api/poll.py b/openlp/core/api/poll.py index 848bdf886..215ee34b9 100644 --- a/openlp/core/api/poll.py +++ b/openlp/core/api/poll.py @@ -23,7 +23,7 @@ import json from openlp.core.common import RegistryProperties, Settings - +from openlp.core.common.httputils import get_web_page class Poller(RegistryProperties): """ @@ -34,6 +34,8 @@ class Poller(RegistryProperties): Constructor for the poll builder class. """ super(Poller, self).__init__() + self.live_cache = None + self.stage_cache = None def raw_poll(self): return { @@ -47,8 +49,8 @@ class Poller(RegistryProperties): 'version': 3, 'isSecure': Settings().value('api/authentication enabled'), 'isAuthorised': False, - 'isStagedActive': self.plugin_manager.get_plugin_by_name('remotes').is_stage_active(), - 'isLiveActive': self.plugin_manager.get_plugin_by_name('remotes').is_live_active() + 'isStagedActive': self.is_stage_active(), + 'isLiveActive': self.is_live_active() } def poll(self): @@ -65,3 +67,43 @@ class Poller(RegistryProperties): 'slide_count': self.live_controller.slide_count } return json.dumps({'results': result}).encode() + + def reset_cache(self): + """ + Reset the caches as the web has changed + :return: + """ + self.stage_cache = None + self.live_cache = None + + def is_stage_active(self): + """ + Is stage active - call it and see but only once + :return: if stage is active or not + """ + if self.stage_cache is None: + try: + page = get_web_page("http://localhost:4316/stage") + except: + page = None + if page: + self.stage_cache = True + else: + self.stage_cache = False + return self.stage_cache + + def is_live_active(self): + """ + Is main active - call it and see but only once + :return: if live is active or not + """ + if self.live_cache is None: + try: + page = get_web_page("http://localhost:4316/main") + except: + page = None + if page: + self.live_cache = True + else: + self.live_cache = False + return self.live_cache diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index a83730c93..82de554d7 100644 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -25,7 +25,6 @@ import os from openlp.core.api.http import register_endpoint from openlp.core.common import AppLocation, Registry, OpenLPMixin, check_directory_exists -from openlp.core.common.httputils import get_web_page from openlp.core.lib import Plugin, StringContent, translate, build_icon from openlp.plugins.remotes.endpoint import remote_endpoint from openlp.core.api.deploy import download_and_check @@ -44,8 +43,6 @@ class RemotesPlugin(Plugin, OpenLPMixin): self.icon_path = ':/plugins/plugin_remote.png' self.icon = build_icon(self.icon_path) self.weight = -1 - self.live_cache = None - self.stage_cache = None register_endpoint(remote_endpoint) Registry().register_function('download_website', self.manage_download) @@ -59,7 +56,6 @@ class RemotesPlugin(Plugin, OpenLPMixin): check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'static')) check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'templates')) - @staticmethod def about(): """ @@ -85,46 +81,5 @@ class RemotesPlugin(Plugin, OpenLPMixin): 'title': translate('RemotePlugin', 'Web Remote', 'container title') } - def reset_cache(self): - """ - Reset the caches as the web has changed - :return: - """ - self.stage_cache = None - self.live_cache = None - - def is_stage_active(self): - """ - Is stage active - call it and see buy only once - :return: if stage is active or not - """ - if self.stage_cache is None: - try: - page = get_web_page("http://localhost:4316/stage") - except: - page = None - if page: - self.stage_cache = True - else: - self.stage_cache = False - return self.stage_cache - - def is_live_active(self): - """ - Is main active - call it and see buy only once - :return: if stage is active or not - """ - if self.live_cache is None: - try: - page = get_web_page("http://localhost:4316/main") - except: - page = None - if page: - self.live_cache = True - else: - self.live_cache = False - return self.live_cache - def manage_download(self): download_and_check() - print("manage downlaod") diff --git a/tests/functional/openlp_core_api/test_websockets.py b/tests/functional/openlp_core_api/test_websockets.py index e82930743..80ecb8832 100644 --- a/tests/functional/openlp_core_api/test_websockets.py +++ b/tests/functional/openlp_core_api/test_websockets.py @@ -22,7 +22,7 @@ """ Functional tests to test the Http Server Class. """ -import json + from unittest import TestCase from openlp.core.common import Registry, Settings