forked from openlp/openlp
FoilPresenter
This commit is contained in:
parent
ef97095399
commit
3ae188c287
|
@ -76,6 +76,11 @@ class EasyWorshipSongImport(SongImport):
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
|
|
||||||
def do_import(self):
|
def do_import(self):
|
||||||
|
"""
|
||||||
|
Import the songs
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
# Open the DB and MB files if they exist
|
# Open the DB and MB files if they exist
|
||||||
import_source_mb = self.import_source.replace('.DB', '.MB')
|
import_source_mb = self.import_source.replace('.DB', '.MB')
|
||||||
if not os.path.isfile(self.import_source) or not os.path.isfile(import_source_mb):
|
if not os.path.isfile(self.import_source) or not os.path.isfile(import_source_mb):
|
||||||
|
@ -239,9 +244,20 @@ class EasyWorshipSongImport(SongImport):
|
||||||
self.memo_file.close()
|
self.memo_file.close()
|
||||||
|
|
||||||
def find_field(self, field_name):
|
def find_field(self, field_name):
|
||||||
|
"""
|
||||||
|
Find a field in the descriptions
|
||||||
|
|
||||||
|
:param field_name: field to find
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
return [i for i, x in enumerate(self.field_descriptions) if x.name == field_name][0]
|
return [i for i, x in enumerate(self.field_descriptions) if x.name == field_name][0]
|
||||||
|
|
||||||
def set_record_struct(self, field_descriptions):
|
def set_record_struct(self, field_descriptions):
|
||||||
|
"""
|
||||||
|
Save the record structure
|
||||||
|
|
||||||
|
:param field_descriptions: An array of field descriptions
|
||||||
|
"""
|
||||||
# Begin with empty field struct list
|
# Begin with empty field struct list
|
||||||
fsl = ['>']
|
fsl = ['>']
|
||||||
for field_desc in field_descriptions:
|
for field_desc in field_descriptions:
|
||||||
|
|
|
@ -106,6 +106,7 @@ from openlp.plugins.songs.lib.xml import SongXML
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FoilPresenterImport(SongImport):
|
class FoilPresenterImport(SongImport):
|
||||||
"""
|
"""
|
||||||
This provides the Foilpresenter import.
|
This provides the Foilpresenter import.
|
||||||
|
@ -116,7 +117,7 @@ class FoilPresenterImport(SongImport):
|
||||||
"""
|
"""
|
||||||
log.debug('initialise FoilPresenterImport')
|
log.debug('initialise FoilPresenterImport')
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
self.FoilPresenter = FoilPresenter(self.manager, self)
|
self.foil_presenter = FoilPresenter(self.manager, self)
|
||||||
|
|
||||||
def do_import(self):
|
def do_import(self):
|
||||||
"""
|
"""
|
||||||
|
@ -131,7 +132,7 @@ class FoilPresenterImport(SongImport):
|
||||||
try:
|
try:
|
||||||
parsed_file = etree.parse(file_path, parser)
|
parsed_file = etree.parse(file_path, parser)
|
||||||
xml = etree.tostring(parsed_file).decode()
|
xml = etree.tostring(parsed_file).decode()
|
||||||
self.FoilPresenter.xml_to_song(xml)
|
self.foil_presenter.xml_to_song(xml)
|
||||||
except etree.XMLSyntaxError:
|
except etree.XMLSyntaxError:
|
||||||
self.log_error(file_path, SongStrings.XMLSyntaxError)
|
self.log_error(file_path, SongStrings.XMLSyntaxError)
|
||||||
log.exception('XML syntax error in file %s' % file_path)
|
log.exception('XML syntax error in file %s' % file_path)
|
||||||
|
@ -245,8 +246,7 @@ class FoilPresenter(object):
|
||||||
"""
|
"""
|
||||||
This returns the text of an element as unicode string.
|
This returns the text of an element as unicode string.
|
||||||
|
|
||||||
``element``
|
:param element: The element
|
||||||
The element.
|
|
||||||
"""
|
"""
|
||||||
if element is not None:
|
if element is not None:
|
||||||
return str(element)
|
return str(element)
|
||||||
|
@ -256,11 +256,8 @@ class FoilPresenter(object):
|
||||||
"""
|
"""
|
||||||
Adds the authors specified in the XML to the song.
|
Adds the authors specified in the XML to the song.
|
||||||
|
|
||||||
``foilpresenterfolie``
|
:param foilpresenterfolie: The property object (lxml.objectify.ObjectifiedElement).
|
||||||
The property object (lxml.objectify.ObjectifiedElement).
|
:param song: The song object.
|
||||||
|
|
||||||
``song``
|
|
||||||
The song object.
|
|
||||||
"""
|
"""
|
||||||
authors = []
|
authors = []
|
||||||
try:
|
try:
|
||||||
|
@ -324,8 +321,7 @@ class FoilPresenter(object):
|
||||||
break
|
break
|
||||||
author_temp = []
|
author_temp = []
|
||||||
for author in strings:
|
for author in strings:
|
||||||
temp = re.split(',(?=\D{2})|(?<=\D),|\/(?=\D{3,})|(?<=\D);',
|
temp = re.split(',(?=\D{2})|(?<=\D),|\/(?=\D{3,})|(?<=\D);', author)
|
||||||
author)
|
|
||||||
for tempx in temp:
|
for tempx in temp:
|
||||||
author_temp.append(tempx)
|
author_temp.append(tempx)
|
||||||
for author in author_temp:
|
for author in author_temp:
|
||||||
|
@ -349,7 +345,7 @@ class FoilPresenter(object):
|
||||||
if author is None:
|
if author is None:
|
||||||
# We need to create a new author, as the author does not exist.
|
# We need to create a new author, as the author does not exist.
|
||||||
author = Author.populate(display_name=display_name, last_name=display_name.split(' ')[-1],
|
author = Author.populate(display_name=display_name, last_name=display_name.split(' ')[-1],
|
||||||
first_name=' '.join(display_name.split(' ')[:-1]))
|
first_name=' '.join(display_name.split(' ')[:-1]))
|
||||||
self.manager.save_object(author)
|
self.manager.save_object(author)
|
||||||
song.authors.append(author)
|
song.authors.append(author)
|
||||||
|
|
||||||
|
@ -357,11 +353,8 @@ class FoilPresenter(object):
|
||||||
"""
|
"""
|
||||||
Adds the CCLI number to the song.
|
Adds the CCLI number to the song.
|
||||||
|
|
||||||
``foilpresenterfolie``
|
:param foilpresenterfolie: The property object (lxml.objectify.ObjectifiedElement).
|
||||||
The property object (lxml.objectify.ObjectifiedElement).
|
:param song: The song object.
|
||||||
|
|
||||||
``song``
|
|
||||||
The song object.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
song.ccli_number = self._child(foilpresenterfolie.ccliid)
|
song.ccli_number = self._child(foilpresenterfolie.ccliid)
|
||||||
|
@ -372,11 +365,8 @@ class FoilPresenter(object):
|
||||||
"""
|
"""
|
||||||
Joins the comments specified in the XML and add it to the song.
|
Joins the comments specified in the XML and add it to the song.
|
||||||
|
|
||||||
``foilpresenterfolie``
|
:param foilpresenterfolie: The property object (lxml.objectify.ObjectifiedElement).
|
||||||
The property object (lxml.objectify.ObjectifiedElement).
|
:param song: The song object.
|
||||||
|
|
||||||
``song``
|
|
||||||
The song object.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
song.comments = self._child(foilpresenterfolie.notiz)
|
song.comments = self._child(foilpresenterfolie.notiz)
|
||||||
|
@ -387,11 +377,8 @@ class FoilPresenter(object):
|
||||||
"""
|
"""
|
||||||
Adds the copyright to the song.
|
Adds the copyright to the song.
|
||||||
|
|
||||||
``foilpresenterfolie``
|
:param foilpresenterfolie: The property object (lxml.objectify.ObjectifiedElement).
|
||||||
The property object (lxml.objectify.ObjectifiedElement).
|
:param song: The song object.
|
||||||
|
|
||||||
``song``
|
|
||||||
The song object.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
song.copyright = self._child(foilpresenterfolie.copyright.text_)
|
song.copyright = self._child(foilpresenterfolie.copyright.text_)
|
||||||
|
@ -402,11 +389,8 @@ class FoilPresenter(object):
|
||||||
"""
|
"""
|
||||||
Processes the verses and search_lyrics for the song.
|
Processes the verses and search_lyrics for the song.
|
||||||
|
|
||||||
``foilpresenterfolie``
|
:param foilpresenterfolie: The foilpresenterfolie object (lxml.objectify.ObjectifiedElement).
|
||||||
The foilpresenterfolie object (lxml.objectify.ObjectifiedElement).
|
:param song: The song object.
|
||||||
|
|
||||||
``song``
|
|
||||||
The song object.
|
|
||||||
"""
|
"""
|
||||||
sxml = SongXML()
|
sxml = SongXML()
|
||||||
temp_verse_order = {}
|
temp_verse_order = {}
|
||||||
|
@ -424,8 +408,8 @@ class FoilPresenter(object):
|
||||||
}
|
}
|
||||||
if not hasattr(foilpresenterfolie.strophen, 'strophe'):
|
if not hasattr(foilpresenterfolie.strophen, 'strophe'):
|
||||||
self.importer.log_error(self._child(foilpresenterfolie.titel),
|
self.importer.log_error(self._child(foilpresenterfolie.titel),
|
||||||
str(translate('SongsPlugin.FoilPresenterSongImport',
|
str(translate('SongsPlugin.FoilPresenterSongImport',
|
||||||
'Invalid Foilpresenter song file. No verses found.')))
|
'Invalid Foilpresenter song file. No verses found.')))
|
||||||
self.save_song = False
|
self.save_song = False
|
||||||
return
|
return
|
||||||
for strophe in foilpresenterfolie.strophen.strophe:
|
for strophe in foilpresenterfolie.strophen.strophe:
|
||||||
|
@ -478,10 +462,8 @@ class FoilPresenter(object):
|
||||||
verse_number = str(int(verse_number) + 1)
|
verse_number = str(int(verse_number) + 1)
|
||||||
verse_type_index = VerseType.from_tag(verse_type[0])
|
verse_type_index = VerseType.from_tag(verse_type[0])
|
||||||
verse_type = VerseType.tags[verse_type_index]
|
verse_type = VerseType.tags[verse_type_index]
|
||||||
temp_verse_order[verse_sortnr] = ''.join((verse_type[0],
|
temp_verse_order[verse_sortnr] = ''.join((verse_type[0], verse_number))
|
||||||
verse_number))
|
temp_verse_order_backup.append(''.join((verse_type[0], verse_number)))
|
||||||
temp_verse_order_backup.append(''.join((verse_type[0],
|
|
||||||
verse_number)))
|
|
||||||
sxml.add_verse_to_lyrics(verse_type, verse_number, text)
|
sxml.add_verse_to_lyrics(verse_type, verse_number, text)
|
||||||
song.lyrics = str(sxml.extract_xml(), 'utf-8')
|
song.lyrics = str(sxml.extract_xml(), 'utf-8')
|
||||||
# Process verse order
|
# Process verse order
|
||||||
|
@ -506,11 +488,8 @@ class FoilPresenter(object):
|
||||||
"""
|
"""
|
||||||
Adds the song book and song number specified in the XML to the song.
|
Adds the song book and song number specified in the XML to the song.
|
||||||
|
|
||||||
``foilpresenterfolie``
|
:param foilpresenterfolie: The property object (lxml.objectify.ObjectifiedElement).
|
||||||
The property object (lxml.objectify.ObjectifiedElement).
|
:param song: The song object.
|
||||||
|
|
||||||
``song``
|
|
||||||
The song object.
|
|
||||||
"""
|
"""
|
||||||
song.song_book_id = 0
|
song.song_book_id = 0
|
||||||
song.song_number = ''
|
song.song_number = ''
|
||||||
|
@ -518,8 +497,7 @@ class FoilPresenter(object):
|
||||||
for bucheintrag in foilpresenterfolie.buch.bucheintrag:
|
for bucheintrag in foilpresenterfolie.buch.bucheintrag:
|
||||||
book_name = self._child(bucheintrag.name)
|
book_name = self._child(bucheintrag.name)
|
||||||
if book_name:
|
if book_name:
|
||||||
book = self.manager.get_object_filtered(Book,
|
book = self.manager.get_object_filtered(Book, Book.name == book_name)
|
||||||
Book.name == book_name)
|
|
||||||
if book is None:
|
if book is None:
|
||||||
# We need to create a book, because it does not exist.
|
# We need to create a book, because it does not exist.
|
||||||
book = Book.populate(name=book_name, publisher='')
|
book = Book.populate(name=book_name, publisher='')
|
||||||
|
@ -539,11 +517,8 @@ class FoilPresenter(object):
|
||||||
"""
|
"""
|
||||||
Processes the titles specified in the song's XML.
|
Processes the titles specified in the song's XML.
|
||||||
|
|
||||||
``foilpresenterfolie``
|
:param foilpresenterfolie: The property object (lxml.objectify.ObjectifiedElement).
|
||||||
The property object (lxml.objectify.ObjectifiedElement).
|
:param song: The song object.
|
||||||
|
|
||||||
``song``
|
|
||||||
The song object.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
for title_string in foilpresenterfolie.titel.titelstring:
|
for title_string in foilpresenterfolie.titel.titelstring:
|
||||||
|
@ -561,18 +536,14 @@ class FoilPresenter(object):
|
||||||
"""
|
"""
|
||||||
Adds the topics to the song.
|
Adds the topics to the song.
|
||||||
|
|
||||||
``foilpresenterfolie``
|
:param foilpresenterfolie: The property object (lxml.objectify.ObjectifiedElement).
|
||||||
The property object (lxml.objectify.ObjectifiedElement).
|
:param song: The song object.
|
||||||
|
|
||||||
``song``
|
|
||||||
The song object.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
for name in foilpresenterfolie.kategorien.name:
|
for name in foilpresenterfolie.kategorien.name:
|
||||||
topic_text = self._child(name)
|
topic_text = self._child(name)
|
||||||
if topic_text:
|
if topic_text:
|
||||||
topic = self.manager.get_object_filtered(Topic,
|
topic = self.manager.get_object_filtered(Topic, Topic.name == topic_text)
|
||||||
Topic.name == topic_text)
|
|
||||||
if topic is None:
|
if topic is None:
|
||||||
# We need to create a topic, because it does not exist.
|
# We need to create a topic, because it does not exist.
|
||||||
topic = Topic.populate(name=topic_text)
|
topic = Topic.populate(name=topic_text)
|
||||||
|
|
|
@ -116,17 +116,17 @@ class TestFoilPresenter(TestCase):
|
||||||
|
|
||||||
def create_foil_presenter_test(self):
|
def create_foil_presenter_test(self):
|
||||||
"""
|
"""
|
||||||
Test creating an instance of the FoilPresenter class
|
Test creating an instance of the foil_presenter class
|
||||||
"""
|
"""
|
||||||
# GIVEN: A mocked out "manager" and "SongImport" instance
|
# GIVEN: A mocked out "manager" and "SongImport" instance
|
||||||
mocked_manager = MagicMock()
|
mocked_manager = MagicMock()
|
||||||
mocked_song_import = MagicMock()
|
mocked_song_import = MagicMock()
|
||||||
|
|
||||||
# WHEN: An FoilPresenter instance is created
|
# WHEN: An foil_presenter instance is created
|
||||||
foil_presenter_instance = FoilPresenter(mocked_manager, mocked_song_import)
|
foil_presenter_instance = FoilPresenter(mocked_manager, mocked_song_import)
|
||||||
|
|
||||||
# THEN: The instance should not be None
|
# THEN: The instance should not be None
|
||||||
self.assertIsNotNone(foil_presenter_instance, 'FoilPresenter instance should not be none')
|
self.assertIsNotNone(foil_presenter_instance, 'foil_presenter instance should not be none')
|
||||||
|
|
||||||
def no_xml_test(self):
|
def no_xml_test(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue