start to change error handling

This commit is contained in:
Tim Bentley 2017-06-10 11:53:52 +01:00
parent be145b7675
commit e0308bfce5
4 changed files with 49 additions and 9 deletions

View File

@ -27,6 +27,7 @@ import urllib
from urllib.parse import urlparse from urllib.parse import urlparse
from webob import Response from webob import Response
from openlp.core.api.http.errors import NotFound
from openlp.core.common import Registry, AppLocation from openlp.core.common import Registry, AppLocation
from openlp.core.lib import PluginStatus, image_to_byte from openlp.core.lib import PluginStatus, image_to_byte
@ -49,9 +50,9 @@ def search(request, plugin_name, log):
plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name) plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name)
if plugin.status == PluginStatus.Active and plugin.media_item and plugin.media_item.has_search: if plugin.status == PluginStatus.Active and plugin.media_item and plugin.media_item.has_search:
results = plugin.media_item.search(text, False) results = plugin.media_item.search(text, False)
return {'results': {'items': results}}
else: else:
results = [] raise NotFound()
return {'results': {'items': results}}
def live(request, plugin_name, log): def live(request, plugin_name, log):
@ -71,7 +72,6 @@ def live(request, plugin_name, log):
plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name) plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name)
if plugin.status == PluginStatus.Active and plugin.media_item: if plugin.status == PluginStatus.Active and plugin.media_item:
getattr(plugin.media_item, '{name}_go_live'.format(name=plugin_name)).emit([request_id, True]) getattr(plugin.media_item, '{name}_go_live'.format(name=plugin_name)).emit([request_id, True])
return {'results': {'success': True}}
def service(request, plugin_name, log): def service(request, plugin_name, log):
@ -92,7 +92,6 @@ def service(request, plugin_name, log):
if plugin.status == PluginStatus.Active and plugin.media_item: if plugin.status == PluginStatus.Active and plugin.media_item:
item_id = plugin.media_item.create_item_from_id(request_id) item_id = plugin.media_item.create_item_from_id(request_id)
getattr(plugin.media_item, '{name}_add_to_service'.format(name=plugin_name)).emit([item_id, True]) getattr(plugin.media_item, '{name}_add_to_service'.format(name=plugin_name)).emit([item_id, True])
return {'results': {'success': True}}
def display_thumbnails(request, controller_name, log, dimensions, file_name, slide=None): def display_thumbnails(request, controller_name, log, dimensions, file_name, slide=None):

View File

@ -53,6 +53,9 @@ def check_for_previous_deployment(app_root, create=False):
def download_sha256(): def download_sha256():
"""
Download the config file to extract the sha256 and version number
"""
user_agent = 'OpenLP/' + Registry().get('application').applicationVersion() user_agent = 'OpenLP/' + Registry().get('application').applicationVersion()
try: try:
web_config = get_web_page('{host}{name}'.format(host='https://get.openlp.org/webclient/', name='download.cfg'), web_config = get_web_page('{host}{name}'.format(host='https://get.openlp.org/webclient/', name='download.cfg'),
@ -64,6 +67,9 @@ def download_sha256():
def download_and_check(callback=None): def download_and_check(callback=None):
"""
Download the web site and deploy it.
"""
sha256, version = download_sha256() sha256, version = download_sha256()
if url_get_file(callback, '{host}{name}'.format(host='https://get.openlp.org/webclient/', name='site.zip'), if url_get_file(callback, '{host}{name}'.format(host='https://get.openlp.org/webclient/', name='site.zip'),
os.path.join(AppLocation.get_section_data_path('remotes'), 'site.zip'), os.path.join(AppLocation.get_section_data_path('remotes'), 'site.zip'),

View File

@ -94,6 +94,7 @@ class RemotesPlugin(Plugin, OpenLPMixin):
download_and_check() download_and_check()
self.application.process_events() self.application.process_events()
@staticmethod
def website_version(self): def website_version(self):
""" """
Download and save the website version and sha256 Download and save the website version and sha256

View File

@ -22,6 +22,7 @@
import logging import logging
from openlp.core.api.http.endpoint import Endpoint from openlp.core.api.http.endpoint import Endpoint
from openlp.core.api.http.errors import NotFound
from openlp.core.api.endpoint.pluginhelpers import search, live, service from openlp.core.api.endpoint.pluginhelpers import search, live, service
from openlp.core.api.http import requires_auth from openlp.core.api.http import requires_auth
@ -33,6 +34,15 @@ api_songs_endpoint = Endpoint('api')
@songs_endpoint.route('search') @songs_endpoint.route('search')
def songs_search(request):
"""
Handles requests for searching the songs plugin
:param request: The http request object.
"""
search(request, 'songs', log)
@api_songs_endpoint.route('songs/search') @api_songs_endpoint.route('songs/search')
def songs_search(request): def songs_search(request):
""" """
@ -40,11 +50,13 @@ def songs_search(request):
:param request: The http request object. :param request: The http request object.
""" """
return search(request, 'songs', log) try:
search(request, 'songs', log)
except NotFound:
return {'results': {'items': []}}
@songs_endpoint.route('live') @songs_endpoint.route('live')
@api_songs_endpoint.route('songs/live')
@requires_auth @requires_auth
def songs_live(request): def songs_live(request):
""" """
@ -52,10 +64,20 @@ def songs_live(request):
:param request: The http request object. :param request: The http request object.
""" """
return live(request, 'songs', log) live(request, 'songs', log)
@songs_endpoint.route('songs/live')
@requires_auth
def songs_live(request):
"""
Handles requests for making a song live
:param request: The http request object.
"""
live(request, 'songs', log)
@songs_endpoint.route('add')
@api_songs_endpoint.route('songs/add') @api_songs_endpoint.route('songs/add')
@requires_auth @requires_auth
def songs_service(request): def songs_service(request):
@ -64,4 +86,16 @@ def songs_service(request):
:param request: The http request object. :param request: The http request object.
""" """
return service(request, 'songs', log) service(request, 'songs', log)
return {'results': {'success': True}}
@songs_endpoint.route('songs/add')
@requires_auth
def songs_service(request):
"""
Handles requests for adding a song to the service
:param request: The http request object.
"""
service(request, 'songs', log)