forked from openlp/openlp
add support for non english booknames in OSIS files, additional improve the detection of progressbar maximum
This commit is contained in:
parent
89e0b0b00c
commit
4c24ba59fa
@ -51,8 +51,6 @@ class OSISBible(BibleDB):
|
|||||||
log.debug(self.__class__.__name__)
|
log.debug(self.__class__.__name__)
|
||||||
BibleDB.__init__(self, parent, **kwargs)
|
BibleDB.__init__(self, parent, **kwargs)
|
||||||
self.filename = kwargs[u'filename']
|
self.filename = kwargs[u'filename']
|
||||||
fbibles = None
|
|
||||||
self.books = {}
|
|
||||||
self.language_regex = re.compile(r'<language.*>(.*?)</language>')
|
self.language_regex = re.compile(r'<language.*>(.*?)</language>')
|
||||||
self.verse_regex = re.compile(
|
self.verse_regex = re.compile(
|
||||||
r'<verse osisID="([a-zA-Z0-9 ]*).([0-9]*).([0-9]*)">(.*?)</verse>')
|
r'<verse osisID="([a-zA-Z0-9 ]*).([0-9]*).([0-9]*)">(.*?)</verse>')
|
||||||
@ -75,16 +73,6 @@ class OSISBible(BibleDB):
|
|||||||
filepath = os.path.join(
|
filepath = os.path.join(
|
||||||
AppLocation.get_directory(AppLocation.PluginsDir), u'bibles',
|
AppLocation.get_directory(AppLocation.PluginsDir), u'bibles',
|
||||||
u'resources', u'osisbooks.csv')
|
u'resources', u'osisbooks.csv')
|
||||||
try:
|
|
||||||
fbibles = open(filepath, u'r')
|
|
||||||
for line in fbibles:
|
|
||||||
book = line.split(u',')
|
|
||||||
self.books[book[0]] = (book[1].strip(), book[2].strip())
|
|
||||||
except IOError:
|
|
||||||
log.exception(u'OSIS bible import failed')
|
|
||||||
finally:
|
|
||||||
if fbibles:
|
|
||||||
fbibles.close()
|
|
||||||
|
|
||||||
def do_import(self, bible_name=None):
|
def do_import(self, bible_name=None):
|
||||||
"""
|
"""
|
||||||
@ -102,6 +90,8 @@ class OSISBible(BibleDB):
|
|||||||
try:
|
try:
|
||||||
detect_file = open(self.filename, u'r')
|
detect_file = open(self.filename, u'r')
|
||||||
details = chardet.detect(detect_file.read(1048576))
|
details = chardet.detect(detect_file.read(1048576))
|
||||||
|
detect_file.seek(0)
|
||||||
|
lines_in_file = int(len(detect_file.readlines()))
|
||||||
except IOError:
|
except IOError:
|
||||||
log.exception(u'Failed to detect OSIS file encoding')
|
log.exception(u'Failed to detect OSIS file encoding')
|
||||||
return
|
return
|
||||||
@ -112,6 +102,17 @@ class OSISBible(BibleDB):
|
|||||||
osis = codecs.open(self.filename, u'r', details['encoding'])
|
osis = codecs.open(self.filename, u'r', details['encoding'])
|
||||||
repl = replacement
|
repl = replacement
|
||||||
language_id = False
|
language_id = False
|
||||||
|
# Decide if the bible propably contains only NT or AT and NT or
|
||||||
|
# AT, NT and Apocrypha
|
||||||
|
if lines_in_file < 11500:
|
||||||
|
book_count = 27
|
||||||
|
chapter_count = 260
|
||||||
|
elif lines_in_file < 34200:
|
||||||
|
book_count = 66
|
||||||
|
chapter_count = 1188
|
||||||
|
else:
|
||||||
|
book_count = 67
|
||||||
|
chapter_count = 1336
|
||||||
for file_record in osis:
|
for file_record in osis:
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
break
|
break
|
||||||
@ -135,36 +136,32 @@ class OSISBible(BibleDB):
|
|||||||
% self.filename)
|
% self.filename)
|
||||||
return False
|
return False
|
||||||
match_count += 1
|
match_count += 1
|
||||||
book = match.group(1)
|
book = unicode(match.group(1))
|
||||||
chapter = int(match.group(2))
|
chapter = int(match.group(2))
|
||||||
verse = int(match.group(3))
|
verse = int(match.group(3))
|
||||||
verse_text = match.group(4)
|
verse_text = match.group(4)
|
||||||
if not db_book or db_book.name != self.books[book][0]:
|
book_ref_id = self.get_book_ref_id_by_name(book, book_count,
|
||||||
log.debug(u'New book: "%s"' % self.books[book][0])
|
language_id)
|
||||||
book_ref_id = self.get_book_ref_id_by_name(unicode(
|
if not book_ref_id:
|
||||||
self.books[book][0]), 67, language_id)
|
log.exception(u'Importing books from "%s" failed' %
|
||||||
if not book_ref_id:
|
self.filename)
|
||||||
log.exception(u'Importing books from "%s" '\
|
return False
|
||||||
'failed' % self.filename)
|
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
||||||
return False
|
if not db_book or db_book.name != book_details[u'name']:
|
||||||
book_details = BiblesResourcesDB.get_book_by_id(
|
log.debug(u'New book: "%s"' % book_details[u'name'])
|
||||||
book_ref_id)
|
|
||||||
db_book = self.create_book(
|
db_book = self.create_book(
|
||||||
unicode(self.books[book][0]),
|
book_details[u'name'],
|
||||||
book_ref_id,
|
book_ref_id,
|
||||||
book_details[u'testament_id'])
|
book_details[u'testament_id'])
|
||||||
if last_chapter == 0:
|
if last_chapter == 0:
|
||||||
if book == u'Gen':
|
self.wizard.progressBar.setMaximum(chapter_count)
|
||||||
self.wizard.progressBar.setMaximum(1188)
|
|
||||||
else:
|
|
||||||
self.wizard.progressBar.setMaximum(260)
|
|
||||||
if last_chapter != chapter:
|
if last_chapter != chapter:
|
||||||
if last_chapter != 0:
|
if last_chapter != 0:
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
self.wizard.incrementProgressBar(unicode(translate(
|
self.wizard.incrementProgressBar(unicode(translate(
|
||||||
'BiblesPlugin.OsisImport', 'Importing %s %s...',
|
'BiblesPlugin.OsisImport', 'Importing %s %s...',
|
||||||
'Importing <book name> <chapter>...')) %
|
'Importing <book name> <chapter>...')) %
|
||||||
(self.books[match.group(1)][0], chapter))
|
(book_details[u'name'], chapter))
|
||||||
last_chapter = chapter
|
last_chapter = chapter
|
||||||
# All of this rigmarol below is because the mod2osis
|
# All of this rigmarol below is because the mod2osis
|
||||||
# tool from the Sword library embeds XML in the OSIS
|
# tool from the Sword library embeds XML in the OSIS
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
Gen,Genesis,Gen
|
|
||||||
Exod,Exodus,Exod
|
|
||||||
Lev,Leviticus,Lev
|
|
||||||
Num,Numbers,Num
|
|
||||||
Deut,Deuteronomy,Deut
|
|
||||||
Josh,Joshua,Josh
|
|
||||||
Judg,Judges,Judg
|
|
||||||
Ruth,Ruth,Ruth
|
|
||||||
1Sam,1 Samuel,1Sam
|
|
||||||
2Sam,2 Samuel,2Sam
|
|
||||||
1Kgs,1 Kings,1Kgs
|
|
||||||
2Kgs,2 Kings,2Kgs
|
|
||||||
1Chr,1 Chronicles,1Chr
|
|
||||||
2Chr,2 Chronicles,2Chr
|
|
||||||
Ezra,Ezra,Ezra
|
|
||||||
Neh,Nehemiah,Neh
|
|
||||||
Esth,Esther,Esth
|
|
||||||
Job,Job,Job
|
|
||||||
Ps,Psalms,Ps
|
|
||||||
Prov,Proverbs,Prov
|
|
||||||
Eccl,Ecclesiastes,Eccl
|
|
||||||
Song,Song of Songs,Song
|
|
||||||
Isa,Isaiah,Isa
|
|
||||||
Jer,Jeremiah,Jer
|
|
||||||
Lam,Lamentations,Lam
|
|
||||||
Ezek,Ezekiel,Ezek
|
|
||||||
Dan,Daniel,Dan
|
|
||||||
Hos,Hosea,Hos
|
|
||||||
Joel,Joel,Joel
|
|
||||||
Amos,Amos,Amos
|
|
||||||
Obad,Obad,Obad
|
|
||||||
Jonah,Jonah,Jonah
|
|
||||||
Mic,Micah,Mic
|
|
||||||
Nah,Naham,Nah
|
|
||||||
Hab,Habakkuk,Hab
|
|
||||||
Zeph,Zephaniah,Zeph
|
|
||||||
Hag,Haggai,Hag
|
|
||||||
Zech,Zechariah,Zech
|
|
||||||
Mal,Malachi,Mal
|
|
||||||
Matt,Matthew,Matt
|
|
||||||
Mark,Mark,Mark
|
|
||||||
Luke,Luke,Luke
|
|
||||||
John,John,John
|
|
||||||
Acts,Acts,Acts
|
|
||||||
Rom,Romans,Rom
|
|
||||||
1Cor,1 Corinthians,1Cor
|
|
||||||
2Cor,2 Corinthians,2Cor
|
|
||||||
Gal,Galatians,Gal
|
|
||||||
Eph,Ephesians,Eph
|
|
||||||
Phil,Philippians,Phil
|
|
||||||
Col,Colossians,Col
|
|
||||||
1Thess,1 Thessalonians,1Thess
|
|
||||||
2Thess,2 Thessalonians,2Thess
|
|
||||||
1Tim,1 Timothy,1Tim
|
|
||||||
2Tim,2 Timothy,2Tim
|
|
||||||
Titus,Titus,Titus
|
|
||||||
Phlm,Philemon,Phlm
|
|
||||||
Heb,Hebrews,Heb
|
|
||||||
Jas,James,Jas
|
|
||||||
1Pet,1 Peter,1Pet
|
|
||||||
2Pet,2 Peter,2Pet
|
|
||||||
1John,1 John,1John
|
|
||||||
2John,2 John,2John
|
|
||||||
3John,3 John,3John
|
|
||||||
Jude,Jude,Jude
|
|
||||||
Rev,Revelation,Rev
|
|
||||||
Jdt,Judith,Jdt
|
|
||||||
Wis,Wisdom,Wis
|
|
||||||
Tob,Tobit,Tob
|
|
||||||
Sir,Sirach,Sir
|
|
||||||
Bar,Baruch,Bar
|
|
||||||
1Macc,1 Maccabees,1Macc
|
|
||||||
2Macc,2 Maccabees,2Macc
|
|
||||||
AddDan,Rest of Daniel,AddDan
|
|
||||||
AddEsth,Rest of Esther,AddEsth
|
|
||||||
PrMan,Prayer of Manasses,PrMan
|
|
|
Loading…
Reference in New Issue
Block a user