Merge lp:~tomasgroth/openlp/song-import-fixes into lp:openlp
- song-import-fixes
- Merge into trunk
Proposed by
Tomas Groth
Status: | Merged |
---|---|
Merged at revision: | 2564 |
Proposed branch: | lp:~tomasgroth/openlp/song-import-fixes |
Merge into: | lp:openlp |
Diff against target: |
284 lines (+158/-11) 6 files modified
openlp/plugins/songs/lib/importers/worshipcenterpro.py (+35/-2) openlp/plugins/songs/lib/importers/zionworx.py (+7/-7) tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py (+21/-2) tests/functional/openlp_plugins/songs/test_zionworximport.py (+20/-0) tests/resources/zionworxsongs/zionworx.csv (+45/-0) tests/resources/zionworxsongs/zionworx.json (+30/-0) |
To merge this branch: | bzr merge lp:~tomasgroth/openlp/song-import-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raoul Snyman | Approve | ||
Review via email: mp+276032@code.launchpad.net |
Commit message
Description of the change
Made ZionWorx importer work under python3, fixes bug 1510282.
Improved WorshipCenter Pro import, support more fields and verse types.
To post a comment you must log in.
Revision history for this message
Tomas Groth (tomasgroth) wrote : | # |
Revision history for this message
Raoul Snyman (raoul-snyman) : | # |
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/importers/worshipcenterpro.py' |
2 | --- openlp/plugins/songs/lib/importers/worshipcenterpro.py 2015-01-19 08:34:29 +0000 |
3 | +++ openlp/plugins/songs/lib/importers/worshipcenterpro.py 2015-10-28 17:07:14 +0000 |
4 | @@ -24,7 +24,7 @@ |
5 | a WorshipCenter Pro database into the OpenLP database. |
6 | """ |
7 | import logging |
8 | - |
9 | +import re |
10 | import pyodbc |
11 | |
12 | from openlp.core.common import translate |
13 | @@ -71,8 +71,41 @@ |
14 | break |
15 | self.set_defaults() |
16 | self.title = songs[song]['TITLE'] |
17 | + if 'AUTHOR' in songs[song]: |
18 | + self.parse_author(songs[song]['AUTHOR']) |
19 | + if 'CCLISONGID' in songs[song]: |
20 | + self.ccli_number = songs[song]['CCLISONGID'] |
21 | + if 'COMMENTS' in songs[song]: |
22 | + self.add_comment(songs[song]['COMMENTS']) |
23 | + if 'COPY' in songs[song]: |
24 | + self.add_copyright(songs[song]['COPY']) |
25 | + if 'SUBJECT' in songs[song]: |
26 | + self.topics.append(songs[song]['SUBJECT']) |
27 | lyrics = songs[song]['LYRICS'].strip('&crlf;&crlf;') |
28 | for verse in lyrics.split('&crlf;&crlf;'): |
29 | verse = verse.replace('&crlf;', '\n') |
30 | - self.add_verse(verse) |
31 | + marker_type = 'v' |
32 | + # Find verse markers if any |
33 | + marker_start = verse.find('<') |
34 | + if marker_start > -1: |
35 | + marker_end = verse.find('>') |
36 | + marker = verse[marker_start + 1:marker_end] |
37 | + # Identify the marker type |
38 | + if 'REFRAIN' in marker or 'CHORUS' in marker: |
39 | + marker_type = 'c' |
40 | + elif 'BRIDGE' in marker: |
41 | + marker_type = 'b' |
42 | + elif 'PRECHORUS' in marker: |
43 | + marker_type = 'p' |
44 | + elif 'END' in marker: |
45 | + marker_type = 'e' |
46 | + elif 'INTRO' in marker: |
47 | + marker_type = 'i' |
48 | + elif 'TAG' in marker: |
49 | + marker_type = 'o' |
50 | + else: |
51 | + marker_type = 'v' |
52 | + # Strip tags from text |
53 | + verse = re.sub('<[^<]+?>', '', verse) |
54 | + self.add_verse(verse.strip(), marker_type) |
55 | self.finish() |
56 | |
57 | === modified file 'openlp/plugins/songs/lib/importers/zionworx.py' |
58 | --- openlp/plugins/songs/lib/importers/zionworx.py 2015-03-09 20:57:39 +0000 |
59 | +++ openlp/plugins/songs/lib/importers/zionworx.py 2015-10-28 17:07:14 +0000 |
60 | @@ -75,7 +75,8 @@ |
61 | """ |
62 | Receive a CSV file (from a ZionWorx database dump) to import. |
63 | """ |
64 | - with open(self.import_source, 'rb') as songs_file: |
65 | + # Encoding should always be ISO-8859-1 |
66 | + with open(self.import_source, 'rt', encoding='ISO-8859-1') as songs_file: |
67 | field_names = ['SongNum', 'Title1', 'Title2', 'Lyrics', 'Writer', 'Copyright', 'Keywords', |
68 | 'DefaultStyle'] |
69 | songs_reader = csv.DictReader(songs_file, field_names) |
70 | @@ -112,10 +113,10 @@ |
71 | if line and not line.isspace(): |
72 | verse += line + '\n' |
73 | elif verse: |
74 | - self.add_verse(verse) |
75 | + self.add_verse(verse, 'v') |
76 | verse = '' |
77 | if verse: |
78 | - self.add_verse(verse) |
79 | + self.add_verse(verse, 'v') |
80 | title = self.title |
81 | if not self.finish(): |
82 | self.log_error(translate('SongsPlugin.ZionWorxImport', 'Record %d') % index + |
83 | @@ -123,8 +124,7 @@ |
84 | |
85 | def _decode(self, str): |
86 | """ |
87 | - Decodes CSV input to unicode, stripping all control characters (except new lines). |
88 | + Strips all control characters (except new lines). |
89 | """ |
90 | - # This encoding choice seems OK. ZionWorx has no option for setting the |
91 | - # encoding for its songs, so we assume encoding is always the same. |
92 | - return str(str, 'cp1252').translate(CONTROL_CHARS_MAP) |
93 | + # ZionWorx has no option for setting the encoding for its songs, so we assume encoding is always the same. |
94 | + return str.translate(CONTROL_CHARS_MAP) |
95 | |
96 | === modified file 'tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py' |
97 | --- tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py 2015-01-19 08:34:29 +0000 |
98 | +++ tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py 2015-10-28 17:07:14 +0000 |
99 | @@ -67,6 +67,10 @@ |
100 | |
101 | |
102 | RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'), |
103 | + TestRecord(1, 'AUTHOR', 'John Newton'), |
104 | + TestRecord(1, 'CCLISONGID', '12345'), |
105 | + TestRecord(1, 'COMMENTS', 'The original version'), |
106 | + TestRecord(1, 'COPY', 'Public Domain'), |
107 | TestRecord( |
108 | 1, 'LYRICS', |
109 | 'Amazing grace! How&crlf;sweet the sound&crlf;That saved a wretch like me!&crlf;' |
110 | @@ -113,7 +117,10 @@ |
111 | ('The earth shall soon\ndissolve like snow,\nThe sun forbear to shine;\nBut God, Who called\n' |
112 | 'me here below,\nShall be forever mine.'), |
113 | ('When we\'ve been there\nten thousand years,\nBright shining as the sun,\n' |
114 | - 'We\'ve no less days to\nsing God\'s praise\nThan when we\'d first begun.')]}, |
115 | + 'We\'ve no less days to\nsing God\'s praise\nThan when we\'d first begun.')], |
116 | + 'author': 'John Newton', |
117 | + 'comments': 'The original version', |
118 | + 'copyright': 'Public Domain'}, |
119 | {'title': 'Beautiful Garden Of Prayer, The', |
120 | 'verses': [ |
121 | ('There\'s a garden where\nJesus is waiting,\nThere\'s a place that\nis wondrously fair,\n' |
122 | @@ -191,6 +198,9 @@ |
123 | mocked_manager = MagicMock() |
124 | mocked_import_wizard = MagicMock() |
125 | mocked_add_verse = MagicMock() |
126 | + mocked_parse_author = MagicMock() |
127 | + mocked_add_comment = MagicMock() |
128 | + mocked_add_copyright = MagicMock() |
129 | mocked_finish = MagicMock() |
130 | mocked_pyodbc.connect().cursor().fetchall.return_value = RECORDSET_TEST_DATA |
131 | mocked_translate.return_value = 'Translated Text' |
132 | @@ -198,6 +208,9 @@ |
133 | importer.import_source = 'import_source' |
134 | importer.import_wizard = mocked_import_wizard |
135 | importer.add_verse = mocked_add_verse |
136 | + importer.parse_author = mocked_parse_author |
137 | + importer.add_comment = mocked_add_comment |
138 | + importer.add_copyright = mocked_add_copyright |
139 | importer.stop_import_flag = False |
140 | importer.finish = mocked_finish |
141 | |
142 | @@ -220,6 +233,12 @@ |
143 | verse_calls = song_data['verses'] |
144 | add_verse_call_count += len(verse_calls) |
145 | for call in verse_calls: |
146 | - mocked_add_verse.assert_any_call(call) |
147 | + mocked_add_verse.assert_any_call(call, 'v') |
148 | + if 'author' in song_data: |
149 | + mocked_parse_author.assert_any_call(song_data['author']) |
150 | + if 'comments' in song_data: |
151 | + mocked_add_comment.assert_any_call(song_data['comments']) |
152 | + if 'copyright' in song_data: |
153 | + mocked_add_copyright.assert_any_call(song_data['copyright']) |
154 | self.assertEqual(mocked_add_verse.call_count, add_verse_call_count, |
155 | 'Incorrect number of calls made to add_verse') |
156 | |
157 | === modified file 'tests/functional/openlp_plugins/songs/test_zionworximport.py' |
158 | --- tests/functional/openlp_plugins/songs/test_zionworximport.py 2015-01-18 13:39:21 +0000 |
159 | +++ tests/functional/openlp_plugins/songs/test_zionworximport.py 2015-10-28 17:07:14 +0000 |
160 | @@ -22,14 +22,19 @@ |
161 | """ |
162 | This module contains tests for the ZionWorx song importer. |
163 | """ |
164 | +import os |
165 | |
166 | from unittest import TestCase |
167 | |
168 | from tests.functional import MagicMock, patch |
169 | +from tests.helpers.songfileimport import SongImportTestHelper |
170 | from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport |
171 | from openlp.plugins.songs.lib.importers.songimport import SongImport |
172 | from openlp.core.common import Registry |
173 | |
174 | +TEST_PATH = os.path.abspath( |
175 | + os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'zionworxsongs')) |
176 | + |
177 | |
178 | class TestZionWorxImport(TestCase): |
179 | """ |
180 | @@ -54,3 +59,18 @@ |
181 | |
182 | # THEN: The importer should be an instance of SongImport |
183 | self.assertIsInstance(importer, SongImport) |
184 | + |
185 | + |
186 | +class TestZionWorxFileImport(SongImportTestHelper): |
187 | + |
188 | + def __init__(self, *args, **kwargs): |
189 | + self.importer_class_name = 'ZionWorxImport' |
190 | + self.importer_module_name = 'zionworx' |
191 | + super(TestZionWorxFileImport, self).__init__(*args, **kwargs) |
192 | + |
193 | + def test_song_import(self): |
194 | + """ |
195 | + Test that loading an ZionWorx file works correctly on various files |
196 | + """ |
197 | + self.file_import(os.path.join(TEST_PATH, 'zionworx.csv'), |
198 | + self.load_external_result_data(os.path.join(TEST_PATH, 'zionworx.json'))) |
199 | |
200 | === added directory 'tests/resources/zionworxsongs' |
201 | === added file 'tests/resources/zionworxsongs/zionworx.csv' |
202 | --- tests/resources/zionworxsongs/zionworx.csv 1970-01-01 00:00:00 +0000 |
203 | +++ tests/resources/zionworxsongs/zionworx.csv 2015-10-28 17:07:14 +0000 |
204 | @@ -0,0 +1,45 @@ |
205 | +"1","Crown Him With Many Crowns",,"Crown him with many crowns, |
206 | +The Lamb upon His throne; |
207 | +Hark, how the heavenly anthem drowns |
208 | +All music but its own! |
209 | +Awake, my soul, and sing |
210 | +Of Him who died for thee, |
211 | +And hail Him as thy matchless King |
212 | +Through all eternity. |
213 | + |
214 | +Crown Him the Lord of life, |
215 | +Who triumphed o'er the grave |
216 | +And rose victorious in the strife |
217 | +For those He came to save: |
218 | +His glories now we sing, |
219 | +Who died and rose on high, |
220 | +Who died eternal life to bring |
221 | +And lives that death may die. |
222 | + |
223 | +Crown Him the Lord of love; |
224 | +Behold His hands and side, |
225 | +Those wounds yet visible above |
226 | +In beauty glorified: |
227 | +No angel in the sky |
228 | +Can fully bear that sight, |
229 | +But downward bends His burning eye |
230 | +At mysteries so bright. |
231 | + |
232 | +Crown Him the Lord of peace, |
233 | +Whose power a sceptre sways |
234 | +From pole to pole, that wars may cease, |
235 | +And all be prayer and praise: |
236 | +His reign shall know no end, |
237 | +And round His piercèd feet |
238 | +Fair flowers of paradise extend |
239 | +Their fragrance ever sweet. |
240 | + |
241 | +Crown Him the Lord of years, |
242 | +The Potentate of time, |
243 | +Creator of the rolling spheres, |
244 | +Ineffably sublime! |
245 | +All hail, Redeemer, hail! |
246 | +For Thou hast died for me; |
247 | +Thy praise shall never, never fail |
248 | +Throughout eternity. |
249 | +","Matthew Bridges","Public Domain",, |
250 | |
251 | === added file 'tests/resources/zionworxsongs/zionworx.json' |
252 | --- tests/resources/zionworxsongs/zionworx.json 1970-01-01 00:00:00 +0000 |
253 | +++ tests/resources/zionworxsongs/zionworx.json 2015-10-28 17:07:14 +0000 |
254 | @@ -0,0 +1,30 @@ |
255 | +{ |
256 | + "authors": [ |
257 | + "Matthew Bridges" |
258 | + ], |
259 | + "copyright": "Public Domain", |
260 | + "title": "Crown Him With Many Crowns", |
261 | + "verse_order_list": [], |
262 | + "verses": [ |
263 | + [ |
264 | + "Crown him with many crowns,\nThe Lamb upon His throne;\nHark, how the heavenly anthem drowns\nAll music but its own!\nAwake, my soul, and sing\nOf Him who died for thee,\nAnd hail Him as thy matchless King\nThrough all eternity.\n", |
265 | + "v" |
266 | + ], |
267 | + [ |
268 | + "Crown Him the Lord of life,\nWho triumphed o'er the grave\nAnd rose victorious in the strife\nFor those He came to save:\nHis glories now we sing,\nWho died and rose on high,\nWho died eternal life to bring\nAnd lives that death may die.\n", |
269 | + "v" |
270 | + ], |
271 | + [ |
272 | + "Crown Him the Lord of love;\nBehold His hands and side,\nThose wounds yet visible above\nIn beauty glorified:\nNo angel in the sky\nCan fully bear that sight,\nBut downward bends His burning eye\nAt mysteries so bright.\n", |
273 | + "v" |
274 | + ], |
275 | + [ |
276 | + "Crown Him the Lord of peace,\nWhose power a sceptre sways\nFrom pole to pole, that wars may cease,\nAnd all be prayer and praise:\nHis reign shall know no end,\nAnd round His piercèd feet\nFair flowers of paradise extend\nTheir fragrance ever sweet.\n", |
277 | + "v" |
278 | + ], |
279 | + [ |
280 | + "Crown Him the Lord of years,\nThe Potentate of time,\nCreator of the rolling spheres,\nIneffably sublime!\nAll hail, Redeemer, hail!\nFor Thou hast died for me;\nThy praise shall never, never fail\nThroughout eternity.\n", |
281 | + "v" |
282 | + ] |
283 | + ] |
284 | +} |
lp:~tomasgroth/openlp/song-import-fixes (revision 2568) ci.openlp. io/job/ Branch- 01-Pull/ 1163/ ci.openlp. io/job/ Branch- 02-Functional- Tests/1086/ ci.openlp. io/job/ Branch- 03-Interface- Tests/1027/ ci.openlp. io/job/ Branch- 04a-Windows_ Functional_ Tests/874/ ci.openlp. io/job/ Branch- 04b-Windows_ Interface_ Tests/470/ ci.openlp. io/job/ Branch- 05a-Code_ Analysis/ 590/ ci.openlp. io/job/ Branch- 05b-Test_ Coverage/ 461/
[SUCCESS] https//
[SUCCESS] https//
[SUCCESS] https//
[SUCCESS] https//
[SUCCESS] https//
[SUCCESS] https//
[SUCCESS] https//