Fix traceback on windows in the OO/LO song importer.

Improved the robustness of the download-webbibles-form. Fixes bug 1489757.
Fix SongPro import. Fixes bug 1489376.
Fix traceback on linux when VLC isn't installed. Fixes bug 1489143.

bzr-revno: 2552
This commit is contained in:
Tomas Groth 2015-08-28 22:05:57 +01:00 committed by Tim Bentley
commit 0b4cf91c42
9 changed files with 311 additions and 16 deletions

View File

@ -80,10 +80,8 @@ def get_vlc():
if is_win():
if not isinstance(e, WindowsError) and e.winerror != 126:
raise
elif is_macosx():
pass
else:
raise
pass
if is_vlc_available:
try:
VERSION = vlc.libvlc_get_version().decode('UTF-8')
@ -103,7 +101,7 @@ def get_vlc():
# On linux we need to initialise X threads, but not when running tests.
# This needs to happen on module load and not in get_vlc(), otherwise it can cause crashes on some DE on some setups
# (reported on Gnome3, Unity, Cinnamon, all GTK+ based) when using native filedialogs...
if get_vlc() and is_linux() and 'nose' not in sys.argv[0]:
if is_linux() and 'nose' not in sys.argv[0] and get_vlc():
import ctypes
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')

View File

@ -517,17 +517,19 @@ class BibleImportForm(OpenLPWizard):
critical_error_message_box(translate('BiblesPlugin.ImportWizardForm', 'Error during download'),
translate('BiblesPlugin.ImportWizardForm',
'An error occurred while downloading the list of bibles from %s.'))
self.web_bible_list[download_type] = {}
for (bible_name, bible_key, language_code) in bibles:
self.web_bible_list[download_type][bible_name] = (bible_key, language_code)
bibles = None
if bibles:
self.web_bible_list[download_type] = {}
for (bible_name, bible_key, language_code) in bibles:
self.web_bible_list[download_type][bible_name] = (bible_key, language_code)
self.web_progress_bar.setValue(download_type + 1)
# Update combo box if something got into the list
if self.web_bible_list:
self.on_web_source_combo_box_index_changed(0)
self.web_source_combo_box.setEnabled(True)
self.web_translation_combo_box.setEnabled(True)
self.web_update_button.setEnabled(True)
self.web_progress_bar.setVisible(False)
self.web_source_combo_box.setEnabled(True)
self.web_translation_combo_box.setEnabled(True)
self.web_update_button.setEnabled(True)
self.web_progress_bar.setVisible(False)
def register_fields(self):
"""

View File

@ -30,7 +30,8 @@ from openlp.core.lib.searchedit import SearchEdit
from openlp.core.lib.ui import set_case_insensitive_completer, create_horizontal_adjusting_combo_box, \
critical_error_message_box, find_and_set_in_combo_box, build_icon
from openlp.core.utils import get_locale_key
from openlp.plugins.bibles.forms import BibleImportForm, EditBibleForm
from openlp.plugins.bibles.forms.bibleimportform import BibleImportForm
from openlp.plugins.bibles.forms.editbibleform import EditBibleForm
from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, VerseReferenceList, get_reference_separator, \
LanguageSelection, BibleStrings
from openlp.plugins.bibles.lib.db import BiblesResourcesDB

View File

@ -171,7 +171,7 @@ class OpenOfficeImport(SongImport):
"""
log.debug('create property OpenOffice')
if is_win():
property_object = self.controller.manager.Bridge_GetStruct('com.sun.star.beans.PropertyValue')
property_object = self.ooo_manager.Bridge_GetStruct('com.sun.star.beans.PropertyValue')
else:
property_object = PropertyValue()
property_object.Name = name

View File

@ -65,21 +65,20 @@ class SongProImport(SongImport):
"""
Initialise the SongPro importer.
"""
SongImport.__init__(self, manager, **kwargs)
super(SongProImport, self).__init__(manager, **kwargs)
def do_import(self):
"""
Receive a single file or a list of files to import.
"""
self.encoding = None
with open(self.import_source, 'r') as songs_file:
with open(self.import_source, 'rt') as songs_file:
self.import_wizard.progress_bar.setMaximum(0)
tag = ''
text = ''
for file_line in songs_file:
if self.stop_import_flag:
break
file_line = str(file_line, 'cp1252')
file_text = file_line.rstrip()
if file_text and file_text[0] == '#':
self.process_section(tag, text.rstrip())
@ -87,6 +86,7 @@ class SongProImport(SongImport):
text = ''
else:
text += file_line
self.finish()
def process_section(self, tag, text):
"""

View File

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2015 OpenLP Developers #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The :mod:`songproimport` module provides the functionality for importing
SongPro song files into the current installation database.
"""
import os
from tests.helpers.songfileimport import SongImportTestHelper
TEST_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'songprosongs'))
class TestSongProFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'SongProImport'
self.importer_module_name = 'songpro'
super(TestSongProFileImport, self).__init__(*args, **kwargs)
def test_song_import(self):
"""
Test that loading an SongPro file works correctly
"""
self.file_import(os.path.join(TEST_PATH, 'amazing-grace.txt'),
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))

View File

@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2015 OpenLP Developers #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
Package to test the openlp.plugins.bibles.forms.bibleimportform package.
"""
from unittest import TestCase
from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry
from openlp.plugins.bibles.forms.bibleimportform import BibleImportForm, WebDownload
from tests.helpers.testmixin import TestMixin
from tests.functional import MagicMock, patch
class TestBibleImportForm(TestCase, TestMixin):
"""
Test the BibleImportForm class
"""
def setUp(self):
"""
Create the UI
"""
Registry.create()
self.setup_application()
self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window)
self.form = BibleImportForm(self.main_window, MagicMock(), MagicMock())
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
del self.form
del self.main_window
@patch('openlp.plugins.bibles.forms.bibleimportform.CWExtract.get_bibles_from_http')
@patch('openlp.plugins.bibles.forms.bibleimportform.BGExtract.get_bibles_from_http')
@patch('openlp.plugins.bibles.forms.bibleimportform.BSExtract.get_bibles_from_http')
def on_web_update_button_clicked_test(self, mocked_bsextract, mocked_bgextract, mocked_cwextract):
"""
Test that on_web_update_button_clicked handles problems correctly
"""
# GIVEN: Some mocked GUI components and mocked bibleextractors
self.form.web_source_combo_box = MagicMock()
self.form.web_translation_combo_box = MagicMock()
self.form.web_update_button = MagicMock()
self.form.web_progress_bar = MagicMock()
mocked_bsextract.return_value = None
mocked_bgextract.return_value = None
mocked_cwextract.return_value = None
# WHEN: Running on_web_update_button_clicked
self.form.on_web_update_button_clicked()
# THEN: The webbible list should still be empty
self.assertEqual(self.form.web_bible_list, {}, 'The webbible list should be empty')

View File

@ -0,0 +1,34 @@
{
"title": "Amazing Grace",
"authors": [
"Words: John Newton (1725-1807)"
],
"copyright" : "Public Domain",
"verse_order_list": ["V1", "V2", "V3", "V4", "V5", "V6"],
"verses": [
[
"Amazing Grace! how sweet the sound\nThat saved a wretch like me;\nI once was lost, but now am found,\nWas blind, but now I see.",
"V"
],
[
"'Twas grace that taught my heart to fear,\nAnd grace my fears relieved;\nHow precious did that grace appear,\nThe hour I first believed!",
"V"
],
[
"Through many dangers, toils and snares\nI have already come;\n'Tis grace that brought me safe thus far,\nAnd grace will lead me home.",
"V"
],
[
"The Lord has promised good to me,\nHis word my hope secures;\nHe will my shield and portion be\nAs long as life endures.",
"V"
],
[
"Yes, when this heart and flesh shall fail,\nAnd mortal life shall cease,\nI shall possess within the veil\nA life of joy and peace.",
"V"
],
[
"When we've been there a thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise\nThan when we first begun.",
"V"
]
]
}

View File

@ -0,0 +1,135 @@
#T
Amazing Grace
#C
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#1
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 Amazing Grace! how sweet the sound
\par That saved a wretch like me;
\par I once was lost, but now am found,
\par Was blind, but now I see.
\par }
#2
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 'Twas grace that taught my heart to fear,
\par And grace my fears relieved;
\par How precious did that grace appear,
\par The hour I first believed!
\par }
#3
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 Through many dangers, toils and snares
\par I have already come;
\par 'Tis grace that brought me safe thus far,
\par And grace will lead me home.
\par }
#4
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 The Lord has promised good to me,
\par His word my hope secures;
\par He will my shield and portion be
\par As long as life endures.
\par }
#5
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang1033\f0\fs20 Yes, when this heart and flesh shall fail,
\par And mortal life shall cease,
\par I shall possess within the veil
\par A life of joy and peace.
\par }
#6
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang1033\f0\fs20 When we've been there a thousand years,
\par Bright shining as the sun,
\par We've no less days to sing God's praise
\par Than when we first begun.
\par }
#7
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#D
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#B
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#PR
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#MS
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#C2
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#NT
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#A
Words: John Newton (1725-1807)
#R
Public Domain
#O
123456
#F
Arial
#FS
34
#I
False
#BD
True
#BE
True
#FC
16777215
#BC
39168
#FF
16777215
#P
Lakes\NZ Lake 3.jpg
#PC
16777215
#SB
True
#SH
False
#BM
I
#IT
S
#CC
2762836
#IN
126444
#E