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, 'selectMode': SongFormatSelect.SingleFile,
'filter': '%s (*.json)' % translate('SongsPlugin.ImportWizardForm', 'VideoPsalm Files'), 'filter': '%s (*.json)' % translate('SongsPlugin.ImportWizardForm', 'VideoPsalm Files'),
'comboBoxText': translate('SongsPlugin.ImportWizardForm', 'VideoPsalm'), 'comboBoxText': translate('SongsPlugin.ImportWizardForm', 'VideoPsalm'),
'descriptionText': translate('SongsPlugin.ImportWizardForm','The VideoPsalm songbooks are normally located ' 'descriptionText': translate('SongsPlugin.ImportWizardForm', 'The VideoPsalm songbooks are normally located'
'in %s') % 'C:\\Users\\Public\\Documents\\VideoPsalm\\SongBooks\\' ' in %s') % 'C:\\Users\\Public\\Documents\\VideoPsalm\\SongBooks\\'
}, },
WordsOfWorship: { WordsOfWorship: {
'class': WordsOfWorshipImport, 'class': WordsOfWorshipImport,

View File

@ -85,7 +85,7 @@ class LyrixImport(SongImport):
# If the CCLI was found, we are near the end # If the CCLI was found, we are near the end
# Find author # Find author
line = next(file) line = next(file)
author = line[line.find(':')+2:].strip() author = line[line.find(':') + 2:].strip()
# Find copyright # Find copyright
copyright = next(file) copyright = next(file)
except StopIteration: except StopIteration:

View File

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

View File

@ -30,7 +30,7 @@ import os
from openlp.core.common import translate from openlp.core.common import translate
from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib import VerseType
from openlp.plugins.songs.lib.importers.songimport import SongImport 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__) log = logging.getLogger(__name__)
@ -57,7 +57,7 @@ class VideoPsalmImport(SongImport):
file_content = song_file.read() file_content = song_file.read()
processed_content = '' processed_content = ''
inside_quotes = False 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) file_content_it = iter(file_content)
for c in file_content_it: for c in file_content_it:
if c == '"': if c == '"':
@ -83,47 +83,36 @@ class VideoPsalmImport(SongImport):
songbook_name = songbook['Text'] songbook_name = songbook['Text']
media_folder = os.path.normpath(os.path.join(os.path.dirname(song_file.name), '..', 'Audio')) media_folder = os.path.normpath(os.path.join(os.path.dirname(song_file.name), '..', 'Audio'))
for song in songs: for song in songs:
#song['Composer']
try:
self.title = song['Text']
except KeyError:
pass
try:
self.add_author(song['Author'])
except KeyError:
pass
try:
self.add_copyright(song['Copyright'].replace('\n', ' ').strip())
except KeyError:
pass
try:
self.ccli_number = song['CCLI']
except KeyError:
pass
try:
self.song_book_name = songbook_name self.song_book_name = songbook_name
except KeyError: if 'Text' in song:
pass self.title = song['Text']
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())
if 'CCLI' in song:
self.ccli_number = song['CCLI']
if 'Theme' in song:
self.topics = song['Theme'].splitlines() self.topics = song['Theme'].splitlines()
except KeyError: if 'AudioFile' in song:
pass self.add_media_file(os.path.join(media_folder, song['AudioFile']))
#try: if 'Memo1' in song:
# self.add_media_file(os.path.join(media_folder, song['AudioFile']))
#except KeyError:
# pass
try:
self.add_comment(song['Memo1']) self.add_comment(song['Memo1'])
except KeyError: if 'Memo2' in song:
pass
try:
self.add_comment(song['Memo2']) self.add_comment(song['Memo2'])
except KeyError: if 'Memo3' in song:
pass
try:
self.add_comment(song['Memo3']) self.add_comment(song['Memo3'])
except KeyError:
pass
for verse in song['Verses']: for verse in song['Verses']:
self.add_verse(verse['Text'], 'v') self.add_verse(verse['Text'], 'v')
if not self.finish(): if not self.finish():

View File

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

View File

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