openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #15297
[Merge] lp:~orangeshirt/openlp/bibles_fixes into lp:openlp
Armin Köhler has proposed merging lp:~orangeshirt/openlp/bibles_fixes into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Related bugs:
Bug #941683 in OpenLP: "OSIS Bible Book Names are not always in English"
https://bugs.launchpad.net/openlp/+bug/941683
For more details, see:
https://code.launchpad.net/~orangeshirt/openlp/bibles_fixes/+merge/102585
fix bug 941683 - add support for non english booknames in OSIS files
additional improve the detection of progressbar maximum in osis import
--
https://code.launchpad.net/~orangeshirt/openlp/bibles_fixes/+merge/102585
Your team OpenLP Core is requested to review the proposed merge of lp:~orangeshirt/openlp/bibles_fixes into lp:openlp.
=== modified file 'openlp/plugins/bibles/lib/osis.py'
--- openlp/plugins/bibles/lib/osis.py 2012-03-01 18:09:47 +0000
+++ openlp/plugins/bibles/lib/osis.py 2012-04-18 20:35:23 +0000
@@ -51,8 +51,6 @@
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>')
@@ -75,16 +73,6 @@
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):
"""
@@ -102,6 +90,8 @@
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
@@ -112,6 +102,17 @@
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
@@ -135,36 +136,32 @@
% 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
=== removed file 'openlp/plugins/bibles/resources/osisbooks.csv'
--- openlp/plugins/bibles/resources/osisbooks.csv 2011-12-18 17:09:40 +0000
+++ openlp/plugins/bibles/resources/osisbooks.csv 1970-01-01 00:00:00 +0000
@@ -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
Follow ups