Merge lp:~trb143/openlp/webfixes into lp:openlp

Proposed by Tim Bentley
Status: Merged
Merged at revision: 2773
Proposed branch: lp:~trb143/openlp/webfixes
Merge into: lp:openlp
Diff against target: 903 lines (+279/-392)
20 files modified
openlp/core/api/deploy.py (+69/-0)
openlp/core/api/endpoint/remote.py (+41/-0)
openlp/core/api/endpoint/service.py (+1/-1)
openlp/core/api/http/server.py (+90/-2)
openlp/core/api/tab.py (+2/-0)
openlp/core/common/settings.py (+1/-0)
openlp/plugins/bibles/endpoint.py (+2/-2)
openlp/plugins/custom/endpoint.py (+2/-2)
openlp/plugins/images/endpoint.py (+2/-2)
openlp/plugins/media/endpoint.py (+2/-2)
openlp/plugins/presentations/endpoint.py (+2/-2)
openlp/plugins/remotes/__init__.py (+0/-21)
openlp/plugins/remotes/deploy.py (+0/-69)
openlp/plugins/remotes/endpoint.py (+0/-46)
openlp/plugins/remotes/remoteplugin.py (+0/-155)
openlp/plugins/songs/endpoint.py (+2/-2)
tests/functional/openlp_core_api/test_deploy.py (+63/-0)
tests/functional/openlp_plugins/remotes/__init__.py (+0/-21)
tests/functional/openlp_plugins/remotes/test_deploy.py (+0/-64)
tests/interfaces/openlp_core_lib/test_pluginmanager.py (+0/-1)
To merge this branch: bzr merge lp:~trb143/openlp/webfixes
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Tomas Groth Pending
Review via email: mp+331600@code.launchpad.net

This proposal supersedes a proposal from 2017-09-27.

Description of the change

To post a comment you must log in.
Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

For the webclient download, should we add a folder level for openlp version? I can easily imaging a scenario where one webclient will not work with all active openlp versions.
Where is the code for the webclient stored ATM? I don't see a repo on LP.

review: Needs Information
Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

https://code.launchpad.net/~trb143/openlp/remoteweb is how the web has been deployed but this will be changed when the angular code comes.

If we need version then that can be added later but this is the same as we have now.

The update of the web version is optional and can allow for other clients to be developed if required,

Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

> For the webclient download, should we add a folder level for openlp version? I
> can easily imaging a scenario where one webclient will not work with all
> active openlp versions.
> Where is the code for the webclient stored ATM? I don't see a repo on LP.

+1
I take it we're downloading version specific code. There's been numerous times in OpenLP when we've needed to 'upgrade' something thing and had to rely on a guess to which version something is. (I.e. has it got this feature) many of these situations could have been advised if version info was added from the start.

Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

> For the webclient download, should we add a folder level for openlp version? I
> can easily imaging a scenario where one webclient will not work with all
> active openlp versions.
> Where is the code for the webclient stored ATM? I don't see a repo on LP.

+1
I take it we're downloading version specific code. There's been numerous times in OpenLP when we've needed to 'upgrade' something thing and had to rely on a guess to which version something is. (I.e. has it got this feature) many of these situations could have been advised if version info was added from the start.

Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

> For the webclient download, should we add a folder level for openlp version? I
> can easily imaging a scenario where one webclient will not work with all
> active openlp versions.
> Where is the code for the webclient stored ATM? I don't see a repo on LP.

+1
I take it we're downloading version specific code. There's been numerous times in OpenLP when we've needed to 'upgrade' something thing and had to rely on a guess to which version something is. (I.e. has it got this feature) many of these situations could have been advised if version info was added from the start.

Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

Sorry about the triplicate!

Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

Please rename the dialog, and let's talk about version numbers.

review: Needs Fixing
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'openlp/core/api/deploy.py'
--- openlp/core/api/deploy.py 1970-01-01 00:00:00 +0000
+++ openlp/core/api/deploy.py 2017-09-29 19:03:48 +0000
@@ -0,0 +1,69 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22"""
23Download and "install" the remote web client
24"""
25import os
26from zipfile import ZipFile
27
28from openlp.core.common import AppLocation, Registry
29from openlp.core.common.httputils import url_get_file, get_web_page, get_url_file_size
30
31
32def deploy_zipfile(app_root, zip_name):
33 """
34 Process the downloaded zip file and add to the correct directory
35
36 :param zip_name: the zip file to be processed
37 :param app_root: the directory where the zip get expanded to
38
39 :return: None
40 """
41 zip_file = os.path.join(app_root, zip_name)
42 web_zip = ZipFile(zip_file)
43 web_zip.extractall(app_root)
44
45
46def download_sha256():
47 """
48 Download the config file to extract the sha256 and version number
49 """
50 user_agent = 'OpenLP/' + Registry().get('application').applicationVersion()
51 try:
52 web_config = get_web_page('https://get.openlp.org/webclient/download.cfg', headers={'User-Agent': user_agent})
53 except ConnectionError:
54 return False
55 file_bits = web_config.split()
56 return file_bits[0], file_bits[2]
57
58
59def download_and_check(callback=None):
60 """
61 Download the web site and deploy it.
62 """
63 sha256, version = download_sha256()
64 file_size = get_url_file_size('https://get.openlp.org/webclient/site.zip')
65 callback.setRange(0, file_size)
66 if url_get_file(callback, 'https://get.openlp.org/webclient/site.zip',
67 AppLocation.get_section_data_path('remotes') / 'site.zip',
68 sha256=sha256):
69 deploy_zipfile(str(AppLocation.get_section_data_path('remotes')), 'site.zip')
070
=== added file 'openlp/core/api/endpoint/remote.py'
--- openlp/core/api/endpoint/remote.py 1970-01-01 00:00:00 +0000
+++ openlp/core/api/endpoint/remote.py 2017-09-29 19:03:48 +0000
@@ -0,0 +1,41 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22import logging
23
24from openlp.core.api.http.endpoint import Endpoint
25from openlp.core.api.endpoint.core import TRANSLATED_STRINGS
26
27
28log = logging.getLogger(__name__)
29
30remote_endpoint = Endpoint('remote', template_dir='remotes', static_dir='remotes')
31
32
33@remote_endpoint.route('{view}')
34def index(request, view):
35 """
36 Handles requests for /remotes url
37
38 :param request: The http request object.
39 :param view: The view name to be servered.
40 """
41 return remote_endpoint.render_template('{view}.mako'.format(view=view), **TRANSLATED_STRINGS)
042
=== modified file 'openlp/core/api/endpoint/service.py'
--- openlp/core/api/endpoint/service.py 2017-03-04 19:17:59 +0000
+++ openlp/core/api/endpoint/service.py 2017-09-29 19:03:48 +0000
@@ -23,7 +23,7 @@
23import json23import json
2424
25from openlp.core.api.http.endpoint import Endpoint25from openlp.core.api.http.endpoint import Endpoint
26from openlp.core.api.http import register_endpoint, requires_auth26from openlp.core.api.http import requires_auth
27from openlp.core.common import Registry27from openlp.core.common import Registry
2828
2929
3030
=== modified file 'openlp/core/api/http/server.py'
--- openlp/core/api/http/server.py 2017-06-18 05:21:23 +0000
+++ openlp/core/api/http/server.py 2017-09-29 19:03:48 +0000
@@ -26,17 +26,24 @@
26"""26"""
2727
28import logging28import logging
29import time
2930
30from PyQt5 import QtCore31from PyQt5 import QtCore, QtWidgets
31from waitress import serve32from waitress import serve
3233
33from openlp.core.api.http import register_endpoint34from openlp.core.api.http import register_endpoint
34from openlp.core.api.http import application35from openlp.core.api.http import application
35from openlp.core.common import RegistryMixin, RegistryProperties, OpenLPMixin, Settings, Registry36from openlp.core.common import AppLocation, RegistryMixin, RegistryProperties, OpenLPMixin, \
37 Settings, Registry, UiStrings, check_directory_exists
38from openlp.core.lib import translate
39
40from openlp.core.api.deploy import download_and_check, download_sha256
36from openlp.core.api.poll import Poller41from openlp.core.api.poll import Poller
37from openlp.core.api.endpoint.controller import controller_endpoint, api_controller_endpoint42from openlp.core.api.endpoint.controller import controller_endpoint, api_controller_endpoint
38from openlp.core.api.endpoint.core import chords_endpoint, stage_endpoint, blank_endpoint, main_endpoint43from openlp.core.api.endpoint.core import chords_endpoint, stage_endpoint, blank_endpoint, main_endpoint
39from openlp.core.api.endpoint.service import service_endpoint, api_service_endpoint44from openlp.core.api.endpoint.service import service_endpoint, api_service_endpoint
45from openlp.core.api.endpoint.remote import remote_endpoint
46
4047
41log = logging.getLogger(__name__)48log = logging.getLogger(__name__)
4249
@@ -59,6 +66,7 @@
59 """66 """
60 address = Settings().value('api/ip address')67 address = Settings().value('api/ip address')
61 port = Settings().value('api/port')68 port = Settings().value('api/port')
69 Registry().execute('get_website_version')
62 serve(application, host=address, port=port)70 serve(application, host=address, port=port)
6371
64 def stop(self):72 def stop(self):
@@ -79,11 +87,15 @@
79 self.worker.moveToThread(self.thread)87 self.worker.moveToThread(self.thread)
80 self.thread.started.connect(self.worker.run)88 self.thread.started.connect(self.worker.run)
81 self.thread.start()89 self.thread.start()
90 Registry().register_function('download_website', self.first_time)
91 Registry().register_function('get_website_version', self.website_version)
92 Registry().set_flag('website_version', '0.0')
8293
83 def bootstrap_post_set_up(self):94 def bootstrap_post_set_up(self):
84 """95 """
85 Register the poll return service and start the servers.96 Register the poll return service and start the servers.
86 """97 """
98 self.initialise()
87 self.poller = Poller()99 self.poller = Poller()
88 Registry().register('poller', self.poller)100 Registry().register('poller', self.poller)
89 application.initialise()101 application.initialise()
@@ -95,3 +107,79 @@
95 register_endpoint(main_endpoint)107 register_endpoint(main_endpoint)
96 register_endpoint(service_endpoint)108 register_endpoint(service_endpoint)
97 register_endpoint(api_service_endpoint)109 register_endpoint(api_service_endpoint)
110 register_endpoint(remote_endpoint)
111
112 @staticmethod
113 def initialise():
114 """
115 Create the internal file structure if it does not exist
116 :return:
117 """
118 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'assets')
119 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'images')
120 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static')
121 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static' / 'index')
122 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'templates')
123
124 def first_time(self):
125 """
126 Import web site code if active
127 """
128 self.application.process_events()
129 progress = DownloadProgressDialog(self)
130 progress.forceShow()
131 self.application.process_events()
132 time.sleep(1)
133 download_and_check(progress)
134 self.application.process_events()
135 time.sleep(1)
136 progress.close()
137 self.application.process_events()
138 Settings().setValue('remotes/download version', self.version)
139
140 def website_version(self):
141 """
142 Download and save the website version and sha256
143 :return: None
144 """
145 sha256, self.version = download_sha256()
146 Registry().set_flag('website_sha256', sha256)
147 Registry().set_flag('website_version', self.version)
148
149
150class DownloadProgressDialog(QtWidgets.QProgressDialog):
151 """
152 Local class to handle download display based and supporting httputils:get_web_page
153 """
154 def __init__(self, parent):
155 super(DownloadProgressDialog, self).__init__(parent.main_window)
156 self.parent = parent
157 self.setWindowModality(QtCore.Qt.WindowModal)
158 self.setWindowTitle(translate('RemotePlugin', 'Importing Website'))
159 self.setLabelText(UiStrings().StartingImport)
160 self.setCancelButton(None)
161 self.setRange(0, 1)
162 self.setMinimumDuration(0)
163 self.was_cancelled = False
164 self.previous_size = 0
165
166 def _download_progress(self, count, block_size):
167 """
168 Calculate and display the download progress.
169 """
170 increment = (count * block_size) - self.previous_size
171 self._increment_progress_bar(None, increment)
172 self.previous_size = count * block_size
173
174 def _increment_progress_bar(self, status_text, increment=1):
175 """
176 Update the wizard progress page.
177
178 :param status_text: Current status information to display.
179 :param increment: The value to increment the progress bar by.
180 """
181 if status_text:
182 self.setText(status_text)
183 if increment > 0:
184 self.setValue(self.value() + increment)
185 self.parent.application.process_events()
98186
=== modified file 'openlp/core/api/tab.py'
--- openlp/core/api/tab.py 2017-06-17 08:51:01 +0000
+++ openlp/core/api/tab.py 2017-09-29 19:03:48 +0000
@@ -222,6 +222,8 @@
222 self.remote_url.setText('<a href="{url}">{url}</a>'.format(url=http_url))222 self.remote_url.setText('<a href="{url}">{url}</a>'.format(url=http_url))
223 http_url_temp = http_url + 'stage'223 http_url_temp = http_url + 'stage'
224 self.stage_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))224 self.stage_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))
225 http_url_temp = http_url + 'chords'
226 self.chords_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))
225 http_url_temp = http_url + 'main'227 http_url_temp = http_url + 'main'
226 self.live_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))228 self.live_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))
227229
228230
=== modified file 'openlp/core/common/settings.py'
--- openlp/core/common/settings.py 2017-09-28 23:28:18 +0000
+++ openlp/core/common/settings.py 2017-09-29 19:03:48 +0000
@@ -178,6 +178,7 @@
178 'images/background color': '#000000',178 'images/background color': '#000000',
179 'media/players': 'system,webkit',179 'media/players': 'system,webkit',
180 'media/override player': QtCore.Qt.Unchecked,180 'media/override player': QtCore.Qt.Unchecked,
181 'remotes/download version': '0.0',
181 'players/background color': '#000000',182 'players/background color': '#000000',
182 'servicemanager/last directory': None,183 'servicemanager/last directory': None,
183 'servicemanager/last file': None,184 'servicemanager/last file': None,
184185
=== modified file 'openlp/plugins/bibles/endpoint.py'
--- openlp/plugins/bibles/endpoint.py 2017-08-13 06:17:47 +0000
+++ openlp/plugins/bibles/endpoint.py 2017-09-29 19:03:48 +0000
@@ -62,7 +62,7 @@
6262
63 :param request: The http request object.63 :param request: The http request object.
64 """64 """
65 service(request, 'bibles', log)65 return service(request, 'bibles', log)
6666
6767
68@api_bibles_endpoint.route('bibles/search')68@api_bibles_endpoint.route('bibles/search')
@@ -95,6 +95,6 @@
95 :param request: The http request object.95 :param request: The http request object.
96 """96 """
97 try:97 try:
98 search(request, 'bibles', log)98 return search(request, 'bibles', log)
99 except NotFound:99 except NotFound:
100 return {'results': {'items': []}}100 return {'results': {'items': []}}
101101
=== modified file 'openlp/plugins/custom/endpoint.py'
--- openlp/plugins/custom/endpoint.py 2017-08-13 06:29:04 +0000
+++ openlp/plugins/custom/endpoint.py 2017-09-29 19:03:48 +0000
@@ -62,7 +62,7 @@
6262
63 :param request: The http request object.63 :param request: The http request object.
64 """64 """
65 service(request, 'custom', log)65 return service(request, 'custom', log)
6666
6767
68@api_custom_endpoint.route('custom/search')68@api_custom_endpoint.route('custom/search')
@@ -95,6 +95,6 @@
95 :param request: The http request object.95 :param request: The http request object.
96 """96 """
97 try:97 try:
98 search(request, 'custom', log)98 return search(request, 'custom', log)
99 except NotFound:99 except NotFound:
100 return {'results': {'items': []}}100 return {'results': {'items': []}}
101101
=== modified file 'openlp/plugins/images/endpoint.py'
--- openlp/plugins/images/endpoint.py 2017-08-13 06:17:47 +0000
+++ openlp/plugins/images/endpoint.py 2017-09-29 19:03:48 +0000
@@ -75,7 +75,7 @@
7575
76 :param request: The http request object.76 :param request: The http request object.
77 """77 """
78 service(request, 'images', log)78 return service(request, 'images', log)
7979
8080
81@api_images_endpoint.route('images/search')81@api_images_endpoint.route('images/search')
@@ -108,6 +108,6 @@
108 :param request: The http request object.108 :param request: The http request object.
109 """109 """
110 try:110 try:
111 search(request, 'images', log)111 return search(request, 'images', log)
112 except NotFound:112 except NotFound:
113 return {'results': {'items': []}}113 return {'results': {'items': []}}
114114
=== modified file 'openlp/plugins/media/endpoint.py'
--- openlp/plugins/media/endpoint.py 2017-08-13 06:17:47 +0000
+++ openlp/plugins/media/endpoint.py 2017-09-29 19:03:48 +0000
@@ -62,7 +62,7 @@
6262
63 :param request: The http request object.63 :param request: The http request object.
64 """64 """
65 service(request, 'media', log)65 return service(request, 'media', log)
6666
6767
68@api_media_endpoint.route('media/search')68@api_media_endpoint.route('media/search')
@@ -95,6 +95,6 @@
95 :param request: The http request object.95 :param request: The http request object.
96 """96 """
97 try:97 try:
98 search(request, 'media', log)98 return search(request, 'media', log)
99 except NotFound:99 except NotFound:
100 return {'results': {'items': []}}100 return {'results': {'items': []}}
101101
=== modified file 'openlp/plugins/presentations/endpoint.py'
--- openlp/plugins/presentations/endpoint.py 2017-08-13 06:17:47 +0000
+++ openlp/plugins/presentations/endpoint.py 2017-09-29 19:03:48 +0000
@@ -76,7 +76,7 @@
7676
77 :param request: The http request object.77 :param request: The http request object.
78 """78 """
79 service(request, 'presentations', log)79 return service(request, 'presentations', log)
8080
8181
82@api_presentations_endpoint.route('presentations/search')82@api_presentations_endpoint.route('presentations/search')
@@ -109,6 +109,6 @@
109 :param request: The http request object.109 :param request: The http request object.
110 """110 """
111 try:111 try:
112 search(request, 'presentations', log)112 return search(request, 'presentations', log)
113 except NotFound:113 except NotFound:
114 return {'results': {'items': []}}114 return {'results': {'items': []}}
115115
=== removed directory 'openlp/plugins/remotes'
=== removed file 'openlp/plugins/remotes/__init__.py'
--- openlp/plugins/remotes/__init__.py 2017-03-03 19:27:31 +0000
+++ openlp/plugins/remotes/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,21 +0,0 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
220
=== removed file 'openlp/plugins/remotes/deploy.py'
--- openlp/plugins/remotes/deploy.py 2017-09-23 04:04:41 +0000
+++ openlp/plugins/remotes/deploy.py 1970-01-01 00:00:00 +0000
@@ -1,69 +0,0 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22"""
23Download and "install" the remote web client
24"""
25import os
26from zipfile import ZipFile
27
28from openlp.core.common import AppLocation, Registry
29from openlp.core.common.httputils import url_get_file, get_web_page, get_url_file_size
30
31
32def deploy_zipfile(app_root, zip_name):
33 """
34 Process the downloaded zip file and add to the correct directory
35
36 :param zip_name: the zip file to be processed
37 :param app_root: the directory where the zip get expanded to
38
39 :return: None
40 """
41 zip_file = os.path.join(app_root, zip_name)
42 web_zip = ZipFile(zip_file)
43 web_zip.extractall(app_root)
44
45
46def download_sha256():
47 """
48 Download the config file to extract the sha256 and version number
49 """
50 user_agent = 'OpenLP/' + Registry().get('application').applicationVersion()
51 try:
52 web_config = get_web_page('https://get.openlp.org/webclient/download.cfg', headers={'User-Agent': user_agent})
53 except ConnectionError:
54 return False
55 file_bits = web_config.split()
56 return file_bits[0], file_bits[2]
57
58
59def download_and_check(callback=None):
60 """
61 Download the web site and deploy it.
62 """
63 sha256, version = download_sha256()
64 file_size = get_url_file_size('https://get.openlp.org/webclient/site.zip')
65 callback.setRange(0, file_size)
66 if url_get_file(callback, '{host}{name}'.format(host='https://get.openlp.org/webclient/', name='site.zip'),
67 AppLocation.get_section_data_path('remotes') / 'site.zip',
68 sha256=sha256):
69 deploy_zipfile(str(AppLocation.get_section_data_path('remotes')), 'site.zip')
700
=== removed file 'openlp/plugins/remotes/endpoint.py'
--- openlp/plugins/remotes/endpoint.py 2017-08-13 05:44:10 +0000
+++ openlp/plugins/remotes/endpoint.py 1970-01-01 00:00:00 +0000
@@ -1,46 +0,0 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22import logging
23
24import os
25
26from openlp.core.api.http.endpoint import Endpoint
27from openlp.core.api.endpoint.core import TRANSLATED_STRINGS
28from openlp.core.common import AppLocation
29
30
31static_dir = os.path.join(str(AppLocation.get_section_data_path('remotes')))
32
33log = logging.getLogger(__name__)
34
35remote_endpoint = Endpoint('remote', template_dir=static_dir, static_dir=static_dir)
36
37
38@remote_endpoint.route('{view}')
39def index(request, view):
40 """
41 Handles requests for /remotes url
42
43 :param request: The http request object.
44 :param view: The view name to be servered.
45 """
46 return remote_endpoint.render_template('{view}.mako'.format(view=view), **TRANSLATED_STRINGS)
470
=== removed file 'openlp/plugins/remotes/remoteplugin.py'
--- openlp/plugins/remotes/remoteplugin.py 2017-08-24 19:53:55 +0000
+++ openlp/plugins/remotes/remoteplugin.py 1970-01-01 00:00:00 +0000
@@ -1,155 +0,0 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22
23import logging
24import os
25import time
26
27from PyQt5 import QtCore, QtWidgets
28
29from openlp.core.api.http import register_endpoint
30from openlp.core.common import AppLocation, Registry, Settings, OpenLPMixin, UiStrings, check_directory_exists
31from openlp.core.lib import Plugin, StringContent, translate, build_icon
32from openlp.plugins.remotes.endpoint import remote_endpoint
33from openlp.plugins.remotes.deploy import download_and_check, download_sha256
34
35log = logging.getLogger(__name__)
36__default_settings__ = {
37 'remotes/download version': '0000_00_00'
38}
39
40
41class RemotesPlugin(Plugin, OpenLPMixin):
42 log.info('Remotes Plugin loaded')
43
44 def __init__(self):
45 """
46 remotes constructor
47 """
48 super(RemotesPlugin, self).__init__('remotes', __default_settings__, {})
49 self.icon_path = ':/plugins/plugin_remote.png'
50 self.icon = build_icon(self.icon_path)
51 self.weight = -1
52 register_endpoint(remote_endpoint)
53 Registry().register_function('download_website', self.first_time)
54 Registry().register_function('get_website_version', self.website_version)
55 Registry().set_flag('website_version', '0001_01_01')
56
57 def initialise(self):
58 """
59 Create the internal file structure if it does not exist
60 :return:
61 """
62 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'assets')
63 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'images')
64 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static')
65 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static', 'index')
66 check_directory_exists(AppLocation.get_section_data_path('remotes') / 'templates')
67
68 @staticmethod
69 def about():
70 """
71 Information about this plugin
72 """
73 about_text = translate(
74 'RemotePlugin',
75 '<strong>Web Interface</strong>'
76 '<br />The web interface plugin provides the ability to develop web based interfaces using OpenLP web '
77 'services.\nPredefined interfaces can be download as well as custom developed interfaces.')
78 return about_text
79
80 def set_plugin_text_strings(self):
81 """
82 Called to define all translatable texts of the plugin
83 """
84 # Name PluginList
85 self.text_strings[StringContent.Name] = {
86 'singular': translate('RemotePlugin', 'Web Interface', 'name singular'),
87 'plural': translate('RemotePlugin', 'Web Interface', 'name plural')
88 }
89 # Name for MediaDockManager, SettingsManager
90 self.text_strings[StringContent.VisibleName] = {
91 'title': translate('RemotePlugin', 'Web Remote', 'container title')
92 }
93
94 def first_time(self):
95 """
96 Import web site code if active
97 """
98 self.application.process_events()
99 progress = Progress(self)
100 progress.forceShow()
101 self.application.process_events()
102 time.sleep(1)
103 download_and_check(progress)
104 self.application.process_events()
105 time.sleep(1)
106 progress.close()
107 self.application.process_events()
108 Settings().setValue('remotes/download version', self.version)
109
110 def website_version(self):
111 """
112 Download and save the website version and sha256
113 :return: None
114 """
115 sha256, self.version = download_sha256()
116 Registry().set_flag('website_sha256', sha256)
117 Registry().set_flag('website_version', self.version)
118
119
120class Progress(QtWidgets.QProgressDialog):
121 """
122 Local class to handle download display based and supporting httputils:get_web_page
123 """
124 def __init__(self, parent):
125 super(Progress, self).__init__(parent.main_window)
126 self.parent = parent
127 self.setWindowModality(QtCore.Qt.WindowModal)
128 self.setWindowTitle(translate('RemotePlugin', 'Importing Website'))
129 self.setLabelText(UiStrings().StartingImport)
130 self.setCancelButton(None)
131 self.setRange(0, 1)
132 self.setMinimumDuration(0)
133 self.was_cancelled = False
134 self.previous_size = 0
135
136 def _download_progress(self, count, block_size):
137 """
138 Calculate and display the download progress.
139 """
140 increment = (count * block_size) - self.previous_size
141 self._increment_progress_bar(None, increment)
142 self.previous_size = count * block_size
143
144 def _increment_progress_bar(self, status_text, increment=1):
145 """
146 Update the wizard progress page.
147
148 :param status_text: Current status information to display.
149 :param increment: The value to increment the progress bar by.
150 """
151 if status_text:
152 self.setText(status_text)
153 if increment > 0:
154 self.setValue(self.value() + increment)
155 self.parent.application.process_events()
1560
=== modified file 'openlp/plugins/songs/endpoint.py'
--- openlp/plugins/songs/endpoint.py 2017-08-13 06:17:47 +0000
+++ openlp/plugins/songs/endpoint.py 2017-09-29 19:03:48 +0000
@@ -62,7 +62,7 @@
6262
63 :param request: The http request object.63 :param request: The http request object.
64 """64 """
65 service(request, 'songs', log)65 return service(request, 'songs', log)
6666
6767
68@api_songs_endpoint.route('songs/search')68@api_songs_endpoint.route('songs/search')
@@ -95,6 +95,6 @@
95 :param request: The http request object.95 :param request: The http request object.
96 """96 """
97 try:97 try:
98 search(request, 'songs', log)98 return service(request, 'songs', log)
99 except NotFound:99 except NotFound:
100 return {'results': {'items': []}}100 return {'results': {'items': []}}
101101
=== added file 'tests/functional/openlp_core_api/test_deploy.py'
--- tests/functional/openlp_core_api/test_deploy.py 1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_core_api/test_deploy.py 2017-09-29 19:03:48 +0000
@@ -0,0 +1,63 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22
23import os
24import shutil
25from tempfile import mkdtemp
26from unittest import TestCase
27
28from openlp.core.api.deploy import deploy_zipfile
29
30TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
31
32
33class TestRemoteDeploy(TestCase):
34 """
35 Test the Remote plugin deploy functions
36 """
37
38 def setUp(self):
39 """
40 Setup for tests
41 """
42 self.app_root = mkdtemp()
43
44 def tearDown(self):
45 """
46 Clean up after tests
47 """
48 shutil.rmtree(self.app_root)
49
50 def test_deploy_zipfile(self):
51 """
52 Remote Deploy tests - test the dummy zip file is processed correctly
53 """
54 # GIVEN: A new downloaded zip file
55 aa = TEST_PATH
56 zip_file = os.path.join(TEST_PATH, 'remotes', 'site.zip')
57 app_root = os.path.join(self.app_root, 'site.zip')
58 shutil.copyfile(zip_file, app_root)
59 # WHEN: I process the zipfile
60 deploy_zipfile(self.app_root, 'site.zip')
61
62 # THEN test if www directory has been created
63 self.assertTrue(os.path.isdir(os.path.join(self.app_root, 'www')), 'We should have a www directory')
064
=== removed directory 'tests/functional/openlp_plugins/remotes'
=== removed file 'tests/functional/openlp_plugins/remotes/__init__.py'
--- tests/functional/openlp_plugins/remotes/__init__.py 2017-03-05 17:07:21 +0000
+++ tests/functional/openlp_plugins/remotes/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,21 +0,0 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
220
=== removed file 'tests/functional/openlp_plugins/remotes/test_deploy.py'
--- tests/functional/openlp_plugins/remotes/test_deploy.py 2017-08-12 19:34:56 +0000
+++ tests/functional/openlp_plugins/remotes/test_deploy.py 1970-01-01 00:00:00 +0000
@@ -1,64 +0,0 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22
23import os
24import shutil
25
26from tempfile import mkdtemp
27from unittest import TestCase
28
29from openlp.plugins.remotes.deploy import deploy_zipfile
30
31
32TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
33
34
35class TestRemoteDeploy(TestCase):
36 """
37 Test the Remote plugin deploy functions
38 """
39
40 def setUp(self):
41 """
42 Setup for tests
43 """
44 self.app_root = mkdtemp()
45
46 def tearDown(self):
47 """
48 Clean up after tests
49 """
50 shutil.rmtree(self.app_root)
51
52 def test_deploy_zipfile(self):
53 """
54 Remote Deploy tests - test the dummy zip file is processed correctly
55 """
56 # GIVEN: A new downloaded zip file
57 zip_file = os.path.join(TEST_PATH, 'remotes', 'site.zip')
58 app_root = os.path.join(self.app_root, 'site.zip')
59 shutil.copyfile(zip_file, app_root)
60 # WHEN: I process the zipfile
61 deploy_zipfile(self.app_root, 'site.zip')
62
63 # THEN test if www directory has been created
64 self.assertTrue(os.path.isdir(os.path.join(self.app_root, 'www')), 'We should have a www directory')
650
=== modified file 'tests/interfaces/openlp_core_lib/test_pluginmanager.py'
--- tests/interfaces/openlp_core_lib/test_pluginmanager.py 2017-08-26 15:06:11 +0000
+++ tests/interfaces/openlp_core_lib/test_pluginmanager.py 2017-09-29 19:03:48 +0000
@@ -94,4 +94,3 @@
94 self.assertIn('custom', plugin_names, 'There should be a "custom" plugin')94 self.assertIn('custom', plugin_names, 'There should be a "custom" plugin')
95 self.assertIn('songusage', plugin_names, 'There should be a "songusage" plugin')95 self.assertIn('songusage', plugin_names, 'There should be a "songusage" plugin')
96 self.assertIn('alerts', plugin_names, 'There should be a "alerts" plugin')96 self.assertIn('alerts', plugin_names, 'There should be a "alerts" plugin')
97 self.assertIn('remotes', plugin_names, 'There should be a "remotes" plugin')