forked from openlp/openlp
Use OpenLyricsException instead.
This commit is contained in:
parent
235e8c6fcf
commit
28fa03b7cd
@ -38,6 +38,7 @@ from openlp.core.ui.wizard import WizardStrings
|
||||
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 OpenLyricsException
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -73,6 +74,10 @@ class OpenLyricsImport(SongImport):
|
||||
except etree.XMLSyntaxError:
|
||||
log.exception(u'XML syntax error in file %s' % file_path)
|
||||
self.logError(file_path, SongStrings.XMLSyntaxError)
|
||||
except Exception as values:
|
||||
log.exception(u'%s in file %s' % (values[0], file_path))
|
||||
self.logError(file_path, SongStrings.XMLSyntaxError)
|
||||
except OpenLyricsException as exception:
|
||||
log.exception(u'OpenLyricsException of type %s: %s in file %s'
|
||||
% (exception.type, exception.message, file_path))
|
||||
if exception.type is 'XML':
|
||||
self.logError(file_path, SongStrings.XMLSyntaxError)
|
||||
else:
|
||||
self.logError(file_path, exception.message)
|
||||
|
@ -676,11 +676,11 @@ class OpenLyrics(object):
|
||||
try:
|
||||
lyrics = song_xml.lyrics
|
||||
except AttributeError:
|
||||
raise Exception('XML error, missing lyrics item')
|
||||
raise OpenLyricsException('XML', 'missing lyrics item')
|
||||
try:
|
||||
verses = lyrics.verse
|
||||
except AttributeError:
|
||||
raise Exception('XML error, missing verse item')
|
||||
raise OpenLyricsException('XML', 'missing verse item')
|
||||
# Loop over the "verse" elements.
|
||||
for verse in verses:
|
||||
text = u''
|
||||
@ -798,3 +798,15 @@ class OpenLyrics(object):
|
||||
"""
|
||||
return etree.tostring(xml, encoding=u'UTF-8',
|
||||
xml_declaration=True, pretty_print=True)
|
||||
|
||||
|
||||
class OpenLyricsException(Exception):
|
||||
"""
|
||||
By now raised only in case of missing lyrics or verse element in XML.
|
||||
"""
|
||||
def __init__(self, exception_type, message):
|
||||
self.type = exception_type
|
||||
self.message = message
|
||||
|
||||
def __str__(self):
|
||||
return "%s: %s" % (self.type, self.message)
|
||||
|
Loading…
Reference in New Issue
Block a user