forked from openlp/openlp
Refactored+update part 1; from UpperCaseWords to lower_case_words
Added attribute songid and changed names bzr-revno: 275
This commit is contained in:
parent
41977dad1c
commit
9887764d51
|
@ -38,6 +38,9 @@ class SongTypeError(SongException):
|
||||||
class SongSlideError(SongException):
|
class SongSlideError(SongException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class SongFeatureError(SongException):
|
||||||
|
pass
|
||||||
|
|
||||||
# TODO: Song: Logging - not all, but enough
|
# TODO: Song: Logging - not all, but enough
|
||||||
# TODO: Song: Handle OpenLP2 format
|
# TODO: Song: Handle OpenLP2 format
|
||||||
# TODO: Song: Import OpenLP1
|
# TODO: Song: Import OpenLP1
|
||||||
|
@ -47,28 +50,6 @@ class SongSlideError(SongException):
|
||||||
# TODO: Song: Import ChangingSong
|
# TODO: Song: Import ChangingSong
|
||||||
# TODO: Song: Export ChangingSong
|
# TODO: Song: Export ChangingSong
|
||||||
|
|
||||||
_blankSongXml = \
|
|
||||||
'''<?xml version="1.0" encoding="iso-8859-1"?>
|
|
||||||
<Song>
|
|
||||||
<title>BlankSong</title>
|
|
||||||
<searchableTitle></searchableTitle>
|
|
||||||
<authorList></authorList>
|
|
||||||
<songCcliNo></songCcliNo>
|
|
||||||
<copyright></copyright>
|
|
||||||
<showTitle>1</showTitle>
|
|
||||||
<showAuthorList>1</showAuthorList>
|
|
||||||
<showSongCcliNo>1</showSongCcliNo>
|
|
||||||
<showCopyright>1</showCopyright>
|
|
||||||
<theme></theme>
|
|
||||||
<categoryArray></categoryArray>
|
|
||||||
<songBook></songBook>
|
|
||||||
<songNumber></songNumber>
|
|
||||||
<comments></comments>
|
|
||||||
<verseOrder></verseOrder>
|
|
||||||
<lyrics></lyrics>
|
|
||||||
</Song>
|
|
||||||
'''
|
|
||||||
|
|
||||||
_blankOpenSongXml = \
|
_blankOpenSongXml = \
|
||||||
'''<?xml version="1.0" encoding="UTF-8"?>
|
'''<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<song>
|
<song>
|
||||||
|
@ -89,20 +70,20 @@ class _OpenSong(XmlRootClass):
|
||||||
def __init__(self, xmlContent = None):
|
def __init__(self, xmlContent = None):
|
||||||
"""Initialize from given xml content"""
|
"""Initialize from given xml content"""
|
||||||
super(_OpenSong, self).__init__()
|
super(_OpenSong, self).__init__()
|
||||||
self.FromBuffer(xmlContent)
|
self.from_buffer(xmlContent)
|
||||||
|
|
||||||
def _reset(self):
|
def _reset(self):
|
||||||
"""Reset all song attributes"""
|
"""Reset all song attributes"""
|
||||||
global _blankOpenSongXml
|
global _blankOpenSongXml
|
||||||
self._setFromXml(_blankOpenSongXml, "song")
|
self._setFromXml(_blankOpenSongXml, "song")
|
||||||
|
|
||||||
def FromBuffer(self, xmlContent):
|
def from_buffer(self, xmlContent):
|
||||||
"""Initialize from buffer(string) with xml content"""
|
"""Initialize from buffer(string) with xml content"""
|
||||||
self._reset()
|
self._reset()
|
||||||
if xmlContent != None :
|
if xmlContent != None :
|
||||||
self._setFromXml(xmlContent, "song")
|
self._setFromXml(xmlContent, "song")
|
||||||
|
|
||||||
def GetAuthorList(self):
|
def get_author_list(self):
|
||||||
"""Convert author field to an authorlist
|
"""Convert author field to an authorlist
|
||||||
|
|
||||||
in OpenSong an author list may be separated by '/'
|
in OpenSong an author list may be separated by '/'
|
||||||
|
@ -116,8 +97,8 @@ class _OpenSong(XmlRootClass):
|
||||||
s = ", ".join(res)
|
s = ", ".join(res)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def GetCategoryArray(self):
|
def get_category_array(self):
|
||||||
"""Convert theme and alttheme into categoryArray
|
"""Convert theme and alttheme into category_array
|
||||||
|
|
||||||
return as a string
|
return as a string
|
||||||
"""
|
"""
|
||||||
|
@ -129,7 +110,7 @@ class _OpenSong(XmlRootClass):
|
||||||
s = ", ".join(res)
|
s = ", ".join(res)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def _reorderVerse(self, tag, tmpVerse):
|
def _reorder_verse(self, tag, tmpVerse):
|
||||||
"""Reorder the verse in case of first char is a number
|
"""Reorder the verse in case of first char is a number
|
||||||
|
|
||||||
tag -- the tag of this verse / verse group
|
tag -- the tag of this verse / verse group
|
||||||
|
@ -160,7 +141,7 @@ class _OpenSong(XmlRootClass):
|
||||||
res.append(l)
|
res.append(l)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def GetLyrics(self):
|
def get_lyrics(self):
|
||||||
"""Convert the lyrics to openlp lyrics format
|
"""Convert the lyrics to openlp lyrics format
|
||||||
|
|
||||||
return as list of strings
|
return as list of strings
|
||||||
|
@ -178,70 +159,119 @@ class _OpenSong(XmlRootClass):
|
||||||
if line.startswith('['):
|
if line.startswith('['):
|
||||||
tag = line
|
tag = line
|
||||||
else :
|
else :
|
||||||
r = self._reorderVerse(tag, tmpVerse)
|
r = self._reorder_verse(tag, tmpVerse)
|
||||||
finalLyrics.extend(r)
|
finalLyrics.extend(r)
|
||||||
tag = ""
|
tag = ""
|
||||||
tmpVerse = []
|
tmpVerse = []
|
||||||
# catch up final verse
|
# catch up final verse
|
||||||
r = self._reorderVerse(tag, tmpVerse)
|
r = self._reorder_verse(tag, tmpVerse)
|
||||||
finalLyrics.extend(r)
|
finalLyrics.extend(r)
|
||||||
return finalLyrics
|
return finalLyrics
|
||||||
|
|
||||||
|
|
||||||
class Song(XmlRootClass) :
|
class Song(object) :
|
||||||
"""Class for handling song properties"""
|
"""Handling song properties and methods
|
||||||
|
|
||||||
def __init__(self, xmlContent = None):
|
handles all conversions between various input and output formats
|
||||||
"""Initialize from given xml content
|
|
||||||
|
|
||||||
xmlContent (string) -- xml formatted string
|
CCLI :
|
||||||
|
from_ccli_text_file
|
||||||
|
to_ccli_text_file
|
||||||
|
from_ccli_text_buffer
|
||||||
|
to_ccli_text_buffer
|
||||||
|
|
||||||
title -- title of the song
|
OpenSong:
|
||||||
searchableTitle -- title without punctuation chars
|
from_opensong_file
|
||||||
authorList -- list of authors
|
to_opensong_file
|
||||||
songCcliNo -- CCLI number for this song
|
from_opensong_buffer
|
||||||
copyright -- copyright string
|
to_opensong_buffer
|
||||||
showTitle -- 0: no show, 1: show
|
|
||||||
showAuthorList -- 0: no show, 1: show
|
presentation (screen):
|
||||||
showCopyright -- 0: no show, 1: show
|
get_number_of_slides
|
||||||
showSongCcliNo -- 0: no show, 1: show
|
get_preview_slide
|
||||||
theme -- name of theme or blank
|
get_render_slide
|
||||||
categoryArray -- list of user defined properties (hymn, gospel)
|
|
||||||
songBook -- name of originating book
|
openlp1 :
|
||||||
songNumber -- number of the song, related to a songbook
|
from_openlp1_lyrics_buffer
|
||||||
comments -- free comment
|
to_openlp1_lyrics_buffer
|
||||||
verseOrder -- presentation order of the slides
|
set_author_list
|
||||||
lyrics -- simple or formatted (tbd)
|
get_author_list
|
||||||
|
|
||||||
|
editing and openlp2 :
|
||||||
|
set_*
|
||||||
|
get_*
|
||||||
"""
|
"""
|
||||||
super(Song, self).__init__()
|
|
||||||
|
def __init__(self, songid = 0):
|
||||||
|
"""Initialize song object
|
||||||
|
|
||||||
|
songid -- database id for this song
|
||||||
|
title -- title of the song
|
||||||
|
search_title -- title without punctuation chars
|
||||||
|
author_list -- list of authors
|
||||||
|
song_cclino -- CCLI number for this song
|
||||||
|
copyright -- copyright string
|
||||||
|
show_title -- 0: no show, 1: show
|
||||||
|
show_author_list -- 0: no show, 1: show
|
||||||
|
show_copyright -- 0: no show, 1: show
|
||||||
|
show_song_cclino -- 0: no show, 1: show
|
||||||
|
theme -- name of theme or blank
|
||||||
|
category_array -- list of user defined properties (hymn, gospel)
|
||||||
|
song_book -- name of originating book
|
||||||
|
song_number -- number of the song, related to a songbook
|
||||||
|
comments -- free comment
|
||||||
|
verse_order -- presentation order of the slides
|
||||||
|
lyrics -- text format
|
||||||
|
search_lyrics -- lowercase lyrics without punctuation
|
||||||
|
"""
|
||||||
|
self.songid = songid
|
||||||
self._reset()
|
self._reset()
|
||||||
if xmlContent != None :
|
|
||||||
self._setFromXml(xmlContent, "Song")
|
|
||||||
self._parseLyrics()
|
|
||||||
|
|
||||||
def _reset(self):
|
def _reset(self):
|
||||||
"""Reset all song attributes"""
|
"""Reset all song attributes"""
|
||||||
global _blankSongXml
|
|
||||||
self.slideList = []
|
self.slideList = []
|
||||||
self._setFromXml(_blankSongXml, "Song")
|
self.set_title("BlankSong")
|
||||||
|
self.author_list = None
|
||||||
|
self.song_cclino = ""
|
||||||
|
self.copyright = ""
|
||||||
|
self.show_author_list = 1
|
||||||
|
self.show_copyright = 1
|
||||||
|
self.show_song_cclino = 1
|
||||||
|
self.show_title = 1
|
||||||
|
self.theme = ""
|
||||||
|
self.category_array = None
|
||||||
|
self.song_book = ""
|
||||||
|
self.song_number = ""
|
||||||
|
self.comments = ""
|
||||||
|
self.verse_order = ""
|
||||||
|
self.set_lyrics("")
|
||||||
|
return
|
||||||
|
|
||||||
def FromOpenSongBuffer(self, xmlcontent):
|
def set_songid(self, songid):
|
||||||
|
"""Set the songid for the database"""
|
||||||
|
self.songid = songid
|
||||||
|
|
||||||
|
def get_songid(self):
|
||||||
|
"""Return the songid for the database"""
|
||||||
|
return self.songid
|
||||||
|
|
||||||
|
def from_opensong_buffer(self, xmlcontent):
|
||||||
"""Initialize from buffer(string) of xml lines in opensong format"""
|
"""Initialize from buffer(string) of xml lines in opensong format"""
|
||||||
self._reset()
|
self._reset()
|
||||||
opensong = _OpenSong(xmlcontent)
|
opensong = _OpenSong(xmlcontent)
|
||||||
if opensong.title != None:
|
if opensong.title != None:
|
||||||
self.SetTitle(opensong.title)
|
self.set_title(opensong.title)
|
||||||
if opensong.copyright != None :
|
if opensong.copyright != None :
|
||||||
self.SetCopyright(opensong.copyright)
|
self.set_copyright(opensong.copyright)
|
||||||
if opensong.presentation != None:
|
if opensong.presentation != None:
|
||||||
self.SetVerseOrder(opensong.presentation)
|
self.set_verse_order(opensong.presentation)
|
||||||
if opensong.ccli != None:
|
if opensong.ccli != None:
|
||||||
self.SetSongCcliNo(opensong.ccli)
|
self.set_song_cclino(opensong.ccli)
|
||||||
self.SetAuthorList(opensong.GetAuthorList())
|
self.set_author_list(opensong.get_author_list())
|
||||||
self.SetCategoryArray(opensong.GetCategoryArray())
|
self.set_category_array(opensong.get_category_array())
|
||||||
self.SetLyrics(opensong.GetLyrics())
|
self.set_lyrics(opensong.get_lyrics())
|
||||||
|
|
||||||
def FromOpenSongFile(self, xmlfilename):
|
def from_opensong_file(self, xmlfilename):
|
||||||
"""Initialize from file containing xml
|
"""Initialize from file containing xml
|
||||||
|
|
||||||
xmlfilename -- path to xml file
|
xmlfilename -- path to xml file
|
||||||
|
@ -252,40 +282,42 @@ class Song(XmlRootClass) :
|
||||||
lst.append(line)
|
lst.append(line)
|
||||||
f.close()
|
f.close()
|
||||||
xml = "".join(lst)
|
xml = "".join(lst)
|
||||||
self.FromOpenSongBuffer(xml)
|
self.from_opensong_buffer(xml)
|
||||||
|
|
||||||
def _RemovePunctuation(self, title):
|
def _remove_punctuation(self, title):
|
||||||
"""Remove the puntuation chars from title
|
"""Remove the puntuation chars from title
|
||||||
|
|
||||||
chars are: .,:;!?&%#/\@`$'|"^~*
|
chars are: .,:;!?&%#/\@`$'|"^~*-
|
||||||
"""
|
"""
|
||||||
punctuation = ".,:;!?&%#'\"/\\@`$|^~*"
|
punctuation = ".,:;!?&%#'\"/\\@`$|^~*-"
|
||||||
s = title
|
s = title
|
||||||
for c in punctuation :
|
for c in punctuation :
|
||||||
s = s.replace(c, '')
|
s = s.replace(c, '')
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def SetTitle(self, title):
|
def set_title(self, title):
|
||||||
"""Set the song title
|
"""Set the song title
|
||||||
|
|
||||||
title (string)
|
title (string)
|
||||||
|
raises SongTitleError if the title is empty
|
||||||
|
raises SongTitleError if the seach_title is empty
|
||||||
"""
|
"""
|
||||||
self.title = title.strip()
|
self.title = title.strip()
|
||||||
self.searchableTitle = self._RemovePunctuation(title).strip()
|
self.search_title = self._remove_punctuation(title).strip()
|
||||||
if len(self.title) < 1 :
|
if len(self.title) < 1 :
|
||||||
raise SongTitleError("The title is empty")
|
raise SongTitleError("The title is empty")
|
||||||
if len(self.searchableTitle) < 1 :
|
if len(self.search_title) < 1 :
|
||||||
raise SongTitleError("The searchable title is empty")
|
raise SongTitleError("The searchable title is empty")
|
||||||
|
|
||||||
def GetTitle(self):
|
def get_title(self):
|
||||||
"""Return title value"""
|
"""Return title value"""
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
def GetSearchableTitle(self):
|
def get_search_title(self):
|
||||||
"""Return searchableTitle"""
|
"""Return search_title"""
|
||||||
return self.searchableTitle
|
return self.search_title
|
||||||
|
|
||||||
def FromTextList(self, textList):
|
def from_ccli_text_buffer(self, textList):
|
||||||
"""Create song from a list of texts (strings) - CCLI text format expected
|
"""Create song from a list of texts (strings) - CCLI text format expected
|
||||||
|
|
||||||
textList (list of strings) -- the song
|
textList (list of strings) -- the song
|
||||||
|
@ -334,14 +366,14 @@ class Song(XmlRootClass) :
|
||||||
lst = sAuthor.split('/')
|
lst = sAuthor.split('/')
|
||||||
if len(lst) < 2:
|
if len(lst) < 2:
|
||||||
lst = sAuthor.split('|')
|
lst = sAuthor.split('|')
|
||||||
authorList = ", ".join(lst)
|
author_list = ", ".join(lst)
|
||||||
self.SetTitle(sName)
|
self.set_title(sName)
|
||||||
self.SetAuthorList(authorList)
|
self.set_author_list(author_list)
|
||||||
self.SetCopyright(sCopyright)
|
self.set_copyright(sCopyright)
|
||||||
self.SetSongCcliNo(sCcli)
|
self.set_song_cclino(sCcli)
|
||||||
self.SetLyrics(lyrics)
|
self.set_lyrics(lyrics)
|
||||||
|
|
||||||
def FromTextFile(self, textFileName):
|
def from_ccli_text_file(self, textFileName):
|
||||||
"""Create song from a list of texts read from given file
|
"""Create song from a list of texts read from given file
|
||||||
|
|
||||||
textFileName -- path to text file
|
textFileName -- path to text file
|
||||||
|
@ -351,9 +383,9 @@ class Song(XmlRootClass) :
|
||||||
for orgline in f:
|
for orgline in f:
|
||||||
lines.append(orgline.rstrip())
|
lines.append(orgline.rstrip())
|
||||||
f.close()
|
f.close()
|
||||||
self.FromTextList(lines)
|
self.from_ccli_text_buffer(lines)
|
||||||
|
|
||||||
def _assureString(self, s):
|
def _assure_string(self, s):
|
||||||
"""Force a string is returned"""
|
"""Force a string is returned"""
|
||||||
if s == None :
|
if s == None :
|
||||||
r = ""
|
r = ""
|
||||||
|
@ -361,7 +393,7 @@ class Song(XmlRootClass) :
|
||||||
r = str(s)
|
r = str(s)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def _splitToList(self, aString):
|
def _split_to_list(self, aString):
|
||||||
"""Split a string into a list - comma separated"""
|
"""Split a string into a list - comma separated"""
|
||||||
res = []
|
res = []
|
||||||
if aString != None :
|
if aString != None :
|
||||||
|
@ -371,10 +403,10 @@ class Song(XmlRootClass) :
|
||||||
res.append(l.strip())
|
res.append(l.strip())
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _listToString(self, strOrList):
|
def _list_to_string(self, strOrList):
|
||||||
"""Force a possibly list into a string"""
|
"""Force a possibly list into a string"""
|
||||||
if type(strOrList) == StringType :
|
if type(strOrList) == StringType :
|
||||||
lst = self._splitToList(strOrList)
|
lst = self._split_to_list(strOrList)
|
||||||
elif type(strOrList) == ListType :
|
elif type(strOrList) == ListType :
|
||||||
lst = strOrList
|
lst = strOrList
|
||||||
elif type(strOrList) == NoneType :
|
elif type(strOrList) == NoneType :
|
||||||
|
@ -384,63 +416,63 @@ class Song(XmlRootClass) :
|
||||||
s = ", ".join(lst)
|
s = ", ".join(lst)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def GetCopyright(self):
|
def get_copyright(self):
|
||||||
"""Return copyright info string"""
|
"""Return copyright info string"""
|
||||||
return self._assureString(self.copyright)
|
return self._assure_string(self.copyright)
|
||||||
|
|
||||||
def SetCopyright(self, copyright):
|
def set_copyright(self, copyright):
|
||||||
"""Set the copyright string"""
|
"""Set the copyright string"""
|
||||||
self.copyright = copyright
|
self.copyright = copyright
|
||||||
|
|
||||||
def GetSongCcliNo(self):
|
def get_song_cclino(self):
|
||||||
"""Return the songCclino"""
|
"""Return the songCclino"""
|
||||||
return self._assureString(self.songCcliNo)
|
return self._assure_string(self.song_cclino)
|
||||||
|
|
||||||
def SetSongCcliNo(self, songCcliNo):
|
def set_song_cclino(self, song_cclino):
|
||||||
"""Set the songCcliNo"""
|
"""Set the song_cclino"""
|
||||||
self.songCcliNo = songCcliNo
|
self.song_cclino = song_cclino
|
||||||
|
|
||||||
def GetTheme(self):
|
def get_theme(self):
|
||||||
"""Return the theme name for the song"""
|
"""Return the theme name for the song"""
|
||||||
return self._assureString(self.theme)
|
return self._assure_string(self.theme)
|
||||||
|
|
||||||
def SetTheme(self, theme):
|
def set_theme(self, theme):
|
||||||
"""Set the theme name (string)"""
|
"""Set the theme name (string)"""
|
||||||
self.theme = theme
|
self.theme = theme
|
||||||
|
|
||||||
def GetSongBook(self):
|
def get_song_book(self):
|
||||||
"""Return the songBook (string)"""
|
"""Return the song_book (string)"""
|
||||||
return self._assureString(self.songBook)
|
return self._assure_string(self.song_book)
|
||||||
|
|
||||||
def SetSongBook(self, songBook):
|
def set_song_book(self, song_book):
|
||||||
"""Set the songBook (string)"""
|
"""Set the song_book (string)"""
|
||||||
self.songBook = songBook
|
self.song_book = song_book
|
||||||
|
|
||||||
def GetSongNumber(self):
|
def get_song_number(self):
|
||||||
"""Return the songNumber (string)"""
|
"""Return the song_number (string)"""
|
||||||
return self._assureString(self.songNumber)
|
return self._assure_string(self.song_number)
|
||||||
|
|
||||||
def SetSongNumber(self, songNumber):
|
def set_song_number(self, song_number):
|
||||||
"""Set the songNumber (string)"""
|
"""Set the song_number (string)"""
|
||||||
self.songNumber = songNumber
|
self.song_number = song_number
|
||||||
|
|
||||||
def GetComments(self):
|
def get_comments(self):
|
||||||
"""Return the comments (string)"""
|
"""Return the comments (string)"""
|
||||||
return self._assureString(self.comments)
|
return self._assure_string(self.comments)
|
||||||
|
|
||||||
def SetComments(self, comments):
|
def set_comments(self, comments):
|
||||||
"""Set the comments (string)"""
|
"""Set the comments (string)"""
|
||||||
self.comments = comments
|
self.comments = comments
|
||||||
|
|
||||||
def GetVerseOrder(self):
|
def get_verse_order(self):
|
||||||
"""Get the verseOrder (string) - preferably space delimited"""
|
"""Get the verseOrder (string) - preferably space delimited"""
|
||||||
return self._assureString(self.verseOrder)
|
return self._assure_string(self.verse_order)
|
||||||
|
|
||||||
def SetVerseOrder(self, verseOrder):
|
def set_verse_order(self, verse_order):
|
||||||
"""Set the verseOrder (string) - space delimited"""
|
"""Set the verse order (string) - space delimited"""
|
||||||
self.verseOrder = verseOrder
|
self.verse_order = verse_order
|
||||||
|
|
||||||
def GetAuthorList(self, asOneString = True):
|
def get_author_list(self, asOneString = True):
|
||||||
"""Return the list of authors as a string
|
"""Return the list of authors as a string
|
||||||
|
|
||||||
asOneString
|
asOneString
|
||||||
|
@ -450,22 +482,22 @@ class Song(XmlRootClass) :
|
||||||
["John Newton", "A Parker"]
|
["John Newton", "A Parker"]
|
||||||
"""
|
"""
|
||||||
if asOneString :
|
if asOneString :
|
||||||
res = self._assureString(self.authorList)
|
res = self._assure_string(self.author_list)
|
||||||
else :
|
else :
|
||||||
res = self._splitToList(self.authorList)
|
res = self._split_to_list(self.author_list)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def SetAuthorList(self, authorList):
|
def set_author_list(self, author_list):
|
||||||
"""Set the authorList
|
"""Set the author_list
|
||||||
|
|
||||||
authorList -- a string or list of strings
|
author_list -- a string or list of strings
|
||||||
"""
|
"""
|
||||||
if authorList == None :
|
if author_list == None :
|
||||||
self.authorList = None
|
self.author_list = None
|
||||||
else :
|
else :
|
||||||
self.authorList = self._listToString(authorList)
|
self.author_list = self._list_to_string(author_list)
|
||||||
|
|
||||||
def GetCategoryArray(self, asOneString = True):
|
def get_category_array(self, asOneString = True):
|
||||||
"""Return the list of categories as a string
|
"""Return the list of categories as a string
|
||||||
|
|
||||||
asOneString
|
asOneString
|
||||||
|
@ -475,66 +507,66 @@ class Song(XmlRootClass) :
|
||||||
["Hymn", "Gospel"]
|
["Hymn", "Gospel"]
|
||||||
"""
|
"""
|
||||||
if asOneString :
|
if asOneString :
|
||||||
res = self._assureString(self.categoryArray)
|
res = self._assure_string(self.category_array)
|
||||||
else :
|
else :
|
||||||
res = self._splitToList(self.categoryArray)
|
res = self._split_to_list(self.category_array)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def SetCategoryArray(self, categoryArray):
|
def set_category_array(self, category_array):
|
||||||
"""Set the categoryArray
|
"""Set the category_array
|
||||||
|
|
||||||
categoryArray -- a string or list of strings
|
category_array -- a string or list of strings
|
||||||
"""
|
"""
|
||||||
if categoryArray == None :
|
if category_array == None :
|
||||||
self.categoryArray = None
|
self.category_array = None
|
||||||
else :
|
else :
|
||||||
self.categoryArray = self._listToString(categoryArray)
|
self.category_array = self._list_to_string(category_array)
|
||||||
|
|
||||||
def GetShowTitle(self):
|
def get_show_title(self):
|
||||||
"""Return the showTitle flag (bool)"""
|
"""Return the show_title flag (bool)"""
|
||||||
return self.showTitle
|
return self.show_title
|
||||||
|
|
||||||
def SetShowTitle(self, showTitle):
|
def set_show_title(self, show_title):
|
||||||
"""Set the showTitle flag (bool)"""
|
"""Set the show_title flag (bool)"""
|
||||||
self.showTitle = showTitle
|
self.show_title = show_title
|
||||||
|
|
||||||
def GetShowAuthorList(self):
|
def get_show_author_list(self):
|
||||||
"""Return the showAuthorList flag"""
|
"""Return the show_author_list flag"""
|
||||||
return self.showAuthorList
|
return self.show_author_list
|
||||||
|
|
||||||
def SetShowAuthorList(self, showAuthorList):
|
def set_show_author_list(self, show_author_list):
|
||||||
"""Set the showAuthorList flag (bool)"""
|
"""Set the show_author_list flag (bool)"""
|
||||||
self.showAuthorList = showAuthorList
|
self.show_author_list = show_author_list
|
||||||
|
|
||||||
def GetShowCopyright(self):
|
def get_show_copyright(self):
|
||||||
"""Return the showCopyright flag"""
|
"""Return the show_copyright flag"""
|
||||||
return self.showCopyright
|
return self.show_copyright
|
||||||
|
|
||||||
def SetShowCopyright(self, showCopyright):
|
def set_show_copyright(self, show_copyright):
|
||||||
"""Set the showCopyright flag (bool)"""
|
"""Set the show_copyright flag (bool)"""
|
||||||
self.showCopyright = showCopyright
|
self.show_copyright = show_copyright
|
||||||
|
|
||||||
def GetShowSongCcliNo(self):
|
def get_show_song_cclino(self):
|
||||||
"""Return the showSongCclino (string)"""
|
"""Return the showSongCclino (string)"""
|
||||||
return self.showSongCcliNo
|
return self.show_song_cclino
|
||||||
|
|
||||||
def SetShowSongCcliNo(self, showSongCcliNo):
|
def set_show_song_cclino(self, show_song_cclino):
|
||||||
"""Set the showSongCcliNo flag (bool)"""
|
"""Set the show_song_cclino flag (bool)"""
|
||||||
self.showSongCcliNo = showSongCcliNo
|
self.show_song_cclino = show_song_cclino
|
||||||
|
|
||||||
def GetLyrics(self):
|
def get_lyrics(self):
|
||||||
"""Return the lyrics as a list of strings
|
"""Return the lyrics as a list of strings
|
||||||
|
|
||||||
this will return all the strings in the song
|
this will return all the strings in the song
|
||||||
"""
|
"""
|
||||||
return self.lyrics
|
return self.lyrics
|
||||||
|
|
||||||
def SetLyrics(self, lyrics):
|
def set_lyrics(self, lyrics):
|
||||||
"""Set the lyrics as a list of strings"""
|
"""Set the lyrics as a list of strings"""
|
||||||
self.lyrics = lyrics
|
self.lyrics = lyrics
|
||||||
self._parseLyrics()
|
self._parse_lyrics()
|
||||||
|
|
||||||
def _parseLyrics(self):
|
def _parse_lyrics(self):
|
||||||
"""Parse lyrics into the slidelist"""
|
"""Parse lyrics into the slidelist"""
|
||||||
# TODO: check font formatting
|
# TODO: check font formatting
|
||||||
self.slideList = []
|
self.slideList = []
|
||||||
|
@ -553,12 +585,12 @@ class Song(XmlRootClass) :
|
||||||
if len(tmpSlide) > 0:
|
if len(tmpSlide) > 0:
|
||||||
self.slideList.append(tmpSlide)
|
self.slideList.append(tmpSlide)
|
||||||
|
|
||||||
def GetNumberOfSlides(self):
|
def get_number_of_slides(self):
|
||||||
"""Return the number of slides in the song (int)"""
|
"""Return the number of slides in the song (int)"""
|
||||||
numOfSlides = len(self.slideList)
|
numOfSlides = len(self.slideList)
|
||||||
return numOfSlides
|
return numOfSlides
|
||||||
|
|
||||||
def GetPreviewSlide(self, slideNumber):
|
def get_preview_slide(self, slideNumber):
|
||||||
"""Return the preview text for specified slide number
|
"""Return the preview text for specified slide number
|
||||||
|
|
||||||
slideNumber -- 0: all slides, 1..n : specific slide
|
slideNumber -- 0: all slides, 1..n : specific slide
|
||||||
|
@ -582,7 +614,7 @@ class Song(XmlRootClass) :
|
||||||
# remove formattingincluding themes
|
# remove formattingincluding themes
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def GetRenderSlide(self, slideNumber):
|
def get_render_slide(self, slideNumber):
|
||||||
"""Return the slide to be rendered including the additional
|
"""Return the slide to be rendered including the additional
|
||||||
properties
|
properties
|
||||||
|
|
||||||
|
@ -601,23 +633,23 @@ class Song(XmlRootClass) :
|
||||||
elif slideNumber > num :
|
elif slideNumber > num :
|
||||||
raise SongSlideError("Slide number too high")
|
raise SongSlideError("Slide number too high")
|
||||||
res = []
|
res = []
|
||||||
if self.showTitle :
|
if self.show_title :
|
||||||
title = self.GetTitle()
|
title = self.get_title()
|
||||||
else :
|
else :
|
||||||
title = ""
|
title = ""
|
||||||
if self.showAuthorList :
|
if self.show_author_list :
|
||||||
author = self.GetAuthorList(True)
|
author = self.get_author_list(True)
|
||||||
else :
|
else :
|
||||||
author = ""
|
author = ""
|
||||||
if self.showCopyright :
|
if self.show_copyright :
|
||||||
cpright = self.GetCopyright()
|
cpright = self.get_copyright()
|
||||||
else :
|
else :
|
||||||
cpright = ""
|
cpright = ""
|
||||||
if self.showSongCcliNo :
|
if self.show_song_cclino :
|
||||||
ccli = self.GetSongCcliNo()
|
ccli = self.get_song_cclino()
|
||||||
else :
|
else :
|
||||||
ccli = ""
|
ccli = ""
|
||||||
theme = self.GetTheme()
|
theme = self.get_theme()
|
||||||
# examine the slide for a theme
|
# examine the slide for a theme
|
||||||
res.append(theme)
|
res.append(theme)
|
||||||
res.append(title)
|
res.append(title)
|
||||||
|
@ -628,4 +660,4 @@ class Song(XmlRootClass) :
|
||||||
return res
|
return res
|
||||||
|
|
||||||
__all__ = ['SongException', 'SongTitleError', 'SongSlideError', 'SongTypeError',
|
__all__ = ['SongException', 'SongTitleError', 'SongSlideError', 'SongTypeError',
|
||||||
'Song']
|
'SongFeatureError', 'Song']
|
||||||
|
|
|
@ -40,149 +40,134 @@ class Test_Basic(object):
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(True)
|
assert(True)
|
||||||
|
|
||||||
def test_str(self):
|
|
||||||
"""Init: Empty, use __str__ to count public attributes & methods"""
|
|
||||||
s = Song()
|
|
||||||
r = s.__str__()
|
|
||||||
l = r.split("\n")
|
|
||||||
assert(len(l) == 55)
|
|
||||||
|
|
||||||
def test_asString(self):
|
|
||||||
"""Init: Empty asString - initial values"""
|
|
||||||
s = Song()
|
|
||||||
r = s._get_as_string()
|
|
||||||
#print r
|
|
||||||
flag = r.endswith("__None__None__None__None__None__None__1__1__1__1__[]__None__None__None__None__BlankSong__None_")
|
|
||||||
assert(flag)
|
|
||||||
|
|
||||||
def test_Title1(self):
|
def test_Title1(self):
|
||||||
"""Set an empty title - raises an exception"""
|
"""Set an empty title - raises an exception"""
|
||||||
s = Song()
|
s = Song()
|
||||||
py.test.raises(SongTitleError, s.SetTitle, "")
|
py.test.raises(SongTitleError, s.set_title, "")
|
||||||
|
|
||||||
def test_Title2(self):
|
def test_Title2(self):
|
||||||
"""Set a normal title"""
|
"""Set a normal title"""
|
||||||
s = Song()
|
s = Song()
|
||||||
t = "A normal title"
|
t = "A normal title"
|
||||||
s.SetTitle(t)
|
s.set_title(t)
|
||||||
assert(s.GetTitle() == t)
|
assert(s.get_title() == t)
|
||||||
assert(s.GetSearchableTitle() == t)
|
assert(s.get_search_title() == t)
|
||||||
|
|
||||||
def test_Title3(self):
|
def test_Title3(self):
|
||||||
"""Set a titel with punctuation 1"""
|
"""Set a titel with punctuation 1"""
|
||||||
s = Song()
|
s = Song()
|
||||||
t1 = "Hey! Come on, ya programmers*"
|
t1 = "Hey! Come on, ya programmers*"
|
||||||
t2 = "Hey Come on ya programmers"
|
t2 = "Hey Come on ya programmers"
|
||||||
s.SetTitle(t1)
|
s.set_title(t1)
|
||||||
assert(s.GetTitle() == t1)
|
assert(s.get_title() == t1)
|
||||||
assert(s.GetSearchableTitle() == t2)
|
assert(s.get_search_title() == t2)
|
||||||
|
|
||||||
def test_Title4(self):
|
def test_Title4(self):
|
||||||
"""Set a titel with punctuation 2"""
|
"""Set a titel with punctuation 2"""
|
||||||
s = Song()
|
s = Song()
|
||||||
t1 = "??#Hey! Come on, ya programmers*"
|
t1 = "??#Hey! Come on, ya programmers*"
|
||||||
t2 = "Hey Come on ya programmers"
|
t2 = "Hey Come on ya programmers"
|
||||||
s.SetTitle(t1)
|
s.set_title(t1)
|
||||||
assert(s.GetTitle() == t1)
|
assert(s.get_title() == t1)
|
||||||
assert(s.GetSearchableTitle() == t2)
|
assert(s.get_search_title() == t2)
|
||||||
|
|
||||||
def test_Title5(self):
|
def test_Title5(self):
|
||||||
"""Set a title, where searchable title becomes empty - raises an exception"""
|
"""Set a title, where searchable title becomes empty - raises an exception"""
|
||||||
s = Song()
|
s = Song()
|
||||||
py.test.raises(SongTitleError, s.SetTitle, ",*")
|
py.test.raises(SongTitleError, s.set_title, ",*")
|
||||||
|
|
||||||
def test_Copyright(self):
|
def test_Copyright(self):
|
||||||
"""Set a copyright string"""
|
"""Set a copyright string"""
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(s.GetCopyright() == "")
|
assert(s.get_copyright() == "")
|
||||||
s.SetCopyright("A B Car")
|
s.set_copyright("A B Car")
|
||||||
assert(s.GetCopyright() == "A B Car")
|
assert(s.get_copyright() == "A B Car")
|
||||||
|
|
||||||
def test_SongCclino(self):
|
def test_SongCclino(self):
|
||||||
"""Set a SongCcliNo"""
|
"""Set a SongCcliNo"""
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(s.GetSongCcliNo() == "")
|
assert(s.get_song_cclino() == "")
|
||||||
s.SetSongCcliNo(12345)
|
s.set_song_cclino(12345)
|
||||||
assert(s.GetSongCcliNo() == "12345")
|
assert(s.get_song_cclino() == "12345")
|
||||||
|
|
||||||
def test_SongBook(self):
|
def test_SongBook(self):
|
||||||
"""Set a songbook value"""
|
"""Set a songbook value"""
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(s.GetSongBook() == "")
|
assert(s.get_song_book() == "")
|
||||||
s.SetSongBook("Hymns")
|
s.set_song_book("Hymns")
|
||||||
assert(s.GetSongBook() == "Hymns")
|
assert(s.get_song_book() == "Hymns")
|
||||||
|
|
||||||
def test_SongNumber(self):
|
def test_SongNumber(self):
|
||||||
"""Set a song number"""
|
"""Set a song number"""
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(s.GetSongNumber() == "")
|
assert(s.get_song_number() == "")
|
||||||
s.SetSongNumber(278)
|
s.set_song_number(278)
|
||||||
assert(s.GetSongNumber() == "278")
|
assert(s.get_song_number() == "278")
|
||||||
|
|
||||||
def test_Theme(self):
|
def test_Theme(self):
|
||||||
"""Set a theme name"""
|
"""Set a theme name"""
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(s.GetTheme() == "")
|
assert(s.get_theme() == "")
|
||||||
s.SetTheme("Red")
|
s.set_theme("Red")
|
||||||
assert(s.GetTheme() == "Red")
|
assert(s.get_theme() == "Red")
|
||||||
|
|
||||||
def test_VerseOrder(self):
|
def test_VerseOrder(self):
|
||||||
"""Set a verse order"""
|
"""Set a verse order"""
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(s.GetVerseOrder() == "")
|
assert(s.get_verse_order() == "")
|
||||||
s.SetVerseOrder("V1 C V2")
|
s.set_verse_order("V1 C V2")
|
||||||
assert(s.GetVerseOrder() == "V1 C V2")
|
assert(s.get_verse_order() == "V1 C V2")
|
||||||
|
|
||||||
def test_Comments(self):
|
def test_Comments(self):
|
||||||
"""Set a comment"""
|
"""Set a comment"""
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(s.GetComments() == "")
|
assert(s.get_comments() == "")
|
||||||
s.SetComments("a comment")
|
s.set_comments("a comment")
|
||||||
assert(s.GetComments() == "a comment")
|
assert(s.get_comments() == "a comment")
|
||||||
|
|
||||||
def test_AuthorList(self):
|
def test_AuthorList(self):
|
||||||
"""Set author lists"""
|
"""Set author lists"""
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(s.GetAuthorList(True) == "")
|
assert(s.get_author_list(True) == "")
|
||||||
assert(s.GetAuthorList(False) == [])
|
assert(s.get_author_list(False) == [])
|
||||||
t1 = "John Newton"
|
t1 = "John Newton"
|
||||||
s.SetAuthorList(t1)
|
s.set_author_list(t1)
|
||||||
assert(s.GetAuthorList(True) == t1)
|
assert(s.get_author_list(True) == t1)
|
||||||
assert(s.GetAuthorList(False) == [t1])
|
assert(s.get_author_list(False) == [t1])
|
||||||
s.SetAuthorList(" Peter Done , John Newton")
|
s.set_author_list(" Peter Done , John Newton")
|
||||||
assert(s.GetAuthorList(True)== "Peter Done, John Newton")
|
assert(s.get_author_list(True)== "Peter Done, John Newton")
|
||||||
assert(s.GetAuthorList(False) == ["Peter Done", "John Newton"])
|
assert(s.get_author_list(False) == ["Peter Done", "John Newton"])
|
||||||
s.SetAuthorList(None)
|
s.set_author_list(None)
|
||||||
assert(s.GetAuthorList(True) == "")
|
assert(s.get_author_list(True) == "")
|
||||||
assert(s.GetAuthorList(False) == [])
|
assert(s.get_author_list(False) == [])
|
||||||
s.SetAuthorList("")
|
s.set_author_list("")
|
||||||
assert(s.GetAuthorList(True) == "")
|
assert(s.get_author_list(True) == "")
|
||||||
assert(s.GetAuthorList(False) == [""])
|
assert(s.get_author_list(False) == [""])
|
||||||
s.SetAuthorList([])
|
s.set_author_list([])
|
||||||
assert(s.GetAuthorList(True) == "")
|
assert(s.get_author_list(True) == "")
|
||||||
assert(s.GetAuthorList(False) == [""])
|
assert(s.get_author_list(False) == [""])
|
||||||
|
|
||||||
def test_CategoryArray(self):
|
def test_CategoryArray(self):
|
||||||
"""Set categories"""
|
"""Set categories"""
|
||||||
s = Song()
|
s = Song()
|
||||||
assert(s.GetCategoryArray(True) == "")
|
assert(s.get_category_array(True) == "")
|
||||||
assert(s.GetCategoryArray(False) == [])
|
assert(s.get_category_array(False) == [])
|
||||||
t1 = "Gospel"
|
t1 = "Gospel"
|
||||||
s.SetCategoryArray(t1)
|
s.set_category_array(t1)
|
||||||
assert(s.GetCategoryArray(True) == t1)
|
assert(s.get_category_array(True) == t1)
|
||||||
assert(s.GetCategoryArray(False) == [t1])
|
assert(s.get_category_array(False) == [t1])
|
||||||
s.SetCategoryArray(" Gospel, Hymns ")
|
s.set_category_array(" Gospel, Hymns ")
|
||||||
assert(s.GetCategoryArray(True) == "Gospel, Hymns")
|
assert(s.get_category_array(True) == "Gospel, Hymns")
|
||||||
assert(s.GetCategoryArray(False) == ["Gospel", "Hymns"])
|
assert(s.get_category_array(False) == ["Gospel", "Hymns"])
|
||||||
s.SetCategoryArray(None)
|
s.set_category_array(None)
|
||||||
assert(s.GetCategoryArray(True) == "")
|
assert(s.get_category_array(True) == "")
|
||||||
assert(s.GetCategoryArray(False) == [])
|
assert(s.get_category_array(False) == [])
|
||||||
s.SetCategoryArray("")
|
s.set_category_array("")
|
||||||
assert(s.GetCategoryArray(True) == "")
|
assert(s.get_category_array(True) == "")
|
||||||
assert(s.GetCategoryArray(False) == [""])
|
assert(s.get_category_array(False) == [""])
|
||||||
s.SetCategoryArray([])
|
s.set_category_array([])
|
||||||
assert(s.GetCategoryArray(True) == "")
|
assert(s.get_category_array(True) == "")
|
||||||
assert(s.GetCategoryArray(False) == [""])
|
assert(s.get_category_array(False) == [""])
|
||||||
|
|
||||||
if '__main__' == __name__:
|
if '__main__' == __name__:
|
||||||
r = Test_Basic()
|
r = Test_Basic()
|
||||||
|
|
|
@ -122,64 +122,64 @@ class Test_OpenSong(object):
|
||||||
def test_sample1(self):
|
def test_sample1(self):
|
||||||
"""OpenSong: handwritten sample1"""
|
"""OpenSong: handwritten sample1"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.FromOpenSongBuffer(_sample1)
|
s.from_opensong_buffer(_sample1)
|
||||||
l = s.GetLyrics()
|
l = s.get_lyrics()
|
||||||
assert(len(l) == (4*3+3))
|
assert(len(l) == (4*3+3))
|
||||||
assert(s.GetNumberOfSlides() == 4)
|
assert(s.get_number_of_slides() == 4)
|
||||||
|
|
||||||
def test_sample2(self):
|
def test_sample2(self):
|
||||||
"""OpenSong: handwritten sample2 - with verses and chorus"""
|
"""OpenSong: handwritten sample2 - with verses and chorus"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.FromOpenSongBuffer(_sample2)
|
s.from_opensong_buffer(_sample2)
|
||||||
l = s.GetLyrics()
|
l = s.get_lyrics()
|
||||||
assert(len(l) == (4*3+3))
|
assert(len(l) == (4*3+3))
|
||||||
assert(s.GetNumberOfSlides() == 4)
|
assert(s.get_number_of_slides() == 4)
|
||||||
|
|
||||||
def test_sample3(self):
|
def test_sample3(self):
|
||||||
"""OpenSong: handwritten sample3 - with verses, chorus, bridge and pre-chorus"""
|
"""OpenSong: handwritten sample3 - with verses, chorus, bridge and pre-chorus"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.FromOpenSongBuffer(_sample3)
|
s.from_opensong_buffer(_sample3)
|
||||||
l = s.GetLyrics()
|
l = s.get_lyrics()
|
||||||
assert(len(l) == (4*3+4+5+4))
|
assert(len(l) == (4*3+4+5+4))
|
||||||
assert(s.GetNumberOfSlides() == 6)
|
assert(s.get_number_of_slides() == 6)
|
||||||
|
|
||||||
def test_file1(self):
|
def test_file1(self):
|
||||||
"""OpenSong: parse Amazing Grace"""
|
"""OpenSong: parse Amazing Grace"""
|
||||||
global __ThisDir__
|
global __ThisDir__
|
||||||
s = Song()
|
s = Song()
|
||||||
s.FromOpenSongFile("%s/data_opensong/Amazing Grace"%(__ThisDir__))
|
s.from_opensong_file("%s/data_opensong/Amazing Grace"%(__ThisDir__))
|
||||||
assert(s.GetTitle() == "Amazing Grace")
|
assert(s.get_title() == "Amazing Grace")
|
||||||
assert(s.GetCopyright() == "1982 Jubilate Hymns Limited")
|
assert(s.get_copyright() == "1982 Jubilate Hymns Limited")
|
||||||
assert(s.GetSongCcliNo() == "1037882")
|
assert(s.get_song_cclino() == "1037882")
|
||||||
assert(s.GetCategoryArray(True) == "God: Attributes")
|
assert(s.get_category_array(True) == "God: Attributes")
|
||||||
assert(s.GetAuthorList(True) == "John Newton")
|
assert(s.get_author_list(True) == "John Newton")
|
||||||
assert(s.GetVerseOrder() == "")
|
assert(s.get_verse_order() == "")
|
||||||
assert(s.GetNumberOfSlides() == 4)
|
assert(s.get_number_of_slides() == 4)
|
||||||
|
|
||||||
def test_file2(self):
|
def test_file2(self):
|
||||||
"""OpenSong: parse The Solid Rock"""
|
"""OpenSong: parse The Solid Rock"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.FromOpenSongFile("%s/data_opensong/The Solid Rock"%(__ThisDir__))
|
s.from_opensong_file("%s/data_opensong/The Solid Rock"%(__ThisDir__))
|
||||||
assert(s.GetTitle() == "The Solid Rock")
|
assert(s.get_title() == "The Solid Rock")
|
||||||
assert(s.GetCopyright() == "Public Domain")
|
assert(s.get_copyright() == "Public Domain")
|
||||||
assert(s.GetSongCcliNo() == "101740")
|
assert(s.get_song_cclino() == "101740")
|
||||||
assert(s.GetCategoryArray(True) == "Christ: Victory, Fruit: Peace/Comfort")
|
assert(s.get_category_array(True) == "Christ: Victory, Fruit: Peace/Comfort")
|
||||||
assert(s.GetAuthorList(True) == "Edward Mote, John B. Dykes")
|
assert(s.get_author_list(True) == "Edward Mote, John B. Dykes")
|
||||||
assert(s.GetVerseOrder() == "V1 C V2 C V3 C V4 C")
|
assert(s.get_verse_order() == "V1 C V2 C V3 C V4 C")
|
||||||
assert(s.GetNumberOfSlides() == 5)
|
assert(s.get_number_of_slides() == 5)
|
||||||
|
|
||||||
def test_file3(self):
|
def test_file3(self):
|
||||||
"""OpenSong: parse 'På en fjern ensom høj' (danish)"""
|
"""OpenSong: parse 'På en fjern ensom høj' (danish)"""
|
||||||
#FIXME: problem with XML convert and danish characters
|
#FIXME: problem with XML convert and danish characters
|
||||||
s = Song()
|
s = Song()
|
||||||
s.FromOpenSongFile("%s/data_opensong/På en fjern ensom høj"%(__ThisDir__))
|
s.from_opensong_file("%s/data_opensong/På en fjern ensom høj"%(__ThisDir__))
|
||||||
assert(s.GetTitle() == u"På en fjern ensom høj")
|
assert(s.get_title() == u"På en fjern ensom høj")
|
||||||
assert(s.GetCopyright() == "")
|
assert(s.get_copyright() == "")
|
||||||
assert(s.GetSongCcliNo() == "")
|
assert(s.get_song_cclino() == "")
|
||||||
assert(s.GetCategoryArray(True) == "")
|
assert(s.get_category_array(True) == "")
|
||||||
assert(s.GetAuthorList(True) == "")
|
assert(s.get_author_list(True) == "")
|
||||||
assert(s.GetVerseOrder() == "V1 C1 V2 C2 V3 C3 V4 C4")
|
assert(s.get_verse_order() == "V1 C1 V2 C2 V3 C3 V4 C4")
|
||||||
assert(s.GetNumberOfSlides() == 8)
|
assert(s.get_number_of_slides() == 8)
|
||||||
|
|
||||||
if '__main__' == __name__:
|
if '__main__' == __name__:
|
||||||
r = Test_OpenSong()
|
r = Test_OpenSong()
|
||||||
|
|
|
@ -35,23 +35,23 @@ class Test_Text(object):
|
||||||
"""OpenSong: parse CCLI example"""
|
"""OpenSong: parse CCLI example"""
|
||||||
global __ThisDir__
|
global __ThisDir__
|
||||||
s = Song()
|
s = Song()
|
||||||
s.FromTextFile("%s/data_text/CCLI example.txt"%(__ThisDir__))
|
s.from_ccli_text_file("%s/data_text/CCLI example.txt"%(__ThisDir__))
|
||||||
assert(s.GetTitle() == "Song Title Here")
|
assert(s.get_title() == "Song Title Here")
|
||||||
assert(s.GetAuthorList(True) == "Author, artist name")
|
assert(s.get_author_list(True) == "Author, artist name")
|
||||||
assert(s.GetCopyright() == "1996 Publisher Info")
|
assert(s.get_copyright() == "1996 Publisher Info")
|
||||||
assert(s.GetSongCcliNo() == "1234567")
|
assert(s.get_song_cclino() == "1234567")
|
||||||
assert(s.GetNumberOfSlides() == 4)
|
assert(s.get_number_of_slides() == 4)
|
||||||
|
|
||||||
def test_file2(self):
|
def test_file2(self):
|
||||||
"""OpenSong: parse PåEnFjern (danish)"""
|
"""OpenSong: parse PåEnFjern (danish)"""
|
||||||
global __ThisDir__
|
global __ThisDir__
|
||||||
s = Song()
|
s = Song()
|
||||||
s.FromTextFile("%s/data_text/PåEnFjern.txt"%(__ThisDir__))
|
s.from_ccli_text_file("%s/data_text/PåEnFjern.txt"%(__ThisDir__))
|
||||||
assert(s.GetTitle() == "På en fjern ensom høj")
|
assert(s.get_title() == "På en fjern ensom høj")
|
||||||
assert(s.GetAuthorList(True) == "Georg Bennard")
|
assert(s.get_author_list(True) == "Georg Bennard")
|
||||||
assert(s.GetCopyright() == "")
|
assert(s.get_copyright() == "")
|
||||||
assert(s.GetSongCcliNo() == "")
|
assert(s.get_song_cclino() == "")
|
||||||
assert(s.GetNumberOfSlides() == 8)
|
assert(s.get_number_of_slides() == 8)
|
||||||
|
|
||||||
if '__main__' == __name__:
|
if '__main__' == __name__:
|
||||||
# for local debugging
|
# for local debugging
|
||||||
|
|
|
@ -39,11 +39,11 @@ class Test_Verse(object):
|
||||||
self.author = "John Newton"
|
self.author = "John Newton"
|
||||||
self.copyright = "Peter Hamil"
|
self.copyright = "Peter Hamil"
|
||||||
self.ccli = "123456"
|
self.ccli = "123456"
|
||||||
s.SetLyrics(["# verse","a single line"])
|
s.set_lyrics(["# verse","a single line"])
|
||||||
s.SetTitle(self.title)
|
s.set_title(self.title)
|
||||||
s.SetCopyright(self.copyright)
|
s.set_copyright(self.copyright)
|
||||||
s.SetAuthorList(self.author)
|
s.set_author_list(self.author)
|
||||||
s.SetSongCcliNo(self.ccli)
|
s.set_song_cclino(self.ccli)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def check_allfields(self, r, isblank = 0):
|
def check_allfields(self, r, isblank = 0):
|
||||||
|
@ -69,84 +69,84 @@ class Test_Verse(object):
|
||||||
def test_title_show_noshow(self):
|
def test_title_show_noshow(self):
|
||||||
"""Test the show title flag"""
|
"""Test the show title flag"""
|
||||||
s = self.stdSong()
|
s = self.stdSong()
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r)
|
self.check_allfields(r)
|
||||||
s.SetShowTitle(False)
|
s.set_show_title(False)
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r, 1)
|
self.check_allfields(r, 1)
|
||||||
s.SetShowTitle(True)
|
s.set_show_title(True)
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r)
|
self.check_allfields(r)
|
||||||
|
|
||||||
def test_author_show_noshow(self):
|
def test_author_show_noshow(self):
|
||||||
"""Test the show author flag"""
|
"""Test the show author flag"""
|
||||||
s = self.stdSong()
|
s = self.stdSong()
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r)
|
self.check_allfields(r)
|
||||||
s.SetShowAuthorList(False)
|
s.set_show_author_list(False)
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r, 2)
|
self.check_allfields(r, 2)
|
||||||
s.SetShowAuthorList(True)
|
s.set_show_author_list(True)
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r)
|
self.check_allfields(r)
|
||||||
|
|
||||||
def test_copyright_show_noshow(self):
|
def test_copyright_show_noshow(self):
|
||||||
"""Test the show copyright flag"""
|
"""Test the show copyright flag"""
|
||||||
s = self.stdSong()
|
s = self.stdSong()
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r)
|
self.check_allfields(r)
|
||||||
s.SetShowCopyright(False)
|
s.set_show_copyright(False)
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r, 3)
|
self.check_allfields(r, 3)
|
||||||
s.SetShowCopyright(True)
|
s.set_show_copyright(True)
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r)
|
self.check_allfields(r)
|
||||||
|
|
||||||
def test_ccli_show_noshow(self):
|
def test_ccli_show_noshow(self):
|
||||||
"""Test the show copyright flag"""
|
"""Test the show copyright flag"""
|
||||||
s = self.stdSong()
|
s = self.stdSong()
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r)
|
self.check_allfields(r)
|
||||||
s.SetShowSongCcliNo(False)
|
s.set_show_song_cclino(False)
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r, 4)
|
self.check_allfields(r, 4)
|
||||||
s.SetShowSongCcliNo(True)
|
s.set_show_song_cclino(True)
|
||||||
r = s.GetRenderSlide(1)
|
r = s.get_render_slide(1)
|
||||||
self.check_allfields(r)
|
self.check_allfields(r)
|
||||||
|
|
||||||
def test_verse1(self):
|
def test_verse1(self):
|
||||||
"""Test an empty verse list"""
|
"""Test an empty verse list"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.SetLyrics([])
|
s.set_lyrics([])
|
||||||
assert(s.GetNumberOfSlides() == 0)
|
assert(s.get_number_of_slides() == 0)
|
||||||
|
|
||||||
def test_verse2(self):
|
def test_verse2(self):
|
||||||
"""Test a list with an empty string"""
|
"""Test a list with an empty string"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.SetLyrics([""])
|
s.set_lyrics([""])
|
||||||
assert(s.GetNumberOfSlides() == 0)
|
assert(s.get_number_of_slides() == 0)
|
||||||
|
|
||||||
def test_verse3a(self):
|
def test_verse3a(self):
|
||||||
"""Test a one liner song"""
|
"""Test a one liner song"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.SetLyrics(["Single verse"])
|
s.set_lyrics(["Single verse"])
|
||||||
assert(s.GetNumberOfSlides() == 1)
|
assert(s.get_number_of_slides() == 1)
|
||||||
|
|
||||||
def test_verse3b(self):
|
def test_verse3b(self):
|
||||||
"""Test a one liner song"""
|
"""Test a one liner song"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.SetLyrics(["", "Single verse"])
|
s.set_lyrics(["", "Single verse"])
|
||||||
assert(s.GetNumberOfSlides() == 1)
|
assert(s.get_number_of_slides() == 1)
|
||||||
|
|
||||||
def test_verse3c(self):
|
def test_verse3c(self):
|
||||||
"""Test a one liner song"""
|
"""Test a one liner song"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.SetLyrics(["", "Single verse", "", ""])
|
s.set_lyrics(["", "Single verse", "", ""])
|
||||||
assert(s.GetNumberOfSlides() == 1)
|
assert(s.get_number_of_slides() == 1)
|
||||||
|
|
||||||
def test_verse3d(self):
|
def test_verse3d(self):
|
||||||
"""Test a one liner song"""
|
"""Test a one liner song"""
|
||||||
s = Song()
|
s = Song()
|
||||||
s.SetLyrics(["", "# Verse", "", ""])
|
s.set_lyrics(["", "# Verse", "", ""])
|
||||||
assert(s.GetNumberOfSlides() == 1)
|
assert(s.get_number_of_slides() == 1)
|
||||||
|
|
Loading…
Reference in New Issue