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

Proposed by Tim Bentley
Status: Merged
Merged at revision: 2648
Proposed branch: lp:~trb143/openlp/media_timer2
Merge into: lp:openlp
Diff against target: 234 lines (+95/-25)
5 files modified
openlp/core/common/__init__.py (+30/-0)
openlp/core/ui/media/mediacontroller.py (+1/-1)
openlp/plugins/media/mediaplugin.py (+31/-1)
openlp/plugins/presentations/lib/pdfcontroller.py (+6/-22)
tests/functional/openlp_plugins/media/test_mediaplugin.py (+27/-1)
To merge this branch: bzr merge lp:~trb143/openlp/media_timer2
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Review via email: mp+292671@code.launchpad.net

This proposal supersedes a proposal from 2016-04-20.

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Nicely done!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/common/__init__.py'
2--- openlp/core/common/__init__.py 2016-04-05 20:07:57 +0000
3+++ openlp/core/common/__init__.py 2016-04-22 17:11:45 +0000
4@@ -24,6 +24,7 @@
5 OpenLP work.
6 """
7 import hashlib
8+
9 import logging
10 import os
11 import re
12@@ -31,6 +32,7 @@
13 import traceback
14 from ipaddress import IPv4Address, IPv6Address, AddressValueError
15 from shutil import which
16+from subprocess import check_output, CalledProcessError, STDOUT
17
18 from PyQt5 import QtCore, QtGui
19 from PyQt5.QtCore import QCryptographicHash as QHash
20@@ -247,6 +249,9 @@
21 from .actions import ActionList
22 from .languagemanager import LanguageManager
23
24+if is_win():
25+ from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW
26+
27
28 def add_actions(target, actions):
29 """
30@@ -371,3 +376,28 @@
31 if not isinstance(filename, str):
32 filename = str(filename, 'utf-8')
33 return INVALID_FILE_CHARS.sub('_', CONTROL_CHARS.sub('', filename))
34+
35+
36+def check_binary_exists(program_path):
37+ """
38+ Function that checks whether a binary exists.
39+
40+ :param program_path:The full path to the binary to check.
41+ :return: program output to be parsed
42+ """
43+ log.debug('testing program_path: %s', program_path)
44+ try:
45+ # Setup startupinfo options for check_output to avoid console popping up on windows
46+ if is_win():
47+ startupinfo = STARTUPINFO()
48+ startupinfo.dwFlags |= STARTF_USESHOWWINDOW
49+ else:
50+ startupinfo = None
51+ runlog = check_output([program_path, '--help'], stderr=STDOUT, startupinfo=startupinfo)
52+ except CalledProcessError as e:
53+ runlog = e.output
54+ except Exception:
55+ trace_error_handler(log)
56+ runlog = ''
57+ log.debug('check_output returned: %s' % runlog)
58+ return runlog
59
60=== modified file 'openlp/core/ui/media/mediacontroller.py'
61--- openlp/core/ui/media/mediacontroller.py 2016-04-13 18:38:49 +0000
62+++ openlp/core/ui/media/mediacontroller.py 2016-04-22 17:11:45 +0000
63@@ -296,7 +296,7 @@
64 tooltip=translate('OpenLP.SlideController', 'Stop playing media.'),
65 triggers=controller.send_to_plugins)
66 controller.mediabar.add_toolbar_action('playbackLoop', text='media_playback_loop',
67- icon=':/slides/media_playback_stop.png', checked=False,
68+ icon=':/media/media_repeat.png', checked=False,
69 tooltip=translate('OpenLP.SlideController', 'Loop playing media.'),
70 triggers=controller.send_to_plugins)
71 controller.position_label = QtWidgets.QLabel()
72
73=== modified file 'openlp/plugins/media/mediaplugin.py'
74--- openlp/plugins/media/mediaplugin.py 2016-02-16 21:14:38 +0000
75+++ openlp/plugins/media/mediaplugin.py 2016-04-22 17:11:45 +0000
76@@ -24,10 +24,13 @@
77 """
78
79 import logging
80+import os
81+import re
82+from shutil import which
83
84 from PyQt5 import QtCore
85
86-from openlp.core.common import Settings, translate
87+from openlp.core.common import AppLocation, Settings, translate, check_binary_exists, is_win
88 from openlp.core.lib import Plugin, StringContent, build_icon
89 from openlp.plugins.media.lib import MediaMediaItem, MediaTab
90
91@@ -62,6 +65,15 @@
92 """
93 super().initialise()
94
95+ def check_pre_conditions(self):
96+ """
97+ Check it we have a valid environment.
98+ :return: true or false
99+ """
100+ log.debug('check_installed Mediainfo')
101+ # Use the user defined program if given
102+ return process_check_binary('mediainfo')
103+
104 def app_startup(self):
105 """
106 Override app_startup() in order to do nothing
107@@ -137,3 +149,21 @@
108 Add html code to htmlbuilder.
109 """
110 return self.media_controller.get_media_display_html()
111+
112+
113+def process_check_binary(program_path):
114+ """
115+ Function that checks whether a binary MediaInfo is present
116+
117+ :param program_path:The full path to the binary to check.
118+ :return: If exists or not
119+ """
120+ program_type = None
121+ runlog = check_binary_exists(program_path)
122+ print(runlog, type(runlog))
123+ # Analyse the output to see it the program is mediainfo
124+ for line in runlog.splitlines():
125+ decoded_line = line.decode()
126+ if re.search('MediaInfo Command line', decoded_line, re.IGNORECASE):
127+ return True
128+ return False
129
130=== modified file 'openlp/plugins/presentations/lib/pdfcontroller.py'
131--- openlp/plugins/presentations/lib/pdfcontroller.py 2016-04-04 21:19:37 +0000
132+++ openlp/plugins/presentations/lib/pdfcontroller.py 2016-04-22 17:11:45 +0000
133@@ -22,13 +22,12 @@
134
135 import os
136 import logging
137-from tempfile import NamedTemporaryFile
138 import re
139 from shutil import which
140-from subprocess import check_output, CalledProcessError, STDOUT
141+from subprocess import check_output, CalledProcessError
142
143-from openlp.core.common import AppLocation
144-from openlp.core.common import Settings, is_win, trace_error_handler
145+from openlp.core.common import AppLocation, check_binary_exists
146+from openlp.core.common import Settings, is_win
147 from openlp.core.lib import ScreenList
148 from .presentationcontroller import PresentationController, PresentationDocument
149
150@@ -61,7 +60,7 @@
151 self.check_installed()
152
153 @staticmethod
154- def check_binary(program_path):
155+ def process_check_binary(program_path):
156 """
157 Function that checks whether a binary is either ghostscript or mudraw or neither.
158 Is also used from presentationtab.py
159@@ -70,22 +69,7 @@
160 :return: Type of the binary, 'gs' if ghostscript, 'mudraw' if mudraw, None if invalid.
161 """
162 program_type = None
163- runlog = ''
164- log.debug('testing program_path: %s', program_path)
165- try:
166- # Setup startupinfo options for check_output to avoid console popping up on windows
167- if is_win():
168- startupinfo = STARTUPINFO()
169- startupinfo.dwFlags |= STARTF_USESHOWWINDOW
170- else:
171- startupinfo = None
172- runlog = check_output([program_path, '--help'], stderr=STDOUT, startupinfo=startupinfo)
173- except CalledProcessError as e:
174- runlog = e.output
175- except Exception:
176- trace_error_handler(log)
177- runlog = ''
178- log.debug('check_output returned: %s' % runlog)
179+ runlog = check_binary_exists(program_path)
180 # Analyse the output to see it the program is mudraw, ghostscript or neither
181 for line in runlog.splitlines():
182 decoded_line = line.decode()
183@@ -122,7 +106,7 @@
184 # Use the user defined program if given
185 if Settings().value('presentations/enable_pdf_program'):
186 pdf_program = Settings().value('presentations/pdf_program')
187- program_type = self.check_binary(pdf_program)
188+ program_type = self.process_check_binary(pdf_program)
189 if program_type == 'gs':
190 self.gsbin = pdf_program
191 elif program_type == 'mudraw':
192
193=== modified file 'tests/functional/openlp_plugins/media/test_mediaplugin.py'
194--- tests/functional/openlp_plugins/media/test_mediaplugin.py 2016-04-13 18:48:46 +0000
195+++ tests/functional/openlp_plugins/media/test_mediaplugin.py 2016-04-22 17:11:45 +0000
196@@ -25,7 +25,7 @@
197 from unittest import TestCase
198
199 from openlp.core import Registry
200-from openlp.plugins.media.mediaplugin import MediaPlugin
201+from openlp.plugins.media.mediaplugin import MediaPlugin, process_check_binary
202
203 from tests.functional import MagicMock, patch
204 from tests.helpers.testmixin import TestMixin
205@@ -63,3 +63,29 @@
206 self.assertIsInstance(MediaPlugin.about(), str)
207 # THEN: about() should return a non-empty string
208 self.assertNotEquals(len(MediaPlugin.about()), 0)
209+
210+ @patch('openlp.plugins.media.mediaplugin.check_binary_exists')
211+ def process_check_binary_pass_test(self, mocked_checked_binary_exists):
212+ """
213+ Test that the Process check returns true if found
214+ """
215+ # GIVEN: A media plugin instance
216+ # WHEN: function is called with the correct name
217+ mocked_checked_binary_exists.return_value = str.encode('MediaInfo Command line')
218+ result = process_check_binary('MediaInfo')
219+
220+ # THEN: The the result should be True
221+ self.assertTrue(result, 'Mediainfo should have been found')
222+
223+ @patch('openlp.plugins.media.mediaplugin.check_binary_exists')
224+ def process_check_binary_fail_test(self, mocked_checked_binary_exists):
225+ """
226+ Test that the Process check returns false if not found
227+ """
228+ # GIVEN: A media plugin instance
229+ # WHEN: function is called with the wrong name
230+ mocked_checked_binary_exists.return_value = str.encode('MediaInfo1 Command line')
231+ result = process_check_binary("MediaInfo1")
232+
233+ # THEN: The the result should be True
234+ self.assertFalse(result, "Mediainfo should not have been found")