removed variable; hopefully fixed windows crahes

This commit is contained in:
Andreas Preikschat 2011-08-13 12:14:20 +02:00
parent 6c96794af1
commit b72b538893

View File

@ -491,16 +491,19 @@ class BibleUpgradeForm(OpenLPWizard):
if self.checkBox[number].checkState() == QtCore.Qt.Checked: if self.checkBox[number].checkState() == QtCore.Qt.Checked:
max_bibles += 1 max_bibles += 1
temp_dir = os.path.join(gettempdir(), u'openlp') temp_dir = os.path.join(gettempdir(), u'openlp')
oldBible = None
for number, filename in enumerate(self.files): for number, filename in enumerate(self.files):
# Close the previous bible's connection.
if oldBible is not None:
oldBible.close_connection()
if self.stop_import_flag: if self.stop_import_flag:
bible_failed = True
break
bible_failed = False
self.success[number] = False self.success[number] = False
break
self.success[number] = True
if not self.checkBox[number].checkState() == QtCore.Qt.Checked: if not self.checkBox[number].checkState() == QtCore.Qt.Checked:
continue continue
self.progressBar.reset() self.progressBar.reset()
oldbible = OldBibleDB(self.mediaItem, path=temp_dir, oldBible = OldBibleDB(self.mediaItem, path=temp_dir,
file=filename[0]) file=filename[0])
name = filename[1] name = filename[1]
if name is None: if name is None:
@ -519,7 +522,7 @@ class BibleUpgradeForm(OpenLPWizard):
self.newbibles[number] = BibleDB(self.mediaItem, path=self.path, self.newbibles[number] = BibleDB(self.mediaItem, path=self.path,
name=name, file=filename[0]) name=name, file=filename[0])
self.newbibles[number].register(self.plugin.upgrade_wizard) self.newbibles[number].register(self.plugin.upgrade_wizard)
metadata = oldbible.get_metadata() metadata = oldBible.get_metadata()
webbible = False webbible = False
meta_data = {} meta_data = {}
for meta in metadata: for meta in metadata:
@ -580,7 +583,7 @@ class BibleUpgradeForm(OpenLPWizard):
self.progressBar.setMaximum(len(books)) self.progressBar.setMaximum(len(books))
for book in books: for book in books:
if self.stop_import_flag: if self.stop_import_flag:
bible_failed = True self.success[number] = False
break break
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
@ -595,22 +598,22 @@ class BibleUpgradeForm(OpenLPWizard):
meta_data[u'download source'], meta_data[u'download source'],
meta_data[u'download name'])) meta_data[u'download name']))
del self.newbibles[number] del self.newbibles[number]
bible_failed = True self.success[number] = False
break break
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
db_book = self.newbibles[number].create_book(book, db_book = self.newbibles[number].create_book(book,
book_ref_id, book_details[u'testament_id']) book_ref_id, book_details[u'testament_id'])
# Try to import already downloaded verses. # Try to import already downloaded verses.
oldbook = oldbible.get_book(book) oldbook = oldBible.get_book(book)
if oldbook: if oldbook:
verses = oldbible.get_verses(oldbook[u'id']) verses = oldBible.get_verses(oldbook[u'id'])
if not verses: if not verses:
log.warn(u'No verses found to import for book ' log.warn(u'No verses found to import for book '
u'"%s"', book) u'"%s"', book)
continue continue
for verse in verses: for verse in verses:
if self.stop_import_flag: if self.stop_import_flag:
bible_failed = True self.success[number] = False
break break
self.newbibles[number].create_verse(db_book.id, self.newbibles[number].create_verse(db_book.id,
int(verse[u'chapter']), int(verse[u'chapter']),
@ -631,11 +634,11 @@ class BibleUpgradeForm(OpenLPWizard):
(number + 1, max_bibles, name), (number + 1, max_bibles, name),
self.progressBar.maximum() - self.progressBar.value()) self.progressBar.maximum() - self.progressBar.value())
continue continue
books = oldbible.get_books() books = oldBible.get_books()
self.progressBar.setMaximum(len(books)) self.progressBar.setMaximum(len(books))
for book in books: for book in books:
if self.stop_import_flag: if self.stop_import_flag:
bible_failed = True self.success[number] = False
break break
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
@ -649,12 +652,12 @@ class BibleUpgradeForm(OpenLPWizard):
log.warn(u'Upgrading books from %s " '\ log.warn(u'Upgrading books from %s " '\
'failed - aborted by user' % name) 'failed - aborted by user' % name)
del self.newbibles[number] del self.newbibles[number]
bible_failed = True self.success[number] = False
break break
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
db_book = self.newbibles[number].create_book(book[u'name'], db_book = self.newbibles[number].create_book(book[u'name'],
book_ref_id, book_details[u'testament_id']) book_ref_id, book_details[u'testament_id'])
verses = oldbible.get_verses(book[u'id']) verses = oldBible.get_verses(book[u'id'])
if not verses: if not verses:
log.warn(u'No verses found to import for book ' log.warn(u'No verses found to import for book '
u'"%s"', book[u'name']) u'"%s"', book[u'name'])
@ -662,28 +665,29 @@ class BibleUpgradeForm(OpenLPWizard):
continue continue
for verse in verses: for verse in verses:
if self.stop_import_flag: if self.stop_import_flag:
bible_failed = True self.success[number] = False
break break
self.newbibles[number].create_verse(db_book.id, self.newbibles[number].create_verse(db_book.id,
int(verse[u'chapter']), int(verse[u'chapter']),
int(verse[u'verse']), unicode(verse[u'text'])) int(verse[u'verse']), unicode(verse[u'text']))
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
self.newbibles[number].session.commit() self.newbibles[number].session.commit()
if not bible_failed: if self.success[number]:
self.newbibles[number].create_meta(u'Version', name) self.newbibles[number].create_meta(u'Version', name)
oldbible.close_connection()
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\n' 'Upgrading Bible %s of %s: "%s"\n'
'Complete')) % 'Complete')) %
(number + 1, max_bibles, name)) (number + 1, max_bibles, name))
self.success[number] = True
else: else:
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nFailed')) % 'Upgrading Bible %s of %s: "%s"\nFailed')) %
(number + 1, max_bibles, name), (number + 1, max_bibles, name),
self.progressBar.maximum() - self.progressBar.value()) self.progressBar.maximum() - self.progressBar.value())
# Close the last bible's connection.
if oldBible is not None:
oldBible.close_connection()
def postWizard(self): def postWizard(self):
""" """