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
=== modified file 'openlp/plugins/songs/lib/__init__.py'
--- openlp/plugins/songs/lib/__init__.py 2014-06-09 08:59:52 +0000
+++ openlp/plugins/songs/lib/__init__.py 2014-07-14 16:54:11 +0000
@@ -374,7 +374,7 @@
374 :param manager: The song database manager object.374 :param manager: The song database manager object.
375 :param song: The song object.375 :param song: The song object.
376 """376 """
377 from .xml import SongXML377 from .openlyricsxml import SongXML
378378
379 if song.title:379 if song.title:
380 song.title = clean_title(song.title)380 song.title = clean_title(song.title)
381381
=== modified file 'openlp/plugins/songs/lib/importer.py'
--- openlp/plugins/songs/lib/importer.py 2014-07-07 16:21:45 +0000
+++ openlp/plugins/songs/lib/importer.py 2014-07-14 16:54:11 +0000
@@ -52,12 +52,11 @@
52from .importers.propresenter import ProPresenterImport52from .importers.propresenter import ProPresenterImport
53from .importers.worshipassistant import WorshipAssistantImport53from .importers.worshipassistant import WorshipAssistantImport
54from .importers.powerpraise import PowerPraiseImport54from .importers.powerpraise import PowerPraiseImport
55from .importers.presentationmanager import PresentationManagerImport
56
57log = logging.getLogger(__name__)
58
55# Imports that might fail59# Imports that might fail
56
57
58log = logging.getLogger(__name__)
59
60
61try:60try:
62 from .importers.songsoffellowship import SongsOfFellowshipImport61 from .importers.songsoffellowship import SongsOfFellowshipImport
63 HAS_SOF = True62 HAS_SOF = True
@@ -163,16 +162,17 @@
163 OpenSong = 10162 OpenSong = 10
164 PowerPraise = 11163 PowerPraise = 11
165 PowerSong = 12164 PowerSong = 12
166 ProPresenter = 13165 PresentationManager = 13
167 SongBeamer = 14166 ProPresenter = 14
168 SongPro = 15167 SongBeamer = 15
169 SongShowPlus = 16168 SongPro = 16
170 SongsOfFellowship = 17169 SongShowPlus = 17
171 SundayPlus = 18170 SongsOfFellowship = 18
172 WordsOfWorship = 19171 SundayPlus = 19
173 WorshipAssistant = 20172 WordsOfWorship = 20
174 WorshipCenterPro = 21173 WorshipAssistant = 21
175 ZionWorx = 22174 WorshipCenterPro = 22
175 ZionWorx = 23
176176
177 # Set optional attribute defaults177 # Set optional attribute defaults
178 __defaults__ = {178 __defaults__ = {
@@ -282,6 +282,12 @@
282 'invalidSourceMsg': translate('SongsPlugin.ImportWizardForm', 'You need to specify a valid PowerSong 1.0 '282 'invalidSourceMsg': translate('SongsPlugin.ImportWizardForm', 'You need to specify a valid PowerSong 1.0 '
283 'database folder.')283 'database folder.')
284 },284 },
285 PresentationManager: {
286 'class': PresentationManagerImport,
287 'name': 'PresentationManager',
288 'prefix': 'presentationManager',
289 'filter': '%s (*.sng)' % translate('SongsPlugin.ImportWizardForm', 'PresentationManager Song Files')
290 },
285 ProPresenter: {291 ProPresenter: {
286 'class': ProPresenterImport,292 'class': ProPresenterImport,
287 'name': 'ProPresenter',293 'name': 'ProPresenter',
@@ -384,6 +390,7 @@
384 SongFormat.OpenSong,390 SongFormat.OpenSong,
385 SongFormat.PowerPraise,391 SongFormat.PowerPraise,
386 SongFormat.PowerSong,392 SongFormat.PowerSong,
393 SongFormat.PresentationManager,
387 SongFormat.ProPresenter,394 SongFormat.ProPresenter,
388 SongFormat.SongBeamer,395 SongFormat.SongBeamer,
389 SongFormat.SongPro,396 SongFormat.SongPro,
390397
=== added file 'openlp/plugins/songs/lib/importers/presentationmanager.py'
--- openlp/plugins/songs/lib/importers/presentationmanager.py 1970-01-01 00:00:00 +0000
+++ openlp/plugins/songs/lib/importers/presentationmanager.py 2014-07-14 16:54:11 +0000
@@ -0,0 +1,93 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2013 Raoul Snyman #
8# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
9# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
10# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
11# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
12# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
13# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
14# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
15# --------------------------------------------------------------------------- #
16# This program is free software; you can redistribute it and/or modify it #
17# under the terms of the GNU General Public License as published by the Free #
18# Software Foundation; version 2 of the License. #
19# #
20# This program is distributed in the hope that it will be useful, but WITHOUT #
21# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
22# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
23# more details. #
24# #
25# You should have received a copy of the GNU General Public License along #
26# with this program; if not, write to the Free Software Foundation, Inc., 59 #
27# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
28###############################################################################
29"""
30The :mod:`presentationmanager` module provides the functionality for importing
31Presentationmanager song files into the current database.
32"""
33
34import os
35from lxml import objectify
36
37from openlp.core.ui.wizard import WizardStrings
38from .songimport import SongImport
39
40
41class PresentationManagerImport(SongImport):
42 """
43 The :class:`PresentationManagerImport` class provides OpenLP with the
44 ability to import Presentationmanager song files.
45 """
46 def do_import(self):
47 self.import_wizard.progress_bar.setMaximum(len(self.import_source))
48 for file_path in self.import_source:
49 if self.stop_import_flag:
50 return
51 self.import_wizard.increment_progress_bar(WizardStrings.ImportingType % os.path.basename(file_path))
52 root = objectify.parse(open(file_path, 'rb')).getroot()
53 self.process_song(root)
54
55 def process_song(self, root):
56 self.set_defaults()
57 self.title = str(root.attributes.title)
58 self.add_author(str(root.attributes.author))
59 self.copyright = str(root.attributes.copyright)
60 self.ccli_number = str(root.attributes.ccli_number)
61 self.comments = str(root.attributes.comments)
62 verse_order_list = []
63 verse_count = {}
64 duplicates = []
65 for verse in root.verses.verse:
66 original_verse_def = verse.get('id')
67 # Presentation Manager stores duplicate verses instead of a verse order.
68 # We need to create the verse order from that.
69 is_duplicate = False
70 if original_verse_def in duplicates:
71 is_duplicate = True
72 else:
73 duplicates.append(original_verse_def)
74 if original_verse_def.startswith("Verse"):
75 verse_def = 'v'
76 elif original_verse_def.startswith("Chorus") or original_verse_def.startswith("Refrain"):
77 verse_def = 'c'
78 elif original_verse_def.startswith("Bridge"):
79 verse_def = 'b'
80 elif original_verse_def.startswith("End"):
81 verse_def = 'e'
82 else:
83 verse_def = 'o'
84 if not is_duplicate: # Only increment verse number if no duplicate
85 verse_count[verse_def] = verse_count.get(verse_def, 0) + 1
86 verse_def = '%s%d' % (verse_def, verse_count[verse_def])
87 if not is_duplicate: # Only add verse if no duplicate
88 self.add_verse(str(verse).strip(), verse_def)
89 verse_order_list.append(verse_def)
90
91 self.verse_order_list = verse_order_list
92 if not self.finish():
93 self.log_error(self.import_source)
094
=== added file 'tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py'
--- tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py 1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py 2014-07-14 16:54:11 +0000
@@ -0,0 +1,53 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2014 Raoul Snyman #
8# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
9# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
10# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
11# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
12# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
13# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
14# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
15# --------------------------------------------------------------------------- #
16# This program is free software; you can redistribute it and/or modify it #
17# under the terms of the GNU General Public License as published by the Free #
18# Software Foundation; version 2 of the License. #
19# #
20# This program is distributed in the hope that it will be useful, but WITHOUT #
21# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
22# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
23# more details. #
24# #
25# You should have received a copy of the GNU General Public License along #
26# with this program; if not, write to the Free Software Foundation, Inc., 59 #
27# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
28###############################################################################
29"""
30This module contains tests for the PresentationManager song importer.
31"""
32
33import os
34
35from tests.helpers.songfileimport import SongImportTestHelper
36
37TEST_PATH = os.path.abspath(
38 os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'presentationmanagersongs'))
39
40
41class TestSongShowPlusFileImport(SongImportTestHelper):
42
43 def __init__(self, *args, **kwargs):
44 self.importer_class_name = 'PresentationManagerImport'
45 self.importer_module_name = 'presentationmanager'
46 super(TestSongShowPlusFileImport, self).__init__(*args, **kwargs)
47
48 def test_song_import(self):
49 """
50 Test that loading a PresentationManager file works correctly
51 """
52 self.file_import([os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.sng')],
53 self.load_external_result_data(os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.json')))
054
=== added directory 'tests/resources/presentationmanagersongs'
=== added file 'tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json'
--- tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json 1970-01-01 00:00:00 +0000
+++ tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.json 2014-07-14 16:54:11 +0000
@@ -0,0 +1,25 @@
1{
2 "title": "Great Is Thy Faithfulness",
3 "authors": [
4 "Thomas O. Chisholm (1866-1960)"
5 ],
6 "verse_order_list": ["v1", "c1", "v2", "c1", "v3", "c1"],
7 "verses": [
8 [
9 "\"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.",
10 "v1"
11 ],
12 [
13 "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!",
14 "c1"
15 ],
16 [
17 "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.",
18 "v2"
19 ],
20 [
21 "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!",
22 "v3"
23 ]
24 ]
25}
026
=== added file 'tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng'
--- tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng 1970-01-01 00:00:00 +0000
+++ tests/resources/presentationmanagersongs/Great Is Thy Faithfulness.sng 2014-07-14 16:54:11 +0000
@@ -0,0 +1,51 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<song xmlns="creativelifestyles/song">
3<attributes>
4<title>Great Is Thy Faithfulness</title>
5<author>Thomas O. Chisholm (1866-1960)</author>
6<copyright></copyright>
7<ccli_number></ccli_number>
8<comments></comments>
9</attributes>
10<verses>
11<verse id="Verse 1">
12"Great is Thy faithfulness", O God my Father.
13There is no shadow of turning with Thee;
14Thou changest not, Thy compassions they fail not,
15As Thou hast been Thou forever shall be.
16</verse>
17<verse id="Chorus">
18Great is Thy faithfulness!
19Great is Thy faithfulness!
20Morning by morning new mercies I see!
21All I have needed Thy hand hath provided -
22"Great is Thy faithfulness", Lord, unto me!
23</verse>
24<verse id="Verse 2">
25Summer and winter, and springtime and harvest,
26Sun, moon, and stars in their courses above,
27Join with all nature in manifold witness,
28To Thy great faithfulness, mercy and love.
29</verse>
30<verse id="Chorus">
31Great is Thy faithfulness!
32Great is Thy faithfulness!
33Morning by morning new mercies I see!
34All I have needed Thy hand hath provided -
35"Great is Thy faithfulness", Lord, unto me!
36</verse>
37<verse id="Verse 3">
38Pardon for sin and a peace that endureth,
39Thine own dear presence to cheer and to guide,
40Strength for today and bright hope for tomorrow,
41Blessings all mine, with ten thousand beside!
42</verse>
43<verse id="Chorus">
44Great is Thy faithfulness!
45Great is Thy faithfulness!
46Morning by morning new mercies I see!
47All I have needed Thy hand hath provided -
48"Great is Thy faithfulness", Lord, unto me!
49</verse>
50</verses>
51</song>