2008-11-30 18:36:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-01-01 16:33:41 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2009-07-13 20:08:43 +00:00
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# 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 <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2009-06-16 18:21:24 +00:00
|
|
|
import logging
|
2008-10-30 20:44:54 +00:00
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common import delete_file
|
|
|
|
from openlp.core.common.applocation import AppLocation
|
|
|
|
from openlp.core.common.i18n import UiStrings, translate
|
2017-10-23 22:09:57 +00:00
|
|
|
from openlp.core.common.mixins import LogMixin, RegistryProperties
|
2017-08-25 20:03:25 +00:00
|
|
|
from openlp.core.common.path import Path
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.settings import Settings
|
2016-09-04 16:15:57 +00:00
|
|
|
from openlp.plugins.bibles.lib import LanguageSelection, parse_reference
|
2011-07-07 18:03:12 +00:00
|
|
|
from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2016-08-09 20:45:25 +00:00
|
|
|
from .importers.csvbible import CSVBible
|
|
|
|
from .importers.http import HTTPBible
|
|
|
|
from .importers.opensong import OpenSongBible
|
|
|
|
from .importers.osis import OSISBible
|
2016-11-24 21:48:51 +00:00
|
|
|
from .importers.wordproject import WordProjectBible
|
2017-12-28 08:08:12 +00:00
|
|
|
from .importers.zefania import ZefaniaBible
|
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2016-03-25 19:58:43 +00:00
|
|
|
try:
|
2016-08-09 20:45:25 +00:00
|
|
|
from .importers.sword import SwordBible
|
2018-10-27 01:40:20 +00:00
|
|
|
except ImportError:
|
2016-03-25 19:58:43 +00:00
|
|
|
pass
|
2013-04-15 21:31:04 +00:00
|
|
|
|
2010-02-27 15:31:23 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-04-17 20:12:53 +00:00
|
|
|
|
2009-12-21 20:58:00 +00:00
|
|
|
class BibleFormat(object):
|
2009-12-27 23:54:00 +00:00
|
|
|
"""
|
2013-04-17 20:12:53 +00:00
|
|
|
This is a special enumeration class that holds the various types of Bibles.
|
2009-12-27 23:54:00 +00:00
|
|
|
"""
|
2009-12-21 20:58:00 +00:00
|
|
|
Unknown = -1
|
|
|
|
OSIS = 0
|
|
|
|
CSV = 1
|
|
|
|
OpenSong = 2
|
|
|
|
WebDownload = 3
|
2014-05-06 19:53:08 +00:00
|
|
|
Zefania = 4
|
2015-12-22 13:04:01 +00:00
|
|
|
SWORD = 5
|
2016-11-24 21:48:51 +00:00
|
|
|
WordProject = 6
|
2009-12-21 20:58:00 +00:00
|
|
|
|
2009-12-27 23:54:00 +00:00
|
|
|
@staticmethod
|
2014-05-01 17:49:43 +00:00
|
|
|
def get_class(bible_format):
|
2009-12-27 23:54:00 +00:00
|
|
|
"""
|
2014-03-09 10:26:28 +00:00
|
|
|
Return the appropriate implementation class.
|
2010-03-21 22:16:43 +00:00
|
|
|
|
2014-05-01 17:49:43 +00:00
|
|
|
:param bible_format: The Bible format.
|
2009-12-27 23:54:00 +00:00
|
|
|
"""
|
2014-05-01 17:49:43 +00:00
|
|
|
if bible_format == BibleFormat.OSIS:
|
2010-01-17 16:48:45 +00:00
|
|
|
return OSISBible
|
2014-05-01 17:49:43 +00:00
|
|
|
elif bible_format == BibleFormat.CSV:
|
2010-01-17 16:48:45 +00:00
|
|
|
return CSVBible
|
2014-05-01 17:49:43 +00:00
|
|
|
elif bible_format == BibleFormat.OpenSong:
|
2010-01-17 16:48:45 +00:00
|
|
|
return OpenSongBible
|
2014-05-01 17:49:43 +00:00
|
|
|
elif bible_format == BibleFormat.WebDownload:
|
2010-01-17 16:48:45 +00:00
|
|
|
return HTTPBible
|
2014-05-06 19:53:08 +00:00
|
|
|
elif bible_format == BibleFormat.Zefania:
|
|
|
|
return ZefaniaBible
|
2015-12-22 13:04:01 +00:00
|
|
|
elif bible_format == BibleFormat.SWORD:
|
|
|
|
return SwordBible
|
2016-11-24 21:48:51 +00:00
|
|
|
elif bible_format == BibleFormat.WordProject:
|
|
|
|
return WordProjectBible
|
2009-12-21 20:58:00 +00:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2009-12-27 23:54:00 +00:00
|
|
|
@staticmethod
|
2011-01-26 02:43:16 +00:00
|
|
|
def get_formats_list():
|
2010-03-21 22:16:43 +00:00
|
|
|
"""
|
|
|
|
Return a list of the supported Bible formats.
|
|
|
|
"""
|
2009-12-27 23:54:00 +00:00
|
|
|
return [
|
|
|
|
BibleFormat.OSIS,
|
|
|
|
BibleFormat.CSV,
|
|
|
|
BibleFormat.OpenSong,
|
2010-12-05 15:44:51 +00:00
|
|
|
BibleFormat.WebDownload,
|
2014-09-11 10:08:44 +00:00
|
|
|
BibleFormat.Zefania,
|
2016-11-24 21:48:51 +00:00
|
|
|
BibleFormat.SWORD,
|
|
|
|
BibleFormat.WordProject
|
2009-12-27 23:54:00 +00:00
|
|
|
]
|
|
|
|
|
2009-12-21 20:58:00 +00:00
|
|
|
|
2017-10-23 22:09:57 +00:00
|
|
|
class BibleManager(LogMixin, RegistryProperties):
|
2009-07-13 20:08:43 +00:00
|
|
|
"""
|
|
|
|
The Bible manager which holds and manages all the Bibles.
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.info('Bible manager loaded')
|
2009-07-13 20:08:43 +00:00
|
|
|
|
2010-04-27 16:27:57 +00:00
|
|
|
def __init__(self, parent):
|
2008-10-30 20:44:54 +00:00
|
|
|
"""
|
2014-03-11 19:01:09 +00:00
|
|
|
Finds all the bibles defined for the system and creates an interface object for each bible containing
|
|
|
|
connection information. Throws Exception if no Bibles are found.
|
2008-10-30 20:44:54 +00:00
|
|
|
|
|
|
|
Init confirms the bible exists and stores the database path.
|
2008-11-30 18:36:13 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.debug('Bible Initialising')
|
2010-01-31 19:49:01 +00:00
|
|
|
self.parent = parent
|
2013-08-31 18:17:38 +00:00
|
|
|
self.settings_section = 'bibles'
|
|
|
|
self.web = 'Web'
|
2009-12-30 17:29:08 +00:00
|
|
|
self.db_cache = None
|
2017-10-10 19:09:20 +00:00
|
|
|
self.path = AppLocation.get_section_data_path(self.settings_section)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.suffix = '.sqlite'
|
2009-12-27 23:54:00 +00:00
|
|
|
self.import_wizard = None
|
2009-02-02 19:54:38 +00:00
|
|
|
self.reload_bibles()
|
2009-10-27 20:52:30 +00:00
|
|
|
self.media = None
|
2009-08-02 13:44:41 +00:00
|
|
|
|
2009-02-02 19:54:38 +00:00
|
|
|
def reload_bibles(self):
|
2010-02-06 10:22:20 +00:00
|
|
|
"""
|
2014-03-11 19:01:09 +00:00
|
|
|
Reloads the Bibles from the available Bible databases on disk. If a web Bible is encountered, an instance
|
|
|
|
of HTTPBible is loaded instead of the BibleDB class.
|
2010-02-06 10:22:20 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.debug('Reload bibles')
|
2017-10-10 19:09:20 +00:00
|
|
|
file_paths = AppLocation.get_files(self.settings_section, self.suffix)
|
|
|
|
if Path('alternative_book_names.sqlite') in file_paths:
|
|
|
|
file_paths.remove(Path('alternative_book_names.sqlite'))
|
|
|
|
log.debug('Bible Files {text}'.format(text=file_paths))
|
2009-12-30 17:29:08 +00:00
|
|
|
self.db_cache = {}
|
2017-10-10 19:09:20 +00:00
|
|
|
for file_path in file_paths:
|
|
|
|
bible = BibleDB(self.parent, path=self.path, file=file_path)
|
2015-01-31 21:52:02 +00:00
|
|
|
if not bible.session:
|
|
|
|
continue
|
2010-03-16 19:46:19 +00:00
|
|
|
name = bible.get_name()
|
2011-03-13 15:58:27 +00:00
|
|
|
# Remove corrupted files.
|
|
|
|
if name is None:
|
2016-11-01 19:17:57 +00:00
|
|
|
bible.session.close_all()
|
2017-10-10 19:09:20 +00:00
|
|
|
delete_file(self.path / file_path)
|
2011-03-13 15:58:27 +00:00
|
|
|
continue
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('Bible Name: "{name}"'.format(name=name))
|
2010-03-16 19:46:19 +00:00
|
|
|
self.db_cache[name] = bible
|
2010-10-01 13:50:29 +00:00
|
|
|
# Look to see if lazy load bible exists and get create getter.
|
2017-05-05 21:00:59 +00:00
|
|
|
if self.db_cache[name].is_web_bible:
|
|
|
|
source = self.db_cache[name].get_object(BibleMeta, 'download_source')
|
2013-08-31 18:17:38 +00:00
|
|
|
download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value
|
2017-10-10 19:09:20 +00:00
|
|
|
web_bible = HTTPBible(self.parent, path=self.path, file=file_path, download_source=source.value,
|
2014-03-09 10:26:28 +00:00
|
|
|
download_name=download_name)
|
2010-01-24 07:08:14 +00:00
|
|
|
self.db_cache[name] = web_bible
|
2013-08-31 18:17:38 +00:00
|
|
|
log.debug('Bibles reloaded')
|
2008-10-30 20:44:54 +00:00
|
|
|
|
2009-12-27 23:54:00 +00:00
|
|
|
def set_process_dialog(self, wizard):
|
2009-07-13 20:08:43 +00:00
|
|
|
"""
|
|
|
|
Sets the reference to the dialog with the progress bar on it.
|
|
|
|
|
2014-03-09 10:26:28 +00:00
|
|
|
:param wizard: The reference to the import wizard.
|
2009-07-13 20:08:43 +00:00
|
|
|
"""
|
2009-12-27 23:54:00 +00:00
|
|
|
self.import_wizard = wizard
|
2008-11-30 18:36:13 +00:00
|
|
|
|
2009-12-21 20:58:00 +00:00
|
|
|
def import_bible(self, type, **kwargs):
|
|
|
|
"""
|
|
|
|
Register a bible in the bible cache, and then import the verses.
|
|
|
|
|
2014-03-09 10:26:28 +00:00
|
|
|
:param type: What type of Bible, one of the ``BibleFormat`` values.
|
|
|
|
:param kwargs: Keyword arguments to send to the actual importer class.
|
2008-10-30 20:44:54 +00:00
|
|
|
"""
|
2009-12-30 17:29:08 +00:00
|
|
|
class_ = BibleFormat.get_class(type)
|
2010-01-17 16:48:45 +00:00
|
|
|
kwargs['path'] = self.path
|
2010-01-31 19:49:01 +00:00
|
|
|
importer = class_(self.parent, **kwargs)
|
2010-01-17 16:48:45 +00:00
|
|
|
name = importer.register(self.import_wizard)
|
2009-12-30 17:29:08 +00:00
|
|
|
self.db_cache[name] = importer
|
2010-03-19 22:08:06 +00:00
|
|
|
return importer
|
2008-11-30 18:36:13 +00:00
|
|
|
|
2012-03-12 05:48:14 +00:00
|
|
|
def delete_bible(self, name):
|
|
|
|
"""
|
2012-09-04 22:39:47 +00:00
|
|
|
Delete a bible completely.
|
2012-03-12 05:48:14 +00:00
|
|
|
|
2014-03-09 10:26:28 +00:00
|
|
|
:param name: The name of the bible.
|
2012-03-12 05:48:14 +00:00
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('BibleManager.delete_bible("{name}")'.format(name=name))
|
2012-09-04 22:39:47 +00:00
|
|
|
bible = self.db_cache[name]
|
2016-11-01 19:17:57 +00:00
|
|
|
bible.session.close_all()
|
2012-09-04 22:39:47 +00:00
|
|
|
bible.session = None
|
2019-04-13 08:24:15 +00:00
|
|
|
return delete_file(bible.path / '{name}{suffix}'.format(name=name, suffix=self.suffix))
|
2012-03-12 05:48:14 +00:00
|
|
|
|
2010-02-06 10:22:20 +00:00
|
|
|
def get_bibles(self):
|
2008-11-19 18:13:22 +00:00
|
|
|
"""
|
2010-10-06 14:15:39 +00:00
|
|
|
Returns a dict with all available Bibles.
|
2008-11-19 18:13:22 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.debug('get_bibles')
|
2010-10-06 14:15:39 +00:00
|
|
|
return self.db_cache
|
2008-11-30 18:36:13 +00:00
|
|
|
|
2010-02-06 10:22:20 +00:00
|
|
|
def get_books(self, bible):
|
2009-12-18 22:31:28 +00:00
|
|
|
"""
|
2010-02-06 10:22:20 +00:00
|
|
|
Returns a list of Bible books, and the number of chapters in that book.
|
2009-12-18 22:31:28 +00:00
|
|
|
|
2014-03-09 10:26:28 +00:00
|
|
|
:param bible: Unicode. The Bible to get the list of books from.
|
2008-11-30 18:36:13 +00:00
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('BibleManager.get_books("{bible}")'.format(bible=bible))
|
2011-04-26 18:18:13 +00:00
|
|
|
return [
|
2010-02-06 10:22:20 +00:00
|
|
|
{
|
2013-08-31 18:17:38 +00:00
|
|
|
'name': book.name,
|
|
|
|
'book_reference_id': book.book_reference_id,
|
|
|
|
'chapters': self.db_cache[bible].get_chapter_count(book)
|
2011-04-26 18:18:13 +00:00
|
|
|
}
|
|
|
|
for book in self.db_cache[bible].get_books()
|
|
|
|
]
|
2008-11-30 18:36:13 +00:00
|
|
|
|
2012-02-29 11:47:21 +00:00
|
|
|
def get_book_by_id(self, bible, id):
|
|
|
|
"""
|
|
|
|
Returns a book object by given id.
|
|
|
|
|
2014-03-09 10:26:28 +00:00
|
|
|
:param bible: Unicode. The Bible to get the list of books from.
|
|
|
|
:param id: Unicode. The book_reference_id to get the book for.
|
2012-02-29 11:47:21 +00:00
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('BibleManager.get_book_by_id("{bible}", "{ref}")'.format(bible=bible, ref=id))
|
2012-02-29 11:47:21 +00:00
|
|
|
return self.db_cache[bible].get_book_by_book_ref_id(id)
|
|
|
|
|
2010-02-06 10:22:20 +00:00
|
|
|
def get_chapter_count(self, bible, book):
|
2008-10-30 20:44:54 +00:00
|
|
|
"""
|
2010-10-01 13:50:29 +00:00
|
|
|
Returns the number of Chapters for a given book.
|
2011-08-12 13:11:30 +00:00
|
|
|
|
2014-03-09 10:26:28 +00:00
|
|
|
:param bible: Unicode. The Bible to get the list of books from.
|
|
|
|
:param book: The book object to get the chapter count for.
|
2008-11-24 19:41:29 +00:00
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('BibleManager.get_book_chapter_count ("{bible}", "{name}")'.format(bible=bible, name=book.name))
|
2010-02-06 10:22:20 +00:00
|
|
|
return self.db_cache[bible].get_chapter_count(book)
|
2008-11-24 19:41:29 +00:00
|
|
|
|
2010-02-06 10:22:20 +00:00
|
|
|
def get_verse_count(self, bible, book, chapter):
|
2008-11-24 19:41:29 +00:00
|
|
|
"""
|
2014-03-09 10:26:28 +00:00
|
|
|
Returns all the number of verses for a given book and chapterMaxBibleBookVerses.
|
2008-11-01 19:50:14 +00:00
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('BibleManager.get_verse_count("{bible}", "{book}", {chapter})'.format(bible=bible,
|
|
|
|
book=book,
|
|
|
|
chapter=chapter))
|
2012-09-20 21:50:23 +00:00
|
|
|
language_selection = self.get_language_selection(bible)
|
2013-01-01 16:33:41 +00:00
|
|
|
book_ref_id = self.db_cache[bible].get_book_ref_id_by_localised_name(book, language_selection)
|
2011-03-23 19:18:51 +00:00
|
|
|
return self.db_cache[bible].get_verse_count(book_ref_id, chapter)
|
2008-10-30 20:44:54 +00:00
|
|
|
|
2012-03-04 20:10:17 +00:00
|
|
|
def get_verse_count_by_book_ref_id(self, bible, book_ref_id, chapter):
|
|
|
|
"""
|
|
|
|
Returns all the number of verses for a given
|
|
|
|
book_ref_id and chapterMaxBibleBookVerses.
|
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('BibleManager.get_verse_count_by_book_ref_id("{bible}", '
|
|
|
|
'"{book}", "{chapter}")'.format(bible=bible, book=book_ref_id, chapter=chapter))
|
2012-03-04 20:10:17 +00:00
|
|
|
return self.db_cache[bible].get_verse_count(book_ref_id, chapter)
|
|
|
|
|
2016-12-18 15:33:51 +00:00
|
|
|
def parse_ref(self, bible, reference_text, book_ref_id=False):
|
|
|
|
if not bible:
|
|
|
|
return
|
|
|
|
language_selection = self.get_language_selection(bible)
|
|
|
|
return parse_reference(reference_text, self.db_cache[bible], language_selection, book_ref_id)
|
|
|
|
|
|
|
|
def get_verses(self, bible, ref_list, show_error=True):
|
2008-10-30 20:44:54 +00:00
|
|
|
"""
|
2010-02-06 10:22:20 +00:00
|
|
|
Parses a scripture reference, fetches the verses from the Bible
|
|
|
|
specified, and returns a list of ``Verse`` objects.
|
|
|
|
|
2014-03-09 10:26:28 +00:00
|
|
|
:param bible: Unicode. The Bible to use.
|
|
|
|
:param verse_text:
|
2017-02-18 07:23:15 +00:00
|
|
|
String. The scripture reference. Valid scripture references are:
|
2010-02-06 10:22:20 +00:00
|
|
|
|
2010-07-29 15:04:09 +00:00
|
|
|
- Genesis 1
|
|
|
|
- Genesis 1-2
|
2010-02-06 10:22:20 +00:00
|
|
|
- Genesis 1:1
|
|
|
|
- Genesis 1:1-10
|
2010-07-29 15:04:09 +00:00
|
|
|
- Genesis 1:1-10,15-20
|
2010-02-06 10:22:20 +00:00
|
|
|
- Genesis 1:1-2:10
|
2010-07-29 15:04:09 +00:00
|
|
|
- Genesis 1:1-10,2:1-10
|
2012-04-04 07:26:51 +00:00
|
|
|
|
2014-03-09 10:26:28 +00:00
|
|
|
:param book_ref_id: Unicode. The book reference id from the book in verse_text.
|
2012-03-04 20:10:17 +00:00
|
|
|
For second bible this is necessary.
|
2014-03-09 10:26:28 +00:00
|
|
|
:param show_error:
|
2008-10-30 20:44:54 +00:00
|
|
|
"""
|
2016-12-18 15:33:51 +00:00
|
|
|
if not bible or not ref_list:
|
2017-05-05 21:00:59 +00:00
|
|
|
return []
|
2016-12-18 15:33:51 +00:00
|
|
|
return self.db_cache[bible].get_verses(ref_list, show_error)
|
2008-10-30 20:44:54 +00:00
|
|
|
|
2012-04-12 20:58:11 +00:00
|
|
|
def get_language_selection(self, bible):
|
|
|
|
"""
|
|
|
|
Returns the language selection of a bible.
|
|
|
|
|
2014-03-09 10:26:28 +00:00
|
|
|
:param bible: Unicode. The Bible to get the language selection from.
|
2012-04-12 20:58:11 +00:00
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('BibleManager.get_language_selection("{bible}")'.format(bible=bible))
|
2013-08-31 18:17:38 +00:00
|
|
|
language_selection = self.get_meta_data(bible, 'book_name_language')
|
2013-01-01 16:33:41 +00:00
|
|
|
if not language_selection or language_selection.value == "None" or language_selection.value == "-1":
|
2012-09-20 21:07:32 +00:00
|
|
|
# If None is returned, it's not the singleton object but a
|
|
|
|
# BibleMeta object with the value "None"
|
2013-08-31 18:17:38 +00:00
|
|
|
language_selection = Settings().value(self.settings_section + '/book name language')
|
2012-09-20 21:07:32 +00:00
|
|
|
else:
|
|
|
|
language_selection = language_selection.value
|
|
|
|
try:
|
|
|
|
language_selection = int(language_selection)
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
language_selection = LanguageSelection.Application
|
2012-05-15 21:06:09 +00:00
|
|
|
return language_selection
|
2012-04-12 20:58:11 +00:00
|
|
|
|
2016-12-18 15:33:51 +00:00
|
|
|
def verse_search(self, bible, text):
|
2010-10-08 17:07:14 +00:00
|
|
|
"""
|
2010-10-09 19:36:05 +00:00
|
|
|
Does a verse search for the given bible and text.
|
|
|
|
|
2017-08-25 20:03:25 +00:00
|
|
|
:param str bible: The bible to search
|
|
|
|
:param str text: The text to search for
|
2017-05-05 21:00:59 +00:00
|
|
|
:return: The search results if valid, or None if the search is invalid.
|
2017-08-25 20:03:25 +00:00
|
|
|
:rtype: None | list
|
2010-10-08 17:07:14 +00:00
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('BibleManager.verse_search("{bible}", "{text}")'.format(bible=bible, text=text))
|
2017-05-05 21:00:59 +00:00
|
|
|
if not text:
|
|
|
|
return None
|
2016-04-10 18:50:22 +00:00
|
|
|
# If no bibles are installed, message is given.
|
2011-05-15 13:06:16 +00:00
|
|
|
if not bible:
|
2013-02-05 21:42:15 +00:00
|
|
|
self.main_window.information_message(
|
2016-05-20 22:02:40 +00:00
|
|
|
UiStrings().BibleNoBiblesTitle,
|
|
|
|
UiStrings().BibleNoBibles)
|
2011-05-15 13:06:16 +00:00
|
|
|
return None
|
2010-11-15 17:47:33 +00:00
|
|
|
# Check if the bible or second_bible is a web bible.
|
2017-05-05 21:00:59 +00:00
|
|
|
if self.db_cache[bible].is_web_bible:
|
2016-04-10 18:50:22 +00:00
|
|
|
# If either Bible is Web, cursor is reset to normal and message is given.
|
2016-03-08 01:34:42 +00:00
|
|
|
self.application.set_normal_cursor()
|
2013-02-05 21:42:15 +00:00
|
|
|
self.main_window.information_message(
|
2016-06-05 11:03:28 +00:00
|
|
|
translate('BiblesPlugin.BibleManager', 'Web Bible cannot be used in Text Search'),
|
|
|
|
translate('BiblesPlugin.BibleManager', 'Text Search is not available with Web Bibles.\n'
|
|
|
|
'Please use the Scripture Reference Search instead.\n\n'
|
2016-12-18 15:33:51 +00:00
|
|
|
'This means that the currently selected Bible is a Web Bible.')
|
2014-03-09 10:26:28 +00:00
|
|
|
)
|
2010-11-12 13:50:13 +00:00
|
|
|
return None
|
2016-06-05 11:03:28 +00:00
|
|
|
# Fetch the results from db. If no results are found, return None, no message is given for this.
|
2017-05-05 21:00:59 +00:00
|
|
|
if text:
|
2010-10-08 17:07:14 +00:00
|
|
|
return self.db_cache[bible].verse_search(text)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2016-12-18 15:33:51 +00:00
|
|
|
def process_verse_range(self, book_ref_id, chapter_from, verse_from, chapter_to, verse_to):
|
|
|
|
verse_ranges = []
|
|
|
|
for chapter in range(chapter_from, chapter_to + 1):
|
|
|
|
if chapter == chapter_from:
|
|
|
|
start_verse = verse_from
|
|
|
|
else:
|
|
|
|
start_verse = 1
|
|
|
|
if chapter == chapter_to:
|
|
|
|
end_verse = verse_to
|
|
|
|
else:
|
|
|
|
end_verse = -1
|
|
|
|
verse_ranges.append((book_ref_id, chapter, start_verse, end_verse))
|
|
|
|
return verse_ranges
|
|
|
|
|
2016-09-14 22:20:33 +00:00
|
|
|
def save_meta_data(self, bible, version, copyright, permissions, full_license, book_name_language=None):
|
2012-03-12 05:48:14 +00:00
|
|
|
"""
|
|
|
|
Saves the bibles meta data.
|
|
|
|
"""
|
2016-09-14 22:20:33 +00:00
|
|
|
log.debug('save_meta data {bible}, {version}, {copyright},'
|
|
|
|
' {perms}, {full_license}'.format(bible=bible, version=version, copyright=copyright,
|
|
|
|
perms=permissions, full_license=full_license))
|
2013-08-31 18:17:38 +00:00
|
|
|
self.db_cache[bible].save_meta('name', version)
|
|
|
|
self.db_cache[bible].save_meta('copyright', copyright)
|
|
|
|
self.db_cache[bible].save_meta('permissions', permissions)
|
2016-09-14 22:20:33 +00:00
|
|
|
self.db_cache[bible].save_meta('full_license', full_license)
|
2014-03-09 10:26:28 +00:00
|
|
|
self.db_cache[bible].save_meta('book_name_language', book_name_language)
|
2012-03-12 05:48:14 +00:00
|
|
|
|
2008-12-16 17:29:39 +00:00
|
|
|
def get_meta_data(self, bible, key):
|
2008-12-14 16:19:28 +00:00
|
|
|
"""
|
2010-10-01 13:50:29 +00:00
|
|
|
Returns the meta data for a given key.
|
2008-12-14 16:19:28 +00:00
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('get_meta {bible},{key}'.format(bible=bible, key=key))
|
2010-06-15 00:44:06 +00:00
|
|
|
return self.db_cache[bible].get_object(BibleMeta, key)
|
2012-05-17 15:13:09 +00:00
|
|
|
|
2012-03-12 05:48:14 +00:00
|
|
|
def update_book(self, bible, book):
|
|
|
|
"""
|
|
|
|
Update a book of the bible.
|
|
|
|
"""
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('BibleManager.update_book("{bible}", "{name}")'.format(bible=bible, name=book.name))
|
2012-03-12 05:48:14 +00:00
|
|
|
self.db_cache[bible].update_book(book)
|
2008-12-14 16:19:28 +00:00
|
|
|
|
2009-12-30 17:29:08 +00:00
|
|
|
def exists(self, name):
|
2008-10-30 20:44:54 +00:00
|
|
|
"""
|
2010-10-01 13:50:29 +00:00
|
|
|
Check cache to see if new bible.
|
2008-10-30 20:44:54 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
if not isinstance(name, str):
|
|
|
|
name = str(name)
|
|
|
|
for bible in list(self.db_cache.keys()):
|
2016-05-21 08:31:24 +00:00
|
|
|
log.debug('Bible from cache in is_new_bible {bible}'.format(bible=bible))
|
2013-08-31 18:17:38 +00:00
|
|
|
if not isinstance(bible, str):
|
|
|
|
bible = str(bible)
|
2009-09-25 23:06:54 +00:00
|
|
|
if bible == name:
|
2009-12-30 17:29:08 +00:00
|
|
|
return True
|
2010-07-27 09:32:52 +00:00
|
|
|
return False
|
2010-10-27 15:30:30 +00:00
|
|
|
|
|
|
|
def finalise(self):
|
|
|
|
"""
|
|
|
|
Loop through the databases to VACUUM them.
|
|
|
|
"""
|
|
|
|
for bible in self.db_cache:
|
2010-10-27 17:42:10 +00:00
|
|
|
self.db_cache[bible].finalise()
|
2010-12-16 20:00:01 +00:00
|
|
|
|
2016-11-15 21:13:52 +00:00
|
|
|
|
2013-08-31 18:17:38 +00:00
|
|
|
__all__ = ['BibleFormat']
|