Added support for author types in tests + some VideoPsalm fixes

This commit is contained in:
Tomas Groth 2015-12-18 23:24:20 +01:00
parent 6eb17b561d
commit 037d3f4f7d
6 changed files with 41 additions and 48 deletions

View File

@ -342,8 +342,8 @@ class SongFormat(object):
'selectMode': SongFormatSelect.SingleFile,
'filter': '%s (*.json)' % translate('SongsPlugin.ImportWizardForm', 'VideoPsalm Files'),
'comboBoxText': translate('SongsPlugin.ImportWizardForm', 'VideoPsalm'),
'descriptionText': translate('SongsPlugin.ImportWizardForm','The VideoPsalm songbooks are normally located '
'in %s') % 'C:\\Users\\Public\\Documents\\VideoPsalm\\SongBooks\\'
'descriptionText': translate('SongsPlugin.ImportWizardForm', 'The VideoPsalm songbooks are normally located'
' in %s') % 'C:\\Users\\Public\\Documents\\VideoPsalm\\SongBooks\\'
},
WordsOfWorship: {
'class': WordsOfWorshipImport,

View File

@ -85,7 +85,7 @@ class LyrixImport(SongImport):
# If the CCLI was found, we are near the end
# Find author
line = next(file)
author = line[line.find(':')+2:].strip()
author = line[line.find(':') + 2:].strip()
# Find copyright
copyright = next(file)
except StopIteration:
@ -111,4 +111,4 @@ class LyrixImport(SongImport):
for verse in verses:
self.add_verse(verse, 'v')
if not self.finish():
self.log_error(file.name)
self.log_error(file.name)

View File

@ -255,13 +255,13 @@ class SongImport(QtCore.QObject):
if author2:
self.add_author(author2)
def add_author(self, author):
def add_author(self, author, type=None):
"""
Add an author to the list
"""
if author in self.authors:
if (author, type) in self.authors:
return
self.authors.append(author)
self.authors.append((author, type))
def add_media_file(self, filename, weight=0):
"""
@ -360,13 +360,13 @@ class SongImport(QtCore.QObject):
song.comments = self.comments
song.theme_name = self.theme_name
song.ccli_number = self.ccli_number
for author_text in self.authors:
for author_text, author_type in self.authors:
author = self.manager.get_object_filtered(Author, Author.display_name == author_text)
if not author:
author = Author.populate(display_name=author_text,
last_name=author_text.split(' ')[-1],
first_name=' '.join(author_text.split(' ')[:-1]))
song.add_author(author)
song.add_author(author, author_type)
if self.song_book_name:
song_book = self.manager.get_object_filtered(Book, Book.name == self.song_book_name)
if song_book is None:

View File

@ -30,7 +30,7 @@ import os
from openlp.core.common import translate
from openlp.plugins.songs.lib import VerseType
from openlp.plugins.songs.lib.importers.songimport import SongImport
from openlp.plugins.songs.lib.ui import SongStrings
from openlp.plugins.songs.lib.db import AuthorType
log = logging.getLogger(__name__)
@ -57,7 +57,7 @@ class VideoPsalmImport(SongImport):
file_content = song_file.read()
processed_content = ''
inside_quotes = False
# The VideoPsalm format is not valid json, it uses illegal line breaks and unquoted keys, this must be fixed.
# The VideoPsalm format is not valid json, it uses illegal line breaks and unquoted keys, this must be fixed
file_content_it = iter(file_content)
for c in file_content_it:
if c == '"':
@ -83,47 +83,36 @@ class VideoPsalmImport(SongImport):
songbook_name = songbook['Text']
media_folder = os.path.normpath(os.path.join(os.path.dirname(song_file.name), '..', 'Audio'))
for song in songs:
#song['Composer']
try:
self.song_book_name = songbook_name
if 'Text' in song:
self.title = song['Text']
except KeyError:
pass
try:
self.add_author(song['Author'])
except KeyError:
pass
try:
composer = None
author = None
if 'Composer' in song:
composer = song['Composer']
if 'Author' in song:
author = song['Author']
if author and composer == author:
self.add_author(author, AuthorType.WordsAndMusic)
else:
if author:
self.add_author(author, AuthorType.Words)
if composer:
self.add_author(composer, AuthorType.Music)
if 'Copyright' in song:
self.add_copyright(song['Copyright'].replace('\n', ' ').strip())
except KeyError:
pass
try:
if 'CCLI' in song:
self.ccli_number = song['CCLI']
except KeyError:
pass
try:
self.song_book_name = songbook_name
except KeyError:
pass
try:
if 'Theme' in song:
self.topics = song['Theme'].splitlines()
except KeyError:
pass
#try:
# self.add_media_file(os.path.join(media_folder, song['AudioFile']))
#except KeyError:
# pass
try:
if 'AudioFile' in song:
self.add_media_file(os.path.join(media_folder, song['AudioFile']))
if 'Memo1' in song:
self.add_comment(song['Memo1'])
except KeyError:
pass
try:
if 'Memo2' in song:
self.add_comment(song['Memo2'])
except KeyError:
pass
try:
if 'Memo3' in song:
self.add_comment(song['Memo3'])
except KeyError:
pass
for verse in song['Verses']:
self.add_verse(verse['Text'], 'v')
if not self.finish():
@ -131,4 +120,4 @@ class VideoPsalmImport(SongImport):
except Exception as e:
self.log_error(translate('SongsPlugin.VideoPsalmImport', 'File %s' % file.name),
translate('SongsPlugin.VideoPsalmImport', 'Error: %s') % e)
song_file.close()
song_file.close()

View File

@ -124,7 +124,10 @@ class SongImportTestHelper(TestCase):
self.assertEqual(importer.title, title, 'title for %s should be "%s"' % (source_file_name, title))
for author in author_calls:
self.mocked_add_author.assert_any_call(author)
if isinstance(author, str):
self.mocked_add_author.assert_any_call(author)
else:
self.mocked_add_author.assert_any_call(author[0], author[1])
if song_copyright:
self.mocked_add_copyright.assert_called_with(song_copyright)
if ccli_number:

View File

@ -1,6 +1,7 @@
{
"authors": [
"Martin Luther"
["Martin Luther", "words"],
["Unknown", "music"]
],
"ccli_number": "12345",
"comments": "This is\nthe first comment\nThis is\nthe second comment\nThis is\nthe third comment\n",