forked from openlp/openlp
parent
ebc4476fdd
commit
c3ed2c02ee
@ -73,13 +73,13 @@ class OpenSongBible(BibleDB):
|
|||||||
log.debug('Starting OpenSong import from "%s"' % self.filename)
|
log.debug('Starting OpenSong import from "%s"' % self.filename)
|
||||||
if not isinstance(self.filename, str):
|
if not isinstance(self.filename, str):
|
||||||
self.filename = str(self.filename, 'utf8')
|
self.filename = str(self.filename, 'utf8')
|
||||||
file = None
|
import_file = None
|
||||||
success = True
|
success = True
|
||||||
try:
|
try:
|
||||||
# NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own encoding
|
# NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own encoding
|
||||||
# detection, and the two mechanisms together interfere with each other.
|
# detection, and the two mechanisms together interfere with each other.
|
||||||
file = open(self.filename, 'r')
|
import_file = open(self.filename, 'rb')
|
||||||
opensong = objectify.parse(file)
|
opensong = objectify.parse(import_file)
|
||||||
bible = opensong.getroot()
|
bible = opensong.getroot()
|
||||||
language_id = self.get_language(bible_name)
|
language_id = self.get_language(bible_name)
|
||||||
if not language_id:
|
if not language_id:
|
||||||
@ -93,7 +93,7 @@ class OpenSongBible(BibleDB):
|
|||||||
log.error('Importing books from "%s" failed' % self.filename)
|
log.error('Importing books from "%s" failed' % self.filename)
|
||||||
return False
|
return False
|
||||||
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(str(book.attrib['n']), book_ref_id, book_details['testament_id'])
|
db_book = self.create_book(book.attrib['n'], book_ref_id, book_details['testament_id'])
|
||||||
chapter_number = 0
|
chapter_number = 0
|
||||||
for chapter in book.c:
|
for chapter in book.c:
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
@ -122,8 +122,8 @@ class OpenSongBible(BibleDB):
|
|||||||
verse_number += 1
|
verse_number += 1
|
||||||
self.create_verse(db_book.id, chapter_number, verse_number, self.get_text(verse))
|
self.create_verse(db_book.id, chapter_number, verse_number, self.get_text(verse))
|
||||||
self.wizard.increment_progress_bar(
|
self.wizard.increment_progress_bar(
|
||||||
translate('BiblesPlugin.Opensong', 'Importing %s %s...',
|
translate('BiblesPlugin.Opensong', 'Importing %(bookname)s %(chapter)s...' %
|
||||||
'Importing <book name> <chapter>...')) % (db_book.name, chapter_number)
|
{'bookname':db_book.name, 'chapter': chapter_number}))
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
self.application.process_events()
|
self.application.process_events()
|
||||||
except etree.XMLSyntaxError as inst:
|
except etree.XMLSyntaxError as inst:
|
||||||
@ -137,8 +137,8 @@ class OpenSongBible(BibleDB):
|
|||||||
log.exception('Loading Bible from OpenSong file failed')
|
log.exception('Loading Bible from OpenSong file failed')
|
||||||
success = False
|
success = False
|
||||||
finally:
|
finally:
|
||||||
if file:
|
if import_file:
|
||||||
file.close()
|
import_file.close()
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user