From 9606b999760237e02f702e09be3ff783c89b1996 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Mon, 13 Nov 2017 20:07:20 +0000 Subject: [PATCH 01/10] Fix md5 thumbnail regression Fixes: https://launchpad.net/bugs/1692187 --- openlp/plugins/presentations/lib/mediaitem.py | 2 +- .../lib/presentationcontroller.py | 6 +++-- .../presentations/presentationplugin.py | 15 ++++++++++++ .../presentations/test_mediaitem.py | 24 +++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index b801597b1..04bec02a9 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -243,7 +243,7 @@ class PresentationMediaItem(MediaManagerItem): """ Clean up the files created such as thumbnails - :param openlp.core.common.path.Path file_path: File path of the presention to clean up after + :param openlp.core.common.path.Path file_path: File path of the presentation to clean up after :param bool clean_for_update: Only clean thumbnails if update is needed :rtype: None """ diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index dd099c130..bb424c9fa 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -139,7 +139,8 @@ class PresentationDocument(object): :return: The path to the thumbnail :rtype: openlp.core.common.path.Path """ - # TODO: If statement can be removed when the upgrade path from 2.0.x to 2.2.x is no longer needed + # TODO: Can be removed when the upgrade path to OpenLP 3.0 is no longer needed, also ensure code in + # get_temp_folder and PresentationPluginapp_startup is removed if Settings().value('presentations/thumbnail_scheme') == 'md5': folder = md5_hash(bytes(self.file_path)) else: @@ -153,7 +154,8 @@ class PresentationDocument(object): :return: The path to the temporary file folder :rtype: openlp.core.common.path.Path """ - # TODO: If statement can be removed when the upgrade path from 2.0.x to 2.2.x is no longer needed + # TODO: Can be removed when the upgrade path to OpenLP 3.0 is no longer needed, also ensure code in + # get_thumbnail_folder and PresentationPluginapp_startup is removed if Settings().value('presentations/thumbnail_scheme') == 'md5': folder = md5_hash(bytes(self.file_path)) else: diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 7f3333049..5e32af7b6 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -31,6 +31,7 @@ from PyQt5 import QtCore from openlp.core.api.http import register_endpoint from openlp.core.common import extension_loader from openlp.core.common.i18n import translate +from openlp.core.common.settings import Settings from openlp.core.lib import Plugin, StringContent, build_icon from openlp.plugins.presentations.endpoint import api_presentations_endpoint, presentations_endpoint from openlp.plugins.presentations.lib import PresentationController, PresentationMediaItem, PresentationTab @@ -136,6 +137,20 @@ class PresentationPlugin(Plugin): self.register_controllers(controller) return bool(self.controllers) + def app_startup(self): + """ + Perform tasks on application startup. + """ + # TODO: Can be removed when the upgrade path to OpenLP 3.0 is no longer needed, also ensure code in + # PresentationDocument.get_thumbnail_folder and PresentationDocument.get_temp_folder is removed + super().app_startup() + files_from_config = Settings().value('presentations/presentations files') + for file in files_from_config: + self.media_item.clean_up_thumbnails(file, clean_for_update=True) + self.media_item.list_view.clear() + Settings().setValue('presentations/thumbnail_scheme', 'md5') + self.media_item.validate_and_load(files_from_config) + @staticmethod def about(): """ diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py index 1116ce4cb..fd28b9b03 100644 --- a/tests/functional/openlp_plugins/presentations/test_mediaitem.py +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -133,3 +133,27 @@ class TestMediaItem(TestCase, TestMixin): # THEN: doc.presentation_deleted should have been called since the presentation file did not exists. mocked_doc.assert_has_calls([call.get_thumbnail_path(1, True), call.presentation_deleted()], True) + + @patch('openlp.plugins.presentations.lib.mediaitem.MediaManagerItem._setup') + @patch('openlp.plugins.presentations.lib.mediaitem.PresentationMediaItem.setup_item') + @patch('openlp.plugins.presentations.lib.mediaitem.Settings') + def test_search(self, mocked_settings, *unreferenced_mocks): + """ + Test that the search method finds the correct results + """ + # GIVEN: A mocked Settings class which returns a list of Path objects, + # and an instance of the PresentationMediaItem + path_1 = Path('some_dir', 'Impress_file_1') + path_2 = Path('some_other_dir', 'impress_file_2') + path_3 = Path('another_dir', 'ppt_file') + mocked_returned_settings = MagicMock() + mocked_returned_settings.value.return_value = [path_1, path_2, path_3] + mocked_settings.return_value = mocked_returned_settings + media_item = PresentationMediaItem(None, MagicMock(), None) + media_item.settings_section = '' + + # WHEN: Calling search + results = media_item.search('IMPRE', False) + + # THEN: The first two results should have been returned + assert results == [[str(path_1), 'Impress_file_1'], [str(path_2), 'impress_file_2']] From 4f769d56229abb4b1e1d3a95693a4000f76fe7a9 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Mon, 13 Nov 2017 21:31:54 +0000 Subject: [PATCH 02/10] Fix the handler passing False Fixes: https://launchpad.net/bugs/1672777 --- openlp/core/ui/servicemanager.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 6d5c16fbd..3e1d0f544 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -216,7 +216,7 @@ class Ui_ServiceManager(object): text=translate('OpenLP.ServiceManager', 'Go Live'), icon=':/general/general_live.png', tooltip=translate('OpenLP.ServiceManager', 'Send the selected item to Live.'), category=UiStrings().Service, - triggers=self.make_live) + triggers=self.on_make_live_action_triggered) self.layout.addWidget(self.order_toolbar) # Connect up our signals and slots self.theme_combo_box.activated.connect(self.on_theme_combo_box_selected) @@ -1730,6 +1730,15 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi self.service_items[item]['service_item'].update_theme(theme) self.regenerate_service_items(True) + def on_make_live_action_triggered(self, checked): + """ + Handle `make_live_action` when the action is triggered. + + :param bool checked: Not Used. + :rtype: None + """ + self.make_live() + def get_drop_position(self): """ Getter for drop_position. Used in: MediaManagerItem From 4e9fcf2e505dbcef742d50c7fe5f19ab23b44620 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Mon, 13 Nov 2017 21:40:49 +0000 Subject: [PATCH 03/10] Sort media items by natural order Fixes: https://launchpad.net/bugs/1625087 --- openlp/plugins/custom/lib/db.py | 6 +++--- openlp/plugins/images/lib/mediaitem.py | 12 ++++++------ openlp/plugins/media/lib/mediaitem.py | 6 +++--- openlp/plugins/presentations/lib/mediaitem.py | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/openlp/plugins/custom/lib/db.py b/openlp/plugins/custom/lib/db.py index dc1f74567..6581ee5ae 100644 --- a/openlp/plugins/custom/lib/db.py +++ b/openlp/plugins/custom/lib/db.py @@ -26,7 +26,7 @@ the Custom plugin from sqlalchemy import Column, Table, types from sqlalchemy.orm import mapper -from openlp.core.common.i18n import get_locale_key +from openlp.core.common.i18n import get_natural_key from openlp.core.lib.db import BaseModel, init_db @@ -36,10 +36,10 @@ class CustomSlide(BaseModel): """ # By default sort the customs by its title considering language specific characters. def __lt__(self, other): - return get_locale_key(self.title) < get_locale_key(other.title) + return get_natural_key(self.title) < get_natural_key(other.title) def __eq__(self, other): - return get_locale_key(self.title) == get_locale_key(other.title) + return get_natural_key(self.title) == get_natural_key(other.title) def __hash__(self): """ diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index a4e76d51b..b678122a5 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -26,7 +26,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets from openlp.core.common import delete_file, get_images_filter from openlp.core.common.applocation import AppLocation -from openlp.core.common.i18n import UiStrings, translate, get_locale_key +from openlp.core.common.i18n import UiStrings, translate, get_natural_key from openlp.core.common.path import Path, create_paths from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings @@ -271,7 +271,7 @@ class ImageMediaItem(MediaManagerItem): :param parent_group_id: The ID of the group that will be added recursively. """ image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == parent_group_id) - image_groups.sort(key=lambda group_object: get_locale_key(group_object.group_name)) + image_groups.sort(key=lambda group_object: get_natural_key(group_object.group_name)) folder_icon = build_icon(':/images/image_group.png') for image_group in image_groups: group = QtWidgets.QTreeWidgetItem() @@ -298,7 +298,7 @@ class ImageMediaItem(MediaManagerItem): combobox.clear() combobox.top_level_group_added = False image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == parent_group_id) - image_groups.sort(key=lambda group_object: get_locale_key(group_object.group_name)) + image_groups.sort(key=lambda group_object: get_natural_key(group_object.group_name)) for image_group in image_groups: combobox.addItem(prefix + image_group.group_name, image_group.id) self.fill_groups_combobox(combobox, image_group.id, prefix + ' ') @@ -355,7 +355,7 @@ class ImageMediaItem(MediaManagerItem): self.expand_group(open_group.id) # Sort the images by its filename considering language specific. # characters. - images.sort(key=lambda image_object: get_locale_key(image_object.file_path.name)) + images.sort(key=lambda image_object: get_natural_key(image_object.file_path.name)) for image in images: log.debug('Loading image: {name}'.format(name=image.file_path)) file_name = image.file_path.name @@ -533,9 +533,9 @@ class ImageMediaItem(MediaManagerItem): group_items.append(item) if isinstance(item.data(0, QtCore.Qt.UserRole), ImageFilenames): image_items.append(item) - group_items.sort(key=lambda item: get_locale_key(item.text(0))) + group_items.sort(key=lambda item: get_natural_key(item.text(0))) target_group.addChildren(group_items) - image_items.sort(key=lambda item: get_locale_key(item.text(0))) + image_items.sort(key=lambda item: get_natural_key(item.text(0))) target_group.addChildren(image_items) def generate_slide_data(self, service_item, item=None, xml_version=False, remote=False, diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index ed787166b..f0ec1dfe2 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -26,7 +26,7 @@ import os from PyQt5 import QtCore, QtWidgets from openlp.core.common.applocation import AppLocation -from openlp.core.common.i18n import UiStrings, translate, get_locale_key +from openlp.core.common.i18n import UiStrings, translate, get_natural_key from openlp.core.common.path import Path, path_to_str, create_paths from openlp.core.common.mixins import RegistryProperties from openlp.core.common.registry import Registry @@ -362,7 +362,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties): :param media: The media :param target_group: """ - media.sort(key=lambda file_name: get_locale_key(os.path.split(str(file_name))[1])) + media.sort(key=lambda file_name: get_natural_key(os.path.split(str(file_name))[1])) for track in media: track_info = QtCore.QFileInfo(track) item_name = None @@ -404,7 +404,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties): :return: The media list """ media_file_paths = Settings().value(self.settings_section + '/media files') - media_file_paths.sort(key=lambda file_path: get_locale_key(file_path.name)) + media_file_paths.sort(key=lambda file_path: get_natural_key(file_path.name)) if media_type == MediaType.Audio: extension = self.media_controller.audio_extensions_list else: diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 04bec02a9..f58ba4861 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -23,7 +23,7 @@ import logging from PyQt5 import QtCore, QtGui, QtWidgets -from openlp.core.common.i18n import UiStrings, translate, get_locale_key +from openlp.core.common.i18n import UiStrings, translate, get_natural_key from openlp.core.common.path import Path, path_to_str, str_to_path from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings @@ -165,7 +165,7 @@ class PresentationMediaItem(MediaManagerItem): if not initial_load: self.main_window.display_progress_bar(len(file_paths)) # Sort the presentations by its filename considering language specific characters. - file_paths.sort(key=lambda file_path: get_locale_key(file_path.name)) + file_paths.sort(key=lambda file_path: get_natural_key(file_path.name)) for file_path in file_paths: if not initial_load: self.main_window.increment_progress_bar() From 66bae6716cccd2f4f712c528c5f2f90702299ee4 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Tue, 14 Nov 2017 17:35:37 +0000 Subject: [PATCH 04/10] chage media replace background context icon, add replace and reset actions to image context menu Fixes: https://launchpad.net/bugs/1650358 --- openlp/plugins/images/lib/mediaitem.py | 14 ++++++++++++++ openlp/plugins/media/lib/mediaitem.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index b678122a5..de347f8ce 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -81,8 +81,12 @@ class ImageMediaItem(MediaManagerItem): self.add_group_action.setToolTip(UiStrings().AddGroupDot) self.replace_action.setText(UiStrings().ReplaceBG) self.replace_action.setToolTip(UiStrings().ReplaceLiveBG) + self.replace_action_context.setText(UiStrings().ReplaceBG) + self.replace_action_context.setToolTip(UiStrings().ReplaceLiveBG) self.reset_action.setText(UiStrings().ResetBG) self.reset_action.setToolTip(UiStrings().ResetLiveBG) + self.reset_action_context.setText(UiStrings().ResetBG) + self.reset_action_context.setToolTip(UiStrings().ResetLiveBG) def required_icons(self): """ @@ -184,6 +188,13 @@ class ImageMediaItem(MediaManagerItem): self.list_view, text=translate('ImagePlugin', 'Add new image(s)'), icon=':/general/general_open.png', triggers=self.on_file_click) + create_widget_action(self.list_view, separator=True) + self.replace_action_context = create_widget_action( + self.list_view, text=UiStrings().ReplaceBG, icon=':/slides/slide_theme.png', + triggers=self.on_replace_click) + self.reset_action_context = create_widget_action( + self.list_view, text=UiStrings().ReplaceLiveBG, icon=':/system/system_close.png', + visible=False, triggers=self.on_reset_click) def add_start_header_bar(self): """ @@ -659,6 +670,7 @@ class ImageMediaItem(MediaManagerItem): Called to reset the Live background with the image selected. """ self.reset_action.setVisible(False) + self.reset_action_context.setVisible(False) self.live_controller.display.reset_image() def live_theme_changed(self): @@ -666,6 +678,7 @@ class ImageMediaItem(MediaManagerItem): Triggered by the change of theme in the slide controller. """ self.reset_action.setVisible(False) + self.reset_action_context.setVisible(False) def on_replace_click(self): """ @@ -683,6 +696,7 @@ class ImageMediaItem(MediaManagerItem): if file_path.exists(): if self.live_controller.display.direct_image(str(file_path), background): self.reset_action.setVisible(True) + self.reset_action_context.setVisible(True) else: critical_error_message_box( UiStrings().LiveBGError, diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index f0ec1dfe2..e47ed70e0 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -176,7 +176,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties): def add_custom_context_actions(self): create_widget_action(self.list_view, separator=True) self.replace_action_context = create_widget_action( - self.list_view, text=UiStrings().ReplaceBG, icon=':/slides/slide_blank.png', + self.list_view, text=UiStrings().ReplaceBG, icon=':/slides/slide_theme.png', triggers=self.on_replace_click) self.reset_action_context = create_widget_action( self.list_view, text=UiStrings().ReplaceLiveBG, icon=':/system/system_close.png', From 2ccd6a01f00da6562e80c15b511a5aa6dfc6df4d Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Tue, 14 Nov 2017 22:13:38 +0000 Subject: [PATCH 05/10] Set the default filter in accordance to the current service file type Fixes: https://launchpad.net/bugs/1673251 --- openlp/core/ui/servicemanager.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 3e1d0f544..81edd4930 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -704,15 +704,19 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi directory_path = Settings().value(self.main_window.service_manager_settings_section + '/last directory') if directory_path: default_file_path = directory_path / default_file_path - # SaveAs from osz to oszl is not valid as the files will be deleted on exit which is not sensible or usable in - # the long term. lite_filter = translate('OpenLP.ServiceManager', 'OpenLP Service Files - lite (*.oszl)') packaged_filter = translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz)') - + if self._file_name.endswith('oszl'): + default_filter = lite_filter + else: + default_filter = packaged_filter + # SaveAs from osz to oszl is not valid as the files will be deleted on exit which is not sensible or usable in + # the long term. if self._file_name.endswith('oszl') or self.service_has_all_original_files: file_path, filter_used = FileDialog.getSaveFileName( self.main_window, UiStrings().SaveService, default_file_path, - '{packaged};; {lite}'.format(packaged=packaged_filter, lite=lite_filter)) + '{packaged};; {lite}'.format(packaged=packaged_filter, lite=lite_filter), + default_filter) else: file_path, filter_used = FileDialog.getSaveFileName( self.main_window, UiStrings().SaveService, default_file_path, From 4fbed73e958f8b62fc60d07013b01cf01572f647 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Tue, 14 Nov 2017 22:30:46 +0000 Subject: [PATCH 06/10] Typo fix --- openlp/plugins/presentations/lib/messagelistener.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index 2bfd1b3ed..33f5e0693 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -191,7 +191,7 @@ class Controller(object): """ Based on the handler passed at startup triggers the previous slide event. """ - log.debug('Live = {live}, previous'.formta(live=self.is_live)) + log.debug('Live = {live}, previous'.format(live=self.is_live)) if not self.doc: return if not self.is_live: From 35e13022a640d57fc3fa318ee763646f89271e79 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Wed, 15 Nov 2017 18:33:21 +0000 Subject: [PATCH 07/10] image media test fixes --- tests/functional/openlp_plugins/images/test_lib.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/functional/openlp_plugins/images/test_lib.py b/tests/functional/openlp_plugins/images/test_lib.py index 4dfef57da..877ad722d 100644 --- a/tests/functional/openlp_plugins/images/test_lib.py +++ b/tests/functional/openlp_plugins/images/test_lib.py @@ -173,12 +173,14 @@ class TestImageMediaItem(TestCase): """ # GIVEN: A mocked version of reset_action self.media_item.reset_action = MagicMock() + self.media_item.reset_action_context = MagicMock() # WHEN: on_reset_click is called self.media_item.on_reset_click() # THEN: the reset_action should be set visible, and the image should be reset self.media_item.reset_action.setVisible.assert_called_with(False) + self.media_item.reset_action_context.setVisible.assert_called_with(False) self.media_item.live_controller.display.reset_image.assert_called_with() @patch('openlp.plugins.images.lib.mediaitem.delete_file') From 3560b27bfb8c6629cbf7668c2e202a6f0929db6e Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Wed, 15 Nov 2017 21:58:19 +0000 Subject: [PATCH 08/10] Use the OLDXML output type for the new version of mediainfo Fixes: https://launchpad.net/bugs/1732348 --- .../core/ui/media/vendor/mediainfoWrapper.py | 20 +++++++++++++++---- .../presentations/lib/pdfcontroller.py | 2 -- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/openlp/core/ui/media/vendor/mediainfoWrapper.py b/openlp/core/ui/media/vendor/mediainfoWrapper.py index 6f270d46e..1b55fb4bb 100644 --- a/openlp/core/ui/media/vendor/mediainfoWrapper.py +++ b/openlp/core/ui/media/vendor/mediainfoWrapper.py @@ -25,10 +25,10 @@ information related to the rwquested media. """ import json import os -from subprocess import Popen +import re +from subprocess import Popen, check_output from tempfile import mkstemp -import six from bs4 import BeautifulSoup, NavigableString ENV_DICT = os.environ @@ -80,7 +80,7 @@ class Track(object): def to_data(self): data = {} - for k, v in six.iteritems(self.__dict__): + for k, v in self.__dict__.items(): if k != 'xml_dom_fragment': data[k] = v return data @@ -100,7 +100,11 @@ class MediaInfoWrapper(object): @staticmethod def parse(filename, environment=ENV_DICT): - command = ["mediainfo", "-f", "--Output=XML", filename] + if MediaInfoWrapper._version(): + format = 'OLDXML' + else: + format = 'XML' + command = ["mediainfo", "-f", "--Output={format}".format(format=format), filename] fileno_out, fname_out = mkstemp(suffix=".xml", prefix="media-") fileno_err, fname_err = mkstemp(suffix=".err", prefix="media-") fp_out = os.fdopen(fileno_out, 'r+b') @@ -116,6 +120,14 @@ class MediaInfoWrapper(object): os.unlink(fname_err) return MediaInfoWrapper(xml_dom) + @staticmethod + def _version(): + # For now we're only intrested in knowing the new style version (yy.mm) + version_str = check_output(['mediainfo', '--version']) + return re.search(b'\d\d\.\d\d', version_str) + + + def _populate_tracks(self): if self.xml_dom is None: return diff --git a/openlp/plugins/presentations/lib/pdfcontroller.py b/openlp/plugins/presentations/lib/pdfcontroller.py index 26eb87d85..715e4e3e7 100644 --- a/openlp/plugins/presentations/lib/pdfcontroller.py +++ b/openlp/plugins/presentations/lib/pdfcontroller.py @@ -19,8 +19,6 @@ # 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 logging import re from subprocess import check_output, CalledProcessError From ab810734d86489eb8721d5b95ad78db5a32cd378 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Thu, 16 Nov 2017 17:17:47 +0000 Subject: [PATCH 09/10] Rework mediainfo fix Fixes: https://launchpad.net/bugs/1732348 --- .../core/ui/media/vendor/mediainfoWrapper.py | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/openlp/core/ui/media/vendor/mediainfoWrapper.py b/openlp/core/ui/media/vendor/mediainfoWrapper.py index 1b55fb4bb..3045bf070 100644 --- a/openlp/core/ui/media/vendor/mediainfoWrapper.py +++ b/openlp/core/ui/media/vendor/mediainfoWrapper.py @@ -100,34 +100,12 @@ class MediaInfoWrapper(object): @staticmethod def parse(filename, environment=ENV_DICT): - if MediaInfoWrapper._version(): - format = 'OLDXML' - else: - format = 'XML' - command = ["mediainfo", "-f", "--Output={format}".format(format=format), filename] - fileno_out, fname_out = mkstemp(suffix=".xml", prefix="media-") - fileno_err, fname_err = mkstemp(suffix=".err", prefix="media-") - fp_out = os.fdopen(fileno_out, 'r+b') - fp_err = os.fdopen(fileno_err, 'r+b') - p = Popen(command, stdout=fp_out, stderr=fp_err, env=environment) - p.wait() - fp_out.seek(0) - - xml_dom = MediaInfoWrapper.parse_xml_data_into_dom(fp_out.read()) - fp_out.close() - fp_err.close() - os.unlink(fname_out) - os.unlink(fname_err) + xml = check_output(['mediainfo', '-f', '--Output=XML', '--Inform=OLDXML', filename]) + if not xml.startswith(b' Date: Thu, 16 Nov 2017 17:43:17 +0000 Subject: [PATCH 10/10] Remove some unused imports --- openlp/core/ui/media/vendor/mediainfoWrapper.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openlp/core/ui/media/vendor/mediainfoWrapper.py b/openlp/core/ui/media/vendor/mediainfoWrapper.py index 3045bf070..97d936d6b 100644 --- a/openlp/core/ui/media/vendor/mediainfoWrapper.py +++ b/openlp/core/ui/media/vendor/mediainfoWrapper.py @@ -25,9 +25,7 @@ information related to the rwquested media. """ import json import os -import re -from subprocess import Popen, check_output -from tempfile import mkstemp +from subprocess import check_output from bs4 import BeautifulSoup, NavigableString