forked from openlp/openlp
Some more fixes for the OpenSong import.
This commit is contained in:
parent
130e315333
commit
2d9b39986a
@ -28,6 +28,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
from lxml import objectify
|
from lxml import objectify
|
||||||
|
from lxml.etree import Error, LxmlError
|
||||||
|
|
||||||
from openlp.plugins.songs.lib.songimport import SongImport
|
from openlp.plugins.songs.lib.songimport import SongImport
|
||||||
|
|
||||||
@ -156,7 +157,12 @@ class OpenSongImport(SongImport):
|
|||||||
Process the OpenSong file - pass in a file-like object,
|
Process the OpenSong file - pass in a file-like object,
|
||||||
not a filename
|
not a filename
|
||||||
"""
|
"""
|
||||||
|
self.authors = []
|
||||||
|
try:
|
||||||
tree = objectify.parse(file)
|
tree = objectify.parse(file)
|
||||||
|
except Error, LxmlError:
|
||||||
|
log.exception(u'Error parsing XML')
|
||||||
|
return
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
fields = dir(root)
|
fields = dir(root)
|
||||||
decode = {
|
decode = {
|
||||||
@ -167,11 +173,11 @@ class OpenSongImport(SongImport):
|
|||||||
u'aka': u'alternate_title',
|
u'aka': u'alternate_title',
|
||||||
u'hymn_number': u'song_number'
|
u'hymn_number': u'song_number'
|
||||||
}
|
}
|
||||||
for (attr, fn_or_string) in decode.items():
|
for attr, fn_or_string in decode.items():
|
||||||
if attr in fields:
|
if attr in fields:
|
||||||
ustring = unicode(root.__getattr__(attr))
|
ustring = unicode(root.__getattr__(attr))
|
||||||
if type(fn_or_string) == type(u''):
|
if isinstance(fn_or_string, basestring):
|
||||||
self.__setattr__(fn_or_string, ustring)
|
setattr(self, fn_or_string, ustring)
|
||||||
else:
|
else:
|
||||||
fn_or_string(ustring)
|
fn_or_string(ustring)
|
||||||
if u'theme' in fields and unicode(root.theme) not in self.topics:
|
if u'theme' in fields and unicode(root.theme) not in self.topics:
|
||||||
@ -252,12 +258,15 @@ class OpenSongImport(SongImport):
|
|||||||
# Keep track of what we have for error checking later
|
# Keep track of what we have for error checking later
|
||||||
versetags[versetag] = 1
|
versetags[versetag] = 1
|
||||||
# now figure out the presentation order
|
# now figure out the presentation order
|
||||||
|
order = []
|
||||||
if u'presentation' in fields and root.presentation != u'':
|
if u'presentation' in fields and root.presentation != u'':
|
||||||
order = unicode(root.presentation)
|
order = unicode(root.presentation)
|
||||||
order = order.split()
|
order = order.split()
|
||||||
else:
|
else:
|
||||||
assert len(our_verse_order)>0
|
if len(our_verse_order) > 0:
|
||||||
order = our_verse_order
|
order = our_verse_order
|
||||||
|
else:
|
||||||
|
log.warn(u'No verse order available for %s, skipping.', self.title)
|
||||||
for tag in order:
|
for tag in order:
|
||||||
if len(tag) == 1:
|
if len(tag) == 1:
|
||||||
tag = tag + u'1' # Assume it's no.1 if it's not there
|
tag = tag + u'1' # Assume it's no.1 if it's not there
|
||||||
|
@ -158,8 +158,7 @@ class SongImport(QtCore.QObject):
|
|||||||
def parse_author(self, text):
|
def parse_author(self, text):
|
||||||
"""
|
"""
|
||||||
Add the author. OpenLP stores them individually so split by 'and', '&'
|
Add the author. OpenLP stores them individually so split by 'and', '&'
|
||||||
and comma.
|
and comma. However need to check for 'Mr and Mrs Smith' and turn it to
|
||||||
However need to check for 'Mr and Mrs Smith' and turn it to
|
|
||||||
'Mr Smith' and 'Mrs Smith'.
|
'Mr Smith' and 'Mrs Smith'.
|
||||||
"""
|
"""
|
||||||
for author in text.split(u','):
|
for author in text.split(u','):
|
||||||
|
Loading…
Reference in New Issue
Block a user