various fixes and improvements to the sword import.

This commit is contained in:
Tomas Groth 2016-04-12 21:55:32 +02:00
parent 6b75148e34
commit d3a57ae46b
2 changed files with 26 additions and 17 deletions

View File

@ -101,7 +101,12 @@ class BibleImportForm(OpenLPWizard):
self.select_stack.setCurrentIndex(0) self.select_stack.setCurrentIndex(0)
if PYSWORD_AVAILABLE: if PYSWORD_AVAILABLE:
self.pysword_folder_modules = modules.SwordModules() self.pysword_folder_modules = modules.SwordModules()
self.pysword_folder_modules_json = self.pysword_folder_modules.parse_modules() try:
self.pysword_folder_modules_json = self.pysword_folder_modules.parse_modules()
except FileNotFoundError:
log.debug('No installed SWORD modules found in the default location')
self.sword_bible_combo_box.clear()
return
bible_keys = self.pysword_folder_modules_json.keys() bible_keys = self.pysword_folder_modules_json.keys()
for key in bible_keys: for key in bible_keys:
self.sword_bible_combo_box.addItem(self.pysword_folder_modules_json[key]['description'], key) self.sword_bible_combo_box.addItem(self.pysword_folder_modules_json[key]['description'], key)
@ -464,6 +469,9 @@ class BibleImportForm(OpenLPWizard):
if self.currentPage() == self.welcome_page: if self.currentPage() == self.welcome_page:
return True return True
elif self.currentPage() == self.select_page: elif self.currentPage() == self.select_page:
self.version_name_edit.clear()
self.permissions_edit.clear()
self.copyright_edit.clear()
if self.field('source_format') == BibleFormat.OSIS: if self.field('source_format') == BibleFormat.OSIS:
if not self.field('osis_location'): if not self.field('osis_location'):
critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OSIS) critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OSIS)
@ -513,6 +521,8 @@ class BibleImportForm(OpenLPWizard):
self.version_name_edit.setText(self.pysword_folder_modules_json[key]['description']) self.version_name_edit.setText(self.pysword_folder_modules_json[key]['description'])
if 'distributionlicense' in self.pysword_folder_modules_json[key]: if 'distributionlicense' in self.pysword_folder_modules_json[key]:
self.permissions_edit.setText(self.pysword_folder_modules_json[key]['distributionlicense']) self.permissions_edit.setText(self.pysword_folder_modules_json[key]['distributionlicense'])
if 'copyright' in self.pysword_folder_modules_json[key]:
self.copyright_edit.setText(self.pysword_folder_modules_json[key]['copyright'])
elif self.sword_tab_widget.currentIndex() == self.sword_tab_widget.indexOf(self.sword_zip_tab): elif self.sword_tab_widget.currentIndex() == self.sword_tab_widget.indexOf(self.sword_zip_tab):
if not self.field('sword_zip_path'): if not self.field('sword_zip_path'):
critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.SWORD) critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.SWORD)

View File

@ -71,22 +71,21 @@ class SwordBible(BibleDB):
num_books += len(books['nt']) num_books += len(books['nt'])
self.wizard.progress_bar.setMaximum(num_books) self.wizard.progress_bar.setMaximum(num_books)
# Import the bible # Import the bible
for testament in ['ot', 'nt']: for testament in books.keys():
if testament in books: for book in books[testament]:
for book in books[testament]: book_ref_id = self.get_book_ref_id_by_name(book.name, num_books, language_id)
book_ref_id = self.get_book_ref_id_by_name(book.name, num_books, language_id) book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) db_book = self.create_book(book_details['name'], book_ref_id, book_details['testament_id'])
db_book = self.create_book(book_details['name'], book_ref_id, book_details['testament_id']) for chapter_number in range(1, book.num_chapters + 1):
for chapter_number in range(1, book.num_chapters + 1): if self.stop_import_flag:
if self.stop_import_flag: break
break verses = bible.get_iter(book.name, chapter_number)
verses = bible.get_iter(book.name, chapter_number) verse_number = 0
verse_number = 0 for verse in verses:
for verse in verses: verse_number += 1
verse_number += 1 self.create_verse(db_book.id, chapter_number, verse_number, verse)
self.create_verse(db_book.id, chapter_number, verse_number, verse) self.wizard.increment_progress_bar(
self.wizard.increment_progress_bar( translate('BiblesPlugin.Sword', 'Importing %s...') % db_book.name)
translate('BiblesPlugin.Sword', 'Importing %s...') % db_book.name)
self.session.commit() self.session.commit()
self.application.process_events() self.application.process_events()
except Exception as e: except Exception as e: