From fbce21baaa2884fdc3bfde9bb2bf810eac13a5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Sat, 2 Apr 2011 22:22:35 +0200 Subject: [PATCH] new function get_language in BibleDB which ask for the language a bible is and return a language_id --- openlp/plugins/bibles/lib/csvbible.py | 11 ++++------- openlp/plugins/bibles/lib/db.py | 16 ++++++++++++++++ openlp/plugins/bibles/lib/http.py | 15 ++++++--------- openlp/plugins/bibles/lib/manager.py | 2 -- openlp/plugins/bibles/lib/openlp1.py | 7 ++----- openlp/plugins/bibles/lib/opensong.py | 7 ++----- openlp/plugins/bibles/lib/osis.py | 7 ++----- 7 files changed, 32 insertions(+), 33 deletions(-) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index 2e1accb45..389ee1aac 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -139,14 +139,11 @@ class CSVBible(BibleDB): self.wizard.progressBar.setMinimum(0) self.wizard.progressBar.setMaximum(66) success = True - language = self.parent.manager.import_wizard.languageDialog() - if not language: - log.exception(u'Importing books from %s " '\ - 'failed' % self.booksfile) + language_id = self.get_language() + if not language_id: + log.exception(u'Importing books from %s " '\ + 'failed' % self.filename) return False - language = BiblesResourcesDB.get_language(language) - language_id = language[u'id'] - self.create_meta(u'language_id', language_id) books_file = None book_list = {} # Populate the Tables diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 6cfb48c21..1960e155b 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -489,6 +489,22 @@ class BibleDB(QtCore.QObject, Manager): else: return count + def get_language(self): + """ + Return the language of a bible. + + ``book`` + The language the bible is. + """ + log.debug(u'BibleDB.get_language()') + language = self.bible_plugin.manager.import_wizard.languageDialog() + if not language: + return False + language = BiblesResourcesDB.get_language(language) + language_id = language[u'id'] + self.create_meta(u'language_id', language_id) + return language_id + def dump_bible(self): """ Utility debugging method to dump the contents of a bible. diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index d0a911b32..75f2c37fc 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -413,16 +413,13 @@ class HTTPBible(BibleDB): self.download_source.lower()) if bible[u'language_id']: language_id = bible[u'language_id'] + self.create_meta(u'language_id', language_id) else: - language = self.parent.manager.import_wizard.languageDialog() - if not language: - log.exception(u'Importing books from %s - download name: "%s" '\ - 'failed' % (self.download_source, self.download_name)) - return False - language = BiblesResourcesDB.get_language(language) - language_id = language[u'id'] - # Store the language_id. - self.create_meta(u'language_id', language_id) + language_id = self.get_language() + if not language_id: + log.exception(u'Importing books from %s " '\ + 'failed' % self.filename) + return False for book in books: self.wizard.incrementProgressBar(unicode(translate( 'BiblesPlugin.HTTPBible', 'Importing %s...', diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 7cca6f4a0..aef00e61b 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -349,9 +349,7 @@ class BibleManager(object): book, language_id) else: book_ref = self.import_wizard.bookNameDialog(book) - log.debug(book_ref) book_temp = BiblesResourcesDB.get_book(book_ref) - log.debug(book_temp) if book_temp: book_id = book_temp[u'id'] else: diff --git a/openlp/plugins/bibles/lib/openlp1.py b/openlp/plugins/bibles/lib/openlp1.py index bc3624479..23c456dda 100644 --- a/openlp/plugins/bibles/lib/openlp1.py +++ b/openlp/plugins/bibles/lib/openlp1.py @@ -58,14 +58,11 @@ class OpenLP1Bible(BibleDB): except: return False #Create the bible language - language = self.parent.manager.import_wizard.languageDialog() - if not language: + language_id = self.get_language() + if not language_id: log.exception(u'Importing books from %s " '\ 'failed' % self.filename) return False - language = BiblesResourcesDB.get_language(language) - language_id = language[u'id'] - self.create_meta(u'language_id', language_id) # Create all books. cursor.execute(u'SELECT id, testament_id, name, abbreviation FROM book') books = cursor.fetchall() diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index 6e4c4826f..714f021cc 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -62,14 +62,11 @@ class OpenSongBible(BibleDB): file = open(self.filename, u'r') opensong = objectify.parse(file) bible = opensong.getroot() - language = self.parent.manager.import_wizard.languageDialog() - if not language: + language_id = self.get_language() + if not language_id: log.exception(u'Importing books from %s " '\ 'failed' % self.filename) return False - language = BiblesResourcesDB.get_language(language) - language_id = language[u'id'] - self.create_meta(u'language_id', language_id) for book in bible.b: if self.stop_import_flag: break diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index cd006bb78..4938e505a 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -107,14 +107,11 @@ class OSISBible(BibleDB): if detect_file: detect_file.close() # Set meta language_id - language = self.parent.manager.import_wizard.languageDialog() - if not language: + language_id = self.get_language() + if not language_id: log.exception(u'Importing books from %s " '\ 'failed' % self.filename) return False - language = BiblesResourcesDB.get_language(language) - language_id = language[u'id'] - self.create_meta(u'language_id', language_id) try: osis = codecs.open(self.filename, u'r', details['encoding']) for file_record in osis: