Bible plugin clean up and Quick web setup

This commit is contained in:
Tim Bentley 2009-10-12 11:18:54 +01:00
parent 4f997d4fb2
commit cc71923682
6 changed files with 136 additions and 105 deletions

View File

@ -38,7 +38,7 @@ def check_latest_version(config, current_version):
if lastTest != thisTest:
version_string = u''
req = urllib2.Request(u'http://www.openlp.org/files/version.txt')
req.add_header(u'User-Agent', u'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
req.add_header(u'User-Agent', u'OpenLP Version Checker')
try:
handle = urllib2.urlopen(req, None, 1)
html = handle.read()

View File

@ -127,13 +127,19 @@ class BibleDBImpl(BibleCommon):
verse = self.session.query(Verse).join(Book).filter(
Book.name == bookname).filter(
Verse.chapter == chapter).order_by(Verse.verse.desc()).first()
return verse.verse
if verse == None:
return 0
else:
return verse.verse
def get_max_bible_book_chapter(self, bookname):
log.debug(u'get_max_bible_book_chapter %s', bookname)
verse = self.session.query(Verse).join(Book).filter(
Book.name == bookname).order_by(Verse.chapter.desc()).first()
return verse.chapter
if verse == None:
return 0
else:
return verse.chapter
def get_bible_book(self, bookname):
log.debug(u'get_bible_book %s', bookname)

View File

@ -104,7 +104,8 @@ class BibleCommon(object):
urllib2.install_opener(opener)
xml_string = u''
req = urllib2.Request(urlstring)
req.add_header(u'User-Agent', u'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
#May us look like an IE Browser on XP to stop blocking by web site
req.add_header(u'User-Agent', u'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)')
try:
handle = urllib2.urlopen(req)
html = handle.read()

View File

@ -25,6 +25,8 @@
import logging
import os
from openlp.core.lib import translate
from bibleOSISimpl import BibleOSISImpl
from bibleCSVimpl import BibleCSVImpl
from bibleDBimpl import BibleDBImpl
@ -55,6 +57,7 @@ class BibleManager(object):
"""
self.config = config
log.debug(u'Bible Initialising')
self.web = translate(u'BibleManager', u'Web')
# dict of bible database objects
self.bible_db_cache = None
# dict of bible http readers
@ -83,6 +86,8 @@ class BibleManager(object):
self.bible_http_cache = {}
# books of the bible with testaments
self.book_testaments = {}
# books of the bible with chapter count
self.book_chapters = []
# books of the bible with abbreviation
self.book_abbreviations = {}
self.web_bibles_present = False
@ -126,6 +131,7 @@ class BibleManager(object):
p = line.split(u',')
self.book_abbreviations[p[0]] = p[1].replace(u'\n', '')
self.book_testaments[p[0]] = p[2].replace(u'\n', '')
self.book_chapters.append({u'book':p[0], u'total':p[3].replace(u'\n', '')})
log.debug(u'Bible Initialised')
def process_dialog(self, dialogobject):
@ -247,33 +253,34 @@ class BibleManager(object):
``BibleMode.Full`` this method returns all the Bibles for the
Advanced Search, and when the mode is ``BibleMode.Partial``
this method returns all the bibles for the Quick Search.
c
"""
log.debug(u'get_bibles')
bible_list = []
for bible_name, bible_object in self.bible_db_cache.iteritems():
if mode == BibleMode.Full:
bible_list.append(bible_name)
else:
if self.bible_http_cache[bible_name] is None:
# we do not have an http bible
bible_list.append(bible_name)
if self.bible_http_cache[bible_name] is not None:
bible_name = u'%s (%s)' % (bible_name, self.web)
bible_list.append(bible_name)
return bible_list
def get_bible_books(self,bible):
"""
Returns a list of the books of the bible from the database
"""
log.debug(u'get_bible_books %s', bible)
return self.bible_db_cache[bible].get_bible_books()
def is_bible_web(self, bible):
pos_end = bible.find(u' (%s)' % self.web)
if pos_end != -1:
return True, bible[:pos_end]
return False, bible
def get_book_chapter_count(self, bible, book):
def get_bible_books(self):
"""
Returns a list of the books of the bible
"""
log.debug(u'get_bible_books')
return self.book_chapters
def get_book_chapter_count(self, book):
"""
Returns the number of Chapters for a given book
"""
log.debug(u'get_book_chapter_count %s, %s', bible, book)
return self.bible_db_cache[bible].get_max_bible_book_chapter(book)
log.debug(u'get_book_chapter_count %s', book)
return self.book_chapters[book]
def get_book_verse_count(self, bible, book, chapter):
"""
@ -281,8 +288,12 @@ c
book and chapterMaxBibleBookVerses
"""
log.debug(u'get_book_verse_count %s,%s,%s', bible, book, chapter)
return self.bible_db_cache[bible].get_max_bible_book_verses(
book, chapter)
web, bible = self.is_bible_web(bible)
if web:
return int(99)
else:
return self.bible_db_cache[bible].get_max_bible_book_verses(
book, chapter)
def get_verse_from_text(self, bible, versetext):
"""

View File

@ -54,7 +54,8 @@ class BibleMediaItem(MediaManagerItem):
self.ServiceItemIconName = u':/media/bible_image.png'
self.servicePath = None
MediaManagerItem.__init__(self, parent, icon, title)
self.search_results = {} # place to store the search results
# place to store the search results
self.search_results = {}
QtCore.QObject.connect(Receiver().get_receiver(),
QtCore.SIGNAL(u'openlpreloadbibles'), self.reloadBibles)
@ -245,6 +246,7 @@ class BibleMediaItem(MediaManagerItem):
def setQuickMessage(self, text):
self.QuickMessage.setText(translate(u'BibleMediaItem', unicode(text)))
self.AdvancedMessage.setText(translate(u'BibleMediaItem', unicode(text)))
Receiver().send_message(u'process_events')
#minor delay to get the events processed
time.sleep(0.1)
@ -279,9 +281,11 @@ class BibleMediaItem(MediaManagerItem):
unicode(self.AdvancedVersionComboBox.currentText()))
def onAdvancedBookComboBox(self):
item = int(self.AdvancedBookComboBox.currentIndex())
self.initialiseChapterVerse(
unicode(self.AdvancedVersionComboBox.currentText()),
unicode(self.AdvancedBookComboBox.currentText()))
unicode(self.AdvancedBookComboBox.currentText()),
self.AdvancedBookComboBox.itemData(item).toInt()[0])
def onNewClick(self):
self.bibleimportform = BibleImportForm(
@ -435,30 +439,39 @@ class BibleMediaItem(MediaManagerItem):
def initialiseBible(self, bible):
log.debug(u'initialiseBible %s', bible)
books = self.parent.biblemanager.get_bible_books(unicode(bible))
book_data = self.parent.biblemanager.get_bible_books()
self.AdvancedBookComboBox.clear()
first = True
for book in books:
self.AdvancedBookComboBox.addItem(book.name)
for book in book_data:
row = self.AdvancedBookComboBox.count()
self.AdvancedBookComboBox.addItem(book[u'book'])
self.AdvancedBookComboBox.setItemData(row, QtCore.QVariant(book[u'total']))
if first:
first = False
self.initialiseChapterVerse(bible, book.name)
self.initialiseChapterVerse(bible, book[u'book'], book[u'total'])
def initialiseChapterVerse(self, bible, book):
def initialiseChapterVerse(self, bible, book, chapters):
log.debug(u'initialiseChapterVerse %s, %s', bible, book)
self.chapters_from = self.parent.biblemanager.get_book_chapter_count(
bible, book)
print bible , book , chapters
self.chapters_from = chapters
self.verses = self.parent.biblemanager.get_book_verse_count(bible,
book, 1)
self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)
self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)
self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)
self.adjustComboBox(1, self.verses, self.AdvancedToVerse)
if self.verses == 0:
self.AdvancedSearchButton.setEnabled(False)
self.AdvancedMessage.setText(
translate(u'BibleMediaItem', u'Bible not fully loaded'))
else:
self.AdvancedSearchButton.setEnabled(True)
self.AdvancedMessage.setText(u'')
self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)
self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)
self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)
self.adjustComboBox(1, self.verses, self.AdvancedToVerse)
def adjustComboBox(self, frm, to, combo):
log.debug(u'adjustComboBox %s, %s, %s', combo, frm, to)
def adjustComboBox(self, range_from, range_to, combo):
log.debug(u'adjustComboBox %s, %s, %s', combo, range_from, range_to)
combo.clear()
for i in range(int(frm), int(to) + 1):
for i in range(int(range_from), int(range_to) + 1):
combo.addItem(unicode(i))
def displayResults(self, bible):

View File

@ -1,66 +1,66 @@
Genesis,ge,1
Exodus,ex,1
Leviticus,le,1
Numbers,nu,1
Deuteronomy,de,1
Joshua,jos,1
Judges,jud,1
Ruth,ru,1
1 Samual,1sa,1
2 Samual,2sa,1
1 Kings,1ki,1
2 Kings,2ki,1
1 Chronicles,1ch,1
2 Chronicles,2ch,1
Ezra,ezr,1
Nehemiah,ne,1
Esther,es,1
Job,job,1
Psalms,ps,1
Proverbs,pr,1
Ecclesiastes,ec,1
Song of Songs,so,1
Isaiah,isa,1
Jeremiah,jer,1
Lamentations,la,1
Ezekiel,exe,1
Daniel,da,1
Hosea,ho,1
Joel,joe,1
Amos,am,1
Obad,ob,1
Jonah,Jonah,1
Micah,mic,1
Naham,na,1
Habakkuk,hab,1
Zephaniah,zep,1
Haggai,hag,1
Zechariah,zec,1
Malachi,mal,1
Matthew,mt,2
Mark,mk,2
Luke,lu,2
John,joh,2
Acts,ac,2
Romans,ro,2
1 Corinthans,1co,2
2 Corinthans,2co,2
Galatians,ga,2
Ephesians,eph,2
Philippians,php,2
Colossians,col,2
1 Thessalonians,1th,2
2 Thessalonians,2th,2
1 Timothy,1ti,2
2 Timothy,2ti,2
Titus,tit,2
Philemon,phm,2
Hebrews,heb,2
James,jas,2
1 Peter,1pe,2
2 Peter,2pe,2
1 John,1jo,2
2 John,2jo,2
3 John,3jo,2
Jude,jude,2
Revelation,re,2
Genesis,Gen,1,50
Exodus,Exod,1,40
Leviticus,Lev,1,27
Numbers,Num,1,36
Deuteronomy,Deut,1,34
Joshua,Josh,1,24
Judges,Judg,1,21
Ruth,Ruth,1,4
1 Samual,1Sam,1,31
2 Samual,2Sam,1,24
1 Kings,1Kgs,1,22
2 Kings,2Kgs,1,25
1 Chronicles,1Chr,1,29
2 Chronicles,2Chr,1,36
Ezra,Esra,1,10
Nehemiah,Neh,1,13
Esther,Esth,1,10
Job,Job,1,42
Psalms,Ps,1,150
Proverbs,Prov,1,31
Ecclesiastes,Eccl,1,12
Song of Songs,Song,1,8
Isaiah,Isa,1,66
Jeremiah,Jer,1,5
Lamentations,Lam,1,5
Ezekiel,Ezek,1,48
Daniel,Dan,1,12
Hosea,Hos,1,14
Joel,Joel,1,3
Amos,Amos,1,9
Obad,Obad,1,1
Jonah,Jonah,1,4
Micah,Mic,1,7
Naham,Nah,1,3
Habakkuk,Hab,1,3
Zephaniah,Zeph,1,3
Haggai,Hag,1,2
Zechariah,Zech,1,3
Malachi,Mal,1,4
Matthew,Matt,2,28
Mark,Mark,2,16
Luke,Luke,2,24
John,John,2,21
Acts,Acts,2,28
Romans,Rom,2,16
1 Corinthans,1Cor,2,16
2 Corinthans,2Cor,2,13
Galatians,Gal,2,6
Ephesians,Eph,2,6
Philippians,Phil,2,4
Colossians,Col,2,4
1 Thessalonians,1Thess,2,5
2 Thessalonians,2Thess,2,3
1 Timothy,1Tim,2,6
2 Timothy,2Tim,2,4
Titus,Titus,2,3
Philemon,Phlm,2,1
Hebrews,Heb,2,13
James,Jas,2,5
1 Peter,1Pet,2,5
2 Peter,2Pet,2,3
1 John,1John,2,5
2 John,2John,2,1
3 John,3John,2,1
Jude,Jude,2,1
Revelation,Rev,2,22

1 Genesis ge Gen 1 50
2 Exodus ex Exod 1 40
3 Leviticus le Lev 1 27
4 Numbers nu Num 1 36
5 Deuteronomy de Deut 1 34
6 Joshua jos Josh 1 24
7 Judges jud Judg 1 21
8 Ruth ru Ruth 1 4
9 1 Samual 1sa 1Sam 1 31
10 2 Samual 2sa 2Sam 1 24
11 1 Kings 1ki 1Kgs 1 22
12 2 Kings 2ki 2Kgs 1 25
13 1 Chronicles 1ch 1Chr 1 29
14 2 Chronicles 2ch 2Chr 1 36
15 Ezra ezr Esra 1 10
16 Nehemiah ne Neh 1 13
17 Esther es Esth 1 10
18 Job job Job 1 42
19 Psalms ps Ps 1 150
20 Proverbs pr Prov 1 31
21 Ecclesiastes ec Eccl 1 12
22 Song of Songs so Song 1 8
23 Isaiah isa Isa 1 66
24 Jeremiah jer Jer 1 5
25 Lamentations la Lam 1 5
26 Ezekiel exe Ezek 1 48
27 Daniel da Dan 1 12
28 Hosea ho Hos 1 14
29 Joel joe Joel 1 3
30 Amos am Amos 1 9
31 Obad ob Obad 1 1
32 Jonah Jonah Jonah 1 4
33 Micah mic Mic 1 7
34 Naham na Nah 1 3
35 Habakkuk hab Hab 1 3
36 Zephaniah zep Zeph 1 3
37 Haggai hag Hag 1 2
38 Zechariah zec Zech 1 3
39 Malachi mal Mal 1 4
40 Matthew mt Matt 2 28
41 Mark mk Mark 2 16
42 Luke lu Luke 2 24
43 John joh John 2 21
44 Acts ac Acts 2 28
45 Romans ro Rom 2 16
46 1 Corinthans 1co 1Cor 2 16
47 2 Corinthans 2co 2Cor 2 13
48 Galatians ga Gal 2 6
49 Ephesians eph Eph 2 6
50 Philippians php Phil 2 4
51 Colossians col Col 2 4
52 1 Thessalonians 1th 1Thess 2 5
53 2 Thessalonians 2th 2Thess 2 3
54 1 Timothy 1ti 1Tim 2 6
55 2 Timothy 2ti 2Tim 2 4
56 Titus tit Titus 2 3
57 Philemon phm Phlm 2 1
58 Hebrews heb Heb 2 13
59 James jas Jas 2 5
60 1 Peter 1pe 1Pet 2 5
61 2 Peter 2pe 2Pet 2 3
62 1 John 1jo 1John 2 5
63 2 John 2jo 2John 2 1
64 3 John 3jo 3John 2 1
65 Jude jude Jude 2 1
66 Revelation re Rev 2 22