forked from openlp/openlp
Fixed a bug where failed/cancelled imported Bible files are not deleted.
bzr-revno: 749
This commit is contained in:
commit
7eaaf22467
@ -315,23 +315,23 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
|
|
||||||
def performImport(self):
|
def performImport(self):
|
||||||
bible_type = self.field(u'source_format').toInt()[0]
|
bible_type = self.field(u'source_format').toInt()[0]
|
||||||
success = False
|
importer = None
|
||||||
if bible_type == BibleFormat.OSIS:
|
if bible_type == BibleFormat.OSIS:
|
||||||
# Import an OSIS bible
|
# 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()),
|
name=unicode(self.field(u'license_version').toString()),
|
||||||
filename=unicode(self.field(u'osis_location').toString())
|
filename=unicode(self.field(u'osis_location').toString())
|
||||||
)
|
)
|
||||||
elif bible_type == BibleFormat.CSV:
|
elif bible_type == BibleFormat.CSV:
|
||||||
# Import a CSV bible
|
# 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()),
|
name=unicode(self.field(u'license_version').toString()),
|
||||||
booksfile=self.field(u'csv_booksfile').toString(),
|
booksfile=self.field(u'csv_booksfile').toString(),
|
||||||
versefile=self.field(u'csv_versefile').toString()
|
versefile=self.field(u'csv_versefile').toString()
|
||||||
)
|
)
|
||||||
elif bible_type == BibleFormat.OpenSong:
|
elif bible_type == BibleFormat.OpenSong:
|
||||||
# Import an OpenSong bible
|
# 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()),
|
name=unicode(self.field(u'license_version').toString()),
|
||||||
filename=self.field(u'opensong_file').toString()
|
filename=self.field(u'opensong_file').toString()
|
||||||
)
|
)
|
||||||
@ -345,7 +345,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
elif download_location == DownloadLocation.BibleGateway:
|
elif download_location == DownloadLocation.BibleGateway:
|
||||||
bible = self.web_bible_list[DownloadLocation.BibleGateway][
|
bible = self.web_bible_list[DownloadLocation.BibleGateway][
|
||||||
unicode(self.BibleComboBox.currentText())]
|
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()),
|
name=unicode(self.field(u'license_version').toString()),
|
||||||
download_source=unicode(DownloadLocation.get_name(download_location)),
|
download_source=unicode(DownloadLocation.get_name(download_location)),
|
||||||
download_name=unicode(bible),
|
download_name=unicode(bible),
|
||||||
@ -353,6 +353,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
proxy_username=unicode(self.field(u'proxy_username').toString()),
|
proxy_username=unicode(self.field(u'proxy_username').toString()),
|
||||||
proxy_password=unicode(self.field(u'proxy_password').toString())
|
proxy_password=unicode(self.field(u'proxy_password').toString())
|
||||||
)
|
)
|
||||||
|
success = importer.do_import()
|
||||||
if success:
|
if success:
|
||||||
self.manager.save_meta_data(
|
self.manager.save_meta_data(
|
||||||
unicode(self.field(u'license_version').toString()),
|
unicode(self.field(u'license_version').toString()),
|
||||||
@ -365,6 +366,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
else:
|
else:
|
||||||
self.ImportProgressLabel.setText(
|
self.ImportProgressLabel.setText(
|
||||||
self.trUtf8('Your Bible import failed.'))
|
self.trUtf8('Your Bible import failed.'))
|
||||||
|
importer.delete()
|
||||||
|
|
||||||
def postImport(self):
|
def postImport(self):
|
||||||
self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())
|
self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())
|
||||||
|
@ -77,7 +77,6 @@ class BibleDB(QtCore.QObject):
|
|||||||
self.file = self.clean_filename(self.name)
|
self.file = self.clean_filename(self.name)
|
||||||
if u'file' in kwargs:
|
if u'file' in kwargs:
|
||||||
self.file = kwargs[u'file']
|
self.file = kwargs[u'file']
|
||||||
|
|
||||||
self.db_file = os.path.join(kwargs[u'path'], self.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)
|
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')
|
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'_')
|
old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_')
|
||||||
return old_filename + u'.sqlite'
|
return old_filename + u'.sqlite'
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
try:
|
||||||
|
os.remove(self.db_file)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
def register(self, wizard):
|
def register(self, wizard):
|
||||||
"""
|
"""
|
||||||
This method basically just initialialises the database. It is called
|
This method basically just initialialises the database. It is called
|
||||||
|
@ -165,7 +165,7 @@ class BibleManager(object):
|
|||||||
importer = class_(self.parent, **kwargs)
|
importer = class_(self.parent, **kwargs)
|
||||||
name = importer.register(self.import_wizard)
|
name = importer.register(self.import_wizard)
|
||||||
self.db_cache[name] = importer
|
self.db_cache[name] = importer
|
||||||
return importer.do_import()
|
return importer
|
||||||
|
|
||||||
def get_bibles(self):
|
def get_bibles(self):
|
||||||
"""
|
"""
|
||||||
|
@ -114,12 +114,14 @@ class OSISBible(BibleDB):
|
|||||||
osis = codecs.open(self.filename, u'r', details['encoding'])
|
osis = codecs.open(self.filename, u'r', details['encoding'])
|
||||||
last_chapter = 0
|
last_chapter = 0
|
||||||
testament = 1
|
testament = 1
|
||||||
|
match_count = 0
|
||||||
db_book = None
|
db_book = None
|
||||||
for file_record in osis:
|
for file_record in osis:
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
break
|
break
|
||||||
match = self.verse_regex.search(file_record)
|
match = self.verse_regex.search(file_record)
|
||||||
if match:
|
if match:
|
||||||
|
match_count += 1
|
||||||
book = match.group(1)
|
book = match.group(1)
|
||||||
chapter = int(match.group(2))
|
chapter = int(match.group(2))
|
||||||
verse = int(match.group(3))
|
verse = int(match.group(3))
|
||||||
@ -166,6 +168,8 @@ class OSISBible(BibleDB):
|
|||||||
Receiver.send_message(u'process_events')
|
Receiver.send_message(u'process_events')
|
||||||
self.commit()
|
self.commit()
|
||||||
self.wizard.incrementProgressBar(u'Finishing import...')
|
self.wizard.incrementProgressBar(u'Finishing import...')
|
||||||
|
if match_count == 0:
|
||||||
|
success = False
|
||||||
except:
|
except:
|
||||||
log.exception(u'Loading bible from OSIS file failed')
|
log.exception(u'Loading bible from OSIS file failed')
|
||||||
success = False
|
success = False
|
||||||
|
Loading…
Reference in New Issue
Block a user