put default hints plugin directory and chnage name to singingthefaith-hints.tag

This commit is contained in:
John Lines 2019-09-04 17:06:44 +01:00
parent 3c677bc077
commit f2c7bf0367
9 changed files with 23 additions and 9 deletions

View File

@ -1,6 +1,6 @@
Tag-STFHints-version: 1.0 Tag-STFHints-version: 1.0
Version: 2 Version: 2
SongbookNumberInTitle: True SongbookNumberInTitle: False
End: End:
Hymn: 2 Hymn: 2
VerseOrder: V1,C1,V2,C1,V3,C1 VerseOrder: V1,C1,V2,C1,V3,C1

View File

@ -30,6 +30,8 @@ from pathlib import Path
from openlp.core.common.i18n import translate from openlp.core.common.i18n import translate
from openlp.plugins.songs.lib.importers.songimport import SongImport from openlp.plugins.songs.lib.importers.songimport import SongImport
from openlp.core.common.applocation import AppLocation
log = logging.getLogger(__name__) 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. 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 singing_the_faith_version = 1
self.set_defaults() self.set_defaults()
# Setup variables # Setup variables
@ -120,12 +123,19 @@ class SingingTheFaithImport(SongImport):
# 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 dir_path = filename.parent
hints_file_path = dir_path / 'hints.tag' hints_file_path = dir_path / hints_file_name
try: try:
with hints_file_path.open('r') as hints_file: 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: 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: try:
for line in file: for line in file:

View File

@ -40,12 +40,15 @@ class TestSingingTheFaithFileImport(SongImportTestHelper):
""" """
Test that loading a Singing The Faith file works correctly on various files 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 # Single verse
self.file_import([TEST_PATH / 'H1.txt'], self.file_import([TEST_PATH / 'H901.txt'],
self.load_external_result_data(TEST_PATH / 'STF001.json')) self.load_external_result_data(TEST_PATH / 'STF901.json'))
# Whole song # Whole song
self.file_import([TEST_PATH / 'H2.txt'], self.file_import([TEST_PATH / 'H902.txt'],
self.load_external_result_data(TEST_PATH / 'STF002.json')) self.load_external_result_data(TEST_PATH / 'STF902.json'))
# Tests with hints - note that the hints directory has a hints.tag which specifies # Tests with hints - note that the hints directory has a hints.tag which specifies
# SongbookNumberInTitle: True # SongbookNumberInTitle: True

View File

@ -153,7 +153,8 @@ class SongImportTestHelper(TestCase):
'song_number for %s should be %s' % (source_file_name, song_number) 'song_number for %s should be %s' % (source_file_name, song_number)
if verse_order_list: if verse_order_list:
assert importer.verse_order_list == 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() self.mocked_finish.assert_called_with()
def _get_data(self, data, key): def _get_data(self, data, key):

View File

@ -6,4 +6,4 @@
John Newton (d. 1807) 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