forked from openlp/openlp
Songs get built correctly
This commit is contained in:
parent
5decd5c466
commit
2c3c0f2255
@ -56,14 +56,14 @@ class CustomXMLBuilder(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Set up the song builder.
|
Set up the custom builder.
|
||||||
"""
|
"""
|
||||||
# Create the minidom document
|
# Create the minidom document
|
||||||
self.custom_xml = Document()
|
self.custom_xml = Document()
|
||||||
|
|
||||||
def new_document(self):
|
def new_document(self):
|
||||||
"""
|
"""
|
||||||
Create a new song XML document.
|
Create a new custom XML document.
|
||||||
"""
|
"""
|
||||||
# Create the <song> base element
|
# Create the <song> base element
|
||||||
self.song = self.custom_xml.createElement(u'song')
|
self.song = self.custom_xml.createElement(u'song')
|
||||||
@ -73,7 +73,7 @@ class CustomXMLBuilder(object):
|
|||||||
def add_lyrics_to_song(self):
|
def add_lyrics_to_song(self):
|
||||||
"""
|
"""
|
||||||
Set up and add a ``<lyrics>`` tag which contains the lyrics of the
|
Set up and add a ``<lyrics>`` tag which contains the lyrics of the
|
||||||
song.
|
custom item.
|
||||||
"""
|
"""
|
||||||
# Create the main <lyrics> element
|
# Create the main <lyrics> element
|
||||||
self.lyrics = self.custom_xml.createElement(u'lyrics')
|
self.lyrics = self.custom_xml.createElement(u'lyrics')
|
||||||
@ -94,7 +94,6 @@ class CustomXMLBuilder(object):
|
|||||||
``content``
|
``content``
|
||||||
The actual text of the verse to be stored.
|
The actual text of the verse to be stored.
|
||||||
"""
|
"""
|
||||||
#log.debug(u'add_verse_to_lyrics %s, %s\n%s' % (type, number, content))
|
|
||||||
verse = self.custom_xml.createElement(u'verse')
|
verse = self.custom_xml.createElement(u'verse')
|
||||||
verse.setAttribute(u'type', type)
|
verse.setAttribute(u'type', type)
|
||||||
verse.setAttribute(u'label', number)
|
verse.setAttribute(u'label', number)
|
||||||
@ -103,7 +102,7 @@ class CustomXMLBuilder(object):
|
|||||||
cds = self.custom_xml.createCDATASection(content)
|
cds = self.custom_xml.createCDATASection(content)
|
||||||
verse.appendChild(cds)
|
verse.appendChild(cds)
|
||||||
|
|
||||||
def dump_xml(self):
|
def _dump_xml(self):
|
||||||
"""
|
"""
|
||||||
Debugging aid to dump XML so that we can see what we have.
|
Debugging aid to dump XML so that we can see what we have.
|
||||||
"""
|
"""
|
||||||
@ -111,23 +110,23 @@ class CustomXMLBuilder(object):
|
|||||||
|
|
||||||
def extract_xml(self):
|
def extract_xml(self):
|
||||||
"""
|
"""
|
||||||
Extract our newly created XML song.
|
Extract our newly created XML custom.
|
||||||
"""
|
"""
|
||||||
return self.custom_xml.toxml(u'utf-8')
|
return self.custom_xml.toxml(u'utf-8')
|
||||||
|
|
||||||
|
|
||||||
class CustomXMLParser(object):
|
class CustomXMLParser(object):
|
||||||
"""
|
"""
|
||||||
A class to read in and parse a song's XML.
|
A class to read in and parse a custom's XML.
|
||||||
"""
|
"""
|
||||||
log.info(u'CustomXMLParser Loaded')
|
log.info(u'CustomXMLParser Loaded')
|
||||||
|
|
||||||
def __init__(self, xml):
|
def __init__(self, xml):
|
||||||
"""
|
"""
|
||||||
Set up our song XML parser.
|
Set up our custom XML parser.
|
||||||
|
|
||||||
``xml``
|
``xml``
|
||||||
The XML of the song to be parsed.
|
The XML of the custom to be parsed.
|
||||||
"""
|
"""
|
||||||
self.custom_xml = None
|
self.custom_xml = None
|
||||||
if xml[:5] == u'<?xml':
|
if xml[:5] == u'<?xml':
|
||||||
@ -151,7 +150,7 @@ class CustomXMLParser(object):
|
|||||||
verse_list.append([element.attrib, unicode(element.text)])
|
verse_list.append([element.attrib, unicode(element.text)])
|
||||||
return verse_list
|
return verse_list
|
||||||
|
|
||||||
def dump_xml(self):
|
def _dump_xml(self):
|
||||||
"""
|
"""
|
||||||
Debugging aid to dump XML so that we can see what we have.
|
Debugging aid to dump XML so that we can see what we have.
|
||||||
"""
|
"""
|
||||||
|
@ -74,9 +74,9 @@ class CustomMediaItem(MediaManagerItem):
|
|||||||
def initialise(self):
|
def initialise(self):
|
||||||
self.loadCustomListView(self.manager.get_all_objects(
|
self.loadCustomListView(self.manager.get_all_objects(
|
||||||
CustomSlide, order_by_ref=CustomSlide.title))
|
CustomSlide, order_by_ref=CustomSlide.title))
|
||||||
#Called to redisplay the song list screen edith from a search
|
# Called to redisplay the custom list screen edith from a search
|
||||||
#or from the exit of the Song edit dialog. If remote editing is active
|
# or from the exit of the Custom edit dialog. If remote editing is
|
||||||
#Trigger it and clean up so it will not update again.
|
# active trigger it and clean up so it will not update again.
|
||||||
if self.remoteTriggered == u'L':
|
if self.remoteTriggered == u'L':
|
||||||
self.onAddClick()
|
self.onAddClick()
|
||||||
if self.remoteTriggered == u'P':
|
if self.remoteTriggered == u'P':
|
||||||
|
@ -293,37 +293,32 @@ class OpenLyricsParser(object):
|
|||||||
if xml[:5] == u'<?xml':
|
if xml[:5] == u'<?xml':
|
||||||
xml = xml[38:]
|
xml = xml[38:]
|
||||||
song_xml = objectify.fromstring(xml)
|
song_xml = objectify.fromstring(xml)
|
||||||
print objectify.dump(song_xml)
|
properties = song_xml.properties
|
||||||
for properties in song_xml.properties:
|
song.copyright = unicode(properties.copyright.text)
|
||||||
song.copyright = unicode(properties.copyright.text)
|
song.verse_order = unicode(properties.verseOrder.text)
|
||||||
song.verse_order = unicode(properties.verseOrder.text)
|
try:
|
||||||
try:
|
song.ccli_number = unicode(properties.ccliNo.text)
|
||||||
song.ccli_number = unicode(properties.ccliNo.text)
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
try:
|
||||||
try:
|
song.theme_name = unicode(properties.themes.theme)
|
||||||
song.theme_name = unicode(properties.themes.theme)
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
# Process Titles
|
||||||
# Process Titles
|
for title in properties.titles.title:
|
||||||
for title in properties.titles.title:
|
if not song.title:
|
||||||
if not song.title:
|
song.title = title.text
|
||||||
song.title = "aa" + title.text
|
song.search_title = unicode(song.title)
|
||||||
song.search_title = unicode(song.title)
|
else:
|
||||||
else:
|
song.alternate_title = unicode(title.text)
|
||||||
song.alternate_title = unicode(title.text)
|
song.search_title += u'@' + song.alternate_title
|
||||||
song.search_title += u'@' + song.alternate_title
|
song.search_title = re.sub(r'[\'"`,;:(){}?]+', u'',
|
||||||
song.search_title = re.sub(r'[\'"`,;:(){}?]+', u'',
|
unicode(song.search_title)).lower()
|
||||||
unicode(song.search_title)).lower()
|
|
||||||
# Process Authors
|
|
||||||
for author in properties.authors.author:
|
|
||||||
self._process_author(author.text, song)
|
|
||||||
# Process Lyrics
|
# Process Lyrics
|
||||||
sxml = SongXMLBuilder()
|
sxml = SongXMLBuilder()
|
||||||
search_text = u''
|
search_text = u''
|
||||||
for lyrics in song_xml.lyrics:
|
for lyrics in song_xml.lyrics:
|
||||||
for verse in song_xml.lyrics.verse:
|
for verse in song_xml.lyrics.verse:
|
||||||
print "verse", verse.attrib
|
|
||||||
text = u''
|
text = u''
|
||||||
for line in verse.lines.line:
|
for line in verse.lines.line:
|
||||||
line = unicode(line)
|
line = unicode(line)
|
||||||
@ -338,6 +333,9 @@ class OpenLyricsParser(object):
|
|||||||
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
||||||
song.comments = u''
|
song.comments = u''
|
||||||
song.song_number = u''
|
song.song_number = u''
|
||||||
|
# Process Authors
|
||||||
|
for author in properties.authors.author:
|
||||||
|
self._process_author(author.text, song)
|
||||||
self.manager.save_object(song)
|
self.manager.save_object(song)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user