diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index 422e869eb..7e8cde45b 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -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()) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 8f55fb5fc..d6a6d10ca 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -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 diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 10ee7b9f9..e3647e129 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -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): """ diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index e4cb79e73..894feb8d8 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -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