From 86cf77db83e7f98f0f7d23955ce6a4c52bf35d06 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Sep 2017 18:21:54 +0100 Subject: [PATCH 01/13] add returns --- openlp/plugins/bibles/endpoint.py | 4 ++-- openlp/plugins/custom/endpoint.py | 4 ++-- openlp/plugins/images/endpoint.py | 4 ++-- openlp/plugins/media/endpoint.py | 4 ++-- openlp/plugins/presentations/endpoint.py | 4 ++-- openlp/plugins/songs/endpoint.py | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) 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/songs/endpoint.py b/openlp/plugins/songs/endpoint.py index 8711fcccd..6bd521872 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 search(request, 'songs', log) except NotFound: return {'results': {'items': []}} From 9fc7f1b39b3d1b5df488050e192185518d671844 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Sep 2017 18:48:01 +0100 Subject: [PATCH 02/13] restart removal --- openlp/plugins/remotes/endpoint.py | 46 -------------------------- openlp/plugins/remotes/remoteplugin.py | 7 ++-- 2 files changed, 3 insertions(+), 50 deletions(-) delete mode 100644 openlp/plugins/remotes/endpoint.py diff --git a/openlp/plugins/remotes/endpoint.py b/openlp/plugins/remotes/endpoint.py deleted file mode 100644 index a9b0d0815..000000000 --- a/openlp/plugins/remotes/endpoint.py +++ /dev/null @@ -1,46 +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 - -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.route('{view}') -def index(request, view): - """ - Handles requests for /remotes url - - :param request: The http request object. - :param view: The view name to be servered. - """ - return remote_endpoint.render_template('{view}.mako'.format(view=view), **TRANSLATED_STRINGS) diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index 1344c66d1..4974e451b 100644 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -20,16 +20,15 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -import logging -import os import time - from PyQt5 import QtCore, QtWidgets +import logging + +from openlp.core.api.endpoint.remote import remote_endpoint 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__) From 5b2ac0f97b7f655c47e33eb00e308ac9ea862abb Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Sep 2017 18:49:41 +0100 Subject: [PATCH 03/13] more moves --- openlp/plugins/remotes/deploy.py | 69 ------------------- openlp/plugins/remotes/remoteplugin.py | 6 +- .../openlp_plugins/remotes/test_deploy.py | 4 +- 3 files changed, 4 insertions(+), 75 deletions(-) delete mode 100644 openlp/plugins/remotes/deploy.py diff --git a/openlp/plugins/remotes/deploy.py b/openlp/plugins/remotes/deploy.py deleted file mode 100644 index 44c628837..000000000 --- a/openlp/plugins/remotes/deploy.py +++ /dev/null @@ -1,69 +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 # -############################################################################### -""" -Download and "install" the remote web client -""" -import os -from zipfile import ZipFile - -from openlp.core.common import AppLocation, Registry -from openlp.core.common.httputils import url_get_file, get_web_page, get_url_file_size - - -def deploy_zipfile(app_root, zip_name): - """ - Process the downloaded zip file and add to the correct directory - - :param zip_name: the zip file to be processed - :param app_root: the directory where the zip get expanded to - - :return: None - """ - zip_file = os.path.join(app_root, zip_name) - web_zip = ZipFile(zip_file) - web_zip.extractall(app_root) - - -def download_sha256(): - """ - Download the config file to extract the sha256 and version number - """ - user_agent = 'OpenLP/' + Registry().get('application').applicationVersion() - try: - web_config = get_web_page('https://get.openlp.org/webclient/download.cfg', headers={'User-Agent': user_agent}) - except ConnectionError: - return False - file_bits = web_config.split() - return file_bits[0], file_bits[2] - - -def download_and_check(callback=None): - """ - Download the web site and deploy it. - """ - 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'), - 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/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index 4974e451b..c223eb99e 100644 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -20,16 +20,16 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +import logging import time + from PyQt5 import QtCore, QtWidgets -import logging - +from openlp.core.api.deploy import download_and_check, download_sha256 from openlp.core.api.endpoint.remote import remote_endpoint 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.deploy import download_and_check, download_sha256 log = logging.getLogger(__name__) __default_settings__ = { diff --git a/tests/functional/openlp_plugins/remotes/test_deploy.py b/tests/functional/openlp_plugins/remotes/test_deploy.py index 1909b94fd..14447a97e 100644 --- a/tests/functional/openlp_plugins/remotes/test_deploy.py +++ b/tests/functional/openlp_plugins/remotes/test_deploy.py @@ -22,12 +22,10 @@ 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')) From 64ba30b24dced2acb9fabf32f143bf28891736a7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Sep 2017 18:51:09 +0100 Subject: [PATCH 04/13] add files --- openlp/core/api/deploy.py | 69 ++++++++++++++++++++++++++++++ openlp/core/api/endpoint/remote.py | 46 ++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 openlp/core/api/deploy.py create mode 100644 openlp/core/api/endpoint/remote.py diff --git a/openlp/core/api/deploy.py b/openlp/core/api/deploy.py new file mode 100644 index 000000000..44c628837 --- /dev/null +++ b/openlp/core/api/deploy.py @@ -0,0 +1,69 @@ +# -*- 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 # +############################################################################### +""" +Download and "install" the remote web client +""" +import os +from zipfile import ZipFile + +from openlp.core.common import AppLocation, Registry +from openlp.core.common.httputils import url_get_file, get_web_page, get_url_file_size + + +def deploy_zipfile(app_root, zip_name): + """ + Process the downloaded zip file and add to the correct directory + + :param zip_name: the zip file to be processed + :param app_root: the directory where the zip get expanded to + + :return: None + """ + zip_file = os.path.join(app_root, zip_name) + web_zip = ZipFile(zip_file) + web_zip.extractall(app_root) + + +def download_sha256(): + """ + Download the config file to extract the sha256 and version number + """ + user_agent = 'OpenLP/' + Registry().get('application').applicationVersion() + try: + web_config = get_web_page('https://get.openlp.org/webclient/download.cfg', headers={'User-Agent': user_agent}) + except ConnectionError: + return False + file_bits = web_config.split() + return file_bits[0], file_bits[2] + + +def download_and_check(callback=None): + """ + Download the web site and deploy it. + """ + 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'), + 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/core/api/endpoint/remote.py b/openlp/core/api/endpoint/remote.py new file mode 100644 index 000000000..a9b0d0815 --- /dev/null +++ b/openlp/core/api/endpoint/remote.py @@ -0,0 +1,46 @@ +# -*- 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 + +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.route('{view}') +def index(request, view): + """ + Handles requests for /remotes url + + :param request: The http request object. + :param view: The view name to be servered. + """ + return remote_endpoint.render_template('{view}.mako'.format(view=view), **TRANSLATED_STRINGS) From b783783a297362f1200f44b73b50311c2b978e00 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Sep 2017 21:33:58 +0100 Subject: [PATCH 05/13] add files --- .../openlp_plugins/remotes/__init__.py | 21 ------- .../openlp_plugins/remotes/test_deploy.py | 62 ------------------- 2 files changed, 83 deletions(-) delete mode 100644 tests/functional/openlp_plugins/remotes/__init__.py delete mode 100644 tests/functional/openlp_plugins/remotes/test_deploy.py 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/functional/openlp_plugins/remotes/test_deploy.py b/tests/functional/openlp_plugins/remotes/test_deploy.py deleted file mode 100644 index 14447a97e..000000000 --- a/tests/functional/openlp_plugins/remotes/test_deploy.py +++ /dev/null @@ -1,62 +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 os -import shutil -from tempfile import mkdtemp -from unittest import TestCase - -from openlp.core.api.deploy import deploy_zipfile - -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources')) - - -class TestRemoteDeploy(TestCase): - """ - Test the Remote plugin deploy functions - """ - - def setUp(self): - """ - Setup for tests - """ - self.app_root = mkdtemp() - - def tearDown(self): - """ - Clean up after tests - """ - shutil.rmtree(self.app_root) - - def test_deploy_zipfile(self): - """ - Remote Deploy tests - test the dummy zip file is processed correctly - """ - # GIVEN: A new downloaded zip file - 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) - # WHEN: I process the zipfile - deploy_zipfile(self.app_root, 'site.zip') - - # THEN test if www directory has been created - self.assertTrue(os.path.isdir(os.path.join(self.app_root, 'www')), 'We should have a www directory') From 4451b65f04c2f6490fdf30902a3e3942d2565e8e Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Sep 2017 21:34:08 +0100 Subject: [PATCH 06/13] add files2 --- .../functional/openlp_core_api/test_deploy.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/functional/openlp_core_api/test_deploy.py diff --git a/tests/functional/openlp_core_api/test_deploy.py b/tests/functional/openlp_core_api/test_deploy.py new file mode 100644 index 000000000..14447a97e --- /dev/null +++ b/tests/functional/openlp_core_api/test_deploy.py @@ -0,0 +1,62 @@ +# -*- 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 os +import shutil +from tempfile import mkdtemp +from unittest import TestCase + +from openlp.core.api.deploy import deploy_zipfile + +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources')) + + +class TestRemoteDeploy(TestCase): + """ + Test the Remote plugin deploy functions + """ + + def setUp(self): + """ + Setup for tests + """ + self.app_root = mkdtemp() + + def tearDown(self): + """ + Clean up after tests + """ + shutil.rmtree(self.app_root) + + def test_deploy_zipfile(self): + """ + Remote Deploy tests - test the dummy zip file is processed correctly + """ + # GIVEN: A new downloaded zip file + 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) + # WHEN: I process the zipfile + deploy_zipfile(self.app_root, 'site.zip') + + # THEN test if www directory has been created + self.assertTrue(os.path.isdir(os.path.join(self.app_root, 'www')), 'We should have a www directory') From f58d1047db8f66ded0b82605495c63e266635b4f Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Sep 2017 22:04:39 +0100 Subject: [PATCH 07/13] move endpoint --- openlp/core/api/endpoint/remote.py | 7 +------ openlp/core/api/endpoint/service.py | 2 +- openlp/core/api/http/server.py | 3 +++ openlp/plugins/songs/endpoint.py | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/openlp/core/api/endpoint/remote.py b/openlp/core/api/endpoint/remote.py index a9b0d0815..4741ada15 100644 --- a/openlp/core/api/endpoint/remote.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..28d883487 100644 --- a/openlp/core/api/http/server.py +++ b/openlp/core/api/http/server.py @@ -37,6 +37,8 @@ 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__) @@ -95,3 +97,4 @@ class HttpServer(RegistryMixin, RegistryProperties, OpenLPMixin): register_endpoint(main_endpoint) register_endpoint(service_endpoint) register_endpoint(api_service_endpoint) + register_endpoint(remote_endpoint) diff --git a/openlp/plugins/songs/endpoint.py b/openlp/plugins/songs/endpoint.py index 6bd521872..c8af62764 100644 --- a/openlp/plugins/songs/endpoint.py +++ b/openlp/plugins/songs/endpoint.py @@ -95,6 +95,6 @@ def songs_service_api(request): :param request: The http request object. """ try: - return search(request, 'songs', log) + return service(request, 'songs', log) except NotFound: return {'results': {'items': []}} From 74cdc761d9459eed5398a9b32a956bce3881d050 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Sep 2017 22:18:09 +0100 Subject: [PATCH 08/13] end of remote and server migration --- openlp/core/api/http/server.py | 88 +++++++++++++- openlp/core/common/settings.py | 1 + openlp/plugins/remotes/__init__.py | 21 ---- openlp/plugins/remotes/remoteplugin.py | 154 ------------------------- 4 files changed, 87 insertions(+), 177 deletions(-) delete mode 100644 openlp/plugins/remotes/__init__.py delete mode 100644 openlp/plugins/remotes/remoteplugin.py diff --git a/openlp/core/api/http/server.py b/openlp/core/api/http/server.py index 28d883487..9ba3a1bb0 100644 --- a/openlp/core/api/http/server.py +++ b/openlp/core/api/http/server.py @@ -26,13 +26,18 @@ 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 @@ -81,11 +86,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', '0001_01_01') 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() @@ -98,3 +107,78 @@ class HttpServer(RegistryMixin, RegistryProperties, OpenLPMixin): 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 = 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() \ No newline at end of file diff --git a/openlp/core/common/settings.py b/openlp/core/common/settings.py index be1b29c75..477925280 100644 --- a/openlp/core/common/settings.py +++ b/openlp/core/common/settings.py @@ -177,6 +177,7 @@ class Settings(QtCore.QSettings): 'images/background color': '#000000', 'media/players': 'system,webkit', 'media/override player': QtCore.Qt.Unchecked, + 'remotes/download version': '0000_00_00', 'players/background color': '#000000', 'servicemanager/last directory': None, 'servicemanager/last file': None, 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 c223eb99e..000000000 --- a/openlp/plugins/remotes/remoteplugin.py +++ /dev/null @@ -1,154 +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 time - -from PyQt5 import QtCore, QtWidgets - -from openlp.core.api.deploy import download_and_check, download_sha256 -from openlp.core.api.endpoint.remote import remote_endpoint -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 - -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() From 71a87f602b1011e47005c98542b6c485e683bfd8 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Sep 2017 19:56:21 +0100 Subject: [PATCH 09/13] fix download date --- openlp/core/api/deploy.py | 2 +- openlp/core/api/http/server.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/core/api/deploy.py b/openlp/core/api/deploy.py index 44c628837..9b1e6e793 100644 --- a/openlp/core/api/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/core/api/http/server.py b/openlp/core/api/http/server.py index 9ba3a1bb0..55f9a2305 100644 --- a/openlp/core/api/http/server.py +++ b/openlp/core/api/http/server.py @@ -66,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): From bfc8a5ae8c52fb0d994ce20b1f611f97fb6e7449 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Sep 2017 20:12:22 +0100 Subject: [PATCH 10/13] fix tests --- tests/functional/openlp_core_api/test_deploy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_api/test_deploy.py b/tests/functional/openlp_core_api/test_deploy.py index 14447a97e..273894b99 100644 --- a/tests/functional/openlp_core_api/test_deploy.py +++ b/tests/functional/openlp_core_api/test_deploy.py @@ -27,7 +27,7 @@ from unittest import TestCase 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): @@ -52,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) From e2fd8beb2a0090271a85475048835c74c88246fe Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Sep 2017 20:16:24 +0100 Subject: [PATCH 11/13] fix tests --- tests/interfaces/openlp_core_lib/test_pluginmanager.py | 1 - 1 file changed, 1 deletion(-) 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') From 0c1b1dc2a5f1f5cc4b4852fea06793463a982328 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Sep 2017 20:21:08 +0100 Subject: [PATCH 12/13] fix tests --- openlp/core/api/http/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/api/http/server.py b/openlp/core/api/http/server.py index 55f9a2305..916aedddd 100644 --- a/openlp/core/api/http/server.py +++ b/openlp/core/api/http/server.py @@ -182,4 +182,4 @@ class Progress(QtWidgets.QProgressDialog): self.setText(status_text) if increment > 0: self.setValue(self.value() + increment) - self.parent.application.process_events() \ No newline at end of file + self.parent.application.process_events() From cd1b6715b6cd01e31cd760140d0b81e723aabed3 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Sep 2017 19:53:04 +0100 Subject: [PATCH 13/13] fix merge comments --- openlp/core/api/http/server.py | 8 ++++---- openlp/core/api/tab.py | 2 ++ openlp/core/common/settings.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/openlp/core/api/http/server.py b/openlp/core/api/http/server.py index 916aedddd..2a2ec7292 100644 --- a/openlp/core/api/http/server.py +++ b/openlp/core/api/http/server.py @@ -89,7 +89,7 @@ class HttpServer(RegistryMixin, RegistryProperties, OpenLPMixin): 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', '0001_01_01') + Registry().set_flag('website_version', '0.0') def bootstrap_post_set_up(self): """ @@ -126,7 +126,7 @@ class HttpServer(RegistryMixin, RegistryProperties, OpenLPMixin): Import web site code if active """ self.application.process_events() - progress = Progress(self) + progress = DownloadProgressDialog(self) progress.forceShow() self.application.process_events() time.sleep(1) @@ -147,12 +147,12 @@ class HttpServer(RegistryMixin, RegistryProperties, OpenLPMixin): Registry().set_flag('website_version', self.version) -class Progress(QtWidgets.QProgressDialog): +class DownloadProgressDialog(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) + super(DownloadProgressDialog, self).__init__(parent.main_window) self.parent = parent self.setWindowModality(QtCore.Qt.WindowModal) self.setWindowTitle(translate('RemotePlugin', 'Importing Website')) 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 477925280..87efd10d3 100644 --- a/openlp/core/common/settings.py +++ b/openlp/core/common/settings.py @@ -177,7 +177,7 @@ class Settings(QtCore.QSettings): 'images/background color': '#000000', 'media/players': 'system,webkit', 'media/override player': QtCore.Qt.Unchecked, - 'remotes/download version': '0000_00_00', + 'remotes/download version': '0.0', 'players/background color': '#000000', 'servicemanager/last directory': None, 'servicemanager/last file': None,