add error handling if the user abort the dialog

This commit is contained in:
Armin Köhler 2011-03-18 10:52:54 +01:00
parent 9510d9713b
commit 4071daec18
6 changed files with 44 additions and 3 deletions

View File

@ -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'])

View File

@ -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'])

View File

@ -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)

View File

@ -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.

View File

@ -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'])

View File

@ -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]),