From 9f345523649b224c549f039fd899b7f96c87c5f0 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 3 Jul 2014 23:30:41 +0200 Subject: [PATCH] PowerPraise importer Fixes: https://launchpad.net/bugs/1336929 --- openlp/plugins/songs/lib/powerpraiseimport.py | 70 +++++++++++++++++++ .../songs/test_powerpraiseimport.py | 54 ++++++++++++++ .../songs/test_propresenterimport.py | 2 +- tests/helpers/songfileimport.py | 20 +++++- .../Näher, mein Gott zu Dir.json | 18 +++++ .../Näher, mein Gott zu Dir.ppl | 2 + 6 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 openlp/plugins/songs/lib/powerpraiseimport.py create mode 100644 tests/functional/openlp_plugins/songs/test_powerpraiseimport.py create mode 100644 tests/resources/powerpraisesongs/Näher, mein Gott zu Dir.json create mode 100644 tests/resources/powerpraisesongs/Näher, mein Gott zu Dir.ppl diff --git a/openlp/plugins/songs/lib/powerpraiseimport.py b/openlp/plugins/songs/lib/powerpraiseimport.py new file mode 100644 index 000000000..56ebff542 --- /dev/null +++ b/openlp/plugins/songs/lib/powerpraiseimport.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +The :mod:`powerpraiseimport` module provides the functionality for importing +Powerpraise song files into the current database. +""" + +import os +import base64 +from lxml import objectify + +from openlp.core.ui.wizard import WizardStrings +from openlp.plugins.songs.lib import strip_rtf +from .songimport import SongImport + + +class PowerpraiseImport(SongImport): + """ + The :class:`PowerpraiseImport` class provides OpenLP with the + ability to import Powerpraise song files. + """ + def do_import(self): + self.import_wizard.progress_bar.setMaximum(len(self.import_source)) + for file_path in self.import_source: + if self.stop_import_flag: + return + self.import_wizard.increment_progress_bar(WizardStrings.ImportingType % os.path.basename(file_path)) + root = objectify.parse(open(file_path, 'rb')).getroot() + self.process_song(root) + + def process_song(self, root): + self.set_defaults() + self.title = root.general.title + count = 0; + for part in root.songtext.part: + verse_text = "" + count += 1 + for slide in part.slide: + for line in slide.line: + verse_text += line + print(verse_text) + self.add_verse(verse_text, "v%d" % count) + if not self.finish(): + self.log_error(self.import_source) diff --git a/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py b/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py new file mode 100644 index 000000000..924cf127c --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +The :mod:`powerpraiseimport` module provides the functionality for importing +ProPresenter song files into the current installation database. +""" + +import os + +from tests.helpers.songfileimport import SongImportTestHelper + +TEST_PATH = os.path.abspath( + os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'powerpraisesongs')) + + +class TestPowerpraiseFileImport(SongImportTestHelper): + + def __init__(self, *args, **kwargs): + self.importer_class_name = 'PowerpraiseImport' + self.importer_module_name = 'powerpraiseimport' + super(TestPowerpraiseFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading a PowerPraise file works correctly + """ + self.file_import([os.path.join(TEST_PATH, 'Näher, mein Gott zu Dir.ppl')], + self.load_external_result_data(os.path.join(TEST_PATH, 'Näher, mein Gott zu Dir.json'))) diff --git a/tests/functional/openlp_plugins/songs/test_propresenterimport.py b/tests/functional/openlp_plugins/songs/test_propresenterimport.py index 10e2defc6..9f5760849 100644 --- a/tests/functional/openlp_plugins/songs/test_propresenterimport.py +++ b/tests/functional/openlp_plugins/songs/test_propresenterimport.py @@ -48,7 +48,7 @@ class TestProPresenterFileImport(SongImportTestHelper): def test_song_import(self): """ - Test that loading an ProPresenter file works correctly + Test that loading a ProPresenter file works correctly """ self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.pro4')], self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index 80b2ee268..afa3e48bd 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -31,10 +31,13 @@ The :mod:`songfileimporthelper` modules provides a helper class and methods to e song files from third party applications. """ import json +import logging from unittest import TestCase from tests.functional import patch, MagicMock, call +log = logging.getLogger(__name__) + class SongImportTestHelper(TestCase): """ @@ -107,9 +110,21 @@ class SongImportTestHelper(TestCase): topics = self._get_data(result_data, 'topics') verse_order_list = self._get_data(result_data, 'verse_order_list') - # THEN: do_import should return none, the song data should be as expected, and finish should have been - # called. + # THEN: do_import should return none, the song data should be as expected, and finish should have been called. self.assertIsNone(importer.do_import(), 'do_import should return None when it has completed') + + # Debug information - will be displayed when the test fails + log.debug("Title imported: %s" % importer.title) + log.debug("Verses imported: %s" % self.mocked_add_verse.mock_calls) + log.debug("Verse order imported: %s" % importer.verse_order_list) + log.debug("Authors imported: %s" % self.mocked_add_author.mock_calls) + log.debug("CCLI No. imported: %s" % importer.ccli_number) + log.debug("Comments imported: %s" % importer.comments) + log.debug("Songbook imported: %s" % importer.song_book_name) + log.debug("Song number imported: %s" % importer.song_number) + log.debug("Song copyright imported: %s" % importer.song_number) + log.debug("Topics imported: %s" % importer.topics) + 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) @@ -119,6 +134,7 @@ class SongImportTestHelper(TestCase): self.assertEqual(importer.ccli_number, ccli_number, 'ccli_number for %s should be %s' % (source_file_name, ccli_number)) expected_calls = [] + print(self.mocked_add_verse.mock_calls) for verse_text, verse_tag in add_verse_calls: self.mocked_add_verse.assert_any_call(verse_text, verse_tag) expected_calls.append(call(verse_text, verse_tag)) diff --git a/tests/resources/powerpraisesongs/Näher, mein Gott zu Dir.json b/tests/resources/powerpraisesongs/Näher, mein Gott zu Dir.json new file mode 100644 index 000000000..54094f748 --- /dev/null +++ b/tests/resources/powerpraisesongs/Näher, mein Gott zu Dir.json @@ -0,0 +1,18 @@ +{ + "title": "Näher, mein Gott, zu Dir", + "verse_order_list": [], + "verses": [ + [ + "Näher, mein Gott, zu Dir,sei meine Bitt'!Näher, o Herr, zu Dirmit jedem Schritt.Nur an dem Herzen Deinkann ich geborgen sein;deshalb die Bitte mein:Näher zu Dir!", + "v1" + ], + [ + "Näher, mein Gott, zu Dir!Ein jeder Tagsoll es neu zeigen mir,was er vermag:Wie seiner Gnade Macht,Erlösung hat gebracht,in uns're Sündennacht.Näher zu Dir!", + "v2" + ], + [ + "Näher, mein Gott, zu Dir!Dich bet' ich an.Wie vieles hast an mir,Du doch getan!Von Banden frei und los,ruh' ich in Deinem Schoss.Ja, Deine Gnad' ist gross!Näher zu Dir!", + "v3" + ] + ] +} \ No newline at end of file diff --git a/tests/resources/powerpraisesongs/Näher, mein Gott zu Dir.ppl b/tests/resources/powerpraisesongs/Näher, mein Gott zu Dir.ppl new file mode 100644 index 000000000..c0c7f8c19 --- /dev/null +++ b/tests/resources/powerpraisesongs/Näher, mein Gott zu Dir.ppl @@ -0,0 +1,2 @@ + +Näher, mein Gott, zu DirAnbetungDeutschNäher, mein Gott, zu Dir,sei meine Bitt'!Näher, o Herr, zu Dirmit jedem Schritt.Nur an dem Herzen Deinkann ich geborgen sein;deshalb die Bitte mein:Näher zu Dir!Näher, mein Gott, zu Dir!Ein jeder Tagsoll es neu zeigen mir,was er vermag:Wie seiner Gnade Macht,Erlösung hat gebracht,in uns're Sündennacht.Näher zu Dir!Näher, mein Gott, zu Dir!Dich bet' ich an.Wie vieles hast an mir,Du doch getan!Von Banden frei und los,ruh' ich in Deinem Schoss.Ja, Deine Gnad' ist gross!Näher zu Dir!Teil 1Teil 2Teil 3lastslideText und Musik: Lowell Mason, 1792-1872firstslidegrünes Buch 339Times New Roman44truetrue167772153015Times New Roman20falsefalse167772153020Times New Roman14falsefalse167772153020Times New Roman30falsefalse167772153020false0true0125Blumen\Blume 3.jpg
30
20
leftcenterinline50406070302040