forked from openlp/openlp
Tried to fix some linux vs windows issues. Also added a test.
This commit is contained in:
parent
9d87fa46ca
commit
33e104d57d
@ -129,7 +129,7 @@ def parse_optical_path(input):
|
|||||||
filename = clip_info[7]
|
filename = clip_info[7]
|
||||||
# Windows path usually contains a colon after the drive letter
|
# Windows path usually contains a colon after the drive letter
|
||||||
if len(clip_info) > 8:
|
if len(clip_info) > 8:
|
||||||
filename += clip_info[8]
|
filename += ':' + clip_info[8]
|
||||||
return filename, title, audio_track, subtitle_track, start, end, clip_name
|
return filename, title, audio_track, subtitle_track, start, end, clip_name
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,13 +210,16 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector):
|
|||||||
'Given path does not exists'))
|
'Given path does not exists'))
|
||||||
self.toggle_disable_load_media(False)
|
self.toggle_disable_load_media(False)
|
||||||
return
|
return
|
||||||
# If on windows fix path for VLC use
|
# VLC behaves a bit differently on windows and linux when loading, which creates problems when trying to
|
||||||
|
# detect if we're dealing with a DVD or CD, so we use different loading approaches depending on the OS.
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
# If the given path is in the format "D:\" or "D:", prefix it with "/" to make VLC happy
|
# If the given path is in the format "D:\" or "D:", prefix it with "/" to make VLC happy
|
||||||
pattern = re.compile('^\w:\\\\*$')
|
pattern = re.compile('^\w:\\\\*$')
|
||||||
if pattern.match(path):
|
if pattern.match(path):
|
||||||
path = '/' + path
|
path = '/' + path
|
||||||
self.vlc_media = self.vlc_instance.media_new_location('dvd://' + path)
|
self.vlc_media = self.vlc_instance.media_new_location('dvd://' + path)
|
||||||
|
else:
|
||||||
|
self.vlc_media = self.vlc_instance.media_new_path(path)
|
||||||
if not self.vlc_media:
|
if not self.vlc_media:
|
||||||
log.debug('vlc media player is none')
|
log.debug('vlc media player is none')
|
||||||
critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm',
|
critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm',
|
||||||
|
@ -32,7 +32,7 @@ Package to test the openlp.core.ui package.
|
|||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from openlp.core.ui.media import get_media_players
|
from openlp.core.ui.media import get_media_players, parse_optical_path
|
||||||
|
|
||||||
from tests.functional import MagicMock, patch
|
from tests.functional import MagicMock, patch
|
||||||
from tests.helpers.testmixin import TestMixin
|
from tests.helpers.testmixin import TestMixin
|
||||||
@ -126,3 +126,59 @@ class TestMedia(TestCase, TestMixin):
|
|||||||
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
|
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
|
||||||
self.assertEqual(['vlc', 'webkit', 'phonon'], used_players, 'Used players should be correct')
|
self.assertEqual(['vlc', 'webkit', 'phonon'], used_players, 'Used players should be correct')
|
||||||
self.assertEqual('vlc,webkit,phonon', overridden_player, 'Overridden player should be a string of players')
|
self.assertEqual('vlc,webkit,phonon', overridden_player, 'Overridden player should be a string of players')
|
||||||
|
|
||||||
|
def test_parse_optical_path_linux(self):
|
||||||
|
"""
|
||||||
|
Test that test_parse_optical_path() parses a optical path with linux device path correctly
|
||||||
|
"""
|
||||||
|
|
||||||
|
# GIVEN: An optical formatted path
|
||||||
|
org_title_track = 1
|
||||||
|
org_audio_track = 2
|
||||||
|
org_subtitle_track = -1
|
||||||
|
org_start = 1234
|
||||||
|
org_end = 4321
|
||||||
|
org_name = 'test name'
|
||||||
|
org_device_path = '/dev/dvd'
|
||||||
|
path = 'optical:%d:%d:%d:%d:%d:%s:%s' % (org_title_track, org_audio_track, org_subtitle_track,
|
||||||
|
org_start, org_end, org_name, org_device_path)
|
||||||
|
|
||||||
|
# WHEN: parsing the path
|
||||||
|
(device_path, title_track, audio_track, subtitle_track, start, end, name) = parse_optical_path(path)
|
||||||
|
|
||||||
|
# THEN: The return values should match the original values
|
||||||
|
self.assertEqual(org_title_track, title_track, 'Returned title_track should match the original')
|
||||||
|
self.assertEqual(org_audio_track, audio_track, 'Returned audio_track should match the original')
|
||||||
|
self.assertEqual(org_subtitle_track, subtitle_track, 'Returned subtitle_track should match the original')
|
||||||
|
self.assertEqual(org_start, start, 'Returned start should match the original')
|
||||||
|
self.assertEqual(org_end, end, 'Returned end should match the original')
|
||||||
|
self.assertEqual(org_name, name, 'Returned end should match the original')
|
||||||
|
self.assertEqual(org_device_path, device_path, 'Returned device_path should match the original')
|
||||||
|
|
||||||
|
def test_parse_optical_path_win(self):
|
||||||
|
"""
|
||||||
|
Test that test_parse_optical_path() parses a optical path with windows device path correctly
|
||||||
|
"""
|
||||||
|
|
||||||
|
# GIVEN: An optical formatted path
|
||||||
|
org_title_track = 1
|
||||||
|
org_audio_track = 2
|
||||||
|
org_subtitle_track = -1
|
||||||
|
org_start = 1234
|
||||||
|
org_end = 4321
|
||||||
|
org_name = 'test name'
|
||||||
|
org_device_path = 'D:'
|
||||||
|
path = 'optical:%d:%d:%d:%d:%d:%s:%s' % (org_title_track, org_audio_track, org_subtitle_track,
|
||||||
|
org_start, org_end, org_name, org_device_path)
|
||||||
|
|
||||||
|
# WHEN: parsing the path
|
||||||
|
(device_path, title_track, audio_track, subtitle_track, start, end, name) = parse_optical_path(path)
|
||||||
|
|
||||||
|
# THEN: The return values should match the original values
|
||||||
|
self.assertEqual(org_title_track, title_track, 'Returned title_track should match the original')
|
||||||
|
self.assertEqual(org_audio_track, audio_track, 'Returned audio_track should match the original')
|
||||||
|
self.assertEqual(org_subtitle_track, subtitle_track, 'Returned subtitle_track should match the original')
|
||||||
|
self.assertEqual(org_start, start, 'Returned start should match the original')
|
||||||
|
self.assertEqual(org_end, end, 'Returned end should match the original')
|
||||||
|
self.assertEqual(org_name, name, 'Returned end should match the original')
|
||||||
|
self.assertEqual(org_device_path, device_path, 'Returned device_path should match the original')
|
||||||
|
Loading…
Reference in New Issue
Block a user