Fix SongPro import. Fixes bug 1489376.

Fixes: https://launchpad.net/bugs/1489376
This commit is contained in:
Tomas Groth 2015-08-27 12:24:24 +01:00
parent f98c35df94
commit 4488fedfdc
4 changed files with 220 additions and 3 deletions

View File

@ -65,21 +65,21 @@ class SongProImport(SongImport):
"""
Initialise the SongPro importer.
"""
SongImport.__init__(self, manager, **kwargs)
super(SongProImport, self).__init__(manager, **kwargs)
def do_import(self):
"""
Receive a single file or a list of files to import.
"""
self.encoding = None
with open(self.import_source, 'r') as songs_file:
with open(self.import_source, 'rt') as songs_file:
self.import_wizard.progress_bar.setMaximum(0)
tag = ''
text = ''
for file_line in songs_file:
if self.stop_import_flag:
break
file_line = str(file_line, 'cp1252')
file_line = file_line
file_text = file_line.rstrip()
if file_text and file_text[0] == '#':
self.process_section(tag, text.rstrip())
@ -87,6 +87,7 @@ class SongProImport(SongImport):
text = ''
else:
text += file_line
self.finish()
def process_section(self, tag, text):
"""

View File

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2015 OpenLP Developers #
# --------------------------------------------------------------------------- #
# 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:`songproimport` module provides the functionality for importing
SongPro song files into the current installation database.
"""
import os
from tests.helpers.songfileimport import SongImportTestHelper
TEST_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'songprosongs'))
class TestSongProFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'SongProImport'
self.importer_module_name = 'songpro'
super(TestSongProFileImport, self).__init__(*args, **kwargs)
def test_song_import(self):
"""
Test that loading an SongPro file works correctly
"""
self.file_import(os.path.join(TEST_PATH, 'amazing-grace.txt'),
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))

View File

@ -0,0 +1,34 @@
{
"title": "Amazing Grace",
"authors": [
"Words: John Newton (1725-1807)"
],
"copyright" : "Public Domain",
"verse_order_list": ["V1", "V2", "V3", "V4", "V5", "V6"],
"verses": [
[
"Amazing Grace! how sweet the sound\nThat saved a wretch like me;\nI once was lost, but now am found,\nWas blind, but now I see.",
"V"
],
[
"'Twas grace that taught my heart to fear,\nAnd grace my fears relieved;\nHow precious did that grace appear,\nThe hour I first believed!",
"V"
],
[
"Through many dangers, toils and snares\nI have already come;\n'Tis grace that brought me safe thus far,\nAnd grace will lead me home.",
"V"
],
[
"The Lord has promised good to me,\nHis word my hope secures;\nHe will my shield and portion be\nAs long as life endures.",
"V"
],
[
"Yes, when this heart and flesh shall fail,\nAnd mortal life shall cease,\nI shall possess within the veil\nA life of joy and peace.",
"V"
],
[
"When we've been there a thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise\nThan when we first begun.",
"V"
]
]
}

View File

@ -0,0 +1,135 @@
#T
Amazing Grace
#C
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#1
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 Amazing Grace! how sweet the sound
\par That saved a wretch like me;
\par I once was lost, but now am found,
\par Was blind, but now I see.
\par }
#2
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 'Twas grace that taught my heart to fear,
\par And grace my fears relieved;
\par How precious did that grace appear,
\par The hour I first believed!
\par }
#3
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 Through many dangers, toils and snares
\par I have already come;
\par 'Tis grace that brought me safe thus far,
\par And grace will lead me home.
\par }
#4
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang2057\f0\fs20 The Lord has promised good to me,
\par His word my hope secures;
\par He will my shield and portion be
\par As long as life endures.
\par }
#5
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang1033\f0\fs20 Yes, when this heart and flesh shall fail,
\par And mortal life shall cease,
\par I shall possess within the veil
\par A life of joy and peace.
\par }
#6
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang1033\f0\fs20 When we've been there a thousand years,
\par Bright shining as the sun,
\par We've no less days to sing God's praise
\par Than when we first begun.
\par }
#7
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#D
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#B
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#PR
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#MS
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#C2
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#NT
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20
\par }
#A
Words: John Newton (1725-1807)
#R
Public Domain
#O
123456
#F
Arial
#FS
34
#I
False
#BD
True
#BE
True
#FC
16777215
#BC
39168
#FF
16777215
#P
Lakes\NZ Lake 3.jpg
#PC
16777215
#SB
True
#SH
False
#BM
I
#IT
S
#CC
2762836
#IN
126444
#E