diff --git a/openlp/plugins/remotes/deploy.py b/openlp/core/api/deploy.py similarity index 96% rename from openlp/plugins/remotes/deploy.py rename to openlp/core/api/deploy.py index 44c628837..9b1e6e793 100644 --- a/openlp/plugins/remotes/deploy.py +++ b/openlp/core/api/deploy.py @@ -63,7 +63,7 @@ def download_and_check(callback=None): sha256, version = download_sha256() file_size = get_url_file_size('https://get.openlp.org/webclient/site.zip') callback.setRange(0, file_size) - if url_get_file(callback, '{host}{name}'.format(host='https://get.openlp.org/webclient/', name='site.zip'), + if url_get_file(callback, 'https://get.openlp.org/webclient/site.zip', AppLocation.get_section_data_path('remotes') / 'site.zip', sha256=sha256): deploy_zipfile(str(AppLocation.get_section_data_path('remotes')), 'site.zip') diff --git a/openlp/plugins/remotes/endpoint.py b/openlp/core/api/endpoint/remote.py similarity index 90% rename from openlp/plugins/remotes/endpoint.py rename to openlp/core/api/endpoint/remote.py index a9b0d0815..4741ada15 100644 --- a/openlp/plugins/remotes/endpoint.py +++ b/openlp/core/api/endpoint/remote.py @@ -21,18 +21,13 @@ ############################################################################### import logging -import os - from openlp.core.api.http.endpoint import Endpoint from openlp.core.api.endpoint.core import TRANSLATED_STRINGS -from openlp.core.common import AppLocation -static_dir = os.path.join(str(AppLocation.get_section_data_path('remotes'))) - log = logging.getLogger(__name__) -remote_endpoint = Endpoint('remote', template_dir=static_dir, static_dir=static_dir) +remote_endpoint = Endpoint('remote', template_dir='remotes', static_dir='remotes') @remote_endpoint.route('{view}') diff --git a/openlp/core/api/endpoint/service.py b/openlp/core/api/endpoint/service.py index acb139b43..4e3b53fbb 100644 --- a/openlp/core/api/endpoint/service.py +++ b/openlp/core/api/endpoint/service.py @@ -23,7 +23,7 @@ import logging import json from openlp.core.api.http.endpoint import Endpoint -from openlp.core.api.http import register_endpoint, requires_auth +from openlp.core.api.http import requires_auth from openlp.core.common import Registry diff --git a/openlp/core/api/http/server.py b/openlp/core/api/http/server.py index a7ec34903..2a2ec7292 100644 --- a/openlp/core/api/http/server.py +++ b/openlp/core/api/http/server.py @@ -26,17 +26,24 @@ with OpenLP. It uses JSON to communicate with the remotes. """ import logging +import time -from PyQt5 import QtCore +from PyQt5 import QtCore, QtWidgets from waitress import serve from openlp.core.api.http import register_endpoint from openlp.core.api.http import application -from openlp.core.common import RegistryMixin, RegistryProperties, OpenLPMixin, Settings, Registry +from openlp.core.common import AppLocation, RegistryMixin, RegistryProperties, OpenLPMixin, \ + Settings, Registry, UiStrings, check_directory_exists +from openlp.core.lib import translate + +from openlp.core.api.deploy import download_and_check, download_sha256 from openlp.core.api.poll import Poller from openlp.core.api.endpoint.controller import controller_endpoint, api_controller_endpoint from openlp.core.api.endpoint.core import chords_endpoint, stage_endpoint, blank_endpoint, main_endpoint from openlp.core.api.endpoint.service import service_endpoint, api_service_endpoint +from openlp.core.api.endpoint.remote import remote_endpoint + log = logging.getLogger(__name__) @@ -59,6 +66,7 @@ class HttpWorker(QtCore.QObject): """ address = Settings().value('api/ip address') port = Settings().value('api/port') + Registry().execute('get_website_version') serve(application, host=address, port=port) def stop(self): @@ -79,11 +87,15 @@ class HttpServer(RegistryMixin, RegistryProperties, OpenLPMixin): self.worker.moveToThread(self.thread) self.thread.started.connect(self.worker.run) self.thread.start() + Registry().register_function('download_website', self.first_time) + Registry().register_function('get_website_version', self.website_version) + Registry().set_flag('website_version', '0.0') def bootstrap_post_set_up(self): """ Register the poll return service and start the servers. """ + self.initialise() self.poller = Poller() Registry().register('poller', self.poller) application.initialise() @@ -95,3 +107,79 @@ class HttpServer(RegistryMixin, RegistryProperties, OpenLPMixin): register_endpoint(main_endpoint) register_endpoint(service_endpoint) register_endpoint(api_service_endpoint) + register_endpoint(remote_endpoint) + + @staticmethod + def initialise(): + """ + Create the internal file structure if it does not exist + :return: + """ + check_directory_exists(AppLocation.get_section_data_path('remotes') / 'assets') + check_directory_exists(AppLocation.get_section_data_path('remotes') / 'images') + check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static') + check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static' / 'index') + check_directory_exists(AppLocation.get_section_data_path('remotes') / 'templates') + + def first_time(self): + """ + Import web site code if active + """ + self.application.process_events() + progress = DownloadProgressDialog(self) + progress.forceShow() + self.application.process_events() + time.sleep(1) + download_and_check(progress) + self.application.process_events() + time.sleep(1) + progress.close() + self.application.process_events() + Settings().setValue('remotes/download version', self.version) + + def website_version(self): + """ + Download and save the website version and sha256 + :return: None + """ + sha256, self.version = download_sha256() + Registry().set_flag('website_sha256', sha256) + Registry().set_flag('website_version', self.version) + + +class DownloadProgressDialog(QtWidgets.QProgressDialog): + """ + Local class to handle download display based and supporting httputils:get_web_page + """ + def __init__(self, parent): + super(DownloadProgressDialog, self).__init__(parent.main_window) + self.parent = parent + self.setWindowModality(QtCore.Qt.WindowModal) + self.setWindowTitle(translate('RemotePlugin', 'Importing Website')) + self.setLabelText(UiStrings().StartingImport) + self.setCancelButton(None) + self.setRange(0, 1) + self.setMinimumDuration(0) + self.was_cancelled = False + self.previous_size = 0 + + def _download_progress(self, count, block_size): + """ + Calculate and display the download progress. + """ + increment = (count * block_size) - self.previous_size + self._increment_progress_bar(None, increment) + self.previous_size = count * block_size + + def _increment_progress_bar(self, status_text, increment=1): + """ + Update the wizard progress page. + + :param status_text: Current status information to display. + :param increment: The value to increment the progress bar by. + """ + if status_text: + self.setText(status_text) + if increment > 0: + self.setValue(self.value() + increment) + self.parent.application.process_events() diff --git a/openlp/core/api/tab.py b/openlp/core/api/tab.py index 3ec8c4515..e10a68238 100644 --- a/openlp/core/api/tab.py +++ b/openlp/core/api/tab.py @@ -222,6 +222,8 @@ class ApiTab(SettingsTab): self.remote_url.setText('{url}'.format(url=http_url)) http_url_temp = http_url + 'stage' self.stage_url.setText('{url}'.format(url=http_url_temp)) + http_url_temp = http_url + 'chords' + self.chords_url.setText('{url}'.format(url=http_url_temp)) http_url_temp = http_url + 'main' self.live_url.setText('{url}'.format(url=http_url_temp)) diff --git a/openlp/core/common/settings.py b/openlp/core/common/settings.py index 0540ff81e..ca59d4e6f 100644 --- a/openlp/core/common/settings.py +++ b/openlp/core/common/settings.py @@ -178,6 +178,7 @@ class Settings(QtCore.QSettings): 'images/background color': '#000000', 'media/players': 'system,webkit', 'media/override player': QtCore.Qt.Unchecked, + 'remotes/download version': '0.0', 'players/background color': '#000000', 'servicemanager/last directory': None, 'servicemanager/last file': None, diff --git a/openlp/plugins/bibles/endpoint.py b/openlp/plugins/bibles/endpoint.py index 08a945e7c..4d34eb966 100644 --- a/openlp/plugins/bibles/endpoint.py +++ b/openlp/plugins/bibles/endpoint.py @@ -62,7 +62,7 @@ def bibles_service(request): :param request: The http request object. """ - service(request, 'bibles', log) + return service(request, 'bibles', log) @api_bibles_endpoint.route('bibles/search') @@ -95,6 +95,6 @@ def bibles_service_api(request): :param request: The http request object. """ try: - search(request, 'bibles', log) + return search(request, 'bibles', log) except NotFound: return {'results': {'items': []}} diff --git a/openlp/plugins/custom/endpoint.py b/openlp/plugins/custom/endpoint.py index 687ffaa1b..ca5c39088 100644 --- a/openlp/plugins/custom/endpoint.py +++ b/openlp/plugins/custom/endpoint.py @@ -62,7 +62,7 @@ def custom_service(request): :param request: The http request object. """ - service(request, 'custom', log) + return service(request, 'custom', log) @api_custom_endpoint.route('custom/search') @@ -95,6 +95,6 @@ def custom_service_api(request): :param request: The http request object. """ try: - search(request, 'custom', log) + return search(request, 'custom', log) except NotFound: return {'results': {'items': []}} diff --git a/openlp/plugins/images/endpoint.py b/openlp/plugins/images/endpoint.py index ca82da00a..05c1e64b4 100644 --- a/openlp/plugins/images/endpoint.py +++ b/openlp/plugins/images/endpoint.py @@ -75,7 +75,7 @@ def images_service(request): :param request: The http request object. """ - service(request, 'images', log) + return service(request, 'images', log) @api_images_endpoint.route('images/search') @@ -108,6 +108,6 @@ def images_service_api(request): :param request: The http request object. """ try: - search(request, 'images', log) + return search(request, 'images', log) except NotFound: return {'results': {'items': []}} diff --git a/openlp/plugins/media/endpoint.py b/openlp/plugins/media/endpoint.py index 014c3c790..c7b703358 100644 --- a/openlp/plugins/media/endpoint.py +++ b/openlp/plugins/media/endpoint.py @@ -62,7 +62,7 @@ def media_service(request): :param request: The http request object. """ - service(request, 'media', log) + return service(request, 'media', log) @api_media_endpoint.route('media/search') @@ -95,6 +95,6 @@ def media_service_api(request): :param request: The http request object. """ try: - search(request, 'media', log) + return search(request, 'media', log) except NotFound: return {'results': {'items': []}} diff --git a/openlp/plugins/presentations/endpoint.py b/openlp/plugins/presentations/endpoint.py index ce622083c..99c828b4b 100644 --- a/openlp/plugins/presentations/endpoint.py +++ b/openlp/plugins/presentations/endpoint.py @@ -76,7 +76,7 @@ def presentations_service(request): :param request: The http request object. """ - service(request, 'presentations', log) + return service(request, 'presentations', log) @api_presentations_endpoint.route('presentations/search') @@ -109,6 +109,6 @@ def presentations_service_api(request): :param request: The http request object. """ try: - search(request, 'presentations', log) + return search(request, 'presentations', log) except NotFound: return {'results': {'items': []}} diff --git a/openlp/plugins/remotes/__init__.py b/openlp/plugins/remotes/__init__.py deleted file mode 100644 index ea62548f4..000000000 --- a/openlp/plugins/remotes/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2017 OpenLP Developers # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py deleted file mode 100644 index 1344c66d1..000000000 --- a/openlp/plugins/remotes/remoteplugin.py +++ /dev/null @@ -1,155 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2017 OpenLP Developers # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### - -import logging -import os -import time - -from PyQt5 import QtCore, QtWidgets - -from openlp.core.api.http import register_endpoint -from openlp.core.common import AppLocation, Registry, Settings, OpenLPMixin, UiStrings, check_directory_exists -from openlp.core.lib import Plugin, StringContent, translate, build_icon -from openlp.plugins.remotes.endpoint import remote_endpoint -from openlp.plugins.remotes.deploy import download_and_check, download_sha256 - -log = logging.getLogger(__name__) -__default_settings__ = { - 'remotes/download version': '0000_00_00' -} - - -class RemotesPlugin(Plugin, OpenLPMixin): - log.info('Remotes Plugin loaded') - - def __init__(self): - """ - remotes constructor - """ - super(RemotesPlugin, self).__init__('remotes', __default_settings__, {}) - self.icon_path = ':/plugins/plugin_remote.png' - self.icon = build_icon(self.icon_path) - self.weight = -1 - register_endpoint(remote_endpoint) - Registry().register_function('download_website', self.first_time) - Registry().register_function('get_website_version', self.website_version) - Registry().set_flag('website_version', '0001_01_01') - - def initialise(self): - """ - Create the internal file structure if it does not exist - :return: - """ - check_directory_exists(AppLocation.get_section_data_path('remotes') / 'assets') - check_directory_exists(AppLocation.get_section_data_path('remotes') / 'images') - check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static') - check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static', 'index') - check_directory_exists(AppLocation.get_section_data_path('remotes') / 'templates') - - @staticmethod - def about(): - """ - Information about this plugin - """ - about_text = translate( - 'RemotePlugin', - 'Web Interface' - '
The web interface plugin provides the ability to develop web based interfaces using OpenLP web ' - 'services.\nPredefined interfaces can be download as well as custom developed interfaces.') - return about_text - - def set_plugin_text_strings(self): - """ - Called to define all translatable texts of the plugin - """ - # Name PluginList - self.text_strings[StringContent.Name] = { - 'singular': translate('RemotePlugin', 'Web Interface', 'name singular'), - 'plural': translate('RemotePlugin', 'Web Interface', 'name plural') - } - # Name for MediaDockManager, SettingsManager - self.text_strings[StringContent.VisibleName] = { - 'title': translate('RemotePlugin', 'Web Remote', 'container title') - } - - def first_time(self): - """ - Import web site code if active - """ - self.application.process_events() - progress = Progress(self) - progress.forceShow() - self.application.process_events() - time.sleep(1) - download_and_check(progress) - self.application.process_events() - time.sleep(1) - progress.close() - self.application.process_events() - Settings().setValue('remotes/download version', self.version) - - def website_version(self): - """ - Download and save the website version and sha256 - :return: None - """ - sha256, self.version = download_sha256() - Registry().set_flag('website_sha256', sha256) - Registry().set_flag('website_version', self.version) - - -class Progress(QtWidgets.QProgressDialog): - """ - Local class to handle download display based and supporting httputils:get_web_page - """ - def __init__(self, parent): - super(Progress, self).__init__(parent.main_window) - self.parent = parent - self.setWindowModality(QtCore.Qt.WindowModal) - self.setWindowTitle(translate('RemotePlugin', 'Importing Website')) - self.setLabelText(UiStrings().StartingImport) - self.setCancelButton(None) - self.setRange(0, 1) - self.setMinimumDuration(0) - self.was_cancelled = False - self.previous_size = 0 - - def _download_progress(self, count, block_size): - """ - Calculate and display the download progress. - """ - increment = (count * block_size) - self.previous_size - self._increment_progress_bar(None, increment) - self.previous_size = count * block_size - - def _increment_progress_bar(self, status_text, increment=1): - """ - Update the wizard progress page. - - :param status_text: Current status information to display. - :param increment: The value to increment the progress bar by. - """ - if status_text: - self.setText(status_text) - if increment > 0: - self.setValue(self.value() + increment) - self.parent.application.process_events() diff --git a/openlp/plugins/songs/endpoint.py b/openlp/plugins/songs/endpoint.py index 8711fcccd..c8af62764 100644 --- a/openlp/plugins/songs/endpoint.py +++ b/openlp/plugins/songs/endpoint.py @@ -62,7 +62,7 @@ def songs_service(request): :param request: The http request object. """ - service(request, 'songs', log) + return service(request, 'songs', log) @api_songs_endpoint.route('songs/search') @@ -95,6 +95,6 @@ def songs_service_api(request): :param request: The http request object. """ try: - search(request, 'songs', log) + return service(request, 'songs', log) except NotFound: return {'results': {'items': []}} diff --git a/tests/functional/openlp_plugins/remotes/test_deploy.py b/tests/functional/openlp_core_api/test_deploy.py similarity index 96% rename from tests/functional/openlp_plugins/remotes/test_deploy.py rename to tests/functional/openlp_core_api/test_deploy.py index 1909b94fd..273894b99 100644 --- a/tests/functional/openlp_plugins/remotes/test_deploy.py +++ b/tests/functional/openlp_core_api/test_deploy.py @@ -22,14 +22,12 @@ import os import shutil - from tempfile import mkdtemp from unittest import TestCase -from openlp.plugins.remotes.deploy import deploy_zipfile +from openlp.core.api.deploy import deploy_zipfile - -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources')) +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources')) class TestRemoteDeploy(TestCase): @@ -54,6 +52,7 @@ class TestRemoteDeploy(TestCase): Remote Deploy tests - test the dummy zip file is processed correctly """ # GIVEN: A new downloaded zip file + aa = TEST_PATH zip_file = os.path.join(TEST_PATH, 'remotes', 'site.zip') app_root = os.path.join(self.app_root, 'site.zip') shutil.copyfile(zip_file, app_root) diff --git a/tests/functional/openlp_plugins/remotes/__init__.py b/tests/functional/openlp_plugins/remotes/__init__.py deleted file mode 100644 index ea62548f4..000000000 --- a/tests/functional/openlp_plugins/remotes/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2017 OpenLP Developers # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py index 2e9e8342f..3dbae0e03 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -94,4 +94,3 @@ class TestPluginManager(TestCase, TestMixin): self.assertIn('custom', plugin_names, 'There should be a "custom" plugin') self.assertIn('songusage', plugin_names, 'There should be a "songusage" plugin') self.assertIn('alerts', plugin_names, 'There should be a "alerts" plugin') - self.assertIn('remotes', plugin_names, 'There should be a "remotes" plugin')