fix failure dectection

This commit is contained in:
Andreas Preikschat 2011-08-15 10:55:36 +02:00
parent da1db9994d
commit 07e9e3fe93
2 changed files with 22 additions and 18 deletions

View File

@ -394,8 +394,8 @@ class BibleUpgradeForm(OpenLPWizard):
if self.stop_import_flag: if self.stop_import_flag:
self.success[number] = False self.success[number] = False
break break
self.success[number] = True
if not self.checkBox[number].checkState() == QtCore.Qt.Checked: if not self.checkBox[number].checkState() == QtCore.Qt.Checked:
self.success[number] = False
continue continue
self.progressBar.reset() self.progressBar.reset()
oldBible = OldBibleDB(self.mediaItem, path=self.temp_dir, oldBible = OldBibleDB(self.mediaItem, path=self.temp_dir,
@ -407,6 +407,7 @@ class BibleUpgradeForm(OpenLPWizard):
'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())
self.success[number] = False
continue continue
self.progressLabel.setText(unicode(translate( self.progressLabel.setText(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
@ -454,6 +455,7 @@ class BibleUpgradeForm(OpenLPWizard):
'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())
self.success[number] = False
continue continue
bible = BiblesResourcesDB.get_webbible( bible = BiblesResourcesDB.get_webbible(
meta_data[u'download name'], meta_data[u'download name'],
@ -472,6 +474,7 @@ class BibleUpgradeForm(OpenLPWizard):
'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())
self.success[number] = False
continue continue
self.progressBar.setMaximum(len(books)) self.progressBar.setMaximum(len(books))
for book in books: for book in books:
@ -526,6 +529,7 @@ class BibleUpgradeForm(OpenLPWizard):
'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())
self.success[number] = False
continue continue
books = oldBible.get_books() books = oldBible.get_books()
self.progressBar.setMaximum(len(books)) self.progressBar.setMaximum(len(books))
@ -565,20 +569,22 @@ class BibleUpgradeForm(OpenLPWizard):
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 self.success[number]: if self.success.has_key(number) and not self.success[number]:
print u'11111'
self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nFailed')) %
(number + 1, max_bibles, name),
self.progressBar.maximum() - self.progressBar.value())
else:
self.success[number] = True
self.newbibles[number].create_meta(u'Version', name) self.newbibles[number].create_meta(u'Version', name)
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))
else: # Close the last bible's connection if possible.
self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nFailed')) %
(number + 1, max_bibles, name),
self.progressBar.maximum() - self.progressBar.value())
# Close the last bible's connection.
if oldBible is not None: if oldBible is not None:
oldBible.close_connection() oldBible.close_connection()
@ -591,13 +597,12 @@ class BibleUpgradeForm(OpenLPWizard):
for number, filename in enumerate(self.files): for number, filename in enumerate(self.files):
if self.success.has_key(number) and self.success[number]: if self.success.has_key(number) and self.success[number]:
successful_import += 1 successful_import += 1
else: elif self.checkBox[number].checkState() == QtCore.Qt.Checked:
failed_import += 1
# Delete upgraded (but not complete, corrupted, ...) bible. # Delete upgraded (but not complete, corrupted, ...) bible.
delete_file(os.path.join(self.path, filename[0])) delete_file(os.path.join(self.path, filename[0]))
# Copy not upgraded bible back. # Copy not upgraded bible back.
shutil.move(os.path.join(self.temp_dir, filename[0]), self.path) shutil.move(os.path.join(self.temp_dir, filename[0]), self.path)
if self.checkBox[number].checkState() == QtCore.Qt.Checked:
failed_import += 1
if failed_import > 0: if failed_import > 0:
failed_import_text = unicode(translate( failed_import_text = unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',

View File

@ -45,7 +45,7 @@ class LanguageForm(QDialog, Ui_LanguageDialog):
""" """
log.info(u'LanguageForm loaded') log.info(u'LanguageForm loaded')
def __init__(self, parent = None): def __init__(self, parent=None):
""" """
Constructor Constructor
""" """
@ -57,12 +57,11 @@ class LanguageForm(QDialog, Ui_LanguageDialog):
if bible_name: if bible_name:
self.bibleLabel.setText(unicode(bible_name)) self.bibleLabel.setText(unicode(bible_name))
items = BiblesResourcesDB.get_languages() items = BiblesResourcesDB.get_languages()
for item in items: self.languageComboBox.addItems([item[u'name'] for item in items])
self.languageComboBox.addItem(item[u'name'])
return QDialog.exec_(self) return QDialog.exec_(self)
def accept(self): def accept(self):
if self.languageComboBox.currentText() == u'': if not self.languageComboBox.currentText():
critical_error_message_box( critical_error_message_box(
message=translate('BiblesPlugin.LanguageForm', message=translate('BiblesPlugin.LanguageForm',
'You need to choose a language.')) 'You need to choose a language.'))