From 4071daec18cec5bdae0a0ae86defb6944568206f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Fri, 18 Mar 2011 10:52:54 +0100 Subject: [PATCH] add error handling if the user abort the dialog --- openlp/plugins/bibles/lib/csvbible.py | 8 ++++++++ openlp/plugins/bibles/lib/http.py | 8 ++++++++ openlp/plugins/bibles/lib/manager.py | 5 ++++- openlp/plugins/bibles/lib/openlp1.py | 8 ++++++++ openlp/plugins/bibles/lib/opensong.py | 8 ++++++++ openlp/plugins/bibles/lib/osis.py | 10 ++++++++-- 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index 7d1791281..8884c436a 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -137,6 +137,10 @@ class CSVBible(BibleDB): self.wizard.progressBar.setMaximum(66) success = True language = self.parent.mediaItem.importRequest(u'language') + if not language: + log.exception(u'Importing books from %s " '\ + 'failed' % self.booksfile) + return False language = BiblesResourcesDB.get_language(language) language_id = language[u'id'] self.create_meta(u'language_id', language_id) @@ -155,6 +159,10 @@ class CSVBible(BibleDB): unicode(line[2], details['encoding'])) book_ref_id = self.parent.manager.get_book_ref_id_by_name( unicode(line[2], details['encoding']), language_id) + if not book_ref_id: + log.exception(u'Importing books from %s " '\ + 'failed' % self.booksfile) + return False book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) self.create_book(unicode(line[2], details['encoding']), book_ref_id, book_details[u'testament_id']) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index cd5f5a2d9..9d91298d0 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -406,6 +406,10 @@ class HTTPBible(BibleDB): language_id = bible[u'language_id'] else: language = self.parent.mediaItem.importRequest(u'language') + 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. @@ -413,6 +417,10 @@ class HTTPBible(BibleDB): for book in books: book_ref_id = self.parent.manager.get_book_ref_id_by_name(book, language_id) + if not book_ref_id: + log.exception(u'Importing books from %s - download name: "%s" '\ + 'failed' % (self.download_source, self.download_name)) + return False book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) log.debug(u'Book details: Name:%s; id:%s; testament_id:%s', book, book_ref_id, book_details[u'testament_id']) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 4fa405c24..58e7b052f 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -352,7 +352,10 @@ class BibleManager(object): log.debug(book_ref) book_temp = BiblesResourcesDB.get_book(book_ref) log.debug(book_temp) - book_id = book_temp[u'id'] + if book_temp: + book_id = book_temp[u'id'] + else: + return None if book_id: self.spelling_cache[u'spelling'].create_spelling(book, book_id, language_id) diff --git a/openlp/plugins/bibles/lib/openlp1.py b/openlp/plugins/bibles/lib/openlp1.py index 508add469..2d7ed903b 100644 --- a/openlp/plugins/bibles/lib/openlp1.py +++ b/openlp/plugins/bibles/lib/openlp1.py @@ -59,6 +59,10 @@ class OpenLP1Bible(BibleDB): return False #Create the bible language language = self.parent.mediaItem.importRequest(u'language') + if not language: + 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) @@ -76,6 +80,10 @@ class OpenLP1Bible(BibleDB): abbreviation = unicode(book[3], u'cp1252') book_ref_id = self.parent.manager.get_book_ref_id_by_name(name, language_id) + if not book_ref_id: + log.exception(u'Importing books from %s " '\ + 'failed' % self.filename) + return False book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) self.create_book(name, book_ref_id, book_details[u'testament_id']) # Update the progess bar. diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index 91b96abf2..f1a64c2e7 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -63,6 +63,10 @@ class OpenSongBible(BibleDB): opensong = objectify.parse(file) bible = opensong.getroot() language = self.parent.mediaItem.importRequest(u'language') + if not language: + 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) @@ -71,6 +75,10 @@ class OpenSongBible(BibleDB): break book_ref_id = self.parent.manager.get_book_ref_id_by_name( unicode(book.attrib[u'n']), language_id) + if not book_ref_id: + log.exception(u'Importing books from %s " '\ + 'failed' % self.filename) + return False book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) db_book = self.create_book(unicode(book.attrib[u'n']), book_ref_id, book_details[u'testament_id']) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 6c8b2153b..277b73a23 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -107,6 +107,10 @@ class OSISBible(BibleDB): detect_file.close() # Set meta language_id language = self.parent.mediaItem.importRequest(u'language') + if not language: + 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) @@ -126,10 +130,12 @@ class OSISBible(BibleDB): log.debug(u'New book: "%s"', self.books[book][0]) if book == u'Matt' or book == u'Jdt': testament += 1 - #TODO: change create_book to the new database model - #(name, bk_ref_id, testament) book_ref_id = self.parent.manager.get_book_ref_id_by_name( unicode(self.books[book][0]), language_id) + if not book_ref_id: + log.exception(u'Importing books from %s " '\ + 'failed' % self.filename) + return False book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) db_book = self.create_book( unicode(self.books[book][0]),