forked from openlp/openlp
Handles versetypes like 'V3a'
This commit is contained in:
parent
192010588f
commit
11a9d3d8f5
@ -29,6 +29,7 @@ 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 lxml.etree import Error, LxmlError
|
||||||
|
import re
|
||||||
|
|
||||||
from openlp.plugins.songs.lib.songimport import SongImport
|
from openlp.plugins.songs.lib.songimport import SongImport
|
||||||
|
|
||||||
@ -190,9 +191,9 @@ class OpenSongImport(SongImport):
|
|||||||
topics.append(unicode(root.theme))
|
topics.append(unicode(root.theme))
|
||||||
if u'alttheme' in fields and unicode(root.alttheme) not in topics:
|
if u'alttheme' in fields and unicode(root.alttheme) not in topics:
|
||||||
topics.append(unicode(root.alttheme))
|
topics.append(unicode(root.alttheme))
|
||||||
|
lyrics = unicode(root.lyrics)
|
||||||
# data storage while importing
|
# data storage while importing
|
||||||
verses = {}
|
verses = {}
|
||||||
lyrics = unicode(root.lyrics)
|
|
||||||
# keep track of a "default" verse order, in case none is specified
|
# keep track of a "default" verse order, in case none is specified
|
||||||
our_verse_order = []
|
our_verse_order = []
|
||||||
verses_seen = {}
|
verses_seen = {}
|
||||||
@ -214,24 +215,28 @@ class OpenSongImport(SongImport):
|
|||||||
continue
|
continue
|
||||||
# verse/chorus/etc. marker
|
# verse/chorus/etc. marker
|
||||||
if thisline[0] == u'[':
|
if thisline[0] == u'[':
|
||||||
versetype = thisline[1].upper()
|
# drop the square brackets
|
||||||
if versetype.isdigit():
|
right_bracket = thisline.find(u']')
|
||||||
versenum = versetype
|
content = thisline[1:right_bracket].upper()
|
||||||
versetype = u''
|
print '"', content, '"'
|
||||||
elif thisline[2] != u']':
|
# have we got any digits? If so, versenumber is everything from the digits
|
||||||
# there's a number to go with it - extract that as well
|
# to the end (even if there are some alpha chars on the end)
|
||||||
right_bracket = thisline.find(u']')
|
match = re.match(u'(.*)(\d+.*)', content)
|
||||||
versenum = thisline[2:right_bracket]
|
if match is not None:
|
||||||
|
print "Got digits"
|
||||||
|
versetype = match.group(1)
|
||||||
|
versenum = match.group(2)
|
||||||
|
# otherwise we assume number 1 and take the whole prefix as versetype
|
||||||
else:
|
else:
|
||||||
# if there's no number, assume it's no.1
|
versetype = content
|
||||||
versenum = u'1'
|
versenum = u'1'
|
||||||
|
print versetype, versenum
|
||||||
continue
|
continue
|
||||||
words = None
|
words = None
|
||||||
# number at start of line.. it's verse number
|
# number at start of line.. it's verse number
|
||||||
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 \
|
if words is None:# and \
|
||||||
#versenum is not None and \
|
#versenum is not None and \
|
||||||
#versetype is not None:
|
#versetype is not None:
|
||||||
@ -248,6 +253,7 @@ class OpenSongImport(SongImport):
|
|||||||
if not verses_seen.has_key(versetag):
|
if not verses_seen.has_key(versetag):
|
||||||
verses_seen[versetag] = 1
|
verses_seen[versetag] = 1
|
||||||
our_verse_order.append(versetag)
|
our_verse_order.append(versetag)
|
||||||
|
print ">>", (versetype,), (versenum,), versetag, words
|
||||||
if words:
|
if words:
|
||||||
# Tidy text and remove the ____s from extended words
|
# Tidy text and remove the ____s from extended words
|
||||||
words = self.tidy_text(words)
|
words = self.tidy_text(words)
|
||||||
@ -273,18 +279,21 @@ class OpenSongImport(SongImport):
|
|||||||
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()
|
# We make all the tags in the lyrics upper case, so match that here
|
||||||
|
# and then split into a list on the whitespace
|
||||||
|
order = order.upper().split()
|
||||||
else:
|
else:
|
||||||
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 (either explicit or inferred) 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:
|
print tag
|
||||||
if not tag.isdigit():
|
if tag[0].isdigit():
|
||||||
tag = tag + u'1' # Assume it's no.1 if it's not there
|
tag = u'V' + tag # Assume it's a verse if it has no prefix
|
||||||
else:
|
elif not re.search('\d+', tag):
|
||||||
tag = u'V' + tag # Assume it's a verse if it has no prefix
|
tag = tag + u'1' # Assume it's no.1 if there's no digits
|
||||||
|
print tag
|
||||||
if not versetags.has_key(tag):
|
if not versetags.has_key(tag):
|
||||||
log.info(u'Got order %s but not in versetags, dropping this item from presentation order', tag)
|
log.info(u'Got order %s but not in versetags, dropping this item from presentation order', tag)
|
||||||
else:
|
else:
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<author>MartiÑ & Martin2 Thómpson</author>
|
<author>MartiÑ & Martin2 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 3 B1 V1 T U</presentation>
|
<presentation>V1 C V2 C2 3a 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,7 @@
|
|||||||
<alttheme>TestAltTheme</alttheme>
|
<alttheme>TestAltTheme</alttheme>
|
||||||
<tempo></tempo>
|
<tempo></tempo>
|
||||||
<time_sig></time_sig>
|
<time_sig></time_sig>
|
||||||
<lyrics>[3]
|
<lyrics>[3a]
|
||||||
. G A B
|
. G A B
|
||||||
V3 Line 1
|
V3 Line 1
|
||||||
. G A B
|
. G A B
|
||||||
|
@ -63,9 +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 [u'V3', u'V3 Line 1\nV3 Line 2'] in o.verses
|
assert [u'V3A', u'V3 Line 1\nV3 Line 2'] in o.verses
|
||||||
assert [u'X1', u'Unreferenced verse line 1'] 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.verse_order_list == [u'V1', u'C1', u'V2', u'C2', u'V3A', 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']
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user