openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #30403
Re: [Merge] lp:~phill-ridout/openlp/even-more-refactors into lp:openlp
Review: Needs Fixing
Sorry one small change needed.
Diff comments:
>
> === modified file 'openlp/plugins/bibles/lib/bibleimport.py'
> --- openlp/plugins/bibles/lib/bibleimport.py 2016-08-09 19:32:29 +0000
> +++ openlp/plugins/bibles/lib/bibleimport.py 2016-09-09 21:59:44 +0000
> @@ -20,25 +20,84 @@
> # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
> ###############################################################################
>
> -import logging
> -
> from lxml import etree, objectify
> +from zipfile import is_zipfile
>
> -from openlp.core.common import OpenLPMixin, languages
> +from openlp.core.common import OpenLPMixin, Registry, RegistryProperties, languages, translate
> from openlp.core.lib import ValidationError
> -from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB
> -
> -log = logging.getLogger(__name__)
> -
> -
> -class BibleImport(OpenLPMixin, BibleDB):
> +from openlp.core.lib.ui import critical_error_message_box
> +from openlp.plugins.bibles.lib.db import AlternativeBookNamesDB, BibleDB, BiblesResourcesDB
> +
> +
> +class BibleImport(OpenLPMixin, RegistryProperties, BibleDB):
> """
> Helper class to import bibles from a third party source into OpenLP
> """
> - # TODO: Test
> def __init__(self, *args, **kwargs):
> super().__init__(*args, **kwargs)
> self.filename = kwargs['filename'] if 'filename' in kwargs else None
> + self.wizard = None
> + self.stop_import_flag = False
> + Registry().register_function('openlp_stop_wizard', self.stop_import)
> +
> + @staticmethod
> + def is_compressed(file):
> + """
> + Check if the supplied file is compressed
> +
> + :param file: A path to the file to check
> + """
> + if is_zipfile(file):
> + critical_error_message_box(
> + message=translate('BiblesPlugin.BibleImport',
> + 'The file "{file}" you supplied is compressed. You must decompress it before import.'
> + ).format(file=file))
> + return True
> + return False
> +
> + def get_book_ref_id_by_name(self, book, maxbooks=66, language_id=None):
> + """
> + Find the book id from the name or abbreviation of the book. If it doesn't currently exist, ask the user.
> +
> + :param book: The name or abbreviation of the book
> + :param maxbooks: The number of books in the bible
> + :param language_id: The language_id of the bible
> + :return: The id of the bible, or None
> + """
> + self.log_debug('BibleDB.get_book_ref_id_by_name:("{book}", "{lang}")'.format(book=book, lang=language_id))
> + book_temp = BiblesResourcesDB.get_book(book, True)
> + if book_temp:
> + return book_temp['id']
> + book_id = BiblesResourcesDB.get_alternative_book_name(book)
> + if book_id:
> + return book_id
> + book_id = AlternativeBookNamesDB.get_book_reference_id(book)
> + if book_id:
> + return book_id
> + from openlp.plugins.bibles.forms import BookNameForm
> + book_name = BookNameForm(self.wizard)
> + if book_name.exec(book, self.get_books(), maxbooks) and book_name.book_id:
> + AlternativeBookNamesDB.create_alternative_book_name(book, book_name.book_id, language_id)
> + return book_name.book_id
> +
> + def get_language(self, bible_name=None):
> + """
> + If no language is given it calls a dialog window where the user could select the bible language.
> + Return the language id of a bible.
> +
> + :param bible_name: The language the bible is.
> + """
> + self.log_debug('BibleImpoer.get_language()')
No needed with OpenLPMixin
> + from openlp.plugins.bibles.forms import LanguageForm
> + language_id = None
> + language_form = LanguageForm(self.wizard)
> + if language_form.exec(bible_name):
> + combo_box = language_form.language_combo_box
> + language_id = combo_box.itemData(combo_box.currentIndex())
> + if not language_id:
> + return None
> + self.save_meta('language_id', language_id)
> + return language_id
>
> def get_language_id(self, file_language=None, bible_name=None):
> """
--
https://code.launchpad.net/~phill-ridout/openlp/even-more-refactors/+merge/305388
Your team OpenLP Core is subscribed to branch lp:openlp.
Follow ups
References