Fixed a bug where failed/cancelled imported Bible files are not deleted.

bzr-revno: 749
This commit is contained in:
Raoul Snyman 2010-03-20 17:47:05 +02:00
commit 7eaaf22467
4 changed files with 19 additions and 7 deletions

View File

@ -315,23 +315,23 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
def performImport(self):
bible_type = self.field(u'source_format').toInt()[0]
success = False
importer = None
if bible_type == BibleFormat.OSIS:
# Import an OSIS bible
success = self.manager.import_bible(BibleFormat.OSIS,
importer = self.manager.import_bible(BibleFormat.OSIS,
name=unicode(self.field(u'license_version').toString()),
filename=unicode(self.field(u'osis_location').toString())
)
elif bible_type == BibleFormat.CSV:
# Import a CSV bible
success = self.manager.import_bible(BibleFormat.CSV,
importer = self.manager.import_bible(BibleFormat.CSV,
name=unicode(self.field(u'license_version').toString()),
booksfile=self.field(u'csv_booksfile').toString(),
versefile=self.field(u'csv_versefile').toString()
)
elif bible_type == BibleFormat.OpenSong:
# Import an OpenSong bible
success = self.manager.import_bible(BibleFormat.OpenSong,
importer = self.manager.import_bible(BibleFormat.OpenSong,
name=unicode(self.field(u'license_version').toString()),
filename=self.field(u'opensong_file').toString()
)
@ -345,7 +345,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
elif download_location == DownloadLocation.BibleGateway:
bible = self.web_bible_list[DownloadLocation.BibleGateway][
unicode(self.BibleComboBox.currentText())]
success = self.manager.import_bible(BibleFormat.WebDownload,
importer = self.manager.import_bible(BibleFormat.WebDownload,
name=unicode(self.field(u'license_version').toString()),
download_source=unicode(DownloadLocation.get_name(download_location)),
download_name=unicode(bible),
@ -353,6 +353,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
proxy_username=unicode(self.field(u'proxy_username').toString()),
proxy_password=unicode(self.field(u'proxy_password').toString())
)
success = importer.do_import()
if success:
self.manager.save_meta_data(
unicode(self.field(u'license_version').toString()),
@ -365,6 +366,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
else:
self.ImportProgressLabel.setText(
self.trUtf8('Your Bible import failed.'))
importer.delete()
def postImport(self):
self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())

View File

@ -77,7 +77,6 @@ class BibleDB(QtCore.QObject):
self.file = self.clean_filename(self.name)
if u'file' in kwargs:
self.file = kwargs[u'file']
self.db_file = os.path.join(kwargs[u'path'], self.file)
log.debug(u'Load bible %s on path %s', self.file, self.db_file)
db_type = self.config.get_config(u'db type', u'sqlite')
@ -109,6 +108,13 @@ class BibleDB(QtCore.QObject):
old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_')
return old_filename + u'.sqlite'
def delete(self):
try:
os.remove(self.db_file)
return True
except:
return False
def register(self, wizard):
"""
This method basically just initialialises the database. It is called

View File

@ -165,7 +165,7 @@ class BibleManager(object):
importer = class_(self.parent, **kwargs)
name = importer.register(self.import_wizard)
self.db_cache[name] = importer
return importer.do_import()
return importer
def get_bibles(self):
"""

View File

@ -114,12 +114,14 @@ class OSISBible(BibleDB):
osis = codecs.open(self.filename, u'r', details['encoding'])
last_chapter = 0
testament = 1
match_count = 0
db_book = None
for file_record in osis:
if self.stop_import_flag:
break
match = self.verse_regex.search(file_record)
if match:
match_count += 1
book = match.group(1)
chapter = int(match.group(2))
verse = int(match.group(3))
@ -166,6 +168,8 @@ class OSISBible(BibleDB):
Receiver.send_message(u'process_events')
self.commit()
self.wizard.incrementProgressBar(u'Finishing import...')
if match_count == 0:
success = False
except:
log.exception(u'Loading bible from OSIS file failed')
success = False