forked from openlp/openlp
Fix the api errors found
Remove the remote plugin and move the code to core Add the update of the web package date back in. fix up review comments. lp:~trb143/openlp/webfixes (revision 2785) [SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/2225/ [SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/2128/ [SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/2011/ [SUCCESS] https://ci.openlp.io/job/Branch-04a-Code_Analysis/1376/ [SUCCESS] https://ci.openlp.io/job/Branch-04b-... bzr-revno: 2773
This commit is contained in:
commit
63cdc813b0
@ -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')
|
@ -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}')
|
@ -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
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -222,6 +222,8 @@ class ApiTab(SettingsTab):
|
||||
self.remote_url.setText('<a href="{url}">{url}</a>'.format(url=http_url))
|
||||
http_url_temp = http_url + 'stage'
|
||||
self.stage_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))
|
||||
http_url_temp = http_url + 'chords'
|
||||
self.chords_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))
|
||||
http_url_temp = http_url + 'main'
|
||||
self.live_url.setText('<a href="{url}">{url}</a>'.format(url=http_url_temp))
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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': []}}
|
||||
|
@ -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': []}}
|
||||
|
@ -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': []}}
|
||||
|
@ -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': []}}
|
||||
|
@ -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': []}}
|
||||
|
@ -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 #
|
||||
###############################################################################
|
@ -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',
|
||||
'<strong>Web Interface</strong>'
|
||||
'<br />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()
|
@ -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': []}}
|
||||
|
@ -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)
|
@ -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 #
|
||||
###############################################################################
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user