← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/media_timer2 into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/media_timer2 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #1022053 in OpenLP: "Previewing media item interferes with live media item"
  https://bugs.launchpad.net/openlp/+bug/1022053
  Bug #1079874 in OpenLP: "Time of playing viedeo and video length"
  https://bugs.launchpad.net/openlp/+bug/1079874
  Bug #1225772 in OpenLP: "Replaced background with video appears on main window"
  https://bugs.launchpad.net/openlp/+bug/1225772
  Bug #1414563 in OpenLP: "Volume slider shows in preview controller"
  https://bugs.launchpad.net/openlp/+bug/1414563
  Bug #1458347 in OpenLP: "Expose more playback options for VLC"
  https://bugs.launchpad.net/openlp/+bug/1458347
  Bug #1463286 in OpenLP: "Live media restarts when adding media to servicemanager"
  https://bugs.launchpad.net/openlp/+bug/1463286
  Bug #1514155 in OpenLP: "Videos only play audio after resumed from escape item"
  https://bugs.launchpad.net/openlp/+bug/1514155

For more details, see:
https://code.launchpad.net/~trb143/openlp/media_timer2/+merge/292412
-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/media_timer2 into lp:openlp.
=== modified file 'openlp/core/common/__init__.py'
--- openlp/core/common/__init__.py	2016-04-05 20:07:57 +0000
+++ openlp/core/common/__init__.py	2016-04-20 16:37:03 +0000
@@ -24,6 +24,7 @@
 OpenLP work.
 """
 import hashlib
+
 import logging
 import os
 import re
@@ -31,6 +32,7 @@
 import traceback
 from ipaddress import IPv4Address, IPv6Address, AddressValueError
 from shutil import which
+from subprocess import check_output, CalledProcessError, STDOUT
 
 from PyQt5 import QtCore, QtGui
 from PyQt5.QtCore import QCryptographicHash as QHash
@@ -247,6 +249,9 @@
 from .actions import ActionList
 from .languagemanager import LanguageManager
 
+if is_win():
+    from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW
+
 
 def add_actions(target, actions):
     """
@@ -371,3 +376,29 @@
     if not isinstance(filename, str):
         filename = str(filename, 'utf-8')
     return INVALID_FILE_CHARS.sub('_', CONTROL_CHARS.sub('', filename))
+
+
+def check_binary(program_path):
+    """
+    Function that checks whether a binary exists.
+
+    :param program_path:The full path to the binary to check.
+    :return: program output to be parsed
+    """
+    log.debug('testing program_path: %s', program_path)
+    try:
+        # Setup startupinfo options for check_output to avoid console popping up on windows
+        if is_win():
+            startupinfo = STARTUPINFO()
+            startupinfo.dwFlags |= STARTF_USESHOWWINDOW
+        else:
+            startupinfo = None
+        runlog = check_output([program_path, '--help'], stderr=STDOUT, startupinfo=startupinfo)
+    except CalledProcessError as e:
+        runlog = e.output
+    except Exception:
+        trace_error_handler(log)
+        runlog = ''
+    log.debug('check_output returned: %s' % runlog)
+    return runlog
+

=== modified file 'openlp/core/ui/media/mediacontroller.py'
--- openlp/core/ui/media/mediacontroller.py	2016-04-13 18:38:49 +0000
+++ openlp/core/ui/media/mediacontroller.py	2016-04-20 16:37:03 +0000
@@ -296,7 +296,7 @@
                                                tooltip=translate('OpenLP.SlideController', 'Stop playing media.'),
                                                triggers=controller.send_to_plugins)
         controller.mediabar.add_toolbar_action('playbackLoop', text='media_playback_loop',
-                                               icon=':/slides/media_playback_stop.png', checked=False,
+                                               icon=':/media/media_repeat.png', checked=False,
                                                tooltip=translate('OpenLP.SlideController', 'Loop playing media.'),
                                                triggers=controller.send_to_plugins)
         controller.position_label = QtWidgets.QLabel()

=== modified file 'openlp/plugins/media/mediaplugin.py'
--- openlp/plugins/media/mediaplugin.py	2016-02-16 21:14:38 +0000
+++ openlp/plugins/media/mediaplugin.py	2016-04-20 16:37:03 +0000
@@ -24,10 +24,13 @@
 """
 
 import logging
+import os
+import re
+from shutil import which
 
 from PyQt5 import QtCore
 
-from openlp.core.common import Settings, translate
+from openlp.core.common import AppLocation, Settings, translate, check_binary, is_win
 from openlp.core.lib import Plugin, StringContent, build_icon
 from openlp.plugins.media.lib import MediaMediaItem, MediaTab
 
@@ -62,6 +65,15 @@
         """
         super().initialise()
 
+    def check_pre_conditions(self):
+        """
+        Check it we have a valid environment.
+        :return: true or false
+        """
+        log.debug('check_installed Mediainfo')
+        # Use the user defined program if given
+        return process_check_binary('mediainfo')
+
     def app_startup(self):
         """
         Override app_startup() in order to do nothing
@@ -137,3 +149,21 @@
         Add html code to htmlbuilder.
         """
         return self.media_controller.get_media_display_html()
+
+
+def process_check_binary(program_path):
+    """
+    Function that checks whether a binary MediaInfo is present
+
+    :param program_path:The full path to the binary to check.
+    :return: If exists or not
+    """
+    program_type = None
+    runlog = check_binary(program_path)
+    print(runlog)
+    # Analyse the output to see it the program is mediainfo
+    for line in runlog.splitlines():
+        decoded_line = line.decode()
+        if re.search('MediaInfo Command line', decoded_line, re.IGNORECASE):
+            return True
+    return False

=== modified file 'openlp/plugins/presentations/lib/pdfcontroller.py'
--- openlp/plugins/presentations/lib/pdfcontroller.py	2016-04-04 21:19:37 +0000
+++ openlp/plugins/presentations/lib/pdfcontroller.py	2016-04-20 16:37:03 +0000
@@ -22,13 +22,12 @@
 
 import os
 import logging
-from tempfile import NamedTemporaryFile
 import re
 from shutil import which
-from subprocess import check_output, CalledProcessError, STDOUT
+from subprocess import check_output, CalledProcessError
 
-from openlp.core.common import AppLocation
-from openlp.core.common import Settings, is_win, trace_error_handler
+from openlp.core.common import AppLocation, check_binary
+from openlp.core.common import Settings, is_win
 from openlp.core.lib import ScreenList
 from .presentationcontroller import PresentationController, PresentationDocument
 
@@ -61,7 +60,7 @@
         self.check_installed()
 
     @staticmethod
-    def check_binary(program_path):
+    def process_check_binary(program_path):
         """
         Function that checks whether a binary is either ghostscript or mudraw or neither.
         Is also used from presentationtab.py
@@ -70,22 +69,7 @@
         :return: Type of the binary, 'gs' if ghostscript, 'mudraw' if mudraw, None if invalid.
         """
         program_type = None
-        runlog = ''
-        log.debug('testing program_path: %s', program_path)
-        try:
-            # Setup startupinfo options for check_output to avoid console popping up on windows
-            if is_win():
-                startupinfo = STARTUPINFO()
-                startupinfo.dwFlags |= STARTF_USESHOWWINDOW
-            else:
-                startupinfo = None
-            runlog = check_output([program_path, '--help'], stderr=STDOUT, startupinfo=startupinfo)
-        except CalledProcessError as e:
-            runlog = e.output
-        except Exception:
-            trace_error_handler(log)
-            runlog = ''
-        log.debug('check_output returned: %s' % runlog)
+        runlog = check_binary(program_path)
         # Analyse the output to see it the program is mudraw, ghostscript or neither
         for line in runlog.splitlines():
             decoded_line = line.decode()
@@ -122,7 +106,7 @@
         # Use the user defined program if given
         if Settings().value('presentations/enable_pdf_program'):
             pdf_program = Settings().value('presentations/pdf_program')
-            program_type = self.check_binary(pdf_program)
+            program_type = self.process_check_binary(pdf_program)
             if program_type == 'gs':
                 self.gsbin = pdf_program
             elif program_type == 'mudraw':

=== modified file 'tests/functional/openlp_plugins/media/test_mediaplugin.py'
--- tests/functional/openlp_plugins/media/test_mediaplugin.py	2016-04-13 18:48:46 +0000
+++ tests/functional/openlp_plugins/media/test_mediaplugin.py	2016-04-20 16:37:03 +0000
@@ -25,7 +25,7 @@
 from unittest import TestCase
 
 from openlp.core import Registry
-from openlp.plugins.media.mediaplugin import MediaPlugin
+from openlp.plugins.media.mediaplugin import MediaPlugin, process_check_binary
 
 from tests.functional import MagicMock, patch
 from tests.helpers.testmixin import TestMixin
@@ -63,3 +63,25 @@
         self.assertIsInstance(MediaPlugin.about(), str)
         # THEN: about() should return a non-empty string
         self.assertNotEquals(len(MediaPlugin.about()), 0)
+
+    def process_check_binary_pass_test(self):
+        """
+        Test that the Process check returns true if found
+        """
+        # GIVEN: A media plugin instance
+        # WHEN: function is called with the correct name
+        result = process_check_binary("MediaInfo")
+
+        # THEN: The the result should be True
+        self.assertFalse(result, "Media info should have been found")
+
+    def process_check_binary_fail_test(self):
+        """
+        Test that the Process check returns false if not found
+        """
+        # GIVEN: A media plugin instance
+        # WHEN: function is called with the wrong name
+        result = process_check_binary("MediaInfo1")
+
+        # THEN: The the result should be True
+        self.assertTrue(result, "Media info should not have been found")


Follow ups