openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #14431
[Merge] lp:~mahfiaz/openlp/bug-304 into lp:openlp
mahfiaz has proposed merging lp:~mahfiaz/openlp/bug-304 into lp:openlp.
Requested reviews:
Andreas Preikschat (googol)
Raoul Snyman (raoul-snyman)
For more details, see:
https://code.launchpad.net/~mahfiaz/openlp/bug-304/+merge/96714
OpenLyrics raises OpenLyricsError and opelyricsimporter catches it and lets user know.
--
https://code.launchpad.net/~mahfiaz/openlp/bug-304/+merge/96714
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/songs/lib/openlyricsimport.py'
--- openlp/plugins/songs/lib/openlyricsimport.py 2011-12-27 10:33:55 +0000
+++ openlp/plugins/songs/lib/openlyricsimport.py 2012-03-09 06:29:18 +0000
@@ -38,6 +38,7 @@
from openlp.plugins.songs.lib.songimport import SongImport
from openlp.plugins.songs.lib.ui import SongStrings
from openlp.plugins.songs.lib import OpenLyrics
+from openlp.plugins.songs.lib.xml import OpenLyricsError
log = logging.getLogger(__name__)
@@ -73,3 +74,7 @@
except etree.XMLSyntaxError:
log.exception(u'XML syntax error in file %s' % file_path)
self.logError(file_path, SongStrings.XMLSyntaxError)
+ except OpenLyricsError as exception:
+ log.exception(u'OpenLyricsException %d in file %s: %s'
+ % (exception.type, file_path, exception.log_message))
+ self.logError(file_path, exception.display_message)
=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py 2011-12-27 10:33:55 +0000
+++ openlp/plugins/songs/lib/xml.py 2012-03-09 06:29:18 +0000
@@ -66,7 +66,7 @@
from lxml import etree, objectify
-from openlp.core.lib import FormattingTags
+from openlp.core.lib import FormattingTags, translate
from openlp.plugins.songs.lib import clean_song, VerseType
from openlp.plugins.songs.lib.db import Author, Book, Song, Topic
from openlp.core.utils import get_application_version
@@ -673,9 +673,22 @@
sxml = SongXML()
verses = {}
verse_def_list = []
- lyrics = song_xml.lyrics
+ try:
+ lyrics = song_xml.lyrics
+ except AttributeError:
+ raise OpenLyricsError(OpenLyricsError.LyricsError,
+ '<lyrics> tag is missing.',
+ unicode(translate('OpenLP.OpenLyricsImportError',
+ '<lyrics> tag is missing.')))
+ try:
+ verses = lyrics.verse
+ except AttributeError:
+ raise OpenLyricsError(OpenLyricsError.VerseError,
+ '<verse> tag is missing.',
+ unicode(translate('OpenLP.OpenLyricsImportError',
+ '<verse> tag is missing.')))
# Loop over the "verse" elements.
- for verse in lyrics.verse:
+ for verse in verses:
text = u''
# Loop over the "lines" elements.
for lines in verse.lines:
@@ -791,3 +804,15 @@
"""
return etree.tostring(xml, encoding=u'UTF-8',
xml_declaration=True, pretty_print=True)
+
+
+class OpenLyricsError(Exception):
+ # XML tree is missing the lyrics tag
+ LyricsError = 1
+ # XML tree has no verse tags
+ VerseError = 2
+
+ def __init__(self, type, log_message, display_message):
+ self.type = type
+ self.log_message = log_message
+ self.display_message = display_message
Follow ups