mahfiaz has proposed merging lp:~mahfiaz/openlp/bug-304 into lp:openlp. Requested reviews: Raoul Snyman (raoul-snyman) Andreas Preikschat (googol)
For more details, see: https://code.launchpad.net/~mahfiaz/openlp/bug-304/+merge/86142 OpenLyrics raises OpenLyricsException and opelyricsimporter catches it and lets user know. -- https://code.launchpad.net/~mahfiaz/openlp/bug-304/+merge/86142 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-09-05 12:51:16 +0000 +++ openlp/plugins/songs/lib/openlyricsimport.py 2011-12-17 17:41:23 +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 OpenLyricsException log = logging.getLogger(__name__) @@ -73,3 +74,10 @@ except etree.XMLSyntaxError: log.exception(u'XML syntax error in file %s' % 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) === modified file 'openlp/plugins/songs/lib/xml.py' --- openlp/plugins/songs/lib/xml.py 2011-12-05 19:47:50 +0000 +++ openlp/plugins/songs/lib/xml.py 2011-12-17 17:41:23 +0000 @@ -673,9 +673,16 @@ sxml = SongXML() verses = {} verse_def_list = [] - lyrics = song_xml.lyrics + try: + lyrics = song_xml.lyrics + except AttributeError: + raise OpenLyricsException('XML', 'missing lyrics item') + try: + verses = lyrics.verse + except AttributeError: + raise OpenLyricsException('XML', 'missing verse item') # 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 +798,15 @@ """ 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)
_______________________________________________ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp