forked from openlp/openlp
implemented caching thru the ImageManager
Styling issues Merge with fix-router changes
This commit is contained in:
parent
768b1c77fc
commit
04abbd97d0
@ -76,8 +76,8 @@ class AppLocation(object):
|
|||||||
return get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0])
|
return get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0])
|
||||||
elif dir_type == AppLocation.PluginsDir:
|
elif dir_type == AppLocation.PluginsDir:
|
||||||
app_path = os.path.abspath(os.path.split(sys.argv[0])[0])
|
app_path = os.path.abspath(os.path.split(sys.argv[0])[0])
|
||||||
return get_frozen_path(os.path.join(app_path, 'plugins'),
|
return os.path.normpath(get_frozen_path(os.path.join(app_path, 'plugins'),
|
||||||
os.path.join(os.path.split(openlp.__file__)[0], 'plugins'))
|
os.path.join(os.path.split(openlp.__file__)[0], 'plugins')))
|
||||||
elif dir_type == AppLocation.VersionDir:
|
elif dir_type == AppLocation.VersionDir:
|
||||||
return get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0])
|
return get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0])
|
||||||
elif dir_type == AppLocation.LanguageDir:
|
elif dir_type == AppLocation.LanguageDir:
|
||||||
|
@ -152,8 +152,7 @@ def image_to_byte(image, base_64=True):
|
|||||||
The image to converted.
|
The image to converted.
|
||||||
|
|
||||||
``base_64``
|
``base_64``
|
||||||
If True returns the image as Base64 bytes, otherwise
|
If True returns the image as Base64 bytes, otherwise the image is returned as a byte array
|
||||||
the image is returned as a byte array
|
|
||||||
To preserve original intention, this defaults to True
|
To preserve original intention, this defaults to True
|
||||||
"""
|
"""
|
||||||
log.debug('image_to_byte - start')
|
log.debug('image_to_byte - start')
|
||||||
|
@ -331,8 +331,8 @@ class ServiceItem(object):
|
|||||||
The command of/for the slide.
|
The command of/for the slide.
|
||||||
"""
|
"""
|
||||||
self.service_item_type = ServiceItemType.Command
|
self.service_item_type = ServiceItemType.Command
|
||||||
self._raw_frames.append({'title': file_name, 'image': image,
|
self._raw_frames.append({'title': file_name, 'image': image, 'path': path,
|
||||||
'path': path, 'display_title': display_title, 'notes': notes})
|
'display_title': display_title, 'notes': notes})
|
||||||
self._new_item()
|
self._new_item()
|
||||||
|
|
||||||
def get_service_repr(self, lite_save):
|
def get_service_repr(self, lite_save):
|
||||||
@ -451,12 +451,10 @@ class ServiceItem(object):
|
|||||||
self.title = text_image['title']
|
self.title = text_image['title']
|
||||||
if path:
|
if path:
|
||||||
self.has_original_files = False
|
self.has_original_files = False
|
||||||
self.add_from_command(path, text_image['title'],
|
self.add_from_command(path, text_image['title'], text_image['image'],
|
||||||
text_image['image'], text_image.get('display_title',''),
|
text_image.get('display_title',''), text_image.get('notes', ''))
|
||||||
text_image.get('notes', ''))
|
|
||||||
else:
|
else:
|
||||||
self.add_from_command(text_image['path'],
|
self.add_from_command(text_image['path'], text_image['title'], text_image['image'])
|
||||||
text_image['title'], text_image['image'])
|
|
||||||
self._new_item()
|
self._new_item()
|
||||||
|
|
||||||
def get_display_title(self):
|
def get_display_title(self):
|
||||||
|
@ -815,8 +815,7 @@ class SlideController(DisplayController):
|
|||||||
if not self.service_item:
|
if not self.service_item:
|
||||||
return
|
return
|
||||||
if self.service_item.is_command():
|
if self.service_item.is_command():
|
||||||
Registry().execute('%s_slide' % self.service_item.name.lower(),
|
Registry().execute('%s_slide' % self.service_item.name.lower(), [self.service_item, self.is_live, index])
|
||||||
[self.service_item, self.is_live, index])
|
|
||||||
self.update_preview()
|
self.update_preview()
|
||||||
self.selected_row = index
|
self.selected_row = index
|
||||||
else:
|
else:
|
||||||
|
@ -28,9 +28,6 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import zipfile
|
|
||||||
import re
|
|
||||||
from xml.etree import ElementTree
|
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
from ctypes.wintypes import RECT
|
from ctypes.wintypes import RECT
|
||||||
@ -177,50 +174,6 @@ class PPTViewer(QtGui.QWidget):
|
|||||||
int(self.widthEdit.text()), int(self.heightEdit.text()))
|
int(self.widthEdit.text()), int(self.heightEdit.text()))
|
||||||
filename = str(self.pptEdit.text().replace('/', '\\'))
|
filename = str(self.pptEdit.text().replace('/', '\\'))
|
||||||
folder = str(self.folderEdit.text().replace('/', '\\'))
|
folder = str(self.folderEdit.text().replace('/', '\\'))
|
||||||
if zipfile.is_zipfile(filename):
|
|
||||||
namespaces = {"p":
|
|
||||||
"http://schemas.openxmlformats.org/presentationml/2006/main",
|
|
||||||
"a": "http://schemas.openxmlformats.org/drawingml/2006/main"}
|
|
||||||
with zipfile.ZipFile(filename) as zip_file:
|
|
||||||
with zip_file.open('ppt/presentation.xml') as pres:
|
|
||||||
tree = ElementTree.parse(pres)
|
|
||||||
nodes = tree.getroot().findall(".//p:sldIdLst/p:sldId",
|
|
||||||
namespaces=namespaces)
|
|
||||||
print ("slide count: " + str(len(nodes)))
|
|
||||||
titles = [None for i in range(len(nodes))]
|
|
||||||
notes = [None for i in range(len(nodes))]
|
|
||||||
for zip_info in zip_file.infolist():
|
|
||||||
nodeType = ''
|
|
||||||
index = -1
|
|
||||||
listToAdd = None
|
|
||||||
match = re.search("slides/slide(.+)\.xml",
|
|
||||||
zip_info.filename)
|
|
||||||
if match:
|
|
||||||
index = int(match.group(1))-1
|
|
||||||
nodeType = 'ctrTitle'
|
|
||||||
listToAdd = titles
|
|
||||||
match = re.search("notesSlides/notesSlide(.+)\.xml",
|
|
||||||
zip_info.filename)
|
|
||||||
if match:
|
|
||||||
index = int(match.group(1))-1
|
|
||||||
nodeType = 'body'
|
|
||||||
listToAdd = notes
|
|
||||||
if len(nodeType)>0:
|
|
||||||
with zip_file.open(zip_info) as zipped_file:
|
|
||||||
tree = ElementTree.parse(zipped_file)
|
|
||||||
text = ''
|
|
||||||
nodes = tree.getroot().findall(".//p:ph[@type='" + \
|
|
||||||
nodeType + "']../../..//p:txBody//a:t",
|
|
||||||
namespaces=namespaces)
|
|
||||||
if nodes and len(nodes)>0:
|
|
||||||
for node in nodes:
|
|
||||||
if len(text) > 0:
|
|
||||||
text += '\n'
|
|
||||||
text += node.text
|
|
||||||
print('slide file: ' + zip_info.filename + ' ' + text)
|
|
||||||
listToAdd[index] = text
|
|
||||||
print(titles)
|
|
||||||
print(notes)
|
|
||||||
print(filename, folder)
|
print(filename, folder)
|
||||||
self.pptid = self.pptdll.OpenPPT(filename, None, rect, folder)
|
self.pptid = self.pptdll.OpenPPT(filename, None, rect, folder)
|
||||||
print('id: ' + str(self.pptid))
|
print('id: ' + str(self.pptid))
|
||||||
|
@ -398,5 +398,5 @@ $.ajaxSetup({cache: false});
|
|||||||
$("#search").live("pageinit", function (event) {
|
$("#search").live("pageinit", function (event) {
|
||||||
OpenLP.getSearchablePlugins();
|
OpenLP.getSearchablePlugins();
|
||||||
});
|
});
|
||||||
setInterval("OpenLP.pollServer();", 500);
|
setInterval("OpenLP.pollServer();", 50000);
|
||||||
OpenLP.pollServer();
|
OpenLP.pollServer();
|
||||||
|
@ -124,11 +124,19 @@ from urllib.parse import urlparse, parse_qs
|
|||||||
from mako.template import Template
|
from mako.template import Template
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
from openlp.core.lib import Registry, PluginStatus, StringContent, image_to_byte, resize_image, ItemCapabilities
|
from openlp.core.common import AppLocation, Settings, translate
|
||||||
from openlp.core.utils import AppLocation, translate
|
from openlp.core.lib import Registry, PluginStatus, StringContent, image_to_byte
|
||||||
from openlp.core.common import Settings
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
FILE_TYPES = {
|
||||||
|
'.html': 'text/html',
|
||||||
|
'.css': 'text/css',
|
||||||
|
'.js': 'application/javascript',
|
||||||
|
'.jpg': 'image/jpeg',
|
||||||
|
'.gif': 'image/gif',
|
||||||
|
'.ico': 'image/x-icon',
|
||||||
|
'.png': 'image/png'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class HttpRouter(object):
|
class HttpRouter(object):
|
||||||
@ -350,13 +358,12 @@ class HttpRouter(object):
|
|||||||
if not path.startswith(self.html_dir):
|
if not path.startswith(self.html_dir):
|
||||||
return self.do_not_found()
|
return self.do_not_found()
|
||||||
content = None
|
content = None
|
||||||
ext, content_type = self.get_content_type(file_name)
|
ext, content_type = self.get_content_type(path)
|
||||||
file_handle = None
|
file_handle = None
|
||||||
try:
|
try:
|
||||||
if ext == '.html':
|
if ext == '.html':
|
||||||
variables = self.template_vars
|
variables = self.template_vars
|
||||||
content = Template(filename=path, input_encoding='utf-8',
|
content = Template(filename=path, input_encoding='utf-8', output_encoding='utf-8').render(**variables)
|
||||||
output_encoding='utf-8').render(**variables)
|
|
||||||
else:
|
else:
|
||||||
file_handle = open(path, 'rb')
|
file_handle = open(path, 'rb')
|
||||||
log.debug('Opened %s' % path)
|
log.debug('Opened %s' % path)
|
||||||
@ -375,20 +382,12 @@ class HttpRouter(object):
|
|||||||
def get_content_type(self, file_name):
|
def get_content_type(self, file_name):
|
||||||
"""
|
"""
|
||||||
Examines the extension of the file and determines
|
Examines the extension of the file and determines
|
||||||
what header to send back
|
what the content_type should be, defaults to text/plain
|
||||||
Returns the extension found
|
Returns the extension and the content_type
|
||||||
"""
|
"""
|
||||||
content_type = 'text/plain'
|
content_type = 'text/plain'
|
||||||
file_types = {'.html': 'text/html',
|
|
||||||
'.css': 'text/css',
|
|
||||||
'.js': 'application/javascript',
|
|
||||||
'.jpg': 'image/jpeg',
|
|
||||||
'.gif': 'image/gif',
|
|
||||||
'.ico': 'image/x-icon',
|
|
||||||
'.png': 'image/png'
|
|
||||||
}
|
|
||||||
ext = os.path.splitext(file_name)[1]
|
ext = os.path.splitext(file_name)[1]
|
||||||
content_type = file_types.get(ext, 'text/plain')
|
content_type = FILE_TYPES.get(ext, 'text/plain')
|
||||||
return ext, content_type
|
return ext, content_type
|
||||||
|
|
||||||
def serve_thumbnail(self, controller_name=None, dimensions=None, file_name=None):
|
def serve_thumbnail(self, controller_name=None, dimensions=None, file_name=None):
|
||||||
|
@ -35,8 +35,7 @@ from unittest import TestCase
|
|||||||
from tests.functional import MagicMock, patch
|
from tests.functional import MagicMock, patch
|
||||||
from tests.utils import assert_length, convert_file_service_item
|
from tests.utils import assert_length, convert_file_service_item
|
||||||
|
|
||||||
from openlp.core.lib import ItemCapabilities, ServiceItem, Registry, \
|
from openlp.core.lib import ItemCapabilities, ServiceItem, Registry, ServiceItemType
|
||||||
ServiceItemType
|
|
||||||
|
|
||||||
|
|
||||||
VERSE = 'The Lord said to {r}Noah{/r}: \n'\
|
VERSE = 'The Lord said to {r}Noah{/r}: \n'\
|
||||||
@ -153,10 +152,8 @@ class TestServiceItem(TestCase):
|
|||||||
# GIVEN: A new service item and a mocked add icon function
|
# GIVEN: A new service item and a mocked add icon function
|
||||||
image_name1 = 'image_1.jpg'
|
image_name1 = 'image_1.jpg'
|
||||||
image_name2 = 'image_2.jpg'
|
image_name2 = 'image_2.jpg'
|
||||||
test_file1 = os.path.normpath(os.path.join('/home/openlp',
|
test_file1 = os.path.normpath(os.path.join('/home/openlp', image_name1))
|
||||||
image_name1))
|
test_file2 = os.path.normpath(os.path.join('/home/openlp', image_name2))
|
||||||
test_file2 = os.path.normpath(os.path.join('/home/openlp',
|
|
||||||
image_name2))
|
|
||||||
frame_array1 = {'path': test_file1, 'title': image_name1}
|
frame_array1 = {'path': test_file1, 'title': image_name1}
|
||||||
frame_array2 = {'path': test_file2, 'title': image_name2}
|
frame_array2 = {'path': test_file2, 'title': image_name2}
|
||||||
|
|
||||||
|
@ -39,7 +39,8 @@ from PyQt4 import QtGui
|
|||||||
from openlp.core.lib import Registry
|
from openlp.core.lib import Registry
|
||||||
from openlp.core.common import Settings
|
from openlp.core.common import Settings
|
||||||
from openlp.plugins.remotes.lib.httpserver import HttpRouter
|
from openlp.plugins.remotes.lib.httpserver import HttpRouter
|
||||||
from mock import MagicMock, patch, mock_open
|
from tests.functional import MagicMock, patch
|
||||||
|
from mock import mock_open
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
__default_settings__ = {
|
__default_settings__ = {
|
||||||
@ -53,6 +54,7 @@ __default_settings__ = {
|
|||||||
'remotes/ip address': '0.0.0.0'
|
'remotes/ip address': '0.0.0.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
class TestRouter(TestCase):
|
class TestRouter(TestCase):
|
||||||
"""
|
"""
|
||||||
@ -115,21 +117,65 @@ class TestRouter(TestCase):
|
|||||||
assert function['secure'] == False, \
|
assert function['secure'] == False, \
|
||||||
'The mocked function should not require any security.'
|
'The mocked function should not require any security.'
|
||||||
|
|
||||||
def get_appropriate_content_type_test(self):
|
def get_content_type_test(self):
|
||||||
"""
|
"""
|
||||||
Test the get_content_type logic
|
Test the get_content_type logic
|
||||||
"""
|
"""
|
||||||
|
# GIVEN: a set of files and their corresponding types
|
||||||
headers = [ ['test.html', 'text/html'], ['test.css', 'text/css'],
|
headers = [ ['test.html', 'text/html'], ['test.css', 'text/css'],
|
||||||
['test.js', 'application/javascript'], ['test.jpg', 'image/jpeg'],
|
['test.js', 'application/javascript'], ['test.jpg', 'image/jpeg'],
|
||||||
['test.gif', 'image/gif'], ['test.ico', 'image/x-icon'],
|
['test.gif', 'image/gif'], ['test.ico', 'image/x-icon'],
|
||||||
['test.png', 'image/png'], ['test.whatever', 'text/plain'],
|
['test.png', 'image/png'], ['test.whatever', 'text/plain'],
|
||||||
['test', 'text/plain'], ['', 'text/plain'],
|
['test', 'text/plain'], ['', 'text/plain'],
|
||||||
['/test/test.html', 'text/html'],
|
[os.path.join(TEST_PATH,'test.html'), 'text/html']]
|
||||||
['c:\\test\\test.html', 'text/html']]
|
# WHEN: calling each file type
|
||||||
for header in headers:
|
for header in headers:
|
||||||
ext, content_type = self.router.get_content_type(header[0])
|
ext, content_type = self.router.get_content_type(header[0])
|
||||||
|
# THEN: all types should match
|
||||||
self.assertEqual(content_type, header[1], 'Mismatch of content type')
|
self.assertEqual(content_type, header[1], 'Mismatch of content type')
|
||||||
|
|
||||||
|
def serve_file_without_params_test(self):
|
||||||
|
"""
|
||||||
|
Test the serve_file method without params
|
||||||
|
"""
|
||||||
|
# GIVEN: mocked environment
|
||||||
|
self.router.send_response = MagicMock()
|
||||||
|
self.router.send_header = MagicMock()
|
||||||
|
self.router.end_headers = MagicMock()
|
||||||
|
self.router.wfile = MagicMock()
|
||||||
|
self.router.html_dir = os.path.normpath('test/dir')
|
||||||
|
self.router.template_vars = MagicMock()
|
||||||
|
# WHEN: call serve_file with no file_name
|
||||||
|
self.router.serve_file()
|
||||||
|
# THEN: it should return a 404
|
||||||
|
self.router.send_response.assert_called_once_with(404)
|
||||||
|
self.router.send_header.assert_called_once_with('Content-type','text/html')
|
||||||
|
self.assertEqual(self.router.end_headers.call_count, 1,
|
||||||
|
'end_headers called once')
|
||||||
|
|
||||||
|
def serve_file_with_valid_params_test(self):
|
||||||
|
"""
|
||||||
|
Test the serve_file method with an existing file
|
||||||
|
"""
|
||||||
|
# GIVEN: mocked environment
|
||||||
|
self.router.send_response = MagicMock()
|
||||||
|
self.router.send_header = MagicMock()
|
||||||
|
self.router.end_headers = MagicMock()
|
||||||
|
self.router.wfile = MagicMock()
|
||||||
|
self.router.html_dir = os.path.normpath('test/dir')
|
||||||
|
self.router.template_vars = MagicMock()
|
||||||
|
with patch('openlp.core.lib.os.path.exists') as mocked_exists, \
|
||||||
|
patch('builtins.open', mock_open(read_data='123')):
|
||||||
|
mocked_exists.return_value = True
|
||||||
|
# WHEN: call serve_file with an existing html file
|
||||||
|
self.router.serve_file(os.path.normpath('test/dir/test.html'))
|
||||||
|
# THEN: it should return a 200 and the file
|
||||||
|
self.router.send_response.assert_called_once_with(200)
|
||||||
|
self.router.send_header.assert_called_once_with(
|
||||||
|
'Content-type','text/html')
|
||||||
|
self.assertEqual(self.router.end_headers.call_count, 1,
|
||||||
|
'end_headers called once')
|
||||||
|
|
||||||
def serve_thumbnail_without_params_test(self):
|
def serve_thumbnail_without_params_test(self):
|
||||||
"""
|
"""
|
||||||
Test the serve_thumbnail routine without params
|
Test the serve_thumbnail routine without params
|
||||||
|
Loading…
Reference in New Issue
Block a user