forked from openlp/openlp
Add Presentation Manager import
Fixes: https://launchpad.net/bugs/957017
This commit is contained in:
parent
046f661d37
commit
b7a141f75c
93
openlp/plugins/songs/lib/presentationmanagerimport.py
Normal file
93
openlp/plugins/songs/lib/presentationmanagerimport.py
Normal file
@ -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)
|
@ -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')))
|
@ -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"
|
||||
]
|
||||
]
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<song xmlns="creativelifestyles/song">
|
||||
<attributes>
|
||||
<title>Great Is Thy Faithfulness</title>
|
||||
<author>Thomas O. Chisholm (1866-1960)</author>
|
||||
<copyright></copyright>
|
||||
<ccli_number></ccli_number>
|
||||
<comments></comments>
|
||||
</attributes>
|
||||
<verses>
|
||||
<verse id="Verse 1">
|
||||
"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.
|
||||
</verse>
|
||||
<verse id="Chorus">
|
||||
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!
|
||||
</verse>
|
||||
<verse id="Verse 2">
|
||||
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.
|
||||
</verse>
|
||||
<verse id="Chorus">
|
||||
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!
|
||||
</verse>
|
||||
<verse id="Verse 3">
|
||||
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!
|
||||
</verse>
|
||||
<verse id="Chorus">
|
||||
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!
|
||||
</verse>
|
||||
</verses>
|
||||
</song>
|
Loading…
Reference in New Issue
Block a user