From b7a141f75ce6feb1182d0f18f63a28bff7f75efa Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 7 Jul 2014 15:30:55 +0200 Subject: [PATCH 1/6] Add Presentation Manager import Fixes: https://launchpad.net/bugs/957017 --- .../songs/lib/presentationmanagerimport.py | 93 +++++++++++++++++++ .../songs/test_presentationmanagerimport.py | 53 +++++++++++ .../Great Is Thy Faithfulness.json | 25 +++++ .../Great Is Thy Faithfulness.sng | 51 ++++++++++ 4 files changed, 222 insertions(+) create mode 100644 openlp/plugins/songs/lib/presentationmanagerimport.py create mode 100644 tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py create mode 100644 tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json create mode 100644 tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng diff --git a/openlp/plugins/songs/lib/presentationmanagerimport.py b/openlp/plugins/songs/lib/presentationmanagerimport.py new file mode 100644 index 000000000..11f4be81b --- /dev/null +++ b/openlp/plugins/songs/lib/presentationmanagerimport.py @@ -0,0 +1,93 @@ +# -*- 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:`presentationmanagerimport` module provides the functionality for importing +Presentationmanager song files into the current database. +""" + +import os +from lxml import objectify + +from openlp.core.ui.wizard import WizardStrings +from .songimport import SongImport + + +class PresentationManagerImport(SongImport): + """ + The :class:`PresentationManagerImport` class provides OpenLP with the + ability to import Presentationmanager 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 = str(root.attributes.title) + self.add_author(str(root.attributes.author)) + self.copyright = str(root.attributes.copyright) + self.ccli_number = str(root.attributes.ccli_number) + self.comments = str(root.attributes.comments) + verse_order_list = [] + verse_count = {} + duplicates = [] + for verse in root.verses.verse: + original_verse_def = verse.get('id') + # Presentation Manager stores duplicate verses instead of a verse order. + # We need to create the verse order from that. + is_duplicate = False + if original_verse_def in duplicates: + is_duplicate = True + else: + duplicates.append(original_verse_def) + if original_verse_def.startswith("Verse"): + verse_def = 'v' + elif original_verse_def.startswith("Chorus") or original_verse_def.startswith("Refrain"): + verse_def = 'c' + elif original_verse_def.startswith("Bridge"): + verse_def = 'b' + elif original_verse_def.startswith("End"): + verse_def = 'e' + else: + verse_def = 'o' + if not is_duplicate: # Only increment verse number if no duplicate + verse_count[verse_def] = verse_count.get(verse_def, 0) + 1 + verse_def = '%s%d' % (verse_def, verse_count[verse_def]) + if not is_duplicate: # Only add verse if no duplicate + self.add_verse(str(verse).strip(), verse_def) + verse_order_list.append(verse_def) + + self.verse_order_list = verse_order_list + if not self.finish(): + self.log_error(self.import_source) \ No newline at end of file diff --git a/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py b/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py new file mode 100644 index 000000000..34e49146e --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 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 # +############################################################################### +""" +This module contains tests for the PresentationManager song importer. +""" + +import os + +from tests.helpers.songfileimport import SongImportTestHelper + +TEST_PATH = os.path.abspath( + os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'presentationmanagersongs')) + + +class TestSongShowPlusFileImport(SongImportTestHelper): + + def __init__(self, *args, **kwargs): + self.importer_class_name = 'PresentationManagerImport' + self.importer_module_name = 'presentationmanagerimport' + super(TestSongShowPlusFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading a PresentationManager file works correctly + """ + self.file_import([os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.sng')], + self.load_external_result_data(os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.json'))) diff --git a/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json b/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json new file mode 100644 index 000000000..5a5c3ddaf --- /dev/null +++ b/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json @@ -0,0 +1,25 @@ +{ + "title": "Great Is Thy Faithfulness", + "authors": [ + "Thomas O. Chisholm (1866-1960)" + ], + "verse_order_list": [], + "verses": [ + [ + "\"Great is Thy faithfulness\", O God my Father.\nThere is no shadow of turning with Thee;\nThou changest not, Thy compassions they fail not,\nAs Thou hast been Thou forever shall be.", + "v1" + ], + [ + "Great is Thy faithfulness!\nGreat is Thy faithfulness!\nMorning by morning new mercies I see!\nAll I have needed Thy hand hath provided -\n\"Great is Thy faithfulness\", Lord, unto me!", + "c1" + ], + [ + "Summer and winter, and springtime and harvest,\nSun, moon, and stars in their courses above,\nJoin with all nature in manifold witness,\nTo Thy great faithfulness, mercy and love.", + "v2" + ], + [ + "Pardon for sin and a peace that endureth,\nThine own dear presence to cheer and to guide,\nStrength for today and bright hope for tomorrow,\nBlessings all mine, with ten thousand beside!", + "v3" + ] + ] +} \ No newline at end of file diff --git a/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng b/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng new file mode 100644 index 000000000..49b29c4c7 --- /dev/null +++ b/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng @@ -0,0 +1,51 @@ + + + +Great Is Thy Faithfulness +Thomas O. Chisholm (1866-1960) + + + + + + +"Great is Thy faithfulness", O God my Father. +There is no shadow of turning with Thee; +Thou changest not, Thy compassions they fail not, +As Thou hast been Thou forever shall be. + + +Great is Thy faithfulness! +Great is Thy faithfulness! +Morning by morning new mercies I see! +All I have needed Thy hand hath provided - +"Great is Thy faithfulness", Lord, unto me! + + +Summer and winter, and springtime and harvest, +Sun, moon, and stars in their courses above, +Join with all nature in manifold witness, +To Thy great faithfulness, mercy and love. + + +Great is Thy faithfulness! +Great is Thy faithfulness! +Morning by morning new mercies I see! +All I have needed Thy hand hath provided - +"Great is Thy faithfulness", Lord, unto me! + + +Pardon for sin and a peace that endureth, +Thine own dear presence to cheer and to guide, +Strength for today and bright hope for tomorrow, +Blessings all mine, with ten thousand beside! + + +Great is Thy faithfulness! +Great is Thy faithfulness! +Morning by morning new mercies I see! +All I have needed Thy hand hath provided - +"Great is Thy faithfulness", Lord, unto me! + + + From 398508f49b019c01cc0828e747ffd6fc0803504b Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 7 Jul 2014 15:36:07 +0200 Subject: [PATCH 2/6] Gui entry --- openlp/plugins/songs/lib/importer.py | 33 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 6d01da309..19543575b 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -51,12 +51,11 @@ from .foilpresenterimport import FoilPresenterImport from .zionworximport import ZionWorxImport from .propresenterimport import ProPresenterImport from .worshipassistantimport import WorshipAssistantImport -# Imports that might fail - +from .presentationmanagerimport import PresentationManagerImport log = logging.getLogger(__name__) - +# Imports that might fail try: from .sofimport import SofImport HAS_SOF = True @@ -161,16 +160,17 @@ class SongFormat(object): MediaShout = 9 OpenSong = 10 PowerSong = 11 - ProPresenter = 12 - SongBeamer = 13 - SongPro = 14 - SongShowPlus = 15 - SongsOfFellowship = 16 - SundayPlus = 17 - WordsOfWorship = 18 - WorshipAssistant = 19 - WorshipCenterPro = 20 - ZionWorx = 21 + PresentationManager = 12 + ProPresenter = 13 + SongBeamer = 14 + SongPro = 15 + SongShowPlus = 16 + SongsOfFellowship = 17 + SundayPlus = 18 + WordsOfWorship = 19 + WorshipAssistant = 20 + WorshipCenterPro = 21 + ZionWorx = 22 # Set optional attribute defaults __defaults__ = { @@ -274,6 +274,12 @@ class SongFormat(object): 'invalidSourceMsg': translate('SongsPlugin.ImportWizardForm', 'You need to specify a valid PowerSong 1.0 ' 'database folder.') }, + PresentationManager: { + 'class': PresentationManagerImport, + 'name': 'PresentationManager', + 'prefix': 'presentationManager', + 'filter': '%s (*.sng)' % translate('SongsPlugin.ImportWizardForm', 'PresentationManager Song Files') + }, ProPresenter: { 'class': ProPresenterImport, 'name': 'ProPresenter', @@ -375,6 +381,7 @@ class SongFormat(object): SongFormat.MediaShout, SongFormat.OpenSong, SongFormat.PowerSong, + SongFormat.PresentationManager, SongFormat.ProPresenter, SongFormat.SongBeamer, SongFormat.SongPro, From df6669220a49aba2c141e2ac1375a33db400be54 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 7 Jul 2014 18:17:54 +0200 Subject: [PATCH 3/6] Space --- openlp/plugins/songs/lib/importer.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 6e4aa1fc7..56e4ace01 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -34,7 +34,6 @@ import logging from openlp.core.common import translate, UiStrings from openlp.core.ui.wizard import WizardStrings - from .importers.opensong import OpenSongImport from .importers.easyslides import EasySlidesImport from .importers.openlp import OpenLPSongImport @@ -56,7 +55,6 @@ from .importers.presentationmanager import PresentationManagerImport log = logging.getLogger(__name__) - # Imports that might fail try: from .importers.songsoffellowship import SongsOfFellowshipImport From 53cb11e03e5f3dacbffb3aaf8facacfa594d2af9 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Fri, 11 Jul 2014 16:19:53 +0200 Subject: [PATCH 4/6] EOF; verse order fixed --- openlp/plugins/songs/lib/importers/presentationmanager.py | 2 +- .../presentationmanagersongs/Great Is Thy Faithfulness.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/presentationmanager.py b/openlp/plugins/songs/lib/importers/presentationmanager.py index 4ea08076e..52a047a30 100644 --- a/openlp/plugins/songs/lib/importers/presentationmanager.py +++ b/openlp/plugins/songs/lib/importers/presentationmanager.py @@ -90,4 +90,4 @@ class PresentationManagerImport(SongImport): self.verse_order_list = verse_order_list if not self.finish(): - self.log_error(self.import_source) \ No newline at end of file + self.log_error(self.import_source) diff --git a/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json b/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json index 5a5c3ddaf..1e484b11b 100644 --- a/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json +++ b/tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json @@ -3,7 +3,7 @@ "authors": [ "Thomas O. Chisholm (1866-1960)" ], - "verse_order_list": [], + "verse_order_list": ["v1", "c1", "v2", "c1", "v3", "c1"], "verses": [ [ "\"Great is Thy faithfulness\", O God my Father.\nThere is no shadow of turning with Thee;\nThou changest not, Thy compassions they fail not,\nAs Thou hast been Thou forever shall be.", @@ -22,4 +22,4 @@ "v3" ] ] -} \ No newline at end of file +} From 0ce859c2cd6b7b99bc068b759fe35e7cbddb71a3 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 14 Jul 2014 13:36:33 +0200 Subject: [PATCH 5/6] Fix import --- openlp/plugins/songs/lib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index d03bdefd6..999f51fad 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -374,7 +374,7 @@ def clean_song(manager, song): :param manager: The song database manager object. :param song: The song object. """ - from .xml import SongXML + from .openlyricsxml import SongXML if song.title: song.title = clean_title(song.title) From 5e349c6c24e5a6278a56fae17f71d4403097493b Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 14 Jul 2014 18:50:50 +0200 Subject: [PATCH 6/6] Merge conflict --- openlp/plugins/songs/lib/importer.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index eb8c8b4d6..0084a74de 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -160,23 +160,19 @@ class SongFormat(object): FoilPresenter = 8 MediaShout = 9 OpenSong = 10 -<<<<<<< TREE - PowerSong = 11 - PresentationManager = 12 -======= PowerPraise = 11 PowerSong = 12 ->>>>>>> MERGE-SOURCE - ProPresenter = 13 - SongBeamer = 14 - SongPro = 15 - SongShowPlus = 16 - SongsOfFellowship = 17 - SundayPlus = 18 - WordsOfWorship = 19 - WorshipAssistant = 20 - WorshipCenterPro = 21 - ZionWorx = 22 + PresentationManager = 13 + ProPresenter = 14 + SongBeamer = 15 + SongPro = 16 + SongShowPlus = 17 + SongsOfFellowship = 18 + SundayPlus = 19 + WordsOfWorship = 20 + WorshipAssistant = 21 + WorshipCenterPro = 22 + ZionWorx = 23 # Set optional attribute defaults __defaults__ = {