Fixed bug #941683: Add support for non-English book names in OSIS files.

bzr-revno: 1947
Fixes: https://launchpad.net/bugs/941683
This commit is contained in:
Armin Köhler 2012-04-21 18:33:40 +02:00 committed by Raoul Snyman
commit e4687e4d68
2 changed files with 26 additions and 105 deletions

View File

@ -50,8 +50,6 @@ class OSISBible(BibleDB):
log.debug(self.__class__.__name__)
BibleDB.__init__(self, parent, **kwargs)
self.filename = kwargs[u'filename']
fbibles = None
self.books = {}
self.language_regex = re.compile(r'<language.*>(.*?)</language>')
self.verse_regex = re.compile(
r'<verse osisID="([a-zA-Z0-9 ]*).([0-9]*).([0-9]*)">(.*?)</verse>')
@ -74,16 +72,6 @@ class OSISBible(BibleDB):
filepath = os.path.join(
AppLocation.get_directory(AppLocation.PluginsDir), u'bibles',
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):
"""
@ -101,6 +89,8 @@ class OSISBible(BibleDB):
try:
detect_file = open(self.filename, u'r')
details = chardet.detect(detect_file.read(1048576))
detect_file.seek(0)
lines_in_file = int(len(detect_file.readlines()))
except IOError:
log.exception(u'Failed to detect OSIS file encoding')
return
@ -111,6 +101,17 @@ class OSISBible(BibleDB):
osis = codecs.open(self.filename, u'r', details['encoding'])
repl = replacement
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:
if self.stop_import_flag:
break
@ -134,36 +135,32 @@ class OSISBible(BibleDB):
% self.filename)
return False
match_count += 1
book = match.group(1)
book = unicode(match.group(1))
chapter = int(match.group(2))
verse = int(match.group(3))
verse_text = match.group(4)
if not db_book or db_book.name != self.books[book][0]:
log.debug(u'New book: "%s"' % self.books[book][0])
book_ref_id = self.get_book_ref_id_by_name(unicode(
self.books[book][0]), 67, language_id)
if not book_ref_id:
log.exception(u'Importing books from "%s" '\
'failed' % self.filename)
return False
book_details = BiblesResourcesDB.get_book_by_id(
book_ref_id)
book_ref_id = self.get_book_ref_id_by_name(book, book_count,
language_id)
if not book_ref_id:
log.exception(u'Importing books from "%s" failed' %
self.filename)
return False
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
if not db_book or db_book.name != book_details[u'name']:
log.debug(u'New book: "%s"' % book_details[u'name'])
db_book = self.create_book(
unicode(self.books[book][0]),
book_details[u'name'],
book_ref_id,
book_details[u'testament_id'])
if last_chapter == 0:
if book == u'Gen':
self.wizard.progressBar.setMaximum(1188)
else:
self.wizard.progressBar.setMaximum(260)
self.wizard.progressBar.setMaximum(chapter_count)
if last_chapter != chapter:
if last_chapter != 0:
self.session.commit()
self.wizard.incrementProgressBar(unicode(translate(
'BiblesPlugin.OsisImport', 'Importing %s %s...',
'Importing <book name> <chapter>...')) %
(self.books[match.group(1)][0], chapter))
(book_details[u'name'], chapter))
last_chapter = chapter
# All of this rigmarol below is because the mod2osis
# tool from the Sword library embeds XML in the OSIS

View File

@ -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
1 Gen Genesis Gen
2 Exod Exodus Exod
3 Lev Leviticus Lev
4 Num Numbers Num
5 Deut Deuteronomy Deut
6 Josh Joshua Josh
7 Judg Judges Judg
8 Ruth Ruth Ruth
9 1Sam 1 Samuel 1Sam
10 2Sam 2 Samuel 2Sam
11 1Kgs 1 Kings 1Kgs
12 2Kgs 2 Kings 2Kgs
13 1Chr 1 Chronicles 1Chr
14 2Chr 2 Chronicles 2Chr
15 Ezra Ezra Ezra
16 Neh Nehemiah Neh
17 Esth Esther Esth
18 Job Job Job
19 Ps Psalms Ps
20 Prov Proverbs Prov
21 Eccl Ecclesiastes Eccl
22 Song Song of Songs Song
23 Isa Isaiah Isa
24 Jer Jeremiah Jer
25 Lam Lamentations Lam
26 Ezek Ezekiel Ezek
27 Dan Daniel Dan
28 Hos Hosea Hos
29 Joel Joel Joel
30 Amos Amos Amos
31 Obad Obad Obad
32 Jonah Jonah Jonah
33 Mic Micah Mic
34 Nah Naham Nah
35 Hab Habakkuk Hab
36 Zeph Zephaniah Zeph
37 Hag Haggai Hag
38 Zech Zechariah Zech
39 Mal Malachi Mal
40 Matt Matthew Matt
41 Mark Mark Mark
42 Luke Luke Luke
43 John John John
44 Acts Acts Acts
45 Rom Romans Rom
46 1Cor 1 Corinthians 1Cor
47 2Cor 2 Corinthians 2Cor
48 Gal Galatians Gal
49 Eph Ephesians Eph
50 Phil Philippians Phil
51 Col Colossians Col
52 1Thess 1 Thessalonians 1Thess
53 2Thess 2 Thessalonians 2Thess
54 1Tim 1 Timothy 1Tim
55 2Tim 2 Timothy 2Tim
56 Titus Titus Titus
57 Phlm Philemon Phlm
58 Heb Hebrews Heb
59 Jas James Jas
60 1Pet 1 Peter 1Pet
61 2Pet 2 Peter 2Pet
62 1John 1 John 1John
63 2John 2 John 2John
64 3John 3 John 3John
65 Jude Jude Jude
66 Rev Revelation Rev
67 Jdt Judith Jdt
68 Wis Wisdom Wis
69 Tob Tobit Tob
70 Sir Sirach Sir
71 Bar Baruch Bar
72 1Macc 1 Maccabees 1Macc
73 2Macc 2 Maccabees 2Macc
74 AddDan Rest of Daniel AddDan
75 AddEsth Rest of Esther AddEsth
76 PrMan Prayer of Manasses PrMan