From 20d0b40f8bd4f9f3b93f8834898564978d839777 Mon Sep 17 00:00:00 2001 From: john Date: Mon, 17 Jun 2019 09:30:45 +0100 Subject: [PATCH 01/27] Singing The Faith Importer - Initial version --- openlp/plugins/songs/lib/importer.py | 32 +++++++++++++++++++--------- tests/helpers/songfileimport.py | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index eb3d3f8cc..f1c7db2cd 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -42,6 +42,7 @@ from .importers.powerpraise import PowerPraiseImport from .importers.powersong import PowerSongImport from .importers.presentationmanager import PresentationManagerImport from .importers.propresenter import ProPresenterImport +from .importers.singingthefaith import SingingTheFaithImport from .importers.songbeamer import SongBeamerImport from .importers.songpro import SongProImport from .importers.songshowplus import SongShowPlusImport @@ -173,16 +174,17 @@ class SongFormat(object): PowerSong = 16 PresentationManager = 17 ProPresenter = 18 - SongBeamer = 19 - SongPro = 20 - SongShowPlus = 21 - SongsOfFellowship = 22 - SundayPlus = 23 - VideoPsalm = 24 - WordsOfWorship = 25 - WorshipAssistant = 26 - WorshipCenterPro = 27 - ZionWorx = 28 + SingingTheFaith = 19 + SongBeamer = 20 + SongPro = 21 + SongShowPlus = 22 + SongsOfFellowship = 23 + SundayPlus = 24 + VideoPsalm = 25 + WordsOfWorship = 26 + WorshipAssistant = 27 + WorshipCenterPro = 28 + ZionWorx = 29 # Set optional attribute defaults __defaults__ = { @@ -343,6 +345,15 @@ class SongFormat(object): 'filter': '{text} (*.pro4 *.pro5 *.pro6)'.format(text=translate('SongsPlugin.ImportWizardForm', 'ProPresenter Song Files')) }, + SingingTheFaith: { + 'class': SingingTheFaithImport, + 'name': 'SingingTheFaith', + 'prefix': 'singingTheFaith', + 'filter': '%s (*.txt)' % translate('SongsPlugin.ImportWizardForm', 'Singing The Faith Exported Files'), + 'descriptionText': translate('SongsPlugin.ImportWizardForm', + 'First use Singing The Faith Electonic edition to export ' + 'the song(s) in Text format.') + }, SongBeamer: { 'class': SongBeamerImport, 'name': 'SongBeamer', @@ -462,6 +473,7 @@ class SongFormat(object): SongFormat.PowerSong, SongFormat.PresentationManager, SongFormat.ProPresenter, + SongFormat.SingingTheFaith, SongFormat.SongBeamer, SongFormat.SongPro, SongFormat.SongShowPlus, diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index 8f0f338b2..5229b6f51 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -123,7 +123,7 @@ class SongImportTestHelper(TestCase): log.debug("Song copyright imported: %s" % importer.song_number) log.debug("Topics imported: %s" % importer.topics) - assert importer.title == title, 'title for %s should be "%s"' % (source_file_name, title) + assert importer.title == title, 'title for %s should be "%s" and is "%s"' % (source_file_name, title, importer.title) for author in author_calls: if isinstance(author, str): self.mocked_add_author.assert_any_call(author) From 66712873b48811388b50434f21591484aabd3ddd Mon Sep 17 00:00:00 2001 From: john Date: Mon, 17 Jun 2019 09:44:34 +0100 Subject: [PATCH 02/27] Singing The Faith Importer - Add the importer, and tests --- .../songs/lib/importers/singingthefaith.py | 401 ++++++++++++++++++ .../songs/test_singingthefaithimport.py | 45 ++ tests/resources/songs/singingthefaith/H1.txt | 30 ++ .../songs/singingthefaith/H1.txt.save | 30 ++ .../songs/singingthefaith/STF001.json | 29 ++ 5 files changed, 535 insertions(+) create mode 100644 openlp/plugins/songs/lib/importers/singingthefaith.py create mode 100644 tests/functional/openlp_plugins/songs/test_singingthefaithimport.py create mode 100644 tests/resources/songs/singingthefaith/H1.txt create mode 100644 tests/resources/songs/singingthefaith/H1.txt.save create mode 100644 tests/resources/songs/singingthefaith/STF001.json diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py new file mode 100644 index 000000000..d6943c159 --- /dev/null +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -0,0 +1,401 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2019 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:`singingthefaith` module provides the functionality for importing songs which are +exported from Singing The Faith - an Authorised songbook for the Methodist Church of +Great Britain.""" + + +import logging +import re + +import os + +from openlp.core.common.i18n import translate +from openlp.plugins.songs.lib.importers.songimport import SongImport + +log = logging.getLogger(__name__) + + +class SingingTheFaithImport(SongImport): + """ + Import songs exported from SingingTheFaith + """ + + hints_available = False + checks_needed = True + hintline = {} + hintfile_version = '0' + hint_verseOrder = '' + hint_songtitle = '' + hint_comments = '' + hint_ignoreIndent = False + + def __init__(self, manager, **kwargs): + """ + Initialise the class. + """ + super(SingingTheFaithImport, self).__init__(manager, **kwargs) + + def do_import(self): + """ + Receive a single file or a list of files to import. + """ + if not isinstance(self.import_source, list): + return + self.import_wizard.progress_bar.setMaximum(len(self.import_source)) + for filename in self.import_source: + if self.stop_import_flag: + return + song_file = open(filename, 'rt', encoding='cp1251') + self.do_import_file(song_file) + song_file.close() + + def do_import_file(self, file): + """ + Process the SingingTheFaith file - pass in a file-like object, not a file path. + """ + singingTheFaithVersion = 1 + self.set_defaults() + # Setup variables + line_number = 0 + old_indent = 0 + chorus_indent = 5 # It might be 6, but we test for >= + song_title = 'STF000 -' + song_number = '0' + ccli = '0' + current_verse = '' + current_verse_type = 'v' + current_verse_number = 1 + has_chorus = False + chorus_written = False + verses = [] + author = '' + copyright = '' + check_flag = 'z' # Prepended to title, remove if we think import should be OK + + + self.add_comment("Imported with Singing The Faith Importer v "+str(singingTheFaithVersion)) + +# Get the file_song_number - so we can use it for hints + filename = file.name + song_number_file = os.path.splitext(os.path.basename(filename))[0] + song_number_match = re.search('\d+',song_number_file) + if song_number_match: + song_number_file=song_number_match.group() + +# See if there are hints available at all + # See if there is a hints file in the same location as the file + dir_path = os.path.dirname(os.path.realpath(filename)) +## print("Pathname is ",dir_path) + hints_file_name = os.path.join(dir_path,"hints.tag") + try: + hints_file=open(hints_file_name,"r") + hints_available = self.read_hints(hints_file,song_number_file) + except FileNotFoundError: + hints_available = False + + + try: + # Read the file + for line in file: + line_number += 1 + +## print("Read line",line_number,"-",line) + + if (hints_available and (str(line_number) in self.hintline)): +## print("Found hint for line ",line_number) + hint = self.hintline[str(line_number)] +## print("Hint is ",hint) + if (hint == "Comment"): + line.strip() +## print("Comment hint for line ",line_number," line is ",line) + self.add_comment(line) + line_number += 1 + next(file) + continue + elif (hint == "Ignore"): + line_number += 1 + next(file) + continue + elif (hint == "Author"): + # add as a raw author - do not split and make them a words author + line.strip() + self.add_author(line,'words') + line_number += 1 + next(file) + continue + elif (hint.startswith("VariantVerse")): + ## print("VariantVerse found - hint is ",hint) + (vv,hintverse,replace)=hint.split(" ",2) + this_verse = self.verses[int(hintverse)-1] + this_verse_str = this_verse[1] + new_verse = this_verse_str +# There might be multiple replace pairs separated by | + replaces=replace.split("|") + for rep in replaces: + (source_str,dest_str)=rep.split("/") + new_verse = new_verse.replace(source_str,dest_str) + self.add_verse(new_verse,'v') + self.verse_order_list.append('v'+str(current_verse_number)) + current_verse_number += 1 + line_number += 1 + next(file) + continue + else: + self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), + translate('SongsPlugin.SingingTheFaithImport', 'Unknown hint %s' % hint)) + return + + + # STF exported lines have a leading verse number at the start of each verse. + # remove them - note that we want to track the indent as that shows a chorus + # so will deal with that before stipping all leading spaces. + indent = 0 + if line.strip(): +## print("Dealing non empty line ",line) + verse_num_match = re.search('^\d+',line) + if verse_num_match: + verse_num = verse_num_match.group() +## print("Verse num is ",verse_num) + line = line.lstrip("0123456789") + indent_match = re.search('^\s+',line) + if indent_match: + indent=len(indent_match.group()) +## print("indent is ",indent) + + # Assuming we have sorted out what is verse and what is chorus, strip lines, unless ignoreIndent + if not self.hint_ignoreIndent: + line = line.strip() + else: + line = line.rstrip() +## print("Read line",line_number,"(",indent,")",line) +# line_number += 1 # Now read earlier + if line_number == 2: + # note that songs seem to start with a blank line + song_title = line +## print("Set song title to "+song_title) + # Detect the 'Reproduced from Singing the Faith Electronic Words Edition' line + if line.startswith('Reproduced from Singing the Faith Electronic Words Edition'): + song_number_match = re.search('\d+',line) + if song_number_match: + song_number=song_number_match.group() +## print("Found Reproduced - song is ",song_number) + continue + # If the indent is 0 and it contains '(c)' then it is a Copyright line + elif (indent == 0) and ( "(c)" in line): + copyright = line + continue + elif (indent == 0) and (line.startswith('Liturgical ')): + self.add_comment(line) + continue + elif (indent == 0) and (line.startswith('From The ')): + self.add_comment(line) + continue + elif (indent == 0) and (line.startswith('From Common ')): + self.add_comment(line) + continue + # If indent is 0 it may well be the author (but not if it was the Reproduced line) + elif (indent == 0) and len(line)>0 : +## print ("Possible author ",line) +# May have more than one author, separated by ' and ' + authors = line.split(' and ') + for a in authors: + self.parse_author(a) +# author = line + continue + if line == '': +## print("Starting a new verse") + if current_verse != '': +## print("About to add a verse - type ",current_verse_type," ** ",current_verse) + self.add_verse(current_verse, current_verse_type) + self.verse_order_list.append(current_verse_type+str(current_verse_number)) + if (current_verse_type == 'c'): + chorus_written = True + else: + current_verse_number += 1 + current_verse = '' + if chorus_written: +## print("Setting current_verse_type to v") + current_verse_type = 'v' + else: + # If the line is indented more than or equal chorus_indent then assume it is a chorus + # If then indent has just changed then start a new verse just like hitting a blank line + + if not self.hint_ignoreIndent and ((indent >= chorus_indent) and (old_indent < indent)): +## print("Change of indent - close off old verse") + if current_verse != '': +## print("About to add a verse (indent change) - type ",current_verse_type," ** ",current_verse) + self.add_verse(current_verse, current_verse_type) + self.verse_order_list.append(current_verse_type+str(current_verse_number)) + if current_verse_type == 'v': + current_verse_number += 1 + current_verse = line +## print("Setting current_verse_type to c"); + current_verse_type = 'c' + old_indent=indent + chorus_written = False + has_chorus = True + continue + if current_verse == '': + current_verse += line + else: + current_verse += '\n' + line + old_indent = indent + except Exception as e: + self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), + translate('SongsPlugin.SingingTheFaithImport', 'Error: %s') % e) + return + + if self.hint_songtitle: + song_title = self.hint_songtitle + self.title = check_flag+"STF"+song_number.zfill(3)+" - "+song_title + self.song_book_name="Singing The Faith" + self.song_number = song_number + # self.parse_author(author) + self.ccli_number = ccli + self.add_copyright(copyright) +# If we have a chorus then the generated Verse order will not be useful, so clear the verse_order_list + if has_chorus: +## print ("Has chorus - verse order list is ",self.verse_order_list) + auto_verse_order_ok = False + # Popular case V1 C2 V2 ... + if len(self.verse_order_list) >= 1: # protect against odd cases + if (self.verse_order_list[0] == "v1") and (self.verse_order_list[1] == "c2"): + new_verse_order_list = ['v1','c1'] + i = 2 + auto_verse_order_ok = True + while i < len(self.verse_order_list): + # Should maybe check for vn + if self.verse_order_list[i].startswith('v'): + new_verse_order_list.append(self.verse_order_list[i]) + new_verse_order_list.append("c1") + else: +### Fix this +### self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), +### translate('SongsPlugin.SingingTheFaithImport', 'Error: %s'",self.verse_order_list[i]," in ",str(self.song_number)) +## Should be a logged error +## print("Found strange verseorder entry ",self.verse_order_list[i]," in ",file.name) + auto_verse_order_ok = False + i += 1 +## print(" new verse_order_list is ",new_verse_order_list) + self.verse_order_list = new_verse_order_list + elif (self.verse_order_list[0] == "c1") and (self.verse_order_list[1] == "v1"): + new_verse_order_list = ['c1','v1','c1'] + i = 2 + while i < len(self.verse_order_list): + # Should maybe check for vn + if self.verse_order_list[i].startswith('v'): + new_verse_order_list.append(self.verse_order_list[i]) + new_verse_order_list.append("c1") + else: +## print("Found strange verseorder entry ",self.verse_order_list[i]," in ",file.name) + auto_verse_order_ok = False + i += 1 +## print(" new verse_order_list (Chorus first is ",new_verse_order_list) + self.verse_order_list = new_verse_order_list + else: + if not auto_verse_order_ok: + print ("setting verse_order_list to empty") + self.verse_order_list = [] + # If it is a simple case, + if self.hint_verseOrder: + self.verse_order_list = self.hint_verseOrder.split(',') + if self.hint_comments: + self.add_comment(self.hint_comments) +# Write the title last as by now we will know if we need checks + if ( hints_available and not self.checks_needed): + check_flag='' + elif ( not hints_available and not has_chorus): + check_flag='' + elif ( not hints_available and has_chorus and auto_verse_order_ok): + check_flag='' + self.title = check_flag+"STF"+song_number.zfill(3)+" - "+song_title + if not self.finish(): + self.log_error(file.name) + + + def read_hints(self, file, song_number ): + hintfound = False +# clear hints + self.hint_verseOrder = '' + self.hintline.clear() + self.hint_comments = '' + self.hint_songtitle = '' + self.hint_ignoreIndent = False + +## print("Reading the hints file for ",song_number) + for tl in file: +# if the line is empty then return + if not tl.strip(): + return hintfound + tagval = tl.split(':') + tag = tagval[0].strip() + val = tagval[1].strip() + if (tag == "Version") : + self.hintfile_version = val + continue + if (tag == "Hymn") and (val == song_number): +## print ("Found song ",song_number," in hints") + self.add_comment("Using hints version "+str(self.hintfile_version)) + hintfound = True +# Assume, unless the hints has ManualCheck that if hinted all will be OK + self.checks_needed = False + for tl in file: + tagval = tl.split(':') + tag = tagval[0].strip() + val = tagval[1].strip() + if (tag == "End"): + return hintfound + elif (tag == "CommentsLine"): + vals = val.split(',') + for v in vals: + self.hintline[v] = "Comment" + elif (tag == "IgnoreLine"): + vals = val.split(',') + for v in vals: + self.hintline[v] = "Ignore" + elif (tag == "AuthorLine"): + vals = val.split(',') + for v in vals: + self.hintline[v] = "Author" + elif (tag == "VerseOrder"): + self.hint_verseOrder = val + elif (tag == "ManualCheck"): + self.checks_needed = True + elif (tag == "IgnoreIndent"): + self.hint_ignoreIndent = True + elif (tag == "VariantVerse"): + vvline = val.split(' ',1) + self.hintline[vvline[0].strip()] = "VariantVerse "+vvline[1].strip() + elif (tag == "SongTitle"): + self.hint_songtitle = val + elif (tag == "AddComment"): + self.hint_comments += '\n' + val + else: + print("Unknown tag ",tag," value ",val) + + + + return hintfound + + diff --git a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py new file mode 100644 index 000000000..8491a96e8 --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2019 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## +""" +This module contains tests for the SingingTheFaith song importer. +""" +from tests.helpers.songfileimport import SongImportTestHelper +from tests.utils.constants import RESOURCE_PATH + + +TEST_PATH = RESOURCE_PATH / 'songs' / 'singingthefaith' + + +class TestSingingTheFaithFileImport(SongImportTestHelper): + + def __init__(self, *args, **kwargs): + self.importer_class_name = 'SingingTheFaithImport' + self.importer_module_name = 'singingthefaith' + super(TestSingingTheFaithFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading a Singing The Faith file works correctly on various files + """ + self.file_import([TEST_PATH / 'H1.txt'], + self.load_external_result_data(TEST_PATH / 'STF001.json')) + diff --git a/tests/resources/songs/singingthefaith/H1.txt b/tests/resources/songs/singingthefaith/H1.txt new file mode 100644 index 000000000..85c6d5a3a --- /dev/null +++ b/tests/resources/songs/singingthefaith/H1.txt @@ -0,0 +1,30 @@ + +1 Amazing Grace! how sweet the sound + That saved a wretch like me! + I once was lost, but now am found; + Was blind, but now I see. + +2 'Twas grace that taught my heart to fear, + And grace my fears relieved. + How precious did that grace appear, + The hour I first believed. + +3 The Lord has promised good to me, + His Word my hope secures. + He will my shield and portion be + As long as life endures. + +4 Thro' many dangers, toils and snares + I have already come. + 'Tis grace that brought me safe thus far, + And grace will lead me home. + +5 When we've been there ten thousand years, + Bright shining as the sun, + We've no less days to sing God's praise, + Than when we first begun. + + +John Newton (d. 1807) + +Reproduced from Singing the Faith Electronic Words Edition, number 1 - or not as this is a hand made test file diff --git a/tests/resources/songs/singingthefaith/H1.txt.save b/tests/resources/songs/singingthefaith/H1.txt.save new file mode 100644 index 000000000..22241320d --- /dev/null +++ b/tests/resources/songs/singingthefaith/H1.txt.save @@ -0,0 +1,30 @@ + +1 All people that on earth do dwell, + sing to the Lord with cheerful voice: + him serve with mirth, his praise forth tell; + come ye before him and rejoice. + +2 The Lord, ye know, is God indeed; + without our aid he did us make: + we are his folk, he doth us feed; + and for his sheep he doth us take. + +3 O enter then his gates with praise; + approach with joy his courts unto; + praise, laud, and bless his name always, + for it is seemly so to do. + +4 For why, the Lord our God is good; + his mercy is for ever sure; + his truth at all times firmly stood, + and shall from age to age endure. + +5 To Father, Son and Holy Ghost, + the God whom heaven and earth adore, + from earth and from the angel host + be praise and glory evermore. + + +John Newton (d. 1807) + +Reproduced from Singing the Faith Electronic Words Edition, number 1 - or not as this is a hand made test file diff --git a/tests/resources/songs/singingthefaith/STF001.json b/tests/resources/songs/singingthefaith/STF001.json new file mode 100644 index 000000000..c3cb120c2 --- /dev/null +++ b/tests/resources/songs/singingthefaith/STF001.json @@ -0,0 +1,29 @@ +{ + "title": "STF001 - Amazing Grace! how sweet the sound", + "authors": [ + "John Newton (d. 1807)" + ], + "verse_order_list": ["v1", "v2", "v3", "v4", "v5"], + "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.", + "v1" + ], + [ + "'Twas grace that taught my heart to fear,\nAnd grace my fears relieved.\nHow precious did that grace appear,\nThe hour I first believed.", + "v2" + ], + [ + "The Lord has promised good to me,\nHis Word my hope secures.\nHe will my shield and portion be\nAs long as life endures.", + "v3" + ], + [ + "Thro' many dangers, toils and snares\nI have already come.\n'Tis grace that brought me safe thus far,\nAnd grace will lead me home.", + "v4" + ], + [ + "When we've been there ten thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise,\nThan when we first begun.", + "v5" + ] + ] +} From 8a4c349f9eb1ffbc77edb84cf9d6a629b029e0f0 Mon Sep 17 00:00:00 2001 From: john Date: Thu, 27 Jun 2019 13:01:11 +0100 Subject: [PATCH 03/27] Tidy up auto verse order generation --- .../songs/lib/importers/singingthefaith.py | 38 +++++++------------ .../songs/singingthefaith/H1.txt.save | 30 --------------- 2 files changed, 13 insertions(+), 55 deletions(-) delete mode 100644 tests/resources/songs/singingthefaith/H1.txt.save diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index d6943c159..f1b62c3d3 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -150,7 +150,7 @@ class SingingTheFaithImport(SongImport): this_verse = self.verses[int(hintverse)-1] this_verse_str = this_verse[1] new_verse = this_verse_str -# There might be multiple replace pairs separated by | + # There might be multiple replace pairs separated by | replaces=replace.split("|") for rep in replaces: (source_str,dest_str)=rep.split("/") @@ -189,7 +189,6 @@ class SingingTheFaithImport(SongImport): else: line = line.rstrip() ## print("Read line",line_number,"(",indent,")",line) -# line_number += 1 # Now read earlier if line_number == 2: # note that songs seem to start with a blank line song_title = line @@ -214,14 +213,13 @@ class SingingTheFaithImport(SongImport): elif (indent == 0) and (line.startswith('From Common ')): self.add_comment(line) continue - # If indent is 0 it may well be the author (but not if it was the Reproduced line) + # If indent is 0 it may be the author, unless it was one of the cases covered above elif (indent == 0) and len(line)>0 : ## print ("Possible author ",line) # May have more than one author, separated by ' and ' authors = line.split(' and ') for a in authors: self.parse_author(a) -# author = line continue if line == '': ## print("Starting a new verse") @@ -271,11 +269,12 @@ class SingingTheFaithImport(SongImport): self.title = check_flag+"STF"+song_number.zfill(3)+" - "+song_title self.song_book_name="Singing The Faith" self.song_number = song_number - # self.parse_author(author) self.ccli_number = ccli self.add_copyright(copyright) -# If we have a chorus then the generated Verse order will not be useful, so clear the verse_order_list - if has_chorus: +# If we have a chorus then the generated Verse order can not be used directly, but we can generate +# one for two special cases - Verse followed by one chorus (to be repeated after every verse) +# of Chorus, followed by verses. If hints for ManualCheck or VerseOrder are supplied ignore this + if has_chorus and not self.hint_verseOrder and not self.checks_needed: ## print ("Has chorus - verse order list is ",self.verse_order_list) auto_verse_order_ok = False # Popular case V1 C2 V2 ... @@ -284,35 +283,24 @@ class SingingTheFaithImport(SongImport): new_verse_order_list = ['v1','c1'] i = 2 auto_verse_order_ok = True - while i < len(self.verse_order_list): - # Should maybe check for vn - if self.verse_order_list[i].startswith('v'): - new_verse_order_list.append(self.verse_order_list[i]) - new_verse_order_list.append("c1") - else: -### Fix this -### self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), -### translate('SongsPlugin.SingingTheFaithImport', 'Error: %s'",self.verse_order_list[i]," in ",str(self.song_number)) -## Should be a logged error -## print("Found strange verseorder entry ",self.verse_order_list[i]," in ",file.name) - auto_verse_order_ok = False - i += 1 -## print(" new verse_order_list is ",new_verse_order_list) - self.verse_order_list = new_verse_order_list elif (self.verse_order_list[0] == "c1") and (self.verse_order_list[1] == "v1"): new_verse_order_list = ['c1','v1','c1'] i = 2 - while i < len(self.verse_order_list): - # Should maybe check for vn + auto_verse_order_ok = True + # if we are in a case we can deal with + if auto_verse_order_ok: + while i < len(self.verse_order_list): if self.verse_order_list[i].startswith('v'): new_verse_order_list.append(self.verse_order_list[i]) new_verse_order_list.append("c1") else: + self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), + 'Error: Strange verse order entry '+self.verse_order_list[i]) ## print("Found strange verseorder entry ",self.verse_order_list[i]," in ",file.name) auto_verse_order_ok = False i += 1 ## print(" new verse_order_list (Chorus first is ",new_verse_order_list) - self.verse_order_list = new_verse_order_list + self.verse_order_list = new_verse_order_list else: if not auto_verse_order_ok: print ("setting verse_order_list to empty") diff --git a/tests/resources/songs/singingthefaith/H1.txt.save b/tests/resources/songs/singingthefaith/H1.txt.save deleted file mode 100644 index 22241320d..000000000 --- a/tests/resources/songs/singingthefaith/H1.txt.save +++ /dev/null @@ -1,30 +0,0 @@ - -1 All people that on earth do dwell, - sing to the Lord with cheerful voice: - him serve with mirth, his praise forth tell; - come ye before him and rejoice. - -2 The Lord, ye know, is God indeed; - without our aid he did us make: - we are his folk, he doth us feed; - and for his sheep he doth us take. - -3 O enter then his gates with praise; - approach with joy his courts unto; - praise, laud, and bless his name always, - for it is seemly so to do. - -4 For why, the Lord our God is good; - his mercy is for ever sure; - his truth at all times firmly stood, - and shall from age to age endure. - -5 To Father, Son and Holy Ghost, - the God whom heaven and earth adore, - from earth and from the angel host - be praise and glory evermore. - - -John Newton (d. 1807) - -Reproduced from Singing the Faith Electronic Words Edition, number 1 - or not as this is a hand made test file From 5f2e2b72d7d88f023d40cb97cacb5949c02c9d1c Mon Sep 17 00:00:00 2001 From: john Date: Sat, 29 Jun 2019 12:12:46 +0100 Subject: [PATCH 04/27] Use path objects and remove redundant brackets --- .../songs/lib/importers/singingthefaith.py | 67 ++++++++----------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index f1b62c3d3..a527876d8 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -27,8 +27,8 @@ Great Britain.""" import logging import re - import os +from pathlib import Path from openlp.core.common.i18n import translate from openlp.plugins.songs.lib.importers.songimport import SongImport @@ -50,11 +50,6 @@ class SingingTheFaithImport(SongImport): hint_comments = '' hint_ignoreIndent = False - def __init__(self, manager, **kwargs): - """ - Initialise the class. - """ - super(SingingTheFaithImport, self).__init__(manager, **kwargs) def do_import(self): """ @@ -63,12 +58,11 @@ class SingingTheFaithImport(SongImport): if not isinstance(self.import_source, list): return self.import_wizard.progress_bar.setMaximum(len(self.import_source)) - for filename in self.import_source: + for file_path in self.import_source: if self.stop_import_flag: return - song_file = open(filename, 'rt', encoding='cp1251') - self.do_import_file(song_file) - song_file.close() + with file_path.open('rt', encoding='cp1251') as song_file: + self.do_import_file(song_file) def do_import_file(self, file): """ @@ -93,28 +87,25 @@ class SingingTheFaithImport(SongImport): copyright = '' check_flag = 'z' # Prepended to title, remove if we think import should be OK - self.add_comment("Imported with Singing The Faith Importer v "+str(singingTheFaithVersion)) # Get the file_song_number - so we can use it for hints - filename = file.name - song_number_file = os.path.splitext(os.path.basename(filename))[0] + filename = Path(file.name) + song_number_file = filename.stem song_number_match = re.search('\d+',song_number_file) if song_number_match: song_number_file=song_number_match.group() # See if there are hints available at all # See if there is a hints file in the same location as the file - dir_path = os.path.dirname(os.path.realpath(filename)) -## print("Pathname is ",dir_path) - hints_file_name = os.path.join(dir_path,"hints.tag") + dir_path = filename.parent + hints_file_path = dir_path / 'hints.tag' try: - hints_file=open(hints_file_name,"r") - hints_available = self.read_hints(hints_file,song_number_file) + with hints_file_path.open('r') as hints_file: + hints_available = self.read_hints(hints_file,song_number_file) except FileNotFoundError: hints_available = False - try: # Read the file for line in file: @@ -122,29 +113,29 @@ class SingingTheFaithImport(SongImport): ## print("Read line",line_number,"-",line) - if (hints_available and (str(line_number) in self.hintline)): + if hints_available and (str(line_number) in self.hintline): ## print("Found hint for line ",line_number) hint = self.hintline[str(line_number)] ## print("Hint is ",hint) - if (hint == "Comment"): + if hint == "Comment": line.strip() ## print("Comment hint for line ",line_number," line is ",line) self.add_comment(line) line_number += 1 next(file) continue - elif (hint == "Ignore"): + elif hint == "Ignore": line_number += 1 next(file) continue - elif (hint == "Author"): + elif hint == "Author": # add as a raw author - do not split and make them a words author line.strip() self.add_author(line,'words') line_number += 1 next(file) continue - elif (hint.startswith("VariantVerse")): + elif hint.startswith("VariantVerse"): ## print("VariantVerse found - hint is ",hint) (vv,hintverse,replace)=hint.split(" ",2) this_verse = self.verses[int(hintverse)-1] @@ -227,7 +218,7 @@ class SingingTheFaithImport(SongImport): ## print("About to add a verse - type ",current_verse_type," ** ",current_verse) self.add_verse(current_verse, current_verse_type) self.verse_order_list.append(current_verse_type+str(current_verse_number)) - if (current_verse_type == 'c'): + if current_verse_type == 'c': chorus_written = True else: current_verse_number += 1 @@ -311,11 +302,11 @@ class SingingTheFaithImport(SongImport): if self.hint_comments: self.add_comment(self.hint_comments) # Write the title last as by now we will know if we need checks - if ( hints_available and not self.checks_needed): + if hints_available and not self.checks_needed: check_flag='' - elif ( not hints_available and not has_chorus): + elif not hints_available and not has_chorus: check_flag='' - elif ( not hints_available and has_chorus and auto_verse_order_ok): + elif not hints_available and has_chorus and auto_verse_order_ok: check_flag='' self.title = check_flag+"STF"+song_number.zfill(3)+" - "+song_title if not self.finish(): @@ -352,32 +343,32 @@ class SingingTheFaithImport(SongImport): tagval = tl.split(':') tag = tagval[0].strip() val = tagval[1].strip() - if (tag == "End"): + if tag == "End": return hintfound - elif (tag == "CommentsLine"): + elif tag == "CommentsLine": vals = val.split(',') for v in vals: self.hintline[v] = "Comment" - elif (tag == "IgnoreLine"): + elif tag == "IgnoreLine": vals = val.split(',') for v in vals: self.hintline[v] = "Ignore" - elif (tag == "AuthorLine"): + elif tag == "AuthorLine": vals = val.split(',') for v in vals: self.hintline[v] = "Author" - elif (tag == "VerseOrder"): + elif tag == "VerseOrder": self.hint_verseOrder = val - elif (tag == "ManualCheck"): + elif tag == "ManualCheck": self.checks_needed = True - elif (tag == "IgnoreIndent"): + elif tag == "IgnoreIndent": self.hint_ignoreIndent = True - elif (tag == "VariantVerse"): + elif tag == "VariantVerse": vvline = val.split(' ',1) self.hintline[vvline[0].strip()] = "VariantVerse "+vvline[1].strip() - elif (tag == "SongTitle"): + elif tag == "SongTitle": self.hint_songtitle = val - elif (tag == "AddComment"): + elif tag == "AddComment": self.hint_comments += '\n' + val else: print("Unknown tag ",tag," value ",val) From 184462d85245eb349f328c3f61a746bc4941698c Mon Sep 17 00:00:00 2001 From: john Date: Sat, 29 Jun 2019 14:59:03 +0100 Subject: [PATCH 05/27] Test fixed for single verse, all verses failing test not run yet --- .../songs/test_singingthefaithimport.py | 5 ++++ tests/resources/songs/singingthefaith/H1.txt | 23 +----------------- .../songs/singingthefaith/STF001.json | 24 ++++--------------- 3 files changed, 10 insertions(+), 42 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py index 8491a96e8..190466db3 100644 --- a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py +++ b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py @@ -40,6 +40,11 @@ class TestSingingTheFaithFileImport(SongImportTestHelper): """ Test that loading a Singing The Faith file works correctly on various files """ + # Single verse self.file_import([TEST_PATH / 'H1.txt'], self.load_external_result_data(TEST_PATH / 'STF001.json')) + # Whole song - currently not working - test needs debugging. +## self.file_import([TEST_PATH / 'H2.txt'], +## self.load_external_result_data(TEST_PATH / 'STF002.json')) + diff --git a/tests/resources/songs/singingthefaith/H1.txt b/tests/resources/songs/singingthefaith/H1.txt index 85c6d5a3a..3caf1cd11 100644 --- a/tests/resources/songs/singingthefaith/H1.txt +++ b/tests/resources/songs/singingthefaith/H1.txt @@ -1,30 +1,9 @@ -1 Amazing Grace! how sweet the sound +1 Amazing Grace! how sweet the sound! That saved a wretch like me! I once was lost, but now am found; Was blind, but now I see. -2 'Twas grace that taught my heart to fear, - And grace my fears relieved. - How precious did that grace appear, - The hour I first believed. - -3 The Lord has promised good to me, - His Word my hope secures. - He will my shield and portion be - As long as life endures. - -4 Thro' many dangers, toils and snares - I have already come. - 'Tis grace that brought me safe thus far, - And grace will lead me home. - -5 When we've been there ten thousand years, - Bright shining as the sun, - We've no less days to sing God's praise, - Than when we first begun. - - John Newton (d. 1807) Reproduced from Singing the Faith Electronic Words Edition, number 1 - or not as this is a hand made test file diff --git a/tests/resources/songs/singingthefaith/STF001.json b/tests/resources/songs/singingthefaith/STF001.json index c3cb120c2..edf3ee682 100644 --- a/tests/resources/songs/singingthefaith/STF001.json +++ b/tests/resources/songs/singingthefaith/STF001.json @@ -1,29 +1,13 @@ { - "title": "STF001 - Amazing Grace! how sweet the sound", + "title": "STF001 - Amazing Grace! how sweet the sound!", "authors": [ "John Newton (d. 1807)" ], - "verse_order_list": ["v1", "v2", "v3", "v4", "v5"], + "verse_order_list": ["v1"], "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.", - "v1" - ], - [ - "'Twas grace that taught my heart to fear,\nAnd grace my fears relieved.\nHow precious did that grace appear,\nThe hour I first believed.", - "v2" - ], - [ - "The Lord has promised good to me,\nHis Word my hope secures.\nHe will my shield and portion be\nAs long as life endures.", - "v3" - ], - [ - "Thro' many dangers, toils and snares\nI have already come.\n'Tis grace that brought me safe thus far,\nAnd grace will lead me home.", - "v4" - ], - [ - "When we've been there ten thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise,\nThan when we first begun.", - "v5" + "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" ] ] } From 8f91f0c787949136ca2011619b8a16597475b8d7 Mon Sep 17 00:00:00 2001 From: john Date: Sat, 29 Jun 2019 15:43:32 +0100 Subject: [PATCH 06/27] Fix undefined auto_verse_order_ok case, and add some test resources --- .../songs/lib/importers/singingthefaith.py | 1 + tests/resources/songs/singingthefaith/H2.txt | 30 +++++++++++++++++++ .../songs/singingthefaith/STF002.json | 29 ++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 tests/resources/songs/singingthefaith/H2.txt create mode 100644 tests/resources/songs/singingthefaith/STF002.json diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index a527876d8..53cdfed85 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -82,6 +82,7 @@ class SingingTheFaithImport(SongImport): current_verse_number = 1 has_chorus = False chorus_written = False + auto_verse_order_ok = False verses = [] author = '' copyright = '' diff --git a/tests/resources/songs/singingthefaith/H2.txt b/tests/resources/songs/singingthefaith/H2.txt new file mode 100644 index 000000000..3066293e1 --- /dev/null +++ b/tests/resources/songs/singingthefaith/H2.txt @@ -0,0 +1,30 @@ + +1 Amazing Grace! how sweet the sound! + That saved a wretch like me! + I once was lost, but now am found; + Was blind, but now I see. + +2 'Twas grace that taught my heart to fear, + And grace my fears relieved. + How precious did that grace appear, + The hour I first believed. + +3 The Lord has promised good to me, + His Word my hope secures. + He will my shield and portion be + As long as life endures. + +4 Thro' many dangers, toils and snares + I have already come. + 'Tis grace that brought me safe thus far, + And grace will lead me home. + +5 When we've been there ten thousand years, + Bright shining as the sun, + We've no less days to sing God's praise, + Than when we first begun. + + +John Newton (d. 1807) + +Reproduced from Singing the Faith Electronic Words Edition, number 2 - or not as this is a hand made test file diff --git a/tests/resources/songs/singingthefaith/STF002.json b/tests/resources/songs/singingthefaith/STF002.json new file mode 100644 index 000000000..6bfc655bf --- /dev/null +++ b/tests/resources/songs/singingthefaith/STF002.json @@ -0,0 +1,29 @@ +{ + "title": "STF002 - Amazing Grace! how sweet the sound!", + "authors": [ + "John Newton (d. 1807)" + ], + "verse_order_list": ["v1", "v2", "v3", "v4", "v5"], + "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" + ], + [ + "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" + ], + [ + "Thro' 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" + ], + [ + "When we've been there ten thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise,\nThan when we first begun.", + "v" + ] + ] +} From e566a6788c8b9983f644b517cf5a51437c60cde3 Mon Sep 17 00:00:00 2001 From: John Lines Date: Sun, 30 Jun 2019 19:03:38 +0100 Subject: [PATCH 07/27] Fix flake8 warnings, print statements, inline comments --- .../songs/lib/importers/singingthefaith.py | 174 +++++++----------- 1 file changed, 70 insertions(+), 104 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index 53cdfed85..ca1f67820 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -24,10 +24,8 @@ The :mod:`singingthefaith` module provides the functionality for importing songs exported from Singing The Faith - an Authorised songbook for the Methodist Church of Great Britain.""" - import logging import re -import os from pathlib import Path from openlp.core.common.i18n import translate @@ -50,7 +48,6 @@ class SingingTheFaithImport(SongImport): hint_comments = '' hint_ignoreIndent = False - def do_import(self): """ Receive a single file or a list of files to import. @@ -73,54 +70,52 @@ class SingingTheFaithImport(SongImport): # Setup variables line_number = 0 old_indent = 0 - chorus_indent = 5 # It might be 6, but we test for >= + # The chorus indent is how many spaces the chorus is indented - it might be 6, + # but we test for >= and I do not know how consistent to formatting of the + # exported songs is. + chorus_indent = 5 song_title = 'STF000 -' song_number = '0' ccli = '0' current_verse = '' current_verse_type = 'v' current_verse_number = 1 + # Potentially we could try to track current chorus number to automatically handle + # more than 1 chorus, currently unused. + # current_chorus_number = 1 has_chorus = False chorus_written = False auto_verse_order_ok = False - verses = [] - author = '' copyright = '' - check_flag = 'z' # Prepended to title, remove if we think import should be OK + # the check_flag is prepended to the title, removed if the import should be OK + # all the songs which need manual editing should sort below all the OK songs + check_flag = 'z' - self.add_comment("Imported with Singing The Faith Importer v "+str(singingTheFaithVersion)) + self.add_comment("Imported with Singing The Faith Importer v " + str(singingTheFaithVersion)) -# Get the file_song_number - so we can use it for hints + # Get the file_song_number - so we can use it for hints filename = Path(file.name) song_number_file = filename.stem - song_number_match = re.search('\d+',song_number_file) + song_number_match = re.search(r'\d+', song_number_file) if song_number_match: - song_number_file=song_number_match.group() + song_number_file = song_number_match.group() -# See if there are hints available at all - # See if there is a hints file in the same location as the file + # See if there is a hints file in the same location as the file dir_path = filename.parent hints_file_path = dir_path / 'hints.tag' try: with hints_file_path.open('r') as hints_file: - hints_available = self.read_hints(hints_file,song_number_file) + hints_available = self.read_hints(hints_file, song_number_file) except FileNotFoundError: hints_available = False try: - # Read the file for line in file: line_number += 1 - -## print("Read line",line_number,"-",line) - if hints_available and (str(line_number) in self.hintline): -## print("Found hint for line ",line_number) hint = self.hintline[str(line_number)] -## print("Hint is ",hint) if hint == "Comment": line.strip() -## print("Comment hint for line ",line_number," line is ",line) self.add_comment(line) line_number += 1 next(file) @@ -132,68 +127,61 @@ class SingingTheFaithImport(SongImport): elif hint == "Author": # add as a raw author - do not split and make them a words author line.strip() - self.add_author(line,'words') + self.add_author(line, 'words') line_number += 1 next(file) continue elif hint.startswith("VariantVerse"): - ## print("VariantVerse found - hint is ",hint) - (vv,hintverse,replace)=hint.split(" ",2) - this_verse = self.verses[int(hintverse)-1] + (vv, hintverse, replace) = hint.split(" ", 2) + this_verse = self.verses[int(hintverse) - 1] this_verse_str = this_verse[1] new_verse = this_verse_str # There might be multiple replace pairs separated by | - replaces=replace.split("|") + replaces = replace.split("|") for rep in replaces: - (source_str,dest_str)=rep.split("/") - new_verse = new_verse.replace(source_str,dest_str) - self.add_verse(new_verse,'v') - self.verse_order_list.append('v'+str(current_verse_number)) + (source_str, dest_str) = rep.split("/") + new_verse = new_verse.replace(source_str, dest_str) + self.add_verse(new_verse, 'v') + self.verse_order_list.append('v' + str(current_verse_number)) current_verse_number += 1 line_number += 1 next(file) continue else: self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), - translate('SongsPlugin.SingingTheFaithImport', 'Unknown hint %s' % hint)) + translate('SongsPlugin.SingingTheFaithImport', 'Unknown hint %s' % hint)) return - - # STF exported lines have a leading verse number at the start of each verse. # remove them - note that we want to track the indent as that shows a chorus - # so will deal with that before stipping all leading spaces. + # so will deal with that before stipping all leading spaces. indent = 0 if line.strip(): -## print("Dealing non empty line ",line) - verse_num_match = re.search('^\d+',line) + verse_num_match = re.search(r'^\d+', line) if verse_num_match: - verse_num = verse_num_match.group() -## print("Verse num is ",verse_num) + # Could extract the verse number and check it against the calculated + # verse number - TODO + # verse_num = verse_num_match.group() line = line.lstrip("0123456789") - indent_match = re.search('^\s+',line) + indent_match = re.search(r'^\s+', line) if indent_match: - indent=len(indent_match.group()) -## print("indent is ",indent) - - # Assuming we have sorted out what is verse and what is chorus, strip lines, unless ignoreIndent - if not self.hint_ignoreIndent: - line = line.strip() - else: + indent = len(indent_match.group()) + # Assuming we have sorted out what is verse and what is chorus, strip lines, + # unless ignoreIndent + if self.hint_ignoreIndent: line = line.rstrip() -## print("Read line",line_number,"(",indent,")",line) + else: + line = line.strip() if line_number == 2: # note that songs seem to start with a blank line song_title = line -## print("Set song title to "+song_title) # Detect the 'Reproduced from Singing the Faith Electronic Words Edition' line if line.startswith('Reproduced from Singing the Faith Electronic Words Edition'): - song_number_match = re.search('\d+',line) + song_number_match = re.search(r'\d+', line) if song_number_match: - song_number=song_number_match.group() -## print("Found Reproduced - song is ",song_number) + song_number = song_number_match.group() continue # If the indent is 0 and it contains '(c)' then it is a Copyright line - elif (indent == 0) and ( "(c)" in line): + elif (indent == 0) and ("(c)" in line): copyright = line continue elif (indent == 0) and (line.startswith('Liturgical ')): @@ -206,43 +194,35 @@ class SingingTheFaithImport(SongImport): self.add_comment(line) continue # If indent is 0 it may be the author, unless it was one of the cases covered above - elif (indent == 0) and len(line)>0 : -## print ("Possible author ",line) -# May have more than one author, separated by ' and ' + elif (indent == 0) and len(line) > 0: + # May have more than one author, separated by ' and ' authors = line.split(' and ') for a in authors: self.parse_author(a) continue if line == '': -## print("Starting a new verse") if current_verse != '': -## print("About to add a verse - type ",current_verse_type," ** ",current_verse) self.add_verse(current_verse, current_verse_type) - self.verse_order_list.append(current_verse_type+str(current_verse_number)) + self.verse_order_list.append(current_verse_type + str(current_verse_number)) if current_verse_type == 'c': chorus_written = True else: current_verse_number += 1 current_verse = '' if chorus_written: -## print("Setting current_verse_type to v") current_verse_type = 'v' else: # If the line is indented more than or equal chorus_indent then assume it is a chorus - # If then indent has just changed then start a new verse just like hitting a blank line - + # If the indent has just changed then start a new verse just like hitting a blank line if not self.hint_ignoreIndent and ((indent >= chorus_indent) and (old_indent < indent)): -## print("Change of indent - close off old verse") if current_verse != '': -## print("About to add a verse (indent change) - type ",current_verse_type," ** ",current_verse) self.add_verse(current_verse, current_verse_type) - self.verse_order_list.append(current_verse_type+str(current_verse_number)) + self.verse_order_list.append(current_verse_type + str(current_verse_number)) if current_verse_type == 'v': current_verse_number += 1 current_verse = line -## print("Setting current_verse_type to c"); current_verse_type = 'c' - old_indent=indent + old_indent = indent chorus_written = False has_chorus = True continue @@ -258,8 +238,8 @@ class SingingTheFaithImport(SongImport): if self.hint_songtitle: song_title = self.hint_songtitle - self.title = check_flag+"STF"+song_number.zfill(3)+" - "+song_title - self.song_book_name="Singing The Faith" + self.title = check_flag + "STF" + song_number.zfill(3) + " - " + song_title + self.song_book_name = "Singing The Faith" self.song_number = song_number self.ccli_number = ccli self.add_copyright(copyright) @@ -267,78 +247,69 @@ class SingingTheFaithImport(SongImport): # one for two special cases - Verse followed by one chorus (to be repeated after every verse) # of Chorus, followed by verses. If hints for ManualCheck or VerseOrder are supplied ignore this if has_chorus and not self.hint_verseOrder and not self.checks_needed: -## print ("Has chorus - verse order list is ",self.verse_order_list) auto_verse_order_ok = False # Popular case V1 C2 V2 ... if len(self.verse_order_list) >= 1: # protect against odd cases if (self.verse_order_list[0] == "v1") and (self.verse_order_list[1] == "c2"): - new_verse_order_list = ['v1','c1'] + new_verse_order_list = ['v1', 'c1'] i = 2 auto_verse_order_ok = True elif (self.verse_order_list[0] == "c1") and (self.verse_order_list[1] == "v1"): - new_verse_order_list = ['c1','v1','c1'] + new_verse_order_list = ['c1', 'v1', 'c1'] i = 2 auto_verse_order_ok = True # if we are in a case we can deal with if auto_verse_order_ok: - while i < len(self.verse_order_list): + while i < len(self.verse_order_list): if self.verse_order_list[i].startswith('v'): new_verse_order_list.append(self.verse_order_list[i]) new_verse_order_list.append("c1") else: - self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), - 'Error: Strange verse order entry '+self.verse_order_list[i]) -## print("Found strange verseorder entry ",self.verse_order_list[i]," in ",file.name) + # Would like to notify, but want a warning, which we will do via the + # Check_needed mechanism, as log_error aborts input of that song. + # self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), + # 'Error: Strange verse order entry ' + self.verse_order_list[i]) auto_verse_order_ok = False i += 1 -## print(" new verse_order_list (Chorus first is ",new_verse_order_list) - self.verse_order_list = new_verse_order_list + self.verse_order_list = new_verse_order_list else: if not auto_verse_order_ok: - print ("setting verse_order_list to empty") self.verse_order_list = [] - # If it is a simple case, if self.hint_verseOrder: self.verse_order_list = self.hint_verseOrder.split(',') if self.hint_comments: self.add_comment(self.hint_comments) -# Write the title last as by now we will know if we need checks + # Write the title last as by now we will know if we need checks if hints_available and not self.checks_needed: - check_flag='' + check_flag = '' elif not hints_available and not has_chorus: - check_flag='' + check_flag = '' elif not hints_available and has_chorus and auto_verse_order_ok: - check_flag='' - self.title = check_flag+"STF"+song_number.zfill(3)+" - "+song_title + check_flag = '' + self.title = check_flag + "STF" + song_number.zfill(3) + " - " + song_title if not self.finish(): self.log_error(file.name) - - def read_hints(self, file, song_number ): + def read_hints(self, file, song_number): hintfound = False -# clear hints self.hint_verseOrder = '' self.hintline.clear() self.hint_comments = '' self.hint_songtitle = '' self.hint_ignoreIndent = False - -## print("Reading the hints file for ",song_number) for tl in file: -# if the line is empty then return if not tl.strip(): return hintfound tagval = tl.split(':') tag = tagval[0].strip() val = tagval[1].strip() - if (tag == "Version") : + if tag == "Version": self.hintfile_version = val continue if (tag == "Hymn") and (val == song_number): -## print ("Found song ",song_number," in hints") - self.add_comment("Using hints version "+str(self.hintfile_version)) + self.add_comment("Using hints version " + str(self.hintfile_version)) hintfound = True -# Assume, unless the hints has ManualCheck that if hinted all will be OK + # Assume, unless the hints has ManualCheck that if hinted all will be OK self.checks_needed = False for tl in file: tagval = tl.split(':') @@ -357,7 +328,7 @@ class SingingTheFaithImport(SongImport): elif tag == "AuthorLine": vals = val.split(',') for v in vals: - self.hintline[v] = "Author" + self.hintline[v] = "Author" elif tag == "VerseOrder": self.hint_verseOrder = val elif tag == "ManualCheck": @@ -365,17 +336,12 @@ class SingingTheFaithImport(SongImport): elif tag == "IgnoreIndent": self.hint_ignoreIndent = True elif tag == "VariantVerse": - vvline = val.split(' ',1) - self.hintline[vvline[0].strip()] = "VariantVerse "+vvline[1].strip() + vvline = val.split(' ', 1) + self.hintline[vvline[0].strip()] = "VariantVerse " + vvline[1].strip() elif tag == "SongTitle": self.hint_songtitle = val elif tag == "AddComment": self.hint_comments += '\n' + val else: - print("Unknown tag ",tag," value ",val) - - - - return hintfound - - + self.log_error(file.name, "Unknown tag " + tag + " value " + val) + return hintfound From d52d5bb0e2e314e3bc2558a5952996de667e735f Mon Sep 17 00:00:00 2001 From: John Lines Date: Sun, 30 Jun 2019 20:13:33 +0100 Subject: [PATCH 08/27] Fix lint warning in tests and importer.py --- openlp/plugins/songs/lib/importer.py | 2 +- .../openlp_plugins/songs/test_singingthefaithimport.py | 6 ++---- tests/helpers/songfileimport.py | 3 ++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index f1c7db2cd..5fa758783 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -345,7 +345,7 @@ class SongFormat(object): 'filter': '{text} (*.pro4 *.pro5 *.pro6)'.format(text=translate('SongsPlugin.ImportWizardForm', 'ProPresenter Song Files')) }, - SingingTheFaith: { + SingingTheFaith: { 'class': SingingTheFaithImport, 'name': 'SingingTheFaith', 'prefix': 'singingTheFaith', diff --git a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py index 190466db3..fbbf2a3e1 100644 --- a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py +++ b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py @@ -44,7 +44,5 @@ class TestSingingTheFaithFileImport(SongImportTestHelper): self.file_import([TEST_PATH / 'H1.txt'], self.load_external_result_data(TEST_PATH / 'STF001.json')) # Whole song - currently not working - test needs debugging. -## self.file_import([TEST_PATH / 'H2.txt'], -## self.load_external_result_data(TEST_PATH / 'STF002.json')) - - + # self.file_import([TEST_PATH / 'H2.txt'], + # self.load_external_result_data(TEST_PATH / 'STF002.json')) diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index 5229b6f51..0c007fa18 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -123,7 +123,8 @@ class SongImportTestHelper(TestCase): log.debug("Song copyright imported: %s" % importer.song_number) log.debug("Topics imported: %s" % importer.topics) - assert importer.title == title, 'title for %s should be "%s" and is "%s"' % (source_file_name, title, importer.title) + assert importer.title == title, \ + 'title for %s should be "%s" and is "%s"' % (source_file_name, title, importer.title) for author in author_calls: if isinstance(author, str): self.mocked_add_author.assert_any_call(author) From bc70eea7b9eb4ff45329d6ccf67d600fa049668b Mon Sep 17 00:00:00 2001 From: John Lines Date: Fri, 12 Jul 2019 11:49:00 +0100 Subject: [PATCH 09/27] Minimize differences needed to run under OpenLP 2.4.6 --- openlp/plugins/songs/lib/importers/singingthefaith.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index ca1f67820..2923abd72 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -58,8 +58,13 @@ class SingingTheFaithImport(SongImport): for file_path in self.import_source: if self.stop_import_flag: return - with file_path.open('rt', encoding='cp1251') as song_file: + if isinstance(file_path, str): + song_file = open(file_path, 'rt', encoding='cp1251') self.do_import_file(song_file) + song_file.close() + else: + with file_path.open('rt', encoding='cp1251') as song_file: + self.do_import_file(song_file) def do_import_file(self, file): """ From 515abee3aeb87ca17f56003d57a15c155972c1a7 Mon Sep 17 00:00:00 2001 From: John Lines Date: Fri, 12 Jul 2019 12:26:12 +0100 Subject: [PATCH 10/27] Convert double to single quotes, make hint variable names consistent --- .../songs/lib/importers/singingthefaith.py | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index 2923abd72..ba3c1dbb6 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -41,12 +41,12 @@ class SingingTheFaithImport(SongImport): hints_available = False checks_needed = True - hintline = {} - hintfile_version = '0' - hint_verseOrder = '' - hint_songtitle = '' + hint_line = {} + hint_file_version = '0' + hint_verse_order = '' + hint_song_title = '' hint_comments = '' - hint_ignoreIndent = False + hint_ignore_indent = False def do_import(self): """ @@ -70,7 +70,7 @@ class SingingTheFaithImport(SongImport): """ Process the SingingTheFaith file - pass in a file-like object, not a file path. """ - singingTheFaithVersion = 1 + singing_the_faith_version = 1 self.set_defaults() # Setup variables line_number = 0 @@ -96,7 +96,7 @@ class SingingTheFaithImport(SongImport): # all the songs which need manual editing should sort below all the OK songs check_flag = 'z' - self.add_comment("Imported with Singing The Faith Importer v " + str(singingTheFaithVersion)) + self.add_comment('Imported with Singing The Faith Importer v ' + str(singing_the_faith_version)) # Get the file_song_number - so we can use it for hints filename = Path(file.name) @@ -117,34 +117,34 @@ class SingingTheFaithImport(SongImport): try: for line in file: line_number += 1 - if hints_available and (str(line_number) in self.hintline): - hint = self.hintline[str(line_number)] - if hint == "Comment": + if hints_available and (str(line_number) in self.hint_line): + hint = self.hint_line[str(line_number)] + if hint == 'Comment': line.strip() self.add_comment(line) line_number += 1 next(file) continue - elif hint == "Ignore": + elif hint == 'Ignore': line_number += 1 next(file) continue - elif hint == "Author": + elif hint == 'Author': # add as a raw author - do not split and make them a words author line.strip() self.add_author(line, 'words') line_number += 1 next(file) continue - elif hint.startswith("VariantVerse"): - (vv, hintverse, replace) = hint.split(" ", 2) + elif hint.startswith('VariantVerse'): + (vv, hintverse, replace) = hint.split(' ', 2) this_verse = self.verses[int(hintverse) - 1] this_verse_str = this_verse[1] new_verse = this_verse_str # There might be multiple replace pairs separated by | - replaces = replace.split("|") + replaces = replace.split('|') for rep in replaces: - (source_str, dest_str) = rep.split("/") + (source_str, dest_str) = rep.split('/') new_verse = new_verse.replace(source_str, dest_str) self.add_verse(new_verse, 'v') self.verse_order_list.append('v' + str(current_verse_number)) @@ -166,13 +166,13 @@ class SingingTheFaithImport(SongImport): # Could extract the verse number and check it against the calculated # verse number - TODO # verse_num = verse_num_match.group() - line = line.lstrip("0123456789") + line = line.lstrip('0123456789') indent_match = re.search(r'^\s+', line) if indent_match: indent = len(indent_match.group()) # Assuming we have sorted out what is verse and what is chorus, strip lines, # unless ignoreIndent - if self.hint_ignoreIndent: + if self.hint_ignore_indent: line = line.rstrip() else: line = line.strip() @@ -186,7 +186,7 @@ class SingingTheFaithImport(SongImport): song_number = song_number_match.group() continue # If the indent is 0 and it contains '(c)' then it is a Copyright line - elif (indent == 0) and ("(c)" in line): + elif (indent == 0) and ('(c)' in line): copyright = line continue elif (indent == 0) and (line.startswith('Liturgical ')): @@ -219,7 +219,7 @@ class SingingTheFaithImport(SongImport): else: # If the line is indented more than or equal chorus_indent then assume it is a chorus # If the indent has just changed then start a new verse just like hitting a blank line - if not self.hint_ignoreIndent and ((indent >= chorus_indent) and (old_indent < indent)): + if not self.hint_ignore_indent and ((indent >= chorus_indent) and (old_indent < indent)): if current_verse != '': self.add_verse(current_verse, current_verse_type) self.verse_order_list.append(current_verse_type + str(current_verse_number)) @@ -241,25 +241,25 @@ class SingingTheFaithImport(SongImport): translate('SongsPlugin.SingingTheFaithImport', 'Error: %s') % e) return - if self.hint_songtitle: - song_title = self.hint_songtitle - self.title = check_flag + "STF" + song_number.zfill(3) + " - " + song_title - self.song_book_name = "Singing The Faith" + if self.hint_song_title: + song_title = self.hint_song_title + self.title = check_flag + 'STF' + song_number.zfill(3) + ' - ' + song_title + self.song_book_name = 'Singing The Faith' self.song_number = song_number self.ccli_number = ccli self.add_copyright(copyright) # If we have a chorus then the generated Verse order can not be used directly, but we can generate # one for two special cases - Verse followed by one chorus (to be repeated after every verse) # of Chorus, followed by verses. If hints for ManualCheck or VerseOrder are supplied ignore this - if has_chorus and not self.hint_verseOrder and not self.checks_needed: + if has_chorus and not self.hint_verse_order and not self.checks_needed: auto_verse_order_ok = False # Popular case V1 C2 V2 ... if len(self.verse_order_list) >= 1: # protect against odd cases - if (self.verse_order_list[0] == "v1") and (self.verse_order_list[1] == "c2"): + if (self.verse_order_list[0] == 'v1') and (self.verse_order_list[1] == 'c2'): new_verse_order_list = ['v1', 'c1'] i = 2 auto_verse_order_ok = True - elif (self.verse_order_list[0] == "c1") and (self.verse_order_list[1] == "v1"): + elif (self.verse_order_list[0] == 'c1') and (self.verse_order_list[1] == 'v1'): new_verse_order_list = ['c1', 'v1', 'c1'] i = 2 auto_verse_order_ok = True @@ -268,7 +268,7 @@ class SingingTheFaithImport(SongImport): while i < len(self.verse_order_list): if self.verse_order_list[i].startswith('v'): new_verse_order_list.append(self.verse_order_list[i]) - new_verse_order_list.append("c1") + new_verse_order_list.append('c1') else: # Would like to notify, but want a warning, which we will do via the # Check_needed mechanism, as log_error aborts input of that song. @@ -280,8 +280,8 @@ class SingingTheFaithImport(SongImport): else: if not auto_verse_order_ok: self.verse_order_list = [] - if self.hint_verseOrder: - self.verse_order_list = self.hint_verseOrder.split(',') + if self.hint_verse_order: + self.verse_order_list = self.hint_verse_order.split(',') if self.hint_comments: self.add_comment(self.hint_comments) # Write the title last as by now we will know if we need checks @@ -291,28 +291,28 @@ class SingingTheFaithImport(SongImport): check_flag = '' elif not hints_available and has_chorus and auto_verse_order_ok: check_flag = '' - self.title = check_flag + "STF" + song_number.zfill(3) + " - " + song_title + self.title = check_flag + 'STF' + song_number.zfill(3) + ' - ' + song_title if not self.finish(): self.log_error(file.name) def read_hints(self, file, song_number): hintfound = False - self.hint_verseOrder = '' - self.hintline.clear() + self.hint_verse_order = '' + self.hint_line.clear() self.hint_comments = '' - self.hint_songtitle = '' - self.hint_ignoreIndent = False + self.hint_song_title = '' + self.hint_ignore_indent = False for tl in file: if not tl.strip(): return hintfound tagval = tl.split(':') tag = tagval[0].strip() val = tagval[1].strip() - if tag == "Version": - self.hintfile_version = val + if tag == 'Version': + self.hint_file_version = val continue - if (tag == "Hymn") and (val == song_number): - self.add_comment("Using hints version " + str(self.hintfile_version)) + if (tag == 'Hymn') and (val == song_number): + self.add_comment('Using hints version ' + str(self.hint_file_version)) hintfound = True # Assume, unless the hints has ManualCheck that if hinted all will be OK self.checks_needed = False @@ -320,33 +320,33 @@ class SingingTheFaithImport(SongImport): tagval = tl.split(':') tag = tagval[0].strip() val = tagval[1].strip() - if tag == "End": + if tag == 'End': return hintfound - elif tag == "CommentsLine": + elif tag == 'CommentsLine': vals = val.split(',') for v in vals: - self.hintline[v] = "Comment" - elif tag == "IgnoreLine": + self.hint_line[v] = 'Comment' + elif tag == 'IgnoreLine': vals = val.split(',') for v in vals: - self.hintline[v] = "Ignore" - elif tag == "AuthorLine": + self.hint_line[v] = 'Ignore' + elif tag == 'AuthorLine': vals = val.split(',') for v in vals: - self.hintline[v] = "Author" - elif tag == "VerseOrder": - self.hint_verseOrder = val - elif tag == "ManualCheck": + self.hint_line[v] = 'Author' + elif tag == 'VerseOrder': + self.hint_verse_order = val + elif tag == 'ManualCheck': self.checks_needed = True - elif tag == "IgnoreIndent": - self.hint_ignoreIndent = True - elif tag == "VariantVerse": + elif tag == 'IgnoreIndent': + self.hint_ignore_indent = True + elif tag == 'VariantVerse': vvline = val.split(' ', 1) - self.hintline[vvline[0].strip()] = "VariantVerse " + vvline[1].strip() - elif tag == "SongTitle": - self.hint_songtitle = val - elif tag == "AddComment": + self.hint_line[vvline[0].strip()] = 'VariantVerse ' + vvline[1].strip() + elif tag == 'SongTitle': + self.hint_song_title = val + elif tag == 'AddComment': self.hint_comments += '\n' + val else: - self.log_error(file.name, "Unknown tag " + tag + " value " + val) + self.log_error(file.name, 'Unknown tag ' + tag + ' value ' + val) return hintfound From 36b5528d43b6d71383bd28f2ea9cef5d8b06c52a Mon Sep 17 00:00:00 2001 From: John Lines Date: Fri, 12 Jul 2019 15:36:14 +0100 Subject: [PATCH 11/27] New style string formatting, restructure indent=0 cases --- .../songs/lib/importers/singingthefaith.py | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index ba3c1dbb6..593b3f5c6 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -117,7 +117,7 @@ class SingingTheFaithImport(SongImport): try: for line in file: line_number += 1 - if hints_available and (str(line_number) in self.hint_line): + if hints_available and str(line_number) in self.hint_line: hint = self.hint_line[str(line_number)] if hint == 'Comment': line.strip() @@ -137,24 +137,26 @@ class SingingTheFaithImport(SongImport): next(file) continue elif hint.startswith('VariantVerse'): - (vv, hintverse, replace) = hint.split(' ', 2) + vv, hintverse, replace = hint.split(' ', 2) this_verse = self.verses[int(hintverse) - 1] this_verse_str = this_verse[1] new_verse = this_verse_str # There might be multiple replace pairs separated by | replaces = replace.split('|') for rep in replaces: - (source_str, dest_str) = rep.split('/') + source_str, dest_str = rep.split('/') new_verse = new_verse.replace(source_str, dest_str) self.add_verse(new_verse, 'v') - self.verse_order_list.append('v' + str(current_verse_number)) + self.verse_order_list.append('v{}'.format(str(current_verse_number))) current_verse_number += 1 line_number += 1 next(file) continue else: - self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), - translate('SongsPlugin.SingingTheFaithImport', 'Unknown hint %s' % hint)) + self.log_error(translate('SongsPlugin.SingingTheFaithImport', + 'File {file})'.format(file=file.name)), + translate('SongsPlugin.SingingTheFaithImport', + 'Unknown hint {hint}').format(hint=hint)) return # STF exported lines have a leading verse number at the start of each verse. # remove them - note that we want to track the indent as that shows a chorus @@ -185,26 +187,22 @@ class SingingTheFaithImport(SongImport): if song_number_match: song_number = song_number_match.group() continue - # If the indent is 0 and it contains '(c)' then it is a Copyright line - elif (indent == 0) and ('(c)' in line): - copyright = line - continue - elif (indent == 0) and (line.startswith('Liturgical ')): - self.add_comment(line) - continue - elif (indent == 0) and (line.startswith('From The ')): - self.add_comment(line) - continue - elif (indent == 0) and (line.startswith('From Common ')): - self.add_comment(line) - continue - # If indent is 0 it may be the author, unless it was one of the cases covered above - elif (indent == 0) and len(line) > 0: - # May have more than one author, separated by ' and ' - authors = line.split(' and ') - for a in authors: - self.parse_author(a) - continue + elif indent == 0: + # If the indent is 0 and it contains '(c)' then it is a Copyright line + if '(c)' in line: + copyright = line + continue + elif (line.startswith('Liturgical ') or line.startswith('From The ') or + line.startswith('From Common ')): + self.add_comment(line) + continue + # If indent is 0 it may be the author, unless it was one of the cases covered above + elif len(line) > 0: + # May have more than one author, separated by ' and ' + authors = line.split(' and ') + for a in authors: + self.parse_author(a) + continue if line == '': if current_verse != '': self.add_verse(current_verse, current_verse_type) @@ -237,13 +235,13 @@ class SingingTheFaithImport(SongImport): current_verse += '\n' + line old_indent = indent except Exception as e: - self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), - translate('SongsPlugin.SingingTheFaithImport', 'Error: %s') % e) + self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File {file}').format(file=file.name), + translate('SongsPlugin.SingingTheFaithImport', 'Error: {error}').format(error=e)) return if self.hint_song_title: song_title = self.hint_song_title - self.title = check_flag + 'STF' + song_number.zfill(3) + ' - ' + song_title + self.title = '{}STF{} - {title}'.format(check_flag, song_number.zfill(3), title=song_title) self.song_book_name = 'Singing The Faith' self.song_number = song_number self.ccli_number = ccli @@ -254,7 +252,7 @@ class SingingTheFaithImport(SongImport): if has_chorus and not self.hint_verse_order and not self.checks_needed: auto_verse_order_ok = False # Popular case V1 C2 V2 ... - if len(self.verse_order_list) >= 1: # protect against odd cases + if self.verse_order_list: # protect against odd cases if (self.verse_order_list[0] == 'v1') and (self.verse_order_list[1] == 'c2'): new_verse_order_list = ['v1', 'c1'] i = 2 @@ -291,7 +289,7 @@ class SingingTheFaithImport(SongImport): check_flag = '' elif not hints_available and has_chorus and auto_verse_order_ok: check_flag = '' - self.title = check_flag + 'STF' + song_number.zfill(3) + ' - ' + song_title + self.title = '{}STF{} - {title}'.format(check_flag, song_number.zfill(3), title=song_title) if not self.finish(): self.log_error(file.name) @@ -312,7 +310,7 @@ class SingingTheFaithImport(SongImport): self.hint_file_version = val continue if (tag == 'Hymn') and (val == song_number): - self.add_comment('Using hints version ' + str(self.hint_file_version)) + self.add_comment('Using hints version {}'.format(str(self.hint_file_version))) hintfound = True # Assume, unless the hints has ManualCheck that if hinted all will be OK self.checks_needed = False @@ -342,11 +340,11 @@ class SingingTheFaithImport(SongImport): self.hint_ignore_indent = True elif tag == 'VariantVerse': vvline = val.split(' ', 1) - self.hint_line[vvline[0].strip()] = 'VariantVerse ' + vvline[1].strip() + self.hint_line[vvline[0].strip()] = 'VariantVerse {}'.format(vvline[1].strip()) elif tag == 'SongTitle': self.hint_song_title = val elif tag == 'AddComment': self.hint_comments += '\n' + val else: - self.log_error(file.name, 'Unknown tag ' + tag + ' value ' + val) + self.log_error(file.name, 'Unknown tag {} value {}'.format(tag, val)) return hintfound From 0c1eb5031222a20e677b640c2d0f5fb15fa18bfe Mon Sep 17 00:00:00 2001 From: John Lines Date: Sat, 13 Jul 2019 13:17:06 +0100 Subject: [PATCH 12/27] New hints for AddSpaceAfterSemi and CCLI --- .../songs/lib/importers/singingthefaith.py | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index 593b3f5c6..d0dbb634e 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -46,6 +46,7 @@ class SingingTheFaithImport(SongImport): hint_verse_order = '' hint_song_title = '' hint_comments = '' + hint_ccli = '' hint_ignore_indent = False def do_import(self): @@ -119,15 +120,13 @@ class SingingTheFaithImport(SongImport): line_number += 1 if hints_available and str(line_number) in self.hint_line: hint = self.hint_line[str(line_number)] + # Set to false if this hint does not replace the line + line_replaced = True if hint == 'Comment': line.strip() self.add_comment(line) - line_number += 1 - next(file) continue elif hint == 'Ignore': - line_number += 1 - next(file) continue elif hint == 'Author': # add as a raw author - do not split and make them a words author @@ -152,12 +151,17 @@ class SingingTheFaithImport(SongImport): line_number += 1 next(file) continue + elif hint == 'AddSpaceAfterSemi': + line = line.replace(';', '; ') + line_replaced = False + # note - do not use contine here as the line should now be processed as normal. else: self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File {file})'.format(file=file.name)), translate('SongsPlugin.SingingTheFaithImport', 'Unknown hint {hint}').format(hint=hint)) - return + if line_replaced: + return # STF exported lines have a leading verse number at the start of each verse. # remove them - note that we want to track the indent as that shows a chorus # so will deal with that before stipping all leading spaces. @@ -179,8 +183,9 @@ class SingingTheFaithImport(SongImport): else: line = line.strip() if line_number == 2: - # note that songs seem to start with a blank line - song_title = line + # note that songs seem to start with a blank line so the title is line 2 + # Also we strip blanks from the title, even if ignoring indent. + song_title = line.strip() # Detect the 'Reproduced from Singing the Faith Electronic Words Edition' line if line.startswith('Reproduced from Singing the Faith Electronic Words Edition'): song_number_match = re.search(r'\d+', line) @@ -282,6 +287,8 @@ class SingingTheFaithImport(SongImport): self.verse_order_list = self.hint_verse_order.split(',') if self.hint_comments: self.add_comment(self.hint_comments) + if self.hint_ccli: + self.ccli_number = self.hint_ccli # Write the title last as by now we will know if we need checks if hints_available and not self.checks_needed: check_flag = '' @@ -300,6 +307,7 @@ class SingingTheFaithImport(SongImport): self.hint_comments = '' self.hint_song_title = '' self.hint_ignore_indent = False + self.hint_ccli = '' for tl in file: if not tl.strip(): return hintfound @@ -332,6 +340,10 @@ class SingingTheFaithImport(SongImport): vals = val.split(',') for v in vals: self.hint_line[v] = 'Author' + elif tag == 'AddSpaceAfterSemi': + vals = val.split(',') + for v in vals: + self.hint_line[v] = 'AddSpaceAfterSemi' elif tag == 'VerseOrder': self.hint_verse_order = val elif tag == 'ManualCheck': @@ -345,6 +357,10 @@ class SingingTheFaithImport(SongImport): self.hint_song_title = val elif tag == 'AddComment': self.hint_comments += '\n' + val + elif tag == 'CCLI': + self.hint_ccli = val + elif tag == 'Hymn': + self.log_error(file.name, 'Missing End tag in hint for Hymn: {}'.format(song_number)) else: self.log_error(file.name, 'Unknown tag {} value {}'.format(tag, val)) return hintfound From a9d0e0909f46e40f4a18121ada8a8d765292a774 Mon Sep 17 00:00:00 2001 From: John Lines Date: Mon, 15 Jul 2019 17:25:43 +0100 Subject: [PATCH 13/27] Update GPL version, use constructor, add comment to signal unepected verse order --- .../songs/lib/importers/singingthefaith.py | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index d0dbb634e..b057dcb8c 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -8,7 +8,7 @@ # --------------------------------------------------------------------------- # # 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. # +# Software Foundation; version 3 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 # @@ -39,15 +39,20 @@ class SingingTheFaithImport(SongImport): Import songs exported from SingingTheFaith """ - hints_available = False - checks_needed = True - hint_line = {} - hint_file_version = '0' - hint_verse_order = '' - hint_song_title = '' - hint_comments = '' - hint_ccli = '' - hint_ignore_indent = False + def __init__(self, manager, **kwargs): + """ + Initialise the class. + """ + super(SingingTheFaithImport, self).__init__(manager, **kwargs) + self.hints_available = False + self.checks_needed = True + self.hint_line = {} + self.hint_file_version = '0' + self.hint_verse_order = '' + self.hint_song_title = '' + self.hint_comments = '' + self.hint_ccli = '' + self.hint_ignore_indent = False def do_import(self): """ @@ -251,9 +256,9 @@ class SingingTheFaithImport(SongImport): self.song_number = song_number self.ccli_number = ccli self.add_copyright(copyright) -# If we have a chorus then the generated Verse order can not be used directly, but we can generate -# one for two special cases - Verse followed by one chorus (to be repeated after every verse) -# of Chorus, followed by verses. If hints for ManualCheck or VerseOrder are supplied ignore this + # If we have a chorus then the generated Verse order can not be used directly, but we can generate + # one for two special cases - Verse followed by one chorus (to be repeated after every verse) + # of Chorus, followed by verses. If hints for ManualCheck or VerseOrder are supplied ignore this if has_chorus and not self.hint_verse_order and not self.checks_needed: auto_verse_order_ok = False # Popular case V1 C2 V2 ... @@ -273,11 +278,9 @@ class SingingTheFaithImport(SongImport): new_verse_order_list.append(self.verse_order_list[i]) new_verse_order_list.append('c1') else: - # Would like to notify, but want a warning, which we will do via the - # Check_needed mechanism, as log_error aborts input of that song. - # self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File %s' % file.name), - # 'Error: Strange verse order entry ' + self.verse_order_list[i]) auto_verse_order_ok = False + self.add_comment('Importer detected unexpected verse order entry {}'.format( + self.verse_order_list[i])) i += 1 self.verse_order_list = new_verse_order_list else: @@ -301,6 +304,11 @@ class SingingTheFaithImport(SongImport): self.log_error(file.name) def read_hints(self, file, song_number): + """ + Read the hints used to transform a particular song into version which can be projected, + or improve the transformation process beyond the standard heuristics. Not every song will + have, or need, hints. + """ hintfound = False self.hint_verse_order = '' self.hint_line.clear() From 72747c3936d643110aaa1913a1ab7a538a7f903b Mon Sep 17 00:00:00 2001 From: John Lines Date: Tue, 16 Jul 2019 12:40:23 +0100 Subject: [PATCH 14/27] Add AddSpaceAfterColon hint --- openlp/plugins/songs/lib/importers/singingthefaith.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index b057dcb8c..d31469e73 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -160,6 +160,9 @@ class SingingTheFaithImport(SongImport): line = line.replace(';', '; ') line_replaced = False # note - do not use contine here as the line should now be processed as normal. + elif hint == 'AddSpaceAfterColon': + line = line.replace(':', ': ') + line_replaced = False else: self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File {file})'.format(file=file.name)), @@ -169,7 +172,7 @@ class SingingTheFaithImport(SongImport): return # STF exported lines have a leading verse number at the start of each verse. # remove them - note that we want to track the indent as that shows a chorus - # so will deal with that before stipping all leading spaces. + # so will deal with that before stripping all leading spaces. indent = 0 if line.strip(): verse_num_match = re.search(r'^\d+', line) @@ -352,6 +355,10 @@ class SingingTheFaithImport(SongImport): vals = val.split(',') for v in vals: self.hint_line[v] = 'AddSpaceAfterSemi' + elif tag == 'AddSpaceAfterColon': + vals = val.split(',') + for v in vals: + self.hint_line[v] = 'AddSpaceAfterColon' elif tag == 'VerseOrder': self.hint_verse_order = val elif tag == 'ManualCheck': From bd61ad1f6d7aa6d47e37b3aa0cbee44610a81a1b Mon Sep 17 00:00:00 2001 From: John Lines Date: Wed, 17 Jul 2019 10:54:03 +0100 Subject: [PATCH 15/27] Add BlankLine hint and deal with a leading asterisk on a verse number --- .../songs/lib/importers/singingthefaith.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index d31469e73..ab444f659 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -163,6 +163,9 @@ class SingingTheFaithImport(SongImport): elif hint == 'AddSpaceAfterColon': line = line.replace(':', ': ') line_replaced = False + elif hint == 'BlankLine': + line = ' *Blank*' + line_replaced = False else: self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File {file})'.format(file=file.name)), @@ -175,6 +178,10 @@ class SingingTheFaithImport(SongImport): # so will deal with that before stripping all leading spaces. indent = 0 if line.strip(): + # One hymn has one line which starts '* 6' at the start of a verse + # Strip this out + if line.startswith('* 6'): + line = line.lstrip('* ') verse_num_match = re.search(r'^\d+', line) if verse_num_match: # Could extract the verse number and check it against the calculated @@ -216,6 +223,10 @@ class SingingTheFaithImport(SongImport): for a in authors: self.parse_author(a) continue + # If a blank line has bee replaced by *Blank* then put it back to being + # a simple space since this is past stripping blanks + if '*Blank*' in line: + line = ' ' if line == '': if current_verse != '': self.add_verse(current_verse, current_verse_type) @@ -359,6 +370,10 @@ class SingingTheFaithImport(SongImport): vals = val.split(',') for v in vals: self.hint_line[v] = 'AddSpaceAfterColon' + elif tag == 'BlankLine': + vals = val.split(',') + for v in vals: + self.hint_line[v] = 'BlankLine' elif tag == 'VerseOrder': self.hint_verse_order = val elif tag == 'ManualCheck': From 2e89ec1f2966ab1ab4e9a01163b248b714b4986a Mon Sep 17 00:00:00 2001 From: John Lines Date: Fri, 19 Jul 2019 12:11:16 +0100 Subject: [PATCH 16/27] enable whole song impoerter test --- .../openlp_plugins/songs/test_singingthefaithimport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py index fbbf2a3e1..69e9728c4 100644 --- a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py +++ b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py @@ -43,6 +43,6 @@ class TestSingingTheFaithFileImport(SongImportTestHelper): # Single verse self.file_import([TEST_PATH / 'H1.txt'], self.load_external_result_data(TEST_PATH / 'STF001.json')) - # Whole song - currently not working - test needs debugging. - # self.file_import([TEST_PATH / 'H2.txt'], - # self.load_external_result_data(TEST_PATH / 'STF002.json')) + # Whole song + self.file_import([TEST_PATH / 'H2.txt'], + self.load_external_result_data(TEST_PATH / 'STF002.json')) From f15cc88eb97ab6829add30f492fddd0ce905130a Mon Sep 17 00:00:00 2001 From: John Lines Date: Sat, 27 Jul 2019 09:03:26 +0100 Subject: [PATCH 17/27] Strip unwanted formatting characters --- openlp/plugins/songs/lib/importers/singingthefaith.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index ab444f659..7c61aa76a 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -123,6 +123,9 @@ class SingingTheFaithImport(SongImport): try: for line in file: line_number += 1 + # Strip out leftover formatting (\i and \b) + line = line.replace('\\i', '') + line = line.replace('\\b', '') if hints_available and str(line_number) in self.hint_line: hint = self.hint_line[str(line_number)] # Set to false if this hint does not replace the line From c3eecd04d97b4221d3356d6f2e07345d8805ad4f Mon Sep 17 00:00:00 2001 From: John Lines Date: Sun, 28 Jul 2019 09:46:38 +0100 Subject: [PATCH 18/27] Implement BoldLine hint --- openlp/plugins/songs/lib/importers/singingthefaith.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index 7c61aa76a..1b7233f70 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -169,6 +169,9 @@ class SingingTheFaithImport(SongImport): elif hint == 'BlankLine': line = ' *Blank*' line_replaced = False + elif hint == 'BoldLine': + # processing of the hint is deferred, but pick it up as a known hint here + line_replaced = False else: self.log_error(translate('SongsPlugin.SingingTheFaithImport', 'File {file})'.format(file=file.name)), @@ -204,6 +207,9 @@ class SingingTheFaithImport(SongImport): # note that songs seem to start with a blank line so the title is line 2 # Also we strip blanks from the title, even if ignoring indent. song_title = line.strip() + # Process possible line formatting hints after the verse number has been removed + if hints_available and str(line_number) in self.hint_line and hint == 'BoldLine': + line = '{{st}}{0}{{/st}}'.format(line) # Detect the 'Reproduced from Singing the Faith Electronic Words Edition' line if line.startswith('Reproduced from Singing the Faith Electronic Words Edition'): song_number_match = re.search(r'\d+', line) @@ -377,6 +383,10 @@ class SingingTheFaithImport(SongImport): vals = val.split(',') for v in vals: self.hint_line[v] = 'BlankLine' + elif tag == 'BoldLine': + vals = val.split(',') + for v in vals: + self.hint_line[v] = 'BoldLine' elif tag == 'VerseOrder': self.hint_verse_order = val elif tag == 'ManualCheck': From 8a6e6f767f16a9ba8efa5026bf16d8d8e49eff1b Mon Sep 17 00:00:00 2001 From: John Lines Date: Sun, 28 Jul 2019 21:59:51 +0100 Subject: [PATCH 19/27] Make Based on Psalm an automatic comment, do not automatically make Authors type Word --- openlp/plugins/songs/lib/importers/singingthefaith.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index 1b7233f70..a308bd992 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -137,9 +137,9 @@ class SingingTheFaithImport(SongImport): elif hint == 'Ignore': continue elif hint == 'Author': - # add as a raw author - do not split and make them a words author + # add as a raw author - do not split line.strip() - self.add_author(line, 'words') + self.add_author(line) line_number += 1 next(file) continue @@ -222,7 +222,7 @@ class SingingTheFaithImport(SongImport): copyright = line continue elif (line.startswith('Liturgical ') or line.startswith('From The ') or - line.startswith('From Common ')): + line.startswith('From Common ') or line.startsith('Based on Psalm ')): self.add_comment(line) continue # If indent is 0 it may be the author, unless it was one of the cases covered above From 530976cf7405ae23c7bb6372df1e1bc280bdacdd Mon Sep 17 00:00:00 2001 From: John Lines Date: Sun, 28 Jul 2019 22:16:02 +0100 Subject: [PATCH 20/27] Fix typo --- openlp/plugins/songs/lib/importers/singingthefaith.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index a308bd992..b02d267ce 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -222,7 +222,7 @@ class SingingTheFaithImport(SongImport): copyright = line continue elif (line.startswith('Liturgical ') or line.startswith('From The ') or - line.startswith('From Common ') or line.startsith('Based on Psalm ')): + line.startswith('From Common ') or line.startswith('Based on Psalm ')): self.add_comment(line) continue # If indent is 0 it may be the author, unless it was one of the cases covered above From e42d3431bbc4cbef508e7b7da709de45fb6ea670 Mon Sep 17 00:00:00 2001 From: John Lines Date: Fri, 23 Aug 2019 10:33:48 +0100 Subject: [PATCH 21/27] Use .format in importer.py --- openlp/plugins/songs/lib/importer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 5fa758783..2603f2f23 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -349,7 +349,8 @@ class SongFormat(object): 'class': SingingTheFaithImport, 'name': 'SingingTheFaith', 'prefix': 'singingTheFaith', - 'filter': '%s (*.txt)' % translate('SongsPlugin.ImportWizardForm', 'Singing The Faith Exported Files'), + 'filter': '{text} (*.txt)'.format(text=translate('SongsPlugin.ImportWizardForm', + 'Singing The Faith Exported Files')), 'descriptionText': translate('SongsPlugin.ImportWizardForm', 'First use Singing The Faith Electonic edition to export ' 'the song(s) in Text format.') From f2513c8474dd734b59a8cc4588f295070a9f8186 Mon Sep 17 00:00:00 2001 From: John Lines Date: Fri, 23 Aug 2019 17:29:39 +0100 Subject: [PATCH 22/27] Implement SongbookNumberInTitle hint --- .../songs/lib/importers/singingthefaith.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index b02d267ce..e6fe78b48 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -53,6 +53,7 @@ class SingingTheFaithImport(SongImport): self.hint_comments = '' self.hint_ccli = '' self.hint_ignore_indent = False + self.hint_songbook_number_in_title = False def do_import(self): """ @@ -64,6 +65,9 @@ class SingingTheFaithImport(SongImport): for file_path in self.import_source: if self.stop_import_flag: return + # If this is backported to version 2.4 then do_import is called with a filename + # rather than a path object if called from the development version. + # Check here to minimise differences between versions. if isinstance(file_path, str): song_file = open(file_path, 'rt', encoding='cp1251') self.do_import_file(song_file) @@ -85,6 +89,8 @@ class SingingTheFaithImport(SongImport): # but we test for >= and I do not know how consistent to formatting of the # exported songs is. chorus_indent = 5 + # Initialise the song title - the format of the title finally produced can be affected + # by the SongbookNumberInTitle option in the hints file song_title = 'STF000 -' song_number = '0' ccli = '0' @@ -102,7 +108,8 @@ class SingingTheFaithImport(SongImport): # all the songs which need manual editing should sort below all the OK songs check_flag = 'z' - self.add_comment('Imported with Singing The Faith Importer v ' + str(singing_the_faith_version)) + self.add_comment( + 'Imported with Singing The Faith Importer v{no}'.format(no=singing_the_faith_version)) # Get the file_song_number - so we can use it for hints filename = Path(file.name) @@ -286,11 +293,11 @@ class SingingTheFaithImport(SongImport): auto_verse_order_ok = False # Popular case V1 C2 V2 ... if self.verse_order_list: # protect against odd cases - if (self.verse_order_list[0] == 'v1') and (self.verse_order_list[1] == 'c2'): + if self.verse_order_list[0] == 'v1' and self.verse_order_list[1] == 'c2': new_verse_order_list = ['v1', 'c1'] i = 2 auto_verse_order_ok = True - elif (self.verse_order_list[0] == 'c1') and (self.verse_order_list[1] == 'v1'): + elif self.verse_order_list[0] == 'c1' and self.verse_order_list[1] == 'v1': new_verse_order_list = ['c1', 'v1', 'c1'] i = 2 auto_verse_order_ok = True @@ -322,7 +329,10 @@ class SingingTheFaithImport(SongImport): check_flag = '' elif not hints_available and has_chorus and auto_verse_order_ok: check_flag = '' - self.title = '{}STF{} - {title}'.format(check_flag, song_number.zfill(3), title=song_title) + if self.hint_songbook_number_in_title: + self.title = '{}STF{} - {title}'.format(check_flag, song_number.zfill(3), title=song_title) + else: + self.title = '{}{title}'.format(check_flag, title=song_title) if not self.finish(): self.log_error(file.name) @@ -348,6 +358,14 @@ class SingingTheFaithImport(SongImport): if tag == 'Version': self.hint_file_version = val continue + elif tag == 'SongbookNumberInTitle': + if val == 'False': + self.hint_songbook_number_in_title = False + else: + self.hint_songbook_number_in_title = True + continue + elif tag == 'Comment': + continue if (tag == 'Hymn') and (val == song_number): self.add_comment('Using hints version {}'.format(str(self.hint_file_version))) hintfound = True From 5d494edf44ce93f11f1ac08ec92a79590e8001d2 Mon Sep 17 00:00:00 2001 From: John Lines Date: Thu, 29 Aug 2019 22:50:40 +0100 Subject: [PATCH 23/27] Upload hints.tag into resources --- resources/hints.tag | 666 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 666 insertions(+) create mode 100644 resources/hints.tag diff --git a/resources/hints.tag b/resources/hints.tag new file mode 100644 index 000000000..3791e7be8 --- /dev/null +++ b/resources/hints.tag @@ -0,0 +1,666 @@ +Tag-STFHints-version: 1.0 +Version: 2 +SongbookNumberInTitle: True +End: +Hymn: 2 +VerseOrder: V1,C1,V2,C1,V3,C1 +End: +Hymn: 8 +AddSpaceAfterColon: 2,11,20,33 +End: +Hymn: 10 +CommentsLine: 17 +End: +Hymn: 11 +CommentsLine: 24 +End: +Hymn: 15 +VerseOrder: V1,C1,V2,C1,C2,C1 +End: +Hymn: 18 +CommentsLine: 16 +End: +Hymn: 19 +CommentsLine: 8 +End: +Hymn: 22 +CommentsLine: 20 +End: +Hymn: 24 +IgnoreLine: 13 +VerseOrder: V1,V2,V1 +End: +Hymn: 26 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1,V5,C1 +End: +Hymn: 27 +AddComment: Verse 1 is original Shona +SongTitle: Jesu, tawa pano +IgnoreLine: 2 +CommentsLine: 31 +End: +Hymn: 28 +CommentsLine: 41 +End: +Hymn: 29 +CommentsLine: 18 +End: +Hymn: 30 +CommentsLine: 26 +End: +Hymn: 35 +VerseOrder: V1,C1,V2,C1,V3,C1 +End: +Hymn: 37 +IgnoreLine: 42 +VerseOrder: V1,V2,C1,V3,V4,C1 +End: +Hymn: 38 +ManualCheck: Yes +AddComment: Make all and cantor words Bold tagged for readability +SongTitle: Wa wa wa Emimimo +End: +Hymn: 40 +VariantVerse: 15 1 Blessed be the name of the Lord/Glory to the name of the Lord|blessed be the name/glory to the name +VariantVerse: 17 1 Blessed be the name of the Lord/Holy is the name of the Lord|blessed be the name/holy is the name +VerseOrder: V1,C1,V2,C1,V3,C1 +End: +Hymn: 41 +IgnoreIndent: Yes +IgnoreLine: 35,42 +VerseOrder: V1,V2,V3,V4,V2,V3,V5,V3 +End: +Hymn: 43 +IgnoreIndent: Yes +CommentsLine: 40 +End: +Hymn: 45 +IgnoreIndent: Yes +CommentsLine: 104 +End: +Hymn: 46 +VerseOrder: V1,C1,V2,C1,C2,C1 +End: +Hymn: 48 +VerseOrder: V1,C1,V2,C2 +End: +Hymn: 51 +VerseOrder: V1,C1,V2,C1,V3,C1 +End: +Hymn: 55 +AddSpaceAfterSemi: 15 +End: +Hymn: 60 +CommentsLine: 22 +End: +Hymn: 61 +VerseOrder: C1,V1,C1 +End: +Hymn: 64 +IgnoreLine: 23,25 +VerseOrder: V1,C1,C2,V2,C1,C2,C3 +End: +Hymn: 65 +VerseOrder: V1,C1,V2,C2,V3,C1,V4,C1 +End: +Hymn: 68 +IgnoreLine: 15,31 +VerseOrder: C1,V1,C1,V2,C2,C1 +End: +Hymn: 71 +IgnoreLine: 23 +VerseOrder: V1,C1,V2,C1,V3 +End: +Hymn: 74 +IgnoreIndent: Yes +End: +Hymn: 77 +IgnoreLine: 32 +CommentsLine: 37 +VerseOrder: V1,V2,C1,V3,C1 +End: +Hymn: 78 +VerseOrder: V1,V2,V1,V2,V3 +End: +Hymn: 82 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1 +End: +Hymn: 84 +IgnoreIndent: Yes +End: +Hymn: 86 +CommentsLine: 86 +End: +Hymn: 89 +VerseOrder: V1,V2,C1 +End: +Hymn: 92 +IgnoreIndent: Yes +IgnoreLine: 2,18,48 +SongTitle: Think of a world without any flowers +End: +Hymn: 93 +AddSpaceAfterSemi: 9,10,11,12 +IgnoreLine: 21,30,31,32,33 +VerseOrder: V1,C1,V2,C1,V3,C1 +End: +Hymn: 94 +AuthorLine: 24 +VerseOrder: V1,C1,V2,C1,V3,C1 +End: +Hymn: 95 +AddSpaceAfterSemi: 2 +End: +Hymn: 98 +IgnoreLine: 17,19,24 +VerseOrder: V1,C1,V2,C1,C2,C1 +AddComment: C2 is an optional Bridge +End: +Hymn: 100 +VerseOrder: C1,V1,C1,V2,C1,V3,C1,V4,C1 +End: +Hymn: 102 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1,V5,C1 +End: +Hymn: 103 +AddSpaceAfterColon: 2,3,11,20 +End: +Hymn: 105 +VerseOrder: C1,V1,C1,V2,C1 +End: +Hymn: 118 +IgnoreLine: 15,21 +CommentsLine: 28 +VerseOrder: V1,C1,C1,V2,C1,V3,C1,C1,C2 +End: +Hymn: 123 +CommentsLine: 40 +End: +Hymn: 140 +IgnoreLine: 14 +VerseOrder: V1,C1,V2,C1 +End: +Hymn: 141 +AddSpaceAfterSemi: 2 +End: +Hymn: 145 +ManualCheck: Yes +AddComment: Make cantor and all bold, and add to all verses +SongTitle: Night has fallen +End: +Hymn: 147 +AddSpaceAfterSemi: 22 +End: +Hymn: 165 +IgnoreLine: 2,11,20,29,38 +CommentsLine: 50 +SongTitle: Advent candles tell their story +End: +Hymn: 166 +CommentsLine: 40 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1,V5,C2 +End: +Hymn: 168 +CommentsLine: 30 +End: +Hymn: 170 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C2 +End: +Hymn: 173 +VerseOrder: V1,C1,V2,C1,V3,C2 +End: +Hymn: 174 +CommentsLine: 41 +End: +Hymn: 175 +IgnoreLine: 22,29 +VerseOrder: V1,C1,V2,C1,C2,C1 +End: +Hymn: 176 +CommentsLine: 26 +ManualCheck: Yes +End: +Hymn: 178 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C2 +End: +Hymn: 186 +IgnoreIndent: Yes +CommentsLine: 24 +End: +Hymn: 194 +IgnoreIndent: Yes +End: +Hymn: 200 +AddSpaceAfterColon: 2 +CommentsLine: 24 +End: +Hymn: 209 +IgnoreLine: 11,17,23 +VerseOrder: V1,C1,C1,V2,C1,V3,C1 +End: +Hymn: 212 +CommentsLine: 46 +End: +Hymn: 220 +AddSpaceAfterColon: 30 +End: +Hymn: 227 +VerseOrder: V1,V2,V3,V4,V1 +End: +Hymn: 228 +CommentsLine: 49 +End: +Hymn: 234 +CommentsLine: 7 +End: +Hymn: 235 +IgnoreIndent: Yes +End: +Hymn: 240 +CommentsLine: 24 +End: +Hymn: 241 +IgnoreLine: 39 +VerseOrder: V1,C1,V2,C2,C3,C2 +AddComment: is the final chorus a repeat of C1 or C2 ? +ManualCheck: Yes +End: +Hymn: 246 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1 +End: +Hymn: 247 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1,V5,C1 +End: +Hymn: 248 +AddSpaceAfterSemi: 13 +End: +Hymn: 249 +VerseOrder: C1,V1,C1,V2,C1,V3,C1,V4,C1 +End: +Hymn: 252 +AddSpaceAfterColon: 1,6,9,13,16,20,23,27,30,34 +End: +Hymn: 254 +CommentsLine: 22 +End: +Hymn: 256 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1,V5,C1,V6,C2 +End: +Hymn: 258 +IgnoreLine: 14 +VerseOrder: C1,V1,C1 +End: +Hymn: 261 +AddSpaceAfterSemi: 4 +End: +Hymn: 267 +CommentsLine: 33 +End: +Hymn: 274 +IgnoreLine: 21,30 +VerseOrder: V1,C1,V2,C1,C2,C1 +End: +Hymn: 279 +IgnoreLine: 35 +VerseOrder: V1,V2,C1,V3,V4,C1 +End: +Hymn: 285 +CommentsLine: 25 +End: +Hymn: 298 +IgnoreIndent: Yes +AddSpaceAfterSemi: 8 +End: +Hymn: 299 +IgnoreLine: 26 +CommentsLine: 32 +VerseOrder: V1,C1,V2,V3,V4,C1,C2 +End: +Hymn: 300 +AddSpaceAfterSemi: 8,9,13,17,18 +AddSpaceAfterColon: 7,15,20,25,30 +End: +Hymn: 302 +VerseOrder: C1,V1,C1,V2,C1,V3,C1,V4,C1,V5,C1 +End: +Hymn: 316 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1,V5,C1,V6,C1,V7,C2 +End: +Hymn: 321 +CommentsLine: 15 +End: +Hymn: 323 +AddSpaceAfterSemi: 11 +End: +Hymn: 331 +VerseOrder: V1,C1,V2,C2 +End: +Hymn: 335 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1,V5,C2 +End: +Hymn: 343 +IgnoreLine: 24 +VerseOrder: V1,V2,C1,V3,C1 +End: +Hymn: 349 +AddSpaceAfterSemi: 20,24 +IgnoreLine: 17 +AddComment: The refrain is optional +VerseOrder: V1,V2,V3,C1,V4,V3 +End: +Hymn: 351 +CCLI: 3350395 +End: +Hymn: 353 +AddSpaceAfterSemi: 15 +End: +Hymn: 364 +AddSpaceAfterSemi: 22 +End: +Hymn: 367 +IgnoreLine: 28 +VerseOrder: V1,C1,V2,C1 +End: +Hymn: 373 +CommentsLine: 26 +End: +Hymn: 374 +ManualCheck: Yes +CommentsLine: 24 +End: +Hymn: 377 +VerseOrder: V1,C1,V2,C1,V3,C1 +End: +Hymn: 380 +VerseOrder: V1,C1,V2,C1 +End: +Hymn: 386 +BlankLine: 6,16 +IgnoreLine: 19,26 +VerseOrder: V1,C1,V2,C1,C2,C1 +End: +Hymn: 389 +AuthorLine: 21 +End: +Hymn: 401 +AddSpaceAfterSemi: 27 +End: +Hymn: 403 +AddSpaceAfterColon: 2 +End: +Hymn: 404 +SongTitle: Go tell everyone +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1 +End: +Hymn: 405 +VerseOrder: V1,C1,V2,C1,V3,C1 +End: +Hymn: 406 +IgnoreLine: 18,27 +End: +Hymn: 407 +IgnoreLine: 31 +VerseOrder: V1,V2,C1,V3,C1 +End: +Hymn: 408 +IgnoreIndent: Yes +CommentsLine: 25 +End: +Hymn: 410 +AddSpaceAfterSemi: 15,16 +End: +Hymn: 419 +CommentsLine: 25 +End: +Hymn: 420 +IgnoreIndent: Yes +End: +Hymn: 421 +IgnoreIndent: Yes +CommentsLine: 55 +End: +Hymn: 424 +IgnoreLine: 16 +VerseOrder: V1,C1,V2,C1 +End: +Hymn: 428 +IgnoreLine: 25 +VerseOrder: V1,V2,C1,V3,C1 +End: +Hymn: 432 +AddSpaceAfterSemi: 8 +End: +Hymn: 433 +CommentsLine: 44 +End: +Hymn: 447 +IgnoreLine: 19,21 +VerseOrder: V1,V2,C1,V3,C1,V1 +End: +Hymn: 451 +IgnoreLine: 14,16 +VerseOrder: C1,V1,C1,V1,V2 +End: +Hymn: 454 +CommentsLine: 2,42 +SongTitle: Where shall my wondering soul begin +End: +Hymn: 458 +CommentsLine: 2 +SongTitle: Away with our fears The glad morning appears +End: +Hymn: 469 +ManualCheck: Yes +AddComment: Need a VariantChorus, Chorus2 and Chorus3 are Variants of Chorus1 +VerseOrder: V1,C1,V2,C2,V3,C2,V4,C3 +End: +Hymn: 470 +IgnoreIndent: Yes +End: +Hymn: 476 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C1,V5,C1 +End: +Hymn: 477 +VerseOrder: C1,V1,C1,V2,C1 +End: +Hymn: 480 +CommentsLine: 28 +End: +Hymn: 483 +AddComment: Verses 4 and 5 are the +CommentsLine: 29 +End: +Hymn: 488 +IgnoreLine: 25 +VerseOrder: V1,V2,C1,V3,C1 +End: +Hymn: 492 +AddSpaceAfterSemi: 9,10,15 +End: +Hymn: 499 +CommentsLine: 37 +End: +Hymn: 509 +IgnoreIndent: Yes +CommentsLine: 40 +End: +Hymn: 517 +VerseOrder: V1,C1,V2,C1,V3,C1,V4,C2 +End: +Hymn: 528 +CommentsLine: 32 +End: +Hymn: 541 +IgnoreLine: 17,18,25 +VerseOrder: V1,V2,C1,V1,V2,V3,C1 +End: +Hymn: 545 +CommentsLine: 28 +End: +Hymn: 548 +AuthorLine: 22 +End: +Hymn: 554 +IgnoreLine: 15,21 +VerseOrder: V1,C1,V2,C1,V3,C1,V4 +End: +Hymn: 555 +IgnoreLine: 15 +VerseOrder: V1,V2,C1,V1 +End: +Hymn: 559 +IgnoreIndent: Yes +End: +Hymn: 561 +CommentsLine: 45 +End: +Hymn: 562 +CommentsLine: 38 +End: +Hymn: 565 +IgnoreLine: 21 +VerseOrder: V1,V2,V1 +End: +Hymn: 566 +AddSpaceAfterSemi: 27 +End: +Hymn: 567 +ManualCheck: Yes +AddComment: Check with musician what should be on the screen +End: +Hymn: 570 +VerseOrder: V1,C1,V2,C1,V3,C1 +End: +Hymn: 575 +CommentsLine: 30 +End: +Hymn: 578 +IgnoreLine: 11,18,25 +VerseOrder: C1,V1,C1,V2,C1,V3,C1 +End: +Hymn: 586 +IgnoreLine: 22 +VerseOrder: V1,V2,C1,V3,C1 +End: +Hymn: 587 +VerseOrder: V1,C1,V2,C2,V3 +End: +Hymn: 582 +CommentsLine: 25 +End: +Hymn: 594 +CommentsLine: 41 +End: +Hymn: 601 +CommentsLine: 16 +End: +Hymn: 603 +ManualCheck: Yes +AddComment: Update Verse 4 for names of the couple +CommentsLine: 22 +IgnoreIndent: Yes +End: +Hymn: 609 +CommentsLine: 37 +End: +Hymn: 610 +CommentsLine: 29 +End: +Hymn: 626 +IgnoreLine: 29,31,44 +VerseOrder: V1,C1,C2,V2,C1,C2,C3,C2 +End: +Hymn: 631 +CommentsLine: 15 +End: +Hymn: 627 +IgnoreLine: 25,36 +VerseOrder: V1,C1,V2,C1,C2,C1 +End: +Hymn: 632 +IgnoreLine: 17,24 +VerseOrder: V1,C1,V2,C1,C2,C1 +End: +Hymn: 635 +IgnoreLine: 23,25 +VerseOrder: V1,C1,C2,V2,C1,C2 +End: +Hymn: 637 +CommentsLine: 41 +End: +Hymn: 638 +CommentsLine: 34 +End: +Hymn: 640 +CommentsLine: 19,20 +End: +Hymn: 654 +IgnoreIndent: Yes +End: +Hymn: 657 +IgnoreLine: 20,21,23 +VerseOrder: V1,C1,C2,V2,C1,C2,C3 +End: +Hymn: 662 +AddSpaceAfterSemi: 2,12 +End: +Hymn: 670 +IgnoreLine: 27 +VerseOrder: V1,C1,V2,C1 +End: +Hymn: 677 +CommentsLine: 31 +End: +Hymn: 681 +IgnoreIndent: Yes +End: +Hymn: 684 +IgnoreIndent: Yes +End: +Hymn: 693 +IgnoreLine: 46,57 +VerseOrder: V1,V2,C1,V3,V4,C1,V5,C1 +End: +Hymn: 697 +IgnoreIndent: Yes +CommentsLine: 21 +End: +Hymn: 699 +IgnoreLine: 23,32 +VerseOrder: V1,C1,V2,C1,C1,C2,C1 +End: +Hymn: 700 +IgnoreIndent: Yes +End: +Hymn: 707 +IgnoreLine: 15 +VerseOrder: V1,C1,V2,C1,V3 +End: +Hymn: 729 +IgnoreIndent: Yes +End: +Hymn: 741 +CommentsLine: 25 +End: +Hymn: 753 +CommentsLine: 14 +IgnoreIndent: Yes +End: +Hymn: 754 +IgnoreIndent: Yes +End: +Hymn: 764 +IgnoreIndent: Yes +CommentsLine: 31 +End: +Hymn: 783 +BlankLine: 5 +End: +Hymn: 819 +AddSpaceAfterSemi: 32 +End: +Hymn: 820 +CommentsLine: 2 +BoldLine: 6,7,12,13,17,18,23,24,29,30,32,33,34,35 +SongTitle: Psalm 98 - O sing to the Lord a new song +End: From 6b8352abeab476cacdf1c41dd5cc14db74012e95 Mon Sep 17 00:00:00 2001 From: John Lines Date: Tue, 3 Sep 2019 10:52:09 +0100 Subject: [PATCH 24/27] fix tests to allow for SongbookNumberInTitle defaulting to false and add hints tests --- .../songs/test_singingthefaithimport.py | 15 +++++++++++++++ tests/resources/songs/singingthefaith/STF001.json | 2 +- tests/resources/songs/singingthefaith/STF002.json | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py index 69e9728c4..671c24865 100644 --- a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py +++ b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py @@ -46,3 +46,18 @@ class TestSingingTheFaithFileImport(SongImportTestHelper): # Whole song self.file_import([TEST_PATH / 'H2.txt'], self.load_external_result_data(TEST_PATH / 'STF002.json')) + + # Tests with hints - note that the hints directory has a hints.tag which specifies + # SongbookNumberInTitle: True + # The default is false, so the unhinted tests will not have the title, but the hinted + # song tests will need it + + # Single verse + self.file_import([TEST_PATH / 'hints' / 'H1.txt'], + self.load_external_result_data(TEST_PATH / 'hints' / 'STF001.json')) + # Whole song + self.file_import([TEST_PATH / 'hints' / 'H2.txt'], + self.load_external_result_data(TEST_PATH / 'hints' / 'STF002.json')) + + + diff --git a/tests/resources/songs/singingthefaith/STF001.json b/tests/resources/songs/singingthefaith/STF001.json index edf3ee682..02125d303 100644 --- a/tests/resources/songs/singingthefaith/STF001.json +++ b/tests/resources/songs/singingthefaith/STF001.json @@ -1,5 +1,5 @@ { - "title": "STF001 - Amazing Grace! how sweet the sound!", + "title": "Amazing Grace! how sweet the sound!", "authors": [ "John Newton (d. 1807)" ], diff --git a/tests/resources/songs/singingthefaith/STF002.json b/tests/resources/songs/singingthefaith/STF002.json index 6bfc655bf..f78d23a18 100644 --- a/tests/resources/songs/singingthefaith/STF002.json +++ b/tests/resources/songs/singingthefaith/STF002.json @@ -1,5 +1,5 @@ { - "title": "STF002 - Amazing Grace! how sweet the sound!", + "title": "Amazing Grace! how sweet the sound!", "authors": [ "John Newton (d. 1807)" ], From b2f3496093e9b9ef0954eb417993b80e3a094da6 Mon Sep 17 00:00:00 2001 From: John Lines Date: Tue, 3 Sep 2019 12:53:54 +0100 Subject: [PATCH 25/27] add tests with hints subdirectory --- .../songs/singingthefaith/hints/H1.txt | 9 ++++++ .../songs/singingthefaith/hints/H2.txt | 30 +++++++++++++++++++ .../songs/singingthefaith/hints/STF001.json | 13 ++++++++ .../songs/singingthefaith/hints/STF002.json | 29 ++++++++++++++++++ .../songs/singingthefaith/hints/hints.tag | 5 ++++ 5 files changed, 86 insertions(+) create mode 100644 tests/resources/songs/singingthefaith/hints/H1.txt create mode 100644 tests/resources/songs/singingthefaith/hints/H2.txt create mode 100644 tests/resources/songs/singingthefaith/hints/STF001.json create mode 100644 tests/resources/songs/singingthefaith/hints/STF002.json create mode 100644 tests/resources/songs/singingthefaith/hints/hints.tag diff --git a/tests/resources/songs/singingthefaith/hints/H1.txt b/tests/resources/songs/singingthefaith/hints/H1.txt new file mode 100644 index 000000000..3caf1cd11 --- /dev/null +++ b/tests/resources/songs/singingthefaith/hints/H1.txt @@ -0,0 +1,9 @@ + +1 Amazing Grace! how sweet the sound! + That saved a wretch like me! + I once was lost, but now am found; + Was blind, but now I see. + +John Newton (d. 1807) + +Reproduced from Singing the Faith Electronic Words Edition, number 1 - or not as this is a hand made test file diff --git a/tests/resources/songs/singingthefaith/hints/H2.txt b/tests/resources/songs/singingthefaith/hints/H2.txt new file mode 100644 index 000000000..3066293e1 --- /dev/null +++ b/tests/resources/songs/singingthefaith/hints/H2.txt @@ -0,0 +1,30 @@ + +1 Amazing Grace! how sweet the sound! + That saved a wretch like me! + I once was lost, but now am found; + Was blind, but now I see. + +2 'Twas grace that taught my heart to fear, + And grace my fears relieved. + How precious did that grace appear, + The hour I first believed. + +3 The Lord has promised good to me, + His Word my hope secures. + He will my shield and portion be + As long as life endures. + +4 Thro' many dangers, toils and snares + I have already come. + 'Tis grace that brought me safe thus far, + And grace will lead me home. + +5 When we've been there ten thousand years, + Bright shining as the sun, + We've no less days to sing God's praise, + Than when we first begun. + + +John Newton (d. 1807) + +Reproduced from Singing the Faith Electronic Words Edition, number 2 - or not as this is a hand made test file diff --git a/tests/resources/songs/singingthefaith/hints/STF001.json b/tests/resources/songs/singingthefaith/hints/STF001.json new file mode 100644 index 000000000..edf3ee682 --- /dev/null +++ b/tests/resources/songs/singingthefaith/hints/STF001.json @@ -0,0 +1,13 @@ +{ + "title": "STF001 - Amazing Grace! how sweet the sound!", + "authors": [ + "John Newton (d. 1807)" + ], + "verse_order_list": ["v1"], + "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" + ] + ] +} diff --git a/tests/resources/songs/singingthefaith/hints/STF002.json b/tests/resources/songs/singingthefaith/hints/STF002.json new file mode 100644 index 000000000..6bfc655bf --- /dev/null +++ b/tests/resources/songs/singingthefaith/hints/STF002.json @@ -0,0 +1,29 @@ +{ + "title": "STF002 - Amazing Grace! how sweet the sound!", + "authors": [ + "John Newton (d. 1807)" + ], + "verse_order_list": ["v1", "v2", "v3", "v4", "v5"], + "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" + ], + [ + "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" + ], + [ + "Thro' 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" + ], + [ + "When we've been there ten thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise,\nThan when we first begun.", + "v" + ] + ] +} diff --git a/tests/resources/songs/singingthefaith/hints/hints.tag b/tests/resources/songs/singingthefaith/hints/hints.tag new file mode 100644 index 000000000..d3f791d1e --- /dev/null +++ b/tests/resources/songs/singingthefaith/hints/hints.tag @@ -0,0 +1,5 @@ +Tag-STFHints-version: 1.0 +Version: 2 +SongbookNumberInTitle: True +End: + From 3c677bc077dfa81a740cdfe08cd7759faf00ddb6 Mon Sep 17 00:00:00 2001 From: John Lines Date: Tue, 3 Sep 2019 13:42:06 +0100 Subject: [PATCH 26/27] Linting fix --- .../openlp_plugins/songs/test_singingthefaithimport.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py index 671c24865..1c7a259f4 100644 --- a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py +++ b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py @@ -58,6 +58,3 @@ class TestSingingTheFaithFileImport(SongImportTestHelper): # Whole song self.file_import([TEST_PATH / 'hints' / 'H2.txt'], self.load_external_result_data(TEST_PATH / 'hints' / 'STF002.json')) - - - From f2c7bf0367f935f61315e5e2aaea1a824ab6b9f4 Mon Sep 17 00:00:00 2001 From: John Lines Date: Wed, 4 Sep 2019 17:06:44 +0100 Subject: [PATCH 27/27] put default hints plugin directory and chnage name to singingthefaith-hints.tag --- .../songs/lib/importers/singingthefaith-hints.tag | 2 +- .../plugins/songs/lib/importers/singingthefaith.py | 14 ++++++++++++-- .../songs/test_singingthefaithimport.py | 11 +++++++---- tests/helpers/songfileimport.py | 3 ++- .../songs/singingthefaith/{H1.txt => H901.txt} | 2 +- .../songs/singingthefaith/{H2.txt => H902.txt} | 0 .../singingthefaith/{STF001.json => STF901.json} | 0 .../singingthefaith/{STF002.json => STF902.json} | 0 .../hints/{hints.tag => singingthefaith-hints.tag} | 0 9 files changed, 23 insertions(+), 9 deletions(-) rename resources/hints.tag => openlp/plugins/songs/lib/importers/singingthefaith-hints.tag (99%) rename tests/resources/songs/singingthefaith/{H1.txt => H901.txt} (79%) rename tests/resources/songs/singingthefaith/{H2.txt => H902.txt} (100%) rename tests/resources/songs/singingthefaith/{STF001.json => STF901.json} (100%) rename tests/resources/songs/singingthefaith/{STF002.json => STF902.json} (100%) rename tests/resources/songs/singingthefaith/hints/{hints.tag => singingthefaith-hints.tag} (100%) diff --git a/resources/hints.tag b/openlp/plugins/songs/lib/importers/singingthefaith-hints.tag similarity index 99% rename from resources/hints.tag rename to openlp/plugins/songs/lib/importers/singingthefaith-hints.tag index 3791e7be8..f865e0c3b 100644 --- a/resources/hints.tag +++ b/openlp/plugins/songs/lib/importers/singingthefaith-hints.tag @@ -1,6 +1,6 @@ Tag-STFHints-version: 1.0 Version: 2 -SongbookNumberInTitle: True +SongbookNumberInTitle: False End: Hymn: 2 VerseOrder: V1,C1,V2,C1,V3,C1 diff --git a/openlp/plugins/songs/lib/importers/singingthefaith.py b/openlp/plugins/songs/lib/importers/singingthefaith.py index e6fe78b48..8c5a86c10 100644 --- a/openlp/plugins/songs/lib/importers/singingthefaith.py +++ b/openlp/plugins/songs/lib/importers/singingthefaith.py @@ -30,6 +30,8 @@ from pathlib import Path from openlp.core.common.i18n import translate from openlp.plugins.songs.lib.importers.songimport import SongImport +from openlp.core.common.applocation import AppLocation + log = logging.getLogger(__name__) @@ -80,6 +82,7 @@ class SingingTheFaithImport(SongImport): """ Process the SingingTheFaith file - pass in a file-like object, not a file path. """ + hints_file_name = 'singingthefaith-hints.tag' singing_the_faith_version = 1 self.set_defaults() # Setup variables @@ -120,12 +123,19 @@ class SingingTheFaithImport(SongImport): # See if there is a hints file in the same location as the file dir_path = filename.parent - hints_file_path = dir_path / 'hints.tag' + hints_file_path = dir_path / hints_file_name try: with hints_file_path.open('r') as hints_file: hints_available = self.read_hints(hints_file, song_number_file) except FileNotFoundError: - hints_available = False + # Look for the hints file in the Plugins directory + hints_file_path = AppLocation.get_directory(AppLocation.PluginsDir) / 'songs' / 'lib' / \ + 'importers' / hints_file_name + try: + with hints_file_path.open('r') as hints_file: + hints_available = self.read_hints(hints_file, song_number_file) + except FileNotFoundError: + hints_available = False try: for line in file: diff --git a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py index 1c7a259f4..70aa39544 100644 --- a/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py +++ b/tests/functional/openlp_plugins/songs/test_singingthefaithimport.py @@ -40,12 +40,15 @@ class TestSingingTheFaithFileImport(SongImportTestHelper): """ Test that loading a Singing The Faith file works correctly on various files """ + # Note that the previous tests without hints no longer apply as there is always a + # hints file, which contains the hints for the real Singing The Faith Songs. + # Unhinted songs here must be numbered above any real Singing The Faith Song # Single verse - self.file_import([TEST_PATH / 'H1.txt'], - self.load_external_result_data(TEST_PATH / 'STF001.json')) + self.file_import([TEST_PATH / 'H901.txt'], + self.load_external_result_data(TEST_PATH / 'STF901.json')) # Whole song - self.file_import([TEST_PATH / 'H2.txt'], - self.load_external_result_data(TEST_PATH / 'STF002.json')) + self.file_import([TEST_PATH / 'H902.txt'], + self.load_external_result_data(TEST_PATH / 'STF902.json')) # Tests with hints - note that the hints directory has a hints.tag which specifies # SongbookNumberInTitle: True diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index 0c007fa18..542cc1860 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -153,7 +153,8 @@ class SongImportTestHelper(TestCase): 'song_number for %s should be %s' % (source_file_name, song_number) if verse_order_list: assert importer.verse_order_list == verse_order_list, \ - 'verse_order_list for %s should be %s' % (source_file_name, verse_order_list) + 'verse_order_list for %s should be %s and is %s' % (source_file_name, + verse_order_list, importer.verse_order_list) self.mocked_finish.assert_called_with() def _get_data(self, data, key): diff --git a/tests/resources/songs/singingthefaith/H1.txt b/tests/resources/songs/singingthefaith/H901.txt similarity index 79% rename from tests/resources/songs/singingthefaith/H1.txt rename to tests/resources/songs/singingthefaith/H901.txt index 3caf1cd11..877bbfa1b 100644 --- a/tests/resources/songs/singingthefaith/H1.txt +++ b/tests/resources/songs/singingthefaith/H901.txt @@ -6,4 +6,4 @@ John Newton (d. 1807) -Reproduced from Singing the Faith Electronic Words Edition, number 1 - or not as this is a hand made test file +Reproduced from Singing the Faith Electronic Words Edition, number 901 - or not as this is a hand made test file diff --git a/tests/resources/songs/singingthefaith/H2.txt b/tests/resources/songs/singingthefaith/H902.txt similarity index 100% rename from tests/resources/songs/singingthefaith/H2.txt rename to tests/resources/songs/singingthefaith/H902.txt diff --git a/tests/resources/songs/singingthefaith/STF001.json b/tests/resources/songs/singingthefaith/STF901.json similarity index 100% rename from tests/resources/songs/singingthefaith/STF001.json rename to tests/resources/songs/singingthefaith/STF901.json diff --git a/tests/resources/songs/singingthefaith/STF002.json b/tests/resources/songs/singingthefaith/STF902.json similarity index 100% rename from tests/resources/songs/singingthefaith/STF002.json rename to tests/resources/songs/singingthefaith/STF902.json diff --git a/tests/resources/songs/singingthefaith/hints/hints.tag b/tests/resources/songs/singingthefaith/hints/singingthefaith-hints.tag similarity index 100% rename from tests/resources/songs/singingthefaith/hints/hints.tag rename to tests/resources/songs/singingthefaith/hints/singingthefaith-hints.tag