Merge lp:~sam92/openlp/presentationmanager-import into lp:openlp

Proposed by Samuel Mehrbrodt
Status: Merged
Approved by: Tim Bentley
Approved revision: 2404
Merged at revision: 2407
Proposed branch: lp:~sam92/openlp/presentationmanager-import
Merge into: lp:openlp
Diff against target: 325 lines (+245/-16)
6 files modified
openlp/plugins/songs/lib/__init__.py (+1/-1)
openlp/plugins/songs/lib/importer.py (+22/-15)
openlp/plugins/songs/lib/importers/presentationmanager.py (+93/-0)
tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py (+53/-0)
tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json (+25/-0)
tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng (+51/-0)
To merge this branch: bzr merge lp:~sam92/openlp/presentationmanager-import
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Raoul Snyman Approve
Tomas Groth Approve
Review via email: mp+226707@code.launchpad.net

This proposal supersedes a proposal from 2014-07-07.

To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

How can if Fail when python claims there is a missing end of file!

review: Needs Fixing
Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

If I read the code correctly you do create a verse order during the import, yet in the test the expected verse_order_list is an empty list. Why is that?

review: Needs Information
Revision history for this message
Samuel Mehrbrodt (sam92) wrote : Posted in a previous version of this proposal

Thanks for the review, I've fixed those issues.
Once my powerpraise import branch is in trunk, I'll merge that in here and resubmit.

Revision history for this message
Tomas Groth (tomasgroth) :
review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Looks OK to me.

review: Approve
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/plugins/songs/lib/__init__.py'
2--- openlp/plugins/songs/lib/__init__.py 2014-06-09 08:59:52 +0000
3+++ openlp/plugins/songs/lib/__init__.py 2014-07-14 16:54:11 +0000
4@@ -374,7 +374,7 @@
5 :param manager: The song database manager object.
6 :param song: The song object.
7 """
8- from .xml import SongXML
9+ from .openlyricsxml import SongXML
10
11 if song.title:
12 song.title = clean_title(song.title)
13
14=== modified file 'openlp/plugins/songs/lib/importer.py'
15--- openlp/plugins/songs/lib/importer.py 2014-07-07 16:21:45 +0000
16+++ openlp/plugins/songs/lib/importer.py 2014-07-14 16:54:11 +0000
17@@ -52,12 +52,11 @@
18 from .importers.propresenter import ProPresenterImport
19 from .importers.worshipassistant import WorshipAssistantImport
20 from .importers.powerpraise import PowerPraiseImport
21+from .importers.presentationmanager import PresentationManagerImport
22+
23+log = logging.getLogger(__name__)
24+
25 # Imports that might fail
26-
27-
28-log = logging.getLogger(__name__)
29-
30-
31 try:
32 from .importers.songsoffellowship import SongsOfFellowshipImport
33 HAS_SOF = True
34@@ -163,16 +162,17 @@
35 OpenSong = 10
36 PowerPraise = 11
37 PowerSong = 12
38- ProPresenter = 13
39- SongBeamer = 14
40- SongPro = 15
41- SongShowPlus = 16
42- SongsOfFellowship = 17
43- SundayPlus = 18
44- WordsOfWorship = 19
45- WorshipAssistant = 20
46- WorshipCenterPro = 21
47- ZionWorx = 22
48+ PresentationManager = 13
49+ ProPresenter = 14
50+ SongBeamer = 15
51+ SongPro = 16
52+ SongShowPlus = 17
53+ SongsOfFellowship = 18
54+ SundayPlus = 19
55+ WordsOfWorship = 20
56+ WorshipAssistant = 21
57+ WorshipCenterPro = 22
58+ ZionWorx = 23
59
60 # Set optional attribute defaults
61 __defaults__ = {
62@@ -282,6 +282,12 @@
63 'invalidSourceMsg': translate('SongsPlugin.ImportWizardForm', 'You need to specify a valid PowerSong 1.0 '
64 'database folder.')
65 },
66+ PresentationManager: {
67+ 'class': PresentationManagerImport,
68+ 'name': 'PresentationManager',
69+ 'prefix': 'presentationManager',
70+ 'filter': '%s (*.sng)' % translate('SongsPlugin.ImportWizardForm', 'PresentationManager Song Files')
71+ },
72 ProPresenter: {
73 'class': ProPresenterImport,
74 'name': 'ProPresenter',
75@@ -384,6 +390,7 @@
76 SongFormat.OpenSong,
77 SongFormat.PowerPraise,
78 SongFormat.PowerSong,
79+ SongFormat.PresentationManager,
80 SongFormat.ProPresenter,
81 SongFormat.SongBeamer,
82 SongFormat.SongPro,
83
84=== added file 'openlp/plugins/songs/lib/importers/presentationmanager.py'
85--- openlp/plugins/songs/lib/importers/presentationmanager.py 1970-01-01 00:00:00 +0000
86+++ openlp/plugins/songs/lib/importers/presentationmanager.py 2014-07-14 16:54:11 +0000
87@@ -0,0 +1,93 @@
88+# -*- coding: utf-8 -*-
89+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
90+
91+###############################################################################
92+# OpenLP - Open Source Lyrics Projection #
93+# --------------------------------------------------------------------------- #
94+# Copyright (c) 2008-2013 Raoul Snyman #
95+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
96+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
97+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
98+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
99+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
100+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
101+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
102+# --------------------------------------------------------------------------- #
103+# This program is free software; you can redistribute it and/or modify it #
104+# under the terms of the GNU General Public License as published by the Free #
105+# Software Foundation; version 2 of the License. #
106+# #
107+# This program is distributed in the hope that it will be useful, but WITHOUT #
108+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
109+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
110+# more details. #
111+# #
112+# You should have received a copy of the GNU General Public License along #
113+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
114+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
115+###############################################################################
116+"""
117+The :mod:`presentationmanager` module provides the functionality for importing
118+Presentationmanager song files into the current database.
119+"""
120+
121+import os
122+from lxml import objectify
123+
124+from openlp.core.ui.wizard import WizardStrings
125+from .songimport import SongImport
126+
127+
128+class PresentationManagerImport(SongImport):
129+ """
130+ The :class:`PresentationManagerImport` class provides OpenLP with the
131+ ability to import Presentationmanager song files.
132+ """
133+ def do_import(self):
134+ self.import_wizard.progress_bar.setMaximum(len(self.import_source))
135+ for file_path in self.import_source:
136+ if self.stop_import_flag:
137+ return
138+ self.import_wizard.increment_progress_bar(WizardStrings.ImportingType % os.path.basename(file_path))
139+ root = objectify.parse(open(file_path, 'rb')).getroot()
140+ self.process_song(root)
141+
142+ def process_song(self, root):
143+ self.set_defaults()
144+ self.title = str(root.attributes.title)
145+ self.add_author(str(root.attributes.author))
146+ self.copyright = str(root.attributes.copyright)
147+ self.ccli_number = str(root.attributes.ccli_number)
148+ self.comments = str(root.attributes.comments)
149+ verse_order_list = []
150+ verse_count = {}
151+ duplicates = []
152+ for verse in root.verses.verse:
153+ original_verse_def = verse.get('id')
154+ # Presentation Manager stores duplicate verses instead of a verse order.
155+ # We need to create the verse order from that.
156+ is_duplicate = False
157+ if original_verse_def in duplicates:
158+ is_duplicate = True
159+ else:
160+ duplicates.append(original_verse_def)
161+ if original_verse_def.startswith("Verse"):
162+ verse_def = 'v'
163+ elif original_verse_def.startswith("Chorus") or original_verse_def.startswith("Refrain"):
164+ verse_def = 'c'
165+ elif original_verse_def.startswith("Bridge"):
166+ verse_def = 'b'
167+ elif original_verse_def.startswith("End"):
168+ verse_def = 'e'
169+ else:
170+ verse_def = 'o'
171+ if not is_duplicate: # Only increment verse number if no duplicate
172+ verse_count[verse_def] = verse_count.get(verse_def, 0) + 1
173+ verse_def = '%s%d' % (verse_def, verse_count[verse_def])
174+ if not is_duplicate: # Only add verse if no duplicate
175+ self.add_verse(str(verse).strip(), verse_def)
176+ verse_order_list.append(verse_def)
177+
178+ self.verse_order_list = verse_order_list
179+ if not self.finish():
180+ self.log_error(self.import_source)
181
182=== added file 'tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py'
183--- tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py 1970-01-01 00:00:00 +0000
184+++ tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py 2014-07-14 16:54:11 +0000
185@@ -0,0 +1,53 @@
186+# -*- coding: utf-8 -*-
187+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
188+
189+###############################################################################
190+# OpenLP - Open Source Lyrics Projection #
191+# --------------------------------------------------------------------------- #
192+# Copyright (c) 2008-2014 Raoul Snyman #
193+# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
194+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
195+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
196+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
197+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
198+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
199+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
200+# --------------------------------------------------------------------------- #
201+# This program is free software; you can redistribute it and/or modify it #
202+# under the terms of the GNU General Public License as published by the Free #
203+# Software Foundation; version 2 of the License. #
204+# #
205+# This program is distributed in the hope that it will be useful, but WITHOUT #
206+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
207+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
208+# more details. #
209+# #
210+# You should have received a copy of the GNU General Public License along #
211+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
212+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
213+###############################################################################
214+"""
215+This module contains tests for the PresentationManager song importer.
216+"""
217+
218+import os
219+
220+from tests.helpers.songfileimport import SongImportTestHelper
221+
222+TEST_PATH = os.path.abspath(
223+ os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'presentationmanagersongs'))
224+
225+
226+class TestSongShowPlusFileImport(SongImportTestHelper):
227+
228+ def __init__(self, *args, **kwargs):
229+ self.importer_class_name = 'PresentationManagerImport'
230+ self.importer_module_name = 'presentationmanager'
231+ super(TestSongShowPlusFileImport, self).__init__(*args, **kwargs)
232+
233+ def test_song_import(self):
234+ """
235+ Test that loading a PresentationManager file works correctly
236+ """
237+ self.file_import([os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.sng')],
238+ self.load_external_result_data(os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.json')))
239
240=== added directory 'tests/resources/presentationmanagersongs'
241=== added file 'tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json'
242--- tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json 1970-01-01 00:00:00 +0000
243+++ tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json 2014-07-14 16:54:11 +0000
244@@ -0,0 +1,25 @@
245+{
246+ "title": "Great Is Thy Faithfulness",
247+ "authors": [
248+ "Thomas O. Chisholm (1866-1960)"
249+ ],
250+ "verse_order_list": ["v1", "c1", "v2", "c1", "v3", "c1"],
251+ "verses": [
252+ [
253+ "\"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.",
254+ "v1"
255+ ],
256+ [
257+ "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!",
258+ "c1"
259+ ],
260+ [
261+ "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.",
262+ "v2"
263+ ],
264+ [
265+ "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!",
266+ "v3"
267+ ]
268+ ]
269+}
270
271=== added file 'tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng'
272--- tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng 1970-01-01 00:00:00 +0000
273+++ tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng 2014-07-14 16:54:11 +0000
274@@ -0,0 +1,51 @@
275+<?xml version="1.0" encoding="UTF-8"?>
276+<song xmlns="creativelifestyles/song">
277+<attributes>
278+<title>Great Is Thy Faithfulness</title>
279+<author>Thomas O. Chisholm (1866-1960)</author>
280+<copyright></copyright>
281+<ccli_number></ccli_number>
282+<comments></comments>
283+</attributes>
284+<verses>
285+<verse id="Verse 1">
286+"Great is Thy faithfulness", O God my Father.
287+There is no shadow of turning with Thee;
288+Thou changest not, Thy compassions they fail not,
289+As Thou hast been Thou forever shall be.
290+</verse>
291+<verse id="Chorus">
292+Great is Thy faithfulness!
293+Great is Thy faithfulness!
294+Morning by morning new mercies I see!
295+All I have needed Thy hand hath provided -
296+"Great is Thy faithfulness", Lord, unto me!
297+</verse>
298+<verse id="Verse 2">
299+Summer and winter, and springtime and harvest,
300+Sun, moon, and stars in their courses above,
301+Join with all nature in manifold witness,
302+To Thy great faithfulness, mercy and love.
303+</verse>
304+<verse id="Chorus">
305+Great is Thy faithfulness!
306+Great is Thy faithfulness!
307+Morning by morning new mercies I see!
308+All I have needed Thy hand hath provided -
309+"Great is Thy faithfulness", Lord, unto me!
310+</verse>
311+<verse id="Verse 3">
312+Pardon for sin and a peace that endureth,
313+Thine own dear presence to cheer and to guide,
314+Strength for today and bright hope for tomorrow,
315+Blessings all mine, with ten thousand beside!
316+</verse>
317+<verse id="Chorus">
318+Great is Thy faithfulness!
319+Great is Thy faithfulness!
320+Morning by morning new mercies I see!
321+All I have needed Thy hand hath provided -
322+"Great is Thy faithfulness", Lord, unto me!
323+</verse>
324+</verses>
325+</song>