Songs get built correctly

This commit is contained in:
Tim Bentley 2010-11-29 14:04:37 +00:00
parent 5decd5c466
commit 2c3c0f2255
3 changed files with 36 additions and 39 deletions

View File

@ -56,14 +56,14 @@ class CustomXMLBuilder(object):
def __init__(self):
"""
Set up the song builder.
Set up the custom builder.
"""
# Create the minidom document
self.custom_xml = Document()
def new_document(self):
"""
Create a new song XML document.
Create a new custom XML document.
"""
# Create the <song> base element
self.song = self.custom_xml.createElement(u'song')
@ -73,7 +73,7 @@ class CustomXMLBuilder(object):
def add_lyrics_to_song(self):
"""
Set up and add a ``<lyrics>`` tag which contains the lyrics of the
song.
custom item.
"""
# Create the main <lyrics> element
self.lyrics = self.custom_xml.createElement(u'lyrics')
@ -94,7 +94,6 @@ class CustomXMLBuilder(object):
``content``
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.setAttribute(u'type', type)
verse.setAttribute(u'label', number)
@ -103,7 +102,7 @@ class CustomXMLBuilder(object):
cds = self.custom_xml.createCDATASection(content)
verse.appendChild(cds)
def dump_xml(self):
def _dump_xml(self):
"""
Debugging aid to dump XML so that we can see what we have.
"""
@ -111,23 +110,23 @@ class CustomXMLBuilder(object):
def extract_xml(self):
"""
Extract our newly created XML song.
Extract our newly created XML custom.
"""
return self.custom_xml.toxml(u'utf-8')
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')
def __init__(self, xml):
"""
Set up our song XML parser.
Set up our custom XML parser.
``xml``
The XML of the song to be parsed.
The XML of the custom to be parsed.
"""
self.custom_xml = None
if xml[:5] == u'<?xml':
@ -151,7 +150,7 @@ class CustomXMLParser(object):
verse_list.append([element.attrib, unicode(element.text)])
return verse_list
def dump_xml(self):
def _dump_xml(self):
"""
Debugging aid to dump XML so that we can see what we have.
"""

View File

@ -74,9 +74,9 @@ class CustomMediaItem(MediaManagerItem):
def initialise(self):
self.loadCustomListView(self.manager.get_all_objects(
CustomSlide, order_by_ref=CustomSlide.title))
#Called to redisplay the song list screen edith from a search
#or from the exit of the Song edit dialog. If remote editing is active
#Trigger it and clean up so it will not update again.
# Called to redisplay the custom list screen edith from a search
# or from the exit of the Custom edit dialog. If remote editing is
# active trigger it and clean up so it will not update again.
if self.remoteTriggered == u'L':
self.onAddClick()
if self.remoteTriggered == u'P':

View File

@ -293,37 +293,32 @@ class OpenLyricsParser(object):
if xml[:5] == u'<?xml':
xml = xml[38:]
song_xml = objectify.fromstring(xml)
print objectify.dump(song_xml)
for properties in song_xml.properties:
song.copyright = unicode(properties.copyright.text)
song.verse_order = unicode(properties.verseOrder.text)
try:
song.ccli_number = unicode(properties.ccliNo.text)
except:
pass
try:
song.theme_name = unicode(properties.themes.theme)
except:
pass
# Process Titles
for title in properties.titles.title:
if not song.title:
song.title = "aa" + title.text
song.search_title = unicode(song.title)
else:
song.alternate_title = unicode(title.text)
song.search_title += u'@' + song.alternate_title
song.search_title = re.sub(r'[\'"`,;:(){}?]+', u'',
unicode(song.search_title)).lower()
# Process Authors
for author in properties.authors.author:
self._process_author(author.text, song)
properties = song_xml.properties
song.copyright = unicode(properties.copyright.text)
song.verse_order = unicode(properties.verseOrder.text)
try:
song.ccli_number = unicode(properties.ccliNo.text)
except:
pass
try:
song.theme_name = unicode(properties.themes.theme)
except:
pass
# Process Titles
for title in properties.titles.title:
if not song.title:
song.title = title.text
song.search_title = unicode(song.title)
else:
song.alternate_title = unicode(title.text)
song.search_title += u'@' + song.alternate_title
song.search_title = re.sub(r'[\'"`,;:(){}?]+', u'',
unicode(song.search_title)).lower()
# Process Lyrics
sxml = SongXMLBuilder()
search_text = u''
for lyrics in song_xml.lyrics:
for verse in song_xml.lyrics.verse:
print "verse", verse.attrib
text = u''
for line in verse.lines.line:
line = unicode(line)
@ -338,6 +333,9 @@ class OpenLyricsParser(object):
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
song.comments = u''
song.song_number = u''
# Process Authors
for author in properties.authors.author:
self._process_author(author.text, song)
self.manager.save_object(song)
return 0