forked from openlp/openlp
Import completely unlabelled songs. Import unreferenced verses
This commit is contained in:
parent
733bedebe8
commit
b4cfea211e
@ -159,8 +159,11 @@ 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 = []
|
self.set_defaults()
|
||||||
self.verse_order_list = []
|
# Setup blank storage to append to
|
||||||
|
verse_order_list = []
|
||||||
|
topics = []
|
||||||
|
verselist = []
|
||||||
try:
|
try:
|
||||||
tree = objectify.parse(file)
|
tree = objectify.parse(file)
|
||||||
except Error, LxmlError:
|
except Error, LxmlError:
|
||||||
@ -183,10 +186,10 @@ class OpenSongImport(SongImport):
|
|||||||
setattr(self, 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 topics:
|
||||||
self.topics.append(unicode(root.theme))
|
topics.append(unicode(root.theme))
|
||||||
if u'alttheme' in fields and unicode(root.alttheme) not in self.topics:
|
if u'alttheme' in fields and unicode(root.alttheme) not in topics:
|
||||||
self.topics.append(unicode(root.alttheme))
|
topics.append(unicode(root.alttheme))
|
||||||
# data storage while importing
|
# data storage while importing
|
||||||
verses = {}
|
verses = {}
|
||||||
lyrics = unicode(root.lyrics)
|
lyrics = unicode(root.lyrics)
|
||||||
@ -214,7 +217,7 @@ class OpenSongImport(SongImport):
|
|||||||
versetype = thisline[1].upper()
|
versetype = thisline[1].upper()
|
||||||
if versetype.isdigit():
|
if versetype.isdigit():
|
||||||
versenum = versetype
|
versenum = versetype
|
||||||
versetype = u'V'
|
versetype = u''
|
||||||
elif thisline[2] != u']':
|
elif thisline[2] != u']':
|
||||||
# there's a number to go with it - extract that as well
|
# there's a number to go with it - extract that as well
|
||||||
right_bracket = thisline.find(u']')
|
right_bracket = thisline.find(u']')
|
||||||
@ -228,10 +231,13 @@ class OpenSongImport(SongImport):
|
|||||||
if thisline[0].isdigit():
|
if thisline[0].isdigit():
|
||||||
versenum = thisline[0]
|
versenum = thisline[0]
|
||||||
words = thisline[1:].strip()
|
words = thisline[1:].strip()
|
||||||
if words is None and \
|
|
||||||
versenum is not None and \
|
if words is None:# and \
|
||||||
versetype is not None:
|
#versenum is not None and \
|
||||||
|
#versetype is not None:
|
||||||
words = thisline
|
words = thisline
|
||||||
|
if not versenum:
|
||||||
|
versenum = u'1'
|
||||||
if versenum is not None:
|
if versenum is not None:
|
||||||
versetag = u'%s%s' % (versetype, versenum)
|
versetag = u'%s%s' % (versetype, versenum)
|
||||||
if not verses.has_key(versetype):
|
if not verses.has_key(versetype):
|
||||||
@ -252,12 +258,15 @@ class OpenSongImport(SongImport):
|
|||||||
versetypes.sort()
|
versetypes.sort()
|
||||||
versetags = {}
|
versetags = {}
|
||||||
for versetype in versetypes:
|
for versetype in versetypes:
|
||||||
|
our_verse_type = versetype
|
||||||
|
if our_verse_type == u'':
|
||||||
|
our_verse_type = u'V'
|
||||||
versenums = verses[versetype].keys()
|
versenums = verses[versetype].keys()
|
||||||
versenums.sort()
|
versenums.sort()
|
||||||
for num in versenums:
|
for num in versenums:
|
||||||
versetag = u'%s%s' % (versetype, num)
|
versetag = u'%s%s' % (our_verse_type, num)
|
||||||
lines = u'\n'.join(verses[versetype][num])
|
lines = u'\n'.join(verses[versetype][num])
|
||||||
self.verses.append([versetag, lines])
|
verselist.append([versetag, lines])
|
||||||
# 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
|
||||||
@ -269,11 +278,18 @@ class OpenSongImport(SongImport):
|
|||||||
if len(our_verse_order) > 0:
|
if len(our_verse_order) > 0:
|
||||||
order = our_verse_order
|
order = our_verse_order
|
||||||
else:
|
else:
|
||||||
log.warn(u'No verse order available for %s, skipping.', self.title)
|
log.warn(u'No verse order available (either explicit or inferred) for %s, skipping.', self.title)
|
||||||
for tag in order:
|
for tag in order:
|
||||||
if len(tag) == 1:
|
if len(tag) == 1:
|
||||||
|
if not tag.isdigit():
|
||||||
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
|
||||||
if not versetags.has_key(tag):
|
|
||||||
log.warn(u'Got order %s but not in versetags, skipping', tag)
|
|
||||||
else:
|
else:
|
||||||
self.verse_order_list.append(tag)
|
tag = u'V' + tag # Assume it's a verse if it has no prefix
|
||||||
|
if not versetags.has_key(tag):
|
||||||
|
log.warn(u'Got order %s but not in versetags, dropping this item from presentation order', tag)
|
||||||
|
else:
|
||||||
|
verse_order_list.append(tag)
|
||||||
|
# now copy the data
|
||||||
|
self.topics = topics
|
||||||
|
self.verse_order_list = verse_order_list
|
||||||
|
self.verses = verselist
|
||||||
|
@ -52,6 +52,12 @@ class SongImport(QtCore.QObject):
|
|||||||
"""
|
"""
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
self.stop_import_flag = False
|
self.stop_import_flag = False
|
||||||
|
self.set_defaults()
|
||||||
|
def set_defaults(self):
|
||||||
|
"""
|
||||||
|
Create defaults for properties - call this before each song
|
||||||
|
if importing many songs at once to ensure a clean beginning
|
||||||
|
"""
|
||||||
self.title = u''
|
self.title = u''
|
||||||
self.song_number = u''
|
self.song_number = u''
|
||||||
self.alternate_title = u''
|
self.alternate_title = u''
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<author>MartiÑ Thómpson</author>
|
<author>MartiÑ Thómpson</author>
|
||||||
<copyright>2010 Martin Thompson</copyright>
|
<copyright>2010 Martin Thompson</copyright>
|
||||||
<hymn_number>1</hymn_number>
|
<hymn_number>1</hymn_number>
|
||||||
<presentation>V1 C V2 C2 V3 B1 V1</presentation>
|
<presentation>V1 C V2 C2 3 B1 V1 T U</presentation>
|
||||||
<ccli>Blah</ccli>
|
<ccli>Blah</ccli>
|
||||||
<capo print="false"></capo>
|
<capo print="false"></capo>
|
||||||
<key></key>
|
<key></key>
|
||||||
@ -17,7 +17,12 @@
|
|||||||
<alttheme>TestAltTheme</alttheme>
|
<alttheme>TestAltTheme</alttheme>
|
||||||
<tempo></tempo>
|
<tempo></tempo>
|
||||||
<time_sig></time_sig>
|
<time_sig></time_sig>
|
||||||
<lyrics>;Comment
|
<lyrics>[3]
|
||||||
|
. G A B
|
||||||
|
V3 Line 1
|
||||||
|
. G A B
|
||||||
|
V3 Line 2
|
||||||
|
|
||||||
. A B C
|
. A B C
|
||||||
1 v1 Line 1___
|
1 v1 Line 1___
|
||||||
2 v2 Line 1___
|
2 v2 Line 1___
|
||||||
@ -25,10 +30,6 @@
|
|||||||
1 V1 Line 2
|
1 V1 Line 2
|
||||||
2 V2 Line 2
|
2 V2 Line 2
|
||||||
|
|
||||||
[3]
|
|
||||||
V3 Line 1
|
|
||||||
V3 Line 2
|
|
||||||
|
|
||||||
[b1]
|
[b1]
|
||||||
Bridge 1
|
Bridge 1
|
||||||
---
|
---
|
||||||
@ -42,6 +43,12 @@
|
|||||||
[C2]
|
[C2]
|
||||||
. A B
|
. A B
|
||||||
Chorus 2
|
Chorus 2
|
||||||
|
|
||||||
|
[T]
|
||||||
|
T Line 1
|
||||||
|
|
||||||
|
[X]
|
||||||
|
Unreferenced verse line 1
|
||||||
</lyrics>
|
</lyrics>
|
||||||
<style index="default_style">
|
<style index="default_style">
|
||||||
<title enabled="true" valign="bottom" align="center" include_verse="false" margin-left="0" margin-right="0" margin-top="0" margin-bottom="0" font="Helvetica" size="26" bold="true" italic="true" underline="false" color="#FFFFFF" border="true" border_color="#000000" shadow="true" shadow_color="#000000" fill="false" fill_color="#000000"/>
|
<title enabled="true" valign="bottom" align="center" include_verse="false" margin-left="0" margin-right="0" margin-top="0" margin-bottom="0" font="Helvetica" size="26" bold="true" italic="true" underline="false" color="#FFFFFF" border="true" border_color="#000000" shadow="true" shadow_color="#000000" fill="false" fill_color="#000000"/>
|
||||||
|
@ -63,7 +63,9 @@ def test():
|
|||||||
assert [u'B1', u'Bridge 1\nBridge 1 line 2'] in o.verses
|
assert [u'B1', u'Bridge 1\nBridge 1 line 2'] in o.verses
|
||||||
assert [u'V1', u'v1 Line 1\nV1 Line 2'] in o.verses
|
assert [u'V1', u'v1 Line 1\nV1 Line 2'] in o.verses
|
||||||
assert [u'V2', u'v2 Line 1\nV2 Line 2'] in o.verses
|
assert [u'V2', u'v2 Line 1\nV2 Line 2'] in o.verses
|
||||||
assert o.verse_order_list == [u'V1', u'C1', u'V2', u'C2', u'V3', u'B1', u'V1']
|
assert [u'V3', u'V3 Line 1\nV3 Line 2'] in o.verses
|
||||||
|
assert [u'X1', u'Unreferenced verse line 1'] in o.verses
|
||||||
|
assert o.verse_order_list == [u'V1', u'C1', u'V2', u'C2', u'V3', u'B1', u'V1', u'T1']
|
||||||
assert o.ccli_number == u'Blah'
|
assert o.ccli_number == u'Blah'
|
||||||
assert o.topics == [u'TestTheme', u'TestAltTheme']
|
assert o.topics == [u'TestTheme', u'TestAltTheme']
|
||||||
|
|
||||||
@ -104,6 +106,20 @@ def test():
|
|||||||
print o.verse_order_list
|
print o.verse_order_list
|
||||||
assert o.verse_order_list == [u'V1', u'V2', u'B1', u'C1', u'C2']
|
assert o.verse_order_list == [u'V1', u'V2', u'B1', u'C1', u'C2']
|
||||||
|
|
||||||
|
o.filenames = [u'test3.opensong']
|
||||||
|
o.do_import()
|
||||||
|
# o.finish()
|
||||||
|
o.print_song()
|
||||||
|
assert o.copyright == u'2010'
|
||||||
|
assert o.authors == [u'Martin Thompson']
|
||||||
|
assert o.title == u'Test single verse'
|
||||||
|
assert o.alternate_title == u''
|
||||||
|
assert o.ccli_number == u'123456'
|
||||||
|
assert o.verse_order_list == [u'V1']
|
||||||
|
assert o.topics == [u'Worship: Declaration']
|
||||||
|
print o.verses[0]
|
||||||
|
assert [u'V1', u'Line 1\nLine 2'] in o.verses
|
||||||
|
|
||||||
print "Tests passed"
|
print "Tests passed"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user