Merge lp:~raoul-snyman/openlp/biblefixes into lp:openlp
- biblefixes
- Merge into trunk
Proposed by
Raoul Snyman
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~raoul-snyman/openlp/biblefixes |
Merge into: | lp:openlp |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~raoul-snyman/openlp/biblefixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Thompson (community) | Approve | ||
Tim Bentley | Approve | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Raoul Snyman (raoul-snyman) wrote : | # |
- 493. By Tim Bentley
-
Various bug fixes and code improvements.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Tim Bentley (trb143) wrote : | # |
Looks good.
Approved.
review:
Approve
- 494. By Raoul Snyman
-
Merged in the changes from the biblefixes branch.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Martin Thompson (mjthompson) wrote : | # |
I can't comment on much of the code, not familiar with sqlalchemy, but while I'm here...
Niggles:
420 + osis = codecs.
Is there a reason 'encoding' shouldn't be unicode?
1088 +mapper(
1089 + properties=
1090 +mapper(Book, book_table,
1091 + properties=
More unicode strings?
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'openlp/core/ui/slidecontroller.py' | |||
2 | --- openlp/core/ui/slidecontroller.py 2009-07-11 05:18:34 +0000 | |||
3 | +++ openlp/core/ui/slidecontroller.py 2009-07-12 20:38:34 +0000 | |||
4 | @@ -212,11 +212,12 @@ | |||
5 | 212 | self.ControllerLayout.addWidget(self.Toolbar) | 212 | self.ControllerLayout.addWidget(self.Toolbar) |
6 | 213 | self.BaseToolbar.addServiceManagerItem(item, slideno) | 213 | self.BaseToolbar.addServiceManagerItem(item, slideno) |
7 | 214 | 214 | ||
8 | 215 | |||
9 | 215 | class MasterPreview(QtCore.QObject): | 216 | class MasterPreview(QtCore.QObject): |
10 | 216 | """ | 217 | """ |
14 | 217 | Class from which all Previews should extend allowing plugins to have their own | 218 | Class from which all Previews should extend allowing plugins to |
15 | 218 | previews | 219 | have their own previews |
16 | 219 | s """ | 220 | """ |
17 | 220 | def __init__(self, parent): | 221 | def __init__(self, parent): |
18 | 221 | self.parent = parent | 222 | self.parent = parent |
19 | 222 | QtCore.QObject.__init__(self) | 223 | QtCore.QObject.__init__(self) |
20 | @@ -369,28 +370,30 @@ | |||
21 | 369 | Display the slide number passed | 370 | Display the slide number passed |
22 | 370 | """ | 371 | """ |
23 | 371 | log.debug(u'add Service Manager Item') | 372 | log.debug(u'add Service Manager Item') |
24 | 373 | self.serviceitem = serviceitem | ||
25 | 374 | slide_pixmap = QtGui.QPixmap.fromImage(self.serviceitem.frames[0][u'image']) | ||
26 | 375 | slide_width = 300 | ||
27 | 376 | slide_height = slide_width * slide_pixmap.height() / slide_pixmap.width() | ||
28 | 372 | self.PreviewListWidget.clear() | 377 | self.PreviewListWidget.clear() |
29 | 373 | self.PreviewListWidget.setRowCount(0) | 378 | self.PreviewListWidget.setRowCount(0) |
33 | 374 | self.serviceitem = serviceitem | 379 | self.PreviewListWidget.setColumnWidth(0, slide_width) |
34 | 375 | framenumber = 0 | 380 | for framenumber, frame in enumerate(self.serviceitem.frames): |
32 | 376 | for frame in self.serviceitem.frames: | ||
35 | 377 | self.PreviewListWidget.setRowCount(self.PreviewListWidget.rowCount() + 1) | 381 | self.PreviewListWidget.setRowCount(self.PreviewListWidget.rowCount() + 1) |
36 | 378 | pixmap = QtGui.QPixmap.fromImage(frame[u'image']) | 382 | pixmap = QtGui.QPixmap.fromImage(frame[u'image']) |
37 | 379 | item = QtGui.QTableWidgetItem() | 383 | item = QtGui.QTableWidgetItem() |
38 | 380 | label = QtGui.QLabel() | 384 | label = QtGui.QLabel() |
40 | 381 | label.setMargin(15) | 385 | label.setMargin(8) |
41 | 382 | label.setScaledContents(True) | 386 | label.setScaledContents(True) |
42 | 383 | width = 300 | ||
43 | 384 | height = width * pixmap.height() / pixmap.width() | ||
44 | 385 | label.setPixmap(pixmap) | 387 | label.setPixmap(pixmap) |
50 | 386 | self.PreviewListWidget.setCellWidget(framenumber, 0,label) | 388 | self.PreviewListWidget.setCellWidget(framenumber, 0, label) |
51 | 387 | self.PreviewListWidget.setItem( framenumber, 0, item) | 389 | self.PreviewListWidget.setItem(framenumber, 0, item) |
52 | 388 | self.PreviewListWidget.setRowHeight(framenumber, height) | 390 | self.PreviewListWidget.setRowHeight(framenumber, slide_height) |
53 | 389 | self.PreviewListWidget.setColumnWidth(0, width) | 391 | slide_width = self.PreviewListWidget.viewport().size().width() |
54 | 390 | framenumber += 1 | 392 | self.PreviewListWidget.setColumnWidth(0, slide_width) |
55 | 391 | if slideno > self.PreviewListWidget.rowCount(): | 393 | if slideno > self.PreviewListWidget.rowCount(): |
56 | 392 | self.PreviewListWidget.selectRow(self.PreviewListWidget.rowCount()) | 394 | self.PreviewListWidget.selectRow(self.PreviewListWidget.rowCount()) |
57 | 393 | else: | 395 | else: |
58 | 394 | self.PreviewListWidget.selectRow(slideno) | 396 | self.PreviewListWidget.selectRow(slideno) |
59 | 395 | self.onSlideSelected() | 397 | self.onSlideSelected() |
60 | 396 | self.serviceLoaded() | 398 | self.serviceLoaded() |
61 | 399 | self.PreviewListWidget.setFocus() | ||
62 | 397 | 400 | ||
63 | === modified file 'openlp/plugins/bibles/lib/bibleDBimpl.py' | |||
64 | --- openlp/plugins/bibles/lib/bibleDBimpl.py 2009-06-16 18:21:24 +0000 | |||
65 | +++ openlp/plugins/bibles/lib/bibleDBimpl.py 2009-07-14 19:44:15 +0000 | |||
66 | @@ -1,6 +1,10 @@ | |||
67 | 1 | # -*- coding: utf-8 -*- | ||
68 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 | ||
69 | 1 | """ | 3 | """ |
70 | 2 | OpenLP - Open Source Lyrics Projection | 4 | OpenLP - Open Source Lyrics Projection |
71 | 5 | |||
72 | 3 | Copyright (c) 2008 Raoul Snyman | 6 | Copyright (c) 2008 Raoul Snyman |
73 | 7 | |||
74 | 4 | Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley | 8 | Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley |
75 | 5 | 9 | ||
76 | 6 | This program is free software; you can redistribute it and/or modify it under | 10 | This program is free software; you can redistribute it and/or modify it under |
77 | @@ -16,43 +20,34 @@ | |||
78 | 16 | Place, Suite 330, Boston, MA 02111-1307 USA | 20 | Place, Suite 330, Boston, MA 02111-1307 USA |
79 | 17 | """ | 21 | """ |
80 | 18 | import os | 22 | import os |
81 | 19 | import os.path | ||
82 | 20 | import logging | 23 | import logging |
83 | 21 | 24 | ||
84 | 22 | from sqlalchemy import * | ||
85 | 23 | from sqlalchemy.sql import select | ||
86 | 24 | from sqlalchemy.orm import sessionmaker, mapper, scoped_session | ||
87 | 25 | |||
88 | 26 | from common import BibleCommon | 25 | from common import BibleCommon |
89 | 27 | from openlp.core.utils import ConfigHelper | 26 | from openlp.core.utils import ConfigHelper |
92 | 28 | from openlp.plugins.bibles.lib.tables import * | 27 | from openlp.plugins.bibles.lib.models import * |
91 | 29 | from openlp.plugins.bibles.lib.classes import * | ||
93 | 30 | 28 | ||
94 | 31 | class BibleDBImpl(BibleCommon): | 29 | class BibleDBImpl(BibleCommon): |
95 | 32 | global log | 30 | global log |
96 | 33 | log=logging.getLogger(u'BibleDBImpl') | 31 | log=logging.getLogger(u'BibleDBImpl') |
97 | 34 | log.info(u'BibleDBimpl loaded') | 32 | log.info(u'BibleDBimpl loaded') |
98 | 35 | 33 | ||
100 | 36 | def __init__(self, biblepath , biblename, config): | 34 | def __init__(self, biblepath, biblename, config): |
101 | 37 | # Connect to database | 35 | # Connect to database |
102 | 38 | self.config = config | 36 | self.config = config |
104 | 39 | self.biblefile = os.path.join(biblepath, biblename+u'.sqlite') | 37 | self.biblefile = os.path.join(biblepath, biblename + u'.sqlite') |
105 | 40 | log.debug(u'Load bible %s on path %s', biblename, self.biblefile) | 38 | log.debug(u'Load bible %s on path %s', biblename, self.biblefile) |
106 | 41 | db_type = self.config.get_config(u'db type', u'sqlite') | 39 | db_type = self.config.get_config(u'db type', u'sqlite') |
107 | 40 | db_url = u'' | ||
108 | 42 | if db_type == u'sqlite': | 41 | if db_type == u'sqlite': |
110 | 43 | self.db = create_engine(u'sqlite:///' + self.biblefile) | 42 | db_url = u'sqlite:///' + self.biblefile |
111 | 44 | else: | 43 | else: |
113 | 45 | self.db_url = u'%s://%s:%s@%s/%s' % \ | 44 | db_url = u'%s://%s:%s@%s/%s' % \ |
114 | 46 | (db_type, self.config.get_config(u'db username'), | 45 | (db_type, self.config.get_config(u'db username'), |
115 | 47 | self.config.get_config(u'db password'), | 46 | self.config.get_config(u'db password'), |
116 | 48 | self.config.get_config(u'db hostname'), | 47 | self.config.get_config(u'db hostname'), |
117 | 49 | self.config.get_config(u'db database')) | 48 | self.config.get_config(u'db database')) |
124 | 50 | self.db.echo = False | 49 | self.metadata, self.session = init_models(db_url) |
125 | 51 | metadata.bind = self.db | 50 | self.metadata.create_all(checkfirst=True) |
120 | 52 | metadata.bind.echo = False | ||
121 | 53 | self.session = scoped_session(sessionmaker(autoflush=True, autocommit=False)) | ||
122 | 54 | self.session.configure(bind=self.db) | ||
123 | 55 | metadata.create_all(self.db) | ||
126 | 56 | 51 | ||
127 | 57 | def create_tables(self): | 52 | def create_tables(self): |
128 | 58 | log.debug( u'createTables') | 53 | log.debug( u'createTables') |
129 | @@ -63,122 +58,127 @@ | |||
130 | 63 | 58 | ||
131 | 64 | def add_verse(self, bookid, chap, vse, text): | 59 | def add_verse(self, bookid, chap, vse, text): |
132 | 65 | #log.debug(u'add_verse %s,%s,%s", bookid, chap, vse) | 60 | #log.debug(u'add_verse %s,%s,%s", bookid, chap, vse) |
135 | 66 | metadata.bind.echo = False | 61 | #metadata.bind.echo = False |
134 | 67 | session = self.session() | ||
136 | 68 | verse = Verse() | 62 | verse = Verse() |
137 | 69 | verse.book_id = bookid | 63 | verse.book_id = bookid |
138 | 70 | verse.chapter = chap | 64 | verse.chapter = chap |
139 | 71 | verse.verse = vse | 65 | verse.verse = vse |
140 | 72 | verse.text = text | 66 | verse.text = text |
143 | 73 | session.add(verse) | 67 | self.session.add(verse) |
144 | 74 | session.commit() | 68 | self.session.commit() |
145 | 75 | 69 | ||
146 | 76 | def create_chapter(self, bookid, chap, textlist): | 70 | def create_chapter(self, bookid, chap, textlist): |
147 | 77 | log.debug(u'create_chapter %s,%s', bookid, chap) | 71 | log.debug(u'create_chapter %s,%s', bookid, chap) |
148 | 78 | #log.debug(u'Text %s ", textlist) | 72 | #log.debug(u'Text %s ", textlist) |
151 | 79 | metadata.bind.echo = False | 73 | #metadata.bind.echo = False |
150 | 80 | session = self.session() | ||
152 | 81 | #text list has book and chapter as first to elements of the array | 74 | #text list has book and chapter as first to elements of the array |
154 | 82 | for v , t in textlist.iteritems(): | 75 | for verse_number, verse_text in textlist.iteritems(): |
155 | 83 | verse = Verse() | 76 | verse = Verse() |
156 | 84 | verse.book_id = bookid | 77 | verse.book_id = bookid |
157 | 85 | verse.chapter = chap | 78 | verse.chapter = chap |
162 | 86 | verse.verse = v | 79 | verse.verse = verse_number |
163 | 87 | verse.text = t | 80 | verse.text = verse_text |
164 | 88 | session.add(verse) | 81 | self.session.add(verse) |
165 | 89 | session.commit() | 82 | self.session.commit() |
166 | 90 | 83 | ||
168 | 91 | def create_book(self, bookname, bookabbrev, testament = 1): | 84 | def create_book(self, bookname, bookabbrev, testament=1): |
169 | 92 | log.debug(u'create_book %s,%s', bookname, bookabbrev) | 85 | log.debug(u'create_book %s,%s', bookname, bookabbrev) |
172 | 93 | metadata.bind.echo = False | 86 | #metadata.bind.echo = False |
171 | 94 | session = self.session() | ||
173 | 95 | book = Book() | 87 | book = Book() |
174 | 96 | book.testament_id = testament | 88 | book.testament_id = testament |
175 | 97 | book.name = bookname | 89 | book.name = bookname |
176 | 98 | book.abbreviation = bookabbrev | 90 | book.abbreviation = bookabbrev |
179 | 99 | session.add(book) | 91 | self.session.add(book) |
180 | 100 | session.commit() | 92 | self.session.commit() |
181 | 101 | return book | 93 | return book |
182 | 102 | 94 | ||
183 | 103 | def save_meta(self, key, value): | 95 | def save_meta(self, key, value): |
184 | 104 | log.debug(u'save_meta %s/%s', key, value) | 96 | log.debug(u'save_meta %s/%s', key, value) |
188 | 105 | metadata.bind.echo = False | 97 | #metadata.bind.echo = False |
189 | 106 | session = self.session() | 98 | bmeta = BibleMeta() |
187 | 107 | bmeta= BibleMeta() | ||
190 | 108 | bmeta.key = key | 99 | bmeta.key = key |
191 | 109 | bmeta.value = value | 100 | bmeta.value = value |
194 | 110 | session.add(bmeta) | 101 | self.session.add(bmeta) |
195 | 111 | session.commit() | 102 | self.session.commit() |
196 | 112 | 103 | ||
197 | 113 | def get_meta(self, metakey): | 104 | def get_meta(self, metakey): |
198 | 114 | log.debug(u'get meta %s', metakey) | 105 | log.debug(u'get meta %s', metakey) |
200 | 115 | return self.session.query(BibleMeta).filter_by(key = metakey).first() | 106 | return self.session.query(BibleMeta).filter_by(key=metakey).first() |
201 | 116 | 107 | ||
202 | 117 | def delete_meta(self, metakey): | 108 | def delete_meta(self, metakey): |
203 | 118 | biblemeta = self.get_meta(metakey) | 109 | biblemeta = self.get_meta(metakey) |
204 | 119 | try: | 110 | try: |
207 | 120 | session.delete(biblemeta) | 111 | self.session.delete(biblemeta) |
208 | 121 | session.commit() | 112 | self.session.commit() |
209 | 122 | return True | 113 | return True |
210 | 123 | except: | 114 | except: |
211 | 124 | return False | 115 | return False |
212 | 125 | 116 | ||
213 | 126 | def _load_testament(self, testament): | 117 | def _load_testament(self, testament): |
214 | 127 | log.debug(u'load_testaments %s', testament) | 118 | log.debug(u'load_testaments %s', testament) |
217 | 128 | metadata.bind.echo = False | 119 | #metadata.bind.echo = False |
216 | 129 | session = self.session() | ||
218 | 130 | test = ONTestament() | 120 | test = ONTestament() |
219 | 131 | test.name = testament | 121 | test.name = testament |
222 | 132 | session.add(test) | 122 | self.session.add(test) |
223 | 133 | session.commit() | 123 | self.session.commit() |
224 | 134 | 124 | ||
225 | 135 | def get_bible_books(self): | 125 | def get_bible_books(self): |
227 | 136 | log.debug(u'get_bible_books ') | 126 | log.debug(u'get_bible_books') |
228 | 137 | return self.session.query(Book).order_by(Book.id).all() | 127 | return self.session.query(Book).order_by(Book.id).all() |
229 | 138 | 128 | ||
230 | 139 | def get_max_bible_book_verses(self, bookname, chapter): | 129 | def get_max_bible_book_verses(self, bookname, chapter): |
235 | 140 | log.debug(u'get_max_bible_book_verses %s,%s', bookname , chapter) | 130 | log.debug(u'get_max_bible_book_verses %s, %s', bookname, chapter) |
236 | 141 | metadata.bind.echo = False | 131 | #metadata.bind.echo = False |
237 | 142 | s = text (u'select max(verse.verse) from verse,book where chapter = :c and book_id = book.id and book.name = :b ') | 132 | #s = text (u'select max(verse.verse) from verse,book where chapter = :c and book_id = book.id and book.name = :b ') |
238 | 143 | return self.db.execute(s, c=chapter, b=bookname).fetchone() | 133 | #return self.db.execute(s, c=chapter, b=bookname).fetchone() |
239 | 134 | verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).filter(Verse.chapter==chapter).order_by(Verse.verse.desc()).first() | ||
240 | 135 | return verse.verse | ||
241 | 144 | 136 | ||
242 | 145 | def get_max_bible_book_chapter(self, bookname): | 137 | def get_max_bible_book_chapter(self, bookname): |
247 | 146 | log.debug(u'get_max_bible_book_chapter %s', bookname ) | 138 | log.debug(u'get_max_bible_book_chapter %s', bookname) |
248 | 147 | metadata.bind.echo = False | 139 | #metadata.bind.echo = False |
249 | 148 | s = text (u'select max(verse.chapter) from verse,book where book_id = book.id and book.name = :b') | 140 | #s = text (u'select max(verse.chapter) from verse,book where book_id = book.id and book.name = :b') |
250 | 149 | return self.db.execute(s, b=bookname).fetchone() | 141 | #return self.db.execute(s, b=bookname).fetchone() |
251 | 142 | verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).order_by(Verse.chapter.desc()).first() | ||
252 | 143 | return verse.chapter | ||
253 | 150 | 144 | ||
254 | 151 | def get_bible_book(self, bookname): | 145 | def get_bible_book(self, bookname): |
255 | 152 | log.debug(u'get_bible_book %s', bookname) | 146 | log.debug(u'get_bible_book %s', bookname) |
256 | 153 | bk = self.session.query(Book).filter(Book.name.like(bookname + u'%')).first() | 147 | bk = self.session.query(Book).filter(Book.name.like(bookname + u'%')).first() |
257 | 154 | if bk == None: | 148 | if bk == None: |
259 | 155 | bk = self.session.query(Book).filter(Book.abbreviation.like(bookname+u'%')).first() | 149 | bk = self.session.query(Book).filter(Book.abbreviation.like(bookname + u'%')).first() |
260 | 156 | return bk | 150 | return bk |
261 | 157 | 151 | ||
262 | 158 | def get_bible_chapter(self, id, chapter): | 152 | def get_bible_chapter(self, id, chapter): |
266 | 159 | log.debug(u'get_bible_chapter %s,%s', id, chapter ) | 153 | log.debug(u'get_bible_chapter %s, %s', id, chapter) |
267 | 160 | metadata.bind.echo = False | 154 | #metadata.bind.echo = False |
268 | 161 | return self.session.query(Verse).filter_by(chapter = chapter ).filter_by(book_id = id).first() | 155 | return self.session.query(Verse).filter_by(chapter=chapter).filter_by(book_id=id).first() |
269 | 162 | 156 | ||
270 | 163 | def get_bible_text(self, bookname, chapter, sverse, everse): | 157 | def get_bible_text(self, bookname, chapter, sverse, everse): |
276 | 164 | log.debug(u'get_bible_text %s,%s,%s,%s', bookname, chapter, sverse, everse) | 158 | log.debug(u'get_bible_text %s, %s, %s, %s', bookname, chapter, sverse, everse) |
277 | 165 | metadata.bind.echo = False | 159 | #metadata.bind.echo = False |
278 | 166 | bookname = bookname + u"%" | 160 | #bookname = bookname + u"%" |
279 | 167 | s = text (u'select name,chapter,verse.verse, verse.text FROM verse , book where verse.book_id == book.id AND verse.chapter == :c AND (verse.verse between :v1 and :v2) and (book.name like :b)') | 161 | #s = text (u'select name,chapter,verse.verse, verse.text FROM verse , book where verse.book_id == book.id AND verse.chapter == :c AND (verse.verse between :v1 and :v2) and (book.name like :b)') |
280 | 168 | return self.db.execute(s, c=chapter, v1=sverse , v2=everse, b=bookname).fetchall() | 162 | #return self.db.execute(s, c=chapter, v1=sverse , v2=everse, b=bookname).fetchall() |
281 | 163 | verses = self.session.query(Verse).join(Book).filter(Book.name==bookname).filter(Verse.chapter==chapter).filter(Verse.verse>=sverse).filter(Verse.verse<=everse).order_by(Verse.verse).all() | ||
282 | 164 | return verses | ||
283 | 169 | 165 | ||
285 | 170 | def get_verses_from_text(self,versetext): | 166 | def get_verses_from_text(self, versetext): |
286 | 171 | log.debug(u'get_verses_from_text %s',versetext) | 167 | log.debug(u'get_verses_from_text %s',versetext) |
291 | 172 | metadata.bind.echo = False | 168 | #metadata.bind.echo = False |
292 | 173 | versetext = "%"+versetext+"%" | 169 | versetext = u'%%%s%%' % versetext |
293 | 174 | s = text (u'select book.name, verse.chapter, verse.verse, verse.text FROM verse , book where verse.book_id == book.id and verse.text like :t') | 170 | #s = text (u'select book.name, verse.chapter, verse.verse, verse.text FROM verse , book where verse.book_id == book.id and verse.text like :t') |
294 | 175 | return self.db.execute(s, t=versetext).fetchall() | 171 | #return self.db.execute(s, t=versetext).fetchall() |
295 | 172 | verses = self.session.query(Verse).filter(Verse.text.like(versetext)).all() | ||
296 | 173 | return verses | ||
297 | 176 | 174 | ||
298 | 177 | def dump_bible(self): | 175 | def dump_bible(self): |
299 | 178 | log.debug( u'.........Dumping Bible Database') | 176 | log.debug( u'.........Dumping Bible Database') |
300 | 179 | log.debug( '...............................Books ') | 177 | log.debug( '...............................Books ') |
303 | 180 | s = text (u'select * FROM book ') | 178 | #s = text (u'select * FROM book ') |
304 | 181 | log.debug( self.db.execute(s).fetchall()) | 179 | books = self.session.query(Book).all() |
305 | 180 | log.debug(books) | ||
306 | 182 | log.debug( u'...............................Verses ') | 181 | log.debug( u'...............................Verses ') |
309 | 183 | s = text (u'select * FROM verse ') | 182 | #s = text (u'select * FROM verse ') |
310 | 184 | log.debug( self.db.execute(s).fetchall()) | 183 | verses = self.session.query(Verse).all() |
311 | 184 | log.debug(verses) | ||
312 | 185 | 185 | ||
313 | === modified file 'openlp/plugins/bibles/lib/bibleHTTPimpl.py' | |||
314 | --- openlp/plugins/bibles/lib/bibleHTTPimpl.py 2009-07-12 15:11:57 +0000 | |||
315 | +++ openlp/plugins/bibles/lib/bibleHTTPimpl.py 2009-07-13 20:11:36 +0000 | |||
316 | @@ -97,7 +97,7 @@ | |||
317 | 97 | """ | 97 | """ |
318 | 98 | log.debug(u'get_bible_chapter %s,%s,%s,%s', version, bookid, bookname, chapter) | 98 | log.debug(u'get_bible_chapter %s,%s,%s,%s', version, bookid, bookname, chapter) |
319 | 99 | bookname = bookname.replace(u' ', '') | 99 | bookname = bookname.replace(u' ', '') |
321 | 100 | urlstring = u'http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word='+bookname+u'+'+unicode(chapter)+u'&version='+version | 100 | urlstring = u'http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word=%s+%d&version=%s' % (bookname, chapter, version) |
322 | 101 | xml_string = self._get_web_text(urlstring, self.proxyurl) | 101 | xml_string = self._get_web_text(urlstring, self.proxyurl) |
323 | 102 | #log.debug(u'Return data %s', xml_string) | 102 | #log.debug(u'Return data %s', xml_string) |
324 | 103 | ## Strip Book Title from Heading to return it to system | 103 | ## Strip Book Title from Heading to return it to system |
325 | @@ -207,7 +207,7 @@ | |||
326 | 207 | ev = CWExtract(self.proxyurl) | 207 | ev = CWExtract(self.proxyurl) |
327 | 208 | else: | 208 | else: |
328 | 209 | ev = BGExtract(self.proxyurl) | 209 | ev = BGExtract(self.proxyurl) |
329 | 210 | |||
330 | 211 | return ev.get_bible_chapter(self.bibleid, bookid, bookname, chapter) | 210 | return ev.get_bible_chapter(self.bibleid, bookid, bookname, chapter) |
333 | 212 | except: | 211 | except Exception, e: |
334 | 213 | log.error(u'Error thrown = %s', sys.exc_info()[1]) | 212 | log.error(u'Error thrown = %s', e.args[0]) |
335 | 213 | print e | ||
336 | 214 | 214 | ||
337 | === modified file 'openlp/plugins/bibles/lib/bibleOSISimpl.py' | |||
338 | --- openlp/plugins/bibles/lib/bibleOSISimpl.py 2009-07-10 15:41:08 +0000 | |||
339 | +++ openlp/plugins/bibles/lib/bibleOSISimpl.py 2009-07-13 20:08:43 +0000 | |||
340 | @@ -1,6 +1,8 @@ | |||
341 | 1 | """ | 1 | """ |
342 | 2 | OpenLP - Open Source Lyrics Projection | 2 | OpenLP - Open Source Lyrics Projection |
343 | 3 | |||
344 | 3 | Copyright (c) 2008 Raoul Snyman | 4 | Copyright (c) 2008 Raoul Snyman |
345 | 5 | |||
346 | 4 | Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley | 6 | Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley |
347 | 5 | 7 | ||
348 | 6 | This program is free software; you can redistribute it and/or modify it under | 8 | This program is free software; you can redistribute it and/or modify it under |
349 | @@ -20,37 +22,69 @@ | |||
350 | 20 | import logging | 22 | import logging |
351 | 21 | import chardet | 23 | import chardet |
352 | 22 | import codecs | 24 | import codecs |
353 | 25 | |||
354 | 26 | from PyQt4 import QtCore | ||
355 | 27 | |||
356 | 23 | from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl | 28 | from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl |
357 | 24 | from openlp.core.lib import Receiver | 29 | from openlp.core.lib import Receiver |
358 | 25 | from PyQt4 import QtCore | ||
359 | 26 | 30 | ||
360 | 27 | class BibleOSISImpl(): | 31 | class BibleOSISImpl(): |
361 | 32 | """ | ||
362 | 33 | OSIS Bible format importer class. | ||
363 | 34 | """ | ||
364 | 28 | global log | 35 | global log |
365 | 29 | log = logging.getLogger(u'BibleOSISImpl') | 36 | log = logging.getLogger(u'BibleOSISImpl') |
366 | 30 | log.info(u'BibleOSISImpl loaded') | 37 | log.info(u'BibleOSISImpl loaded') |
367 | 31 | 38 | ||
368 | 32 | def __init__(self, biblepath, bibledb): | 39 | def __init__(self, biblepath, bibledb): |
369 | 40 | """ | ||
370 | 41 | Constructor to create and set up an instance of the | ||
371 | 42 | BibleOSISImpl class. | ||
372 | 43 | |||
373 | 44 | ``biblepath`` | ||
374 | 45 | This does not seem to be used. | ||
375 | 46 | |||
376 | 47 | ``bibledb`` | ||
377 | 48 | A reference to a Bible database object. | ||
378 | 49 | """ | ||
379 | 33 | self.bibledb = bibledb | 50 | self.bibledb = bibledb |
380 | 34 | # books of the bible linked to bibleid {osis , name} | 51 | # books of the bible linked to bibleid {osis , name} |
381 | 35 | self.booksOfBible = {} | 52 | self.booksOfBible = {} |
382 | 36 | # books of the bible linked to bibleid {osis ,Abbrev } | 53 | # books of the bible linked to bibleid {osis ,Abbrev } |
383 | 37 | self.abbrevOfBible = {} | 54 | self.abbrevOfBible = {} |
384 | 38 | |||
385 | 39 | filepath = os.path.split(os.path.abspath(__file__))[0] | 55 | filepath = os.path.split(os.path.abspath(__file__))[0] |
387 | 40 | filepath = os.path.abspath(os.path.join(filepath, u'..', u'resources',u'osisbooks.csv')) | 56 | filepath = os.path.abspath(os.path.join( |
388 | 57 | filepath, u'..', u'resources',u'osisbooks.csv')) | ||
389 | 41 | fbibles=open(filepath, u'r') | 58 | fbibles=open(filepath, u'r') |
390 | 42 | for line in fbibles: | 59 | for line in fbibles: |
391 | 43 | p = line.split(u',') | 60 | p = line.split(u',') |
392 | 44 | self.booksOfBible[p[0]] = p[1].replace(u'\n', u'') | 61 | self.booksOfBible[p[0]] = p[1].replace(u'\n', u'') |
393 | 45 | self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'') | 62 | self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'') |
394 | 46 | self.loadbible = True | 63 | self.loadbible = True |
396 | 47 | QtCore.QObject.connect(Receiver().get_receiver(),QtCore.SIGNAL(u'openlpstopimport'),self.stop_import) | 64 | QtCore.QObject.connect(Receiver().get_receiver(), |
397 | 65 | QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) | ||
398 | 48 | 66 | ||
399 | 49 | def stop_import(self): | 67 | def stop_import(self): |
400 | 68 | """ | ||
401 | 69 | Stops the import of the Bible. | ||
402 | 70 | """ | ||
403 | 50 | self.loadbible = False | 71 | self.loadbible = False |
404 | 51 | 72 | ||
405 | 52 | def load_data(self, osisfile_record, dialogobject=None): | 73 | def load_data(self, osisfile_record, dialogobject=None): |
407 | 53 | osis = codecs.open(osisfile_record, u'r') | 74 | """ |
408 | 75 | Loads a Bible from file. | ||
409 | 76 | |||
410 | 77 | ``osisfile_record`` | ||
411 | 78 | The file to import from. | ||
412 | 79 | |||
413 | 80 | ``dialogobject`` | ||
414 | 81 | The Import dialog, so that we can increase the counter on | ||
415 | 82 | the progress bar. | ||
416 | 83 | """ | ||
417 | 84 | detect_file = open(osisfile_record, u'r') | ||
418 | 85 | details = chardet.detect(detect_file.read(2048)) | ||
419 | 86 | detect_file.close() | ||
420 | 87 | osis = codecs.open(osisfile_record, u'r', details['encoding']) | ||
421 | 54 | book_ptr = None | 88 | book_ptr = None |
422 | 55 | id = 0 | 89 | id = 0 |
423 | 56 | count = 0 | 90 | count = 0 |
424 | @@ -110,8 +144,11 @@ | |||
425 | 110 | if p[0] == u'Matt': | 144 | if p[0] == u'Matt': |
426 | 111 | testament += 1 | 145 | testament += 1 |
427 | 112 | book_ptr = p[0] | 146 | book_ptr = p[0] |
430 | 113 | book = self.bibledb.create_book(self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]], testament) | 147 | book = self.bibledb.create_book( |
431 | 114 | dialogobject.incrementProgressBar(self.booksOfBible[p[0]] ) | 148 | self.booksOfBible[p[0]], |
432 | 149 | self.abbrevOfBible[p[0]], testament) | ||
433 | 150 | dialogobject.incrementProgressBar( | ||
434 | 151 | self.booksOfBible[p[0]]) | ||
435 | 115 | Receiver().send_message(u'openlpprocessevents') | 152 | Receiver().send_message(u'openlpprocessevents') |
436 | 116 | count = 0 | 153 | count = 0 |
437 | 117 | self.bibledb.add_verse(book.id, p[1], p[2], text) | 154 | self.bibledb.add_verse(book.id, p[1], p[2], text) |
438 | @@ -121,10 +158,20 @@ | |||
439 | 121 | Receiver().send_message(u'openlpprocessevents') | 158 | Receiver().send_message(u'openlpprocessevents') |
440 | 122 | count = 0 | 159 | count = 0 |
441 | 123 | 160 | ||
443 | 124 | def remove_block(self, start_tag, end_tag, text): | 161 | def remove_block(self, start_tag, end_tag, text): |
444 | 125 | """ | 162 | """ |
447 | 126 | removes a block of text between two tags | 163 | Removes a block of text between two tags:: |
448 | 127 | <tag attrib=xvf > Some not wanted text </tag> | 164 | |
449 | 165 | <tag attrib="xvf">Some not wanted text</tag> | ||
450 | 166 | |||
451 | 167 | ``start_tag`` | ||
452 | 168 | The XML tag to look for. | ||
453 | 169 | |||
454 | 170 | ``end_tag`` | ||
455 | 171 | The ending XML tag. | ||
456 | 172 | |||
457 | 173 | ``text`` | ||
458 | 174 | The string of XML to search. | ||
459 | 128 | """ | 175 | """ |
460 | 129 | pos = text.find(start_tag) | 176 | pos = text.find(start_tag) |
461 | 130 | while pos > -1: | 177 | while pos > -1: |
462 | @@ -136,10 +183,17 @@ | |||
463 | 136 | pos = text.find(start_tag) | 183 | pos = text.find(start_tag) |
464 | 137 | return text | 184 | return text |
465 | 138 | 185 | ||
467 | 139 | def remove_tag(self, start_tag, text): | 186 | def remove_tag(self, start_tag, text): |
468 | 140 | """ | 187 | """ |
471 | 141 | removes a single tag | 188 | Removes a single tag:: |
472 | 142 | <tag attrib1=fajkdf attrib2=fajkdf attrib2=fajkdf /> | 189 | |
473 | 190 | <tag attrib1="fajkdf" attrib2="fajkdf" attrib3="fajkdf" /> | ||
474 | 191 | |||
475 | 192 | ``start_tag`` | ||
476 | 193 | The XML tag to remove. | ||
477 | 194 | |||
478 | 195 | ``text`` | ||
479 | 196 | The string of XML to search. | ||
480 | 143 | """ | 197 | """ |
481 | 144 | pos = text.find(start_tag) | 198 | pos = text.find(start_tag) |
482 | 145 | while pos > -1: | 199 | while pos > -1: |
483 | 146 | 200 | ||
484 | === removed file 'openlp/plugins/bibles/lib/classes.py' | |||
485 | --- openlp/plugins/bibles/lib/classes.py 2009-02-22 07:44:08 +0000 | |||
486 | +++ openlp/plugins/bibles/lib/classes.py 1970-01-01 00:00:00 +0000 | |||
487 | @@ -1,67 +0,0 @@ | |||
488 | 1 | # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 | ||
489 | 2 | """ | ||
490 | 3 | OpenLP - Open Source Lyrics Projection | ||
491 | 4 | Copyright (c) 2008 Raoul Snyman | ||
492 | 5 | Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley | ||
493 | 6 | |||
494 | 7 | This program is free software; you can redistribute it and/or modify it under | ||
495 | 8 | the terms of the GNU General Public License as published by the Free Software | ||
496 | 9 | Foundation; version 2 of the License. | ||
497 | 10 | |||
498 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
499 | 12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
500 | 13 | PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
501 | 14 | |||
502 | 15 | You should have received a copy of the GNU General Public License along with | ||
503 | 16 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
504 | 17 | Place, Suite 330, Boston, MA 02111-1307 USA | ||
505 | 18 | """ | ||
506 | 19 | from sqlalchemy.orm import mapper, relation | ||
507 | 20 | from openlp.plugins.bibles.lib.tables import * | ||
508 | 21 | |||
509 | 22 | class BaseModel(object): | ||
510 | 23 | """ | ||
511 | 24 | BaseModel provides a base object with a set of generic functions | ||
512 | 25 | """ | ||
513 | 26 | |||
514 | 27 | @classmethod | ||
515 | 28 | def populate(cls, **kwargs): | ||
516 | 29 | """ | ||
517 | 30 | Creates an instance of a class and populates it, returning the instance | ||
518 | 31 | """ | ||
519 | 32 | me = cls() | ||
520 | 33 | keys = kwargs.keys() | ||
521 | 34 | for key in keys: | ||
522 | 35 | me.__setattr__(key, kwargs[key]) | ||
523 | 36 | return me | ||
524 | 37 | |||
525 | 38 | class BibleMeta(BaseModel): | ||
526 | 39 | """ | ||
527 | 40 | Bible Meta Data | ||
528 | 41 | """ | ||
529 | 42 | pass | ||
530 | 43 | |||
531 | 44 | class ONTestament(BaseModel): | ||
532 | 45 | """ | ||
533 | 46 | Bible Testaments | ||
534 | 47 | """ | ||
535 | 48 | pass | ||
536 | 49 | |||
537 | 50 | class Book(BaseModel): | ||
538 | 51 | """ | ||
539 | 52 | Song model | ||
540 | 53 | """ | ||
541 | 54 | pass | ||
542 | 55 | |||
543 | 56 | class Verse(BaseModel): | ||
544 | 57 | """ | ||
545 | 58 | Topic model | ||
546 | 59 | """ | ||
547 | 60 | pass | ||
548 | 61 | |||
549 | 62 | mapper(BibleMeta, meta_table) | ||
550 | 63 | mapper(ONTestament, testament_table, | ||
551 | 64 | properties={'books': relation(Book, backref='testament')}) | ||
552 | 65 | mapper(Book, book_table, | ||
553 | 66 | properties={'verses': relation(Verse, backref='book')}) | ||
554 | 67 | mapper(Verse, verse_table) | ||
555 | 68 | 0 | ||
556 | === modified file 'openlp/plugins/bibles/lib/manager.py' | |||
557 | --- openlp/plugins/bibles/lib/manager.py 2009-07-09 05:15:26 +0000 | |||
558 | +++ openlp/plugins/bibles/lib/manager.py 2009-07-13 20:08:43 +0000 | |||
559 | @@ -2,7 +2,9 @@ | |||
560 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 |
561 | 3 | """ | 3 | """ |
562 | 4 | OpenLP - Open Source Lyrics Projection | 4 | OpenLP - Open Source Lyrics Projection |
563 | 5 | |||
564 | 5 | Copyright (c) 2008 Raoul Snyman | 6 | Copyright (c) 2008 Raoul Snyman |
565 | 7 | |||
566 | 6 | Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley | 8 | Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley |
567 | 7 | 9 | ||
568 | 8 | This program is free software; you can redistribute it and/or modify it under | 10 | This program is free software; you can redistribute it and/or modify it under |
569 | @@ -18,7 +20,7 @@ | |||
570 | 18 | Place, Suite 330, Boston, MA 02111-1307 USA | 20 | Place, Suite 330, Boston, MA 02111-1307 USA |
571 | 19 | """ | 21 | """ |
572 | 20 | import logging | 22 | import logging |
574 | 21 | import os, os.path | 23 | import os |
575 | 22 | import sys | 24 | import sys |
576 | 23 | 25 | ||
577 | 24 | from common import SearchResults | 26 | from common import SearchResults |
578 | @@ -26,72 +28,93 @@ | |||
579 | 26 | from bibleCSVimpl import BibleCSVImpl | 28 | from bibleCSVimpl import BibleCSVImpl |
580 | 27 | from bibleDBimpl import BibleDBImpl | 29 | from bibleDBimpl import BibleDBImpl |
581 | 28 | from bibleHTTPimpl import BibleHTTPImpl | 30 | from bibleHTTPimpl import BibleHTTPImpl |
582 | 31 | |||
583 | 29 | from openlp.plugins.bibles.lib.tables import * | 32 | from openlp.plugins.bibles.lib.tables import * |
584 | 30 | from openlp.plugins.bibles.lib.classes import * | 33 | from openlp.plugins.bibles.lib.classes import * |
585 | 31 | 34 | ||
587 | 32 | class BibleManager(): | 35 | class BibleMode(object): |
588 | 36 | Full = 1 | ||
589 | 37 | Partial = 2 | ||
590 | 38 | |||
591 | 39 | class BibleManager(object): | ||
592 | 40 | """ | ||
593 | 41 | The Bible manager which holds and manages all the Bibles. | ||
594 | 42 | """ | ||
595 | 33 | global log | 43 | global log |
596 | 34 | log=logging.getLogger(u'BibleManager') | 44 | log=logging.getLogger(u'BibleManager') |
597 | 35 | log.info(u'Bible manager loaded') | 45 | log.info(u'Bible manager loaded') |
598 | 46 | |||
599 | 36 | def __init__(self, config): | 47 | def __init__(self, config): |
600 | 37 | """ | 48 | """ |
604 | 38 | Finds all the bibles defined for the system | 49 | Finds all the bibles defined for the system and creates an |
605 | 39 | Creates an Interface Object for each bible containing connection information | 50 | interface object for each bible containing connection |
606 | 40 | Throws Exception if no Bibles are found. | 51 | information. Throws Exception if no Bibles are found. |
607 | 41 | 52 | ||
608 | 42 | Init confirms the bible exists and stores the database path. | 53 | Init confirms the bible exists and stores the database path. |
609 | 54 | |||
610 | 55 | ``config`` | ||
611 | 56 | The plugin's configuration object. | ||
612 | 43 | """ | 57 | """ |
613 | 44 | self.config = config | 58 | self.config = config |
614 | 45 | log.debug(u'Bible Initialising') | 59 | log.debug(u'Bible Initialising') |
617 | 46 | self.bible_db_cache = None # dict of bible database classes | 60 | # dict of bible database objects |
618 | 47 | self.bible_http_cache = None # dict of bible http readers | 61 | self.bible_db_cache = None |
619 | 62 | # dict of bible http readers | ||
620 | 63 | self.bible_http_cache = None | ||
621 | 48 | self.biblePath = self.config.get_data_path() | 64 | self.biblePath = self.config.get_data_path() |
623 | 49 | self.proxyname = self.config.get_config(u'proxy name') #get proxy name for screen | 65 | #get proxy name for screen |
624 | 66 | self.proxyname = self.config.get_config(u'proxy name') | ||
625 | 50 | self.bibleSuffix = u'sqlite' | 67 | self.bibleSuffix = u'sqlite' |
626 | 51 | self.dialogobject = None | 68 | self.dialogobject = None |
627 | 52 | self.reload_bibles() | 69 | self.reload_bibles() |
628 | 53 | 70 | ||
629 | 54 | def reload_bibles(self): | 71 | def reload_bibles(self): |
630 | 55 | log.debug(u'Reload bibles') | 72 | log.debug(u'Reload bibles') |
631 | 56 | |||
632 | 57 | files = self.config.get_files(self.bibleSuffix) | 73 | files = self.config.get_files(self.bibleSuffix) |
633 | 58 | log.debug(u'Bible Files %s', files ) | 74 | log.debug(u'Bible Files %s', files ) |
634 | 59 | |||
635 | 60 | self.bible_db_cache = {} | 75 | self.bible_db_cache = {} |
636 | 61 | self.bible_http_cache = {} | 76 | self.bible_http_cache = {} |
640 | 62 | 77 | # books of the bible with testaments | |
641 | 63 | self.book_testaments = {} # books of the bible with testaments | 78 | self.book_testaments = {} |
642 | 64 | self.book_abbreviations = {} # books of the bible with abbreviation | 79 | # books of the bible with abbreviation |
643 | 80 | self.book_abbreviations = {} | ||
644 | 65 | self.web_bibles_present = False | 81 | self.web_bibles_present = False |
645 | 66 | |||
646 | 67 | |||
647 | 68 | for f in files: | 82 | for f in files: |
648 | 69 | nme = f.split(u'.') | 83 | nme = f.split(u'.') |
649 | 70 | bname = nme[0] | 84 | bname = nme[0] |
652 | 71 | self.bible_db_cache[bname] = BibleDBImpl(self.biblePath, bname, self.config) | 85 | self.bible_db_cache[bname] = BibleDBImpl(self.biblePath, |
653 | 72 | biblesource = self.bible_db_cache[bname].get_meta(u'WEB') # look to see if lazy load bible exists and get create getter. | 86 | bname, self.config) |
654 | 87 | # look to see if lazy load bible exists and get create getter. | ||
655 | 88 | biblesource = self.bible_db_cache[bname].get_meta(u'WEB') | ||
656 | 73 | if biblesource: | 89 | if biblesource: |
657 | 74 | self.web_bibles_present = True | 90 | self.web_bibles_present = True |
658 | 75 | nhttp = BibleHTTPImpl() | 91 | nhttp = BibleHTTPImpl() |
660 | 76 | nhttp.set_bible_source(biblesource.value) # tell The Server where to get the verses from. | 92 | # tell The Server where to get the verses from. |
661 | 93 | nhttp.set_bible_source(biblesource.value) | ||
662 | 77 | self.bible_http_cache [bname] = nhttp | 94 | self.bible_http_cache [bname] = nhttp |
664 | 78 | meta = self.bible_db_cache[bname].get_meta(u'proxy') # look to see if lazy load bible exists and get create getter. | 95 | # look to see if lazy load bible exists and get create getter. |
665 | 96 | meta = self.bible_db_cache[bname].get_meta(u'proxy') | ||
666 | 79 | proxy = None | 97 | proxy = None |
667 | 80 | if meta != None: | 98 | if meta != None: |
668 | 81 | proxy = meta.value | 99 | proxy = meta.value |
672 | 82 | nhttp.set_proxy(proxy) # tell The Server where to get the verses from. | 100 | # tell The Server where to get the verses from. |
673 | 83 | bibleid = self.bible_db_cache[bname].get_meta(u'bibleid').value # look to see if lazy load bible exists and get create getter. | 101 | nhttp.set_proxy(proxy) |
674 | 84 | nhttp.set_bibleid(bibleid) # tell The Server where to get the verses from. | 102 | # look to see if lazy load bible exists and get create getter. |
675 | 103 | bibleid = self.bible_db_cache[bname].get_meta(u'bibleid').value | ||
676 | 104 | # tell The Server where to get the verses from. | ||
677 | 105 | nhttp.set_bibleid(bibleid) | ||
678 | 85 | else: | 106 | else: |
681 | 86 | self.bible_http_cache [bname] = None # makes the Full / partial code easier. | 107 | # makes the Full / partial code easier. |
682 | 87 | 108 | self.bible_http_cache [bname] = None | |
683 | 88 | if self.web_bibles_present: | 109 | if self.web_bibles_present: |
687 | 89 | self.book_testaments = {} # books of the bible linked to bibleid {osis , name} | 110 | # books of the bible linked to bibleid {osis, name} |
688 | 90 | self.book_abbreviations = {} # books of the bible linked to bibleid {osis ,Abbrev } | 111 | self.book_testaments = {} |
689 | 91 | 112 | # books of the bible linked to bibleid {osis, abbrev} | |
690 | 113 | self.book_abbreviations = {} | ||
691 | 92 | filepath = os.path.split(os.path.abspath(__file__))[0] | 114 | filepath = os.path.split(os.path.abspath(__file__))[0] |
694 | 93 | filepath = os.path.abspath(os.path.join(filepath, u'..', u'resources',u'httpbooks.csv')) | 115 | filepath = os.path.abspath(os.path.join( |
695 | 94 | fbibles=open(filepath, 'r') | 116 | filepath, u'..', u'resources',u'httpbooks.csv')) |
696 | 117 | fbibles = open(filepath, u'r') | ||
697 | 95 | for line in fbibles: | 118 | for line in fbibles: |
698 | 96 | p = line.split(u',') | 119 | p = line.split(u',') |
699 | 97 | self.book_abbreviations[p[0]] = p[1].replace(u'\n', '') | 120 | self.book_abbreviations[p[0]] = p[1].replace(u'\n', '') |
700 | @@ -99,31 +122,64 @@ | |||
701 | 99 | log.debug(u'Bible Initialised') | 122 | log.debug(u'Bible Initialised') |
702 | 100 | 123 | ||
703 | 101 | def process_dialog(self, dialogobject): | 124 | def process_dialog(self, dialogobject): |
704 | 125 | """ | ||
705 | 126 | Sets the reference to the dialog with the progress bar on it. | ||
706 | 127 | |||
707 | 128 | ``dialogobject`` | ||
708 | 129 | The reference to the dialog. | ||
709 | 130 | """ | ||
710 | 102 | self.dialogobject = dialogobject | 131 | self.dialogobject = dialogobject |
711 | 103 | 132 | ||
718 | 104 | def register_http_bible(self, biblename, biblesource, bibleid, proxyurl=None, proxyid=None, proxypass=None): | 133 | def register_http_bible(self, biblename, biblesource, bibleid, |
719 | 105 | """ | 134 | proxyurl=None, proxyid=None, proxypass=None): |
720 | 106 | Return a list of bibles from a given URL. | 135 | """ |
721 | 107 | The selected Bible can then be registered and LazyLoaded into a database | 136 | Return a list of bibles from a given URL. The selected Bible |
722 | 108 | """ | 137 | can then be registered and LazyLoaded into a database. |
723 | 109 | log.debug(u'register_HTTP_bible %s,%s,%s,%s,%s,%s', biblename, biblesource, bibleid, proxyurl, proxyid, proxypass) | 138 | |
724 | 139 | ``biblename`` | ||
725 | 140 | The name of the bible to register. | ||
726 | 141 | |||
727 | 142 | ``biblesource`` | ||
728 | 143 | Where this Bible stores it's verses. | ||
729 | 144 | |||
730 | 145 | ``bibleid`` | ||
731 | 146 | The identifier for a Bible. | ||
732 | 147 | |||
733 | 148 | ``proxyurl`` | ||
734 | 149 | Defaults to *None*. An optional URL to a proxy server. | ||
735 | 150 | |||
736 | 151 | ``proxyid`` | ||
737 | 152 | Defaults to *None*. A username for logging into the proxy | ||
738 | 153 | server. | ||
739 | 154 | |||
740 | 155 | ``proxypass`` | ||
741 | 156 | Defaults to *None*. The password to accompany the username. | ||
742 | 157 | """ | ||
743 | 158 | log.debug(u'register_HTTP_bible %s, %s, %s, %s, %s, %s', | ||
744 | 159 | biblename, biblesource, bibleid, proxyurl, proxyid, proxypass) | ||
745 | 110 | if self._is_new_bible(biblename): | 160 | if self._is_new_bible(biblename): |
748 | 111 | nbible = BibleDBImpl(self.biblePath, biblename, self.config) # Create new Bible | 161 | # Create new Bible |
749 | 112 | nbible.create_tables() # Create Database | 162 | nbible = BibleDBImpl(self.biblePath, biblename, self.config) |
750 | 163 | # Create Database | ||
751 | 164 | nbible.create_tables() | ||
752 | 113 | self.bible_db_cache[biblename] = nbible | 165 | self.bible_db_cache[biblename] = nbible |
753 | 114 | |||
754 | 115 | nhttp = BibleHTTPImpl() | 166 | nhttp = BibleHTTPImpl() |
755 | 116 | nhttp.set_bible_source(biblesource) | 167 | nhttp.set_bible_source(biblesource) |
756 | 117 | self.bible_http_cache [biblename] = nhttp | 168 | self.bible_http_cache [biblename] = nhttp |
759 | 118 | nbible.save_meta(u'WEB', biblesource) # register a lazy loading interest | 169 | # register a lazy loading interest |
760 | 119 | nbible.save_meta(u'bibleid', bibleid) # store the we id of the bible | 170 | nbible.save_meta(u'WEB', biblesource) |
761 | 171 | # store the web id of the bible | ||
762 | 172 | nbible.save_meta(u'bibleid', bibleid) | ||
763 | 120 | if proxyurl != None and proxyurl != "": | 173 | if proxyurl != None and proxyurl != "": |
765 | 121 | nbible.save_meta(u'proxy', proxyurl) # store the proxy URL | 174 | # store the proxy URL |
766 | 175 | nbible.save_meta(u'proxy', proxyurl) | ||
767 | 122 | nhttp.set_proxy(proxyurl) | 176 | nhttp.set_proxy(proxyurl) |
768 | 123 | if proxyid != None and proxyid != "": | 177 | if proxyid != None and proxyid != "": |
770 | 124 | nbible.save_meta(u'proxyid', proxyid) # store the proxy userid | 178 | # store the proxy userid |
771 | 179 | nbible.save_meta(u'proxyid', proxyid) | ||
772 | 125 | if proxypass != None and proxypass != "": | 180 | if proxypass != None and proxypass != "": |
774 | 126 | nbible.save_meta(u'proxypass', proxypass) # store the proxy password | 181 | # store the proxy password |
775 | 182 | nbible.save_meta(u'proxypass', proxypass) | ||
776 | 127 | return True | 183 | return True |
777 | 128 | else: | 184 | else: |
778 | 129 | log.debug(u'register_http_file_bible %s not created already exists', biblename) | 185 | log.debug(u'register_http_file_bible %s not created already exists', biblename) |
779 | @@ -165,21 +221,26 @@ | |||
780 | 165 | log.debug(u'register_OSIS_file_bible %s , %s not created already exists', biblename, osisfile) | 221 | log.debug(u'register_OSIS_file_bible %s , %s not created already exists', biblename, osisfile) |
781 | 166 | return False | 222 | return False |
782 | 167 | 223 | ||
784 | 168 | def get_bibles(self, mode=u'full'): | 224 | def get_bibles(self, mode=BibleMode.Full): |
785 | 225 | """ | ||
786 | 226 | Returns a list of Books of the bible. When ``mode`` is set to | ||
787 | 227 | ``BibleMode.Full`` this method returns all the Bibles for the | ||
788 | 228 | Advanced Search, and when the mode is ``BibleMode.Partial`` | ||
789 | 229 | this method returns all the bibles for the Quick Search. | ||
790 | 230 | |||
791 | 231 | ``mode`` | ||
792 | 232 | Defaults to ``BibleMode.Full``. The Bible mode. | ||
793 | 233 | """ | ||
794 | 169 | log.debug(u'get_bibles') | 234 | log.debug(u'get_bibles') |
804 | 170 | """ | 235 | bible_list = [] |
805 | 171 | Returns a list of Books of the bible | 236 | for bible_name, bible_object in self.bible_db_cache.iteritems(): |
806 | 172 | Mode "Full" - Returns all the bibles for the Queck seearch | 237 | if mode == BibleMode.Full: |
807 | 173 | Mode "Partial" - Returns CSV and OSIS bbles for the Advanced Search | 238 | bible_list.append(bible_name) |
799 | 174 | """ | ||
800 | 175 | r=[] | ||
801 | 176 | for b , o in self.bible_db_cache.iteritems(): | ||
802 | 177 | if mode == u'full': | ||
803 | 178 | r.append(b) | ||
808 | 179 | else: | 239 | else: |
812 | 180 | if self.bible_http_cache [b] == None: # we do not have an http bible | 240 | if self.bible_http_cache[bible_name] is None: |
813 | 181 | r.append(b) | 241 | # we do not have an http bible |
814 | 182 | return r | 242 | bible_list.append(bible_name) |
815 | 243 | return bible_list | ||
816 | 183 | 244 | ||
817 | 184 | def get_bible_books(self,bible): | 245 | def get_bible_books(self,bible): |
818 | 185 | """ | 246 | """ |
819 | @@ -192,7 +253,7 @@ | |||
820 | 192 | """ | 253 | """ |
821 | 193 | Returns the number of Chapters for a given book | 254 | Returns the number of Chapters for a given book |
822 | 194 | """ | 255 | """ |
824 | 195 | log.debug(u'get_book_chapter_count %s,%s', bible, book) | 256 | log.debug(u'get_book_chapter_count %s, %s', bible, book) |
825 | 196 | return self.bible_db_cache[bible].get_max_bible_book_chapter(book) | 257 | return self.bible_db_cache[bible].get_max_bible_book_chapter(book) |
826 | 197 | 258 | ||
827 | 198 | def get_book_verse_count(self, bible, book, chapter): | 259 | def get_book_verse_count(self, bible, book, chapter): |
828 | @@ -227,7 +288,7 @@ | |||
829 | 227 | log.debug(u'get_meta %s,%s', bible, key) | 288 | log.debug(u'get_meta %s,%s', bible, key) |
830 | 228 | return self.bible_db_cache[bible].get_meta(key) | 289 | return self.bible_db_cache[bible].get_meta(key) |
831 | 229 | 290 | ||
833 | 230 | def get_verse_text(self, bible, bookname, schapter, echapter, sverse, everse = 0 ): | 291 | def get_verse_text(self, bible, bookname, schapter, echapter, sverse, everse=0): |
834 | 231 | """ | 292 | """ |
835 | 232 | Returns a list of verses for a given Book, Chapter and ranges of verses. | 293 | Returns a list of verses for a given Book, Chapter and ranges of verses. |
836 | 233 | If the end verse(everse) is less then the start verse(sverse) | 294 | If the end verse(everse) is less then the start verse(sverse) |
837 | @@ -237,7 +298,7 @@ | |||
838 | 237 | """ | 298 | """ |
839 | 238 | text = [] | 299 | text = [] |
840 | 239 | log.debug(u'get_verse_text %s,%s,%s,%s,%s,%s', bible, bookname, schapter, echapter, sverse, everse) | 300 | log.debug(u'get_verse_text %s,%s,%s,%s,%s,%s', bible, bookname, schapter, echapter, sverse, everse) |
842 | 240 | if not self.bible_http_cache [bible] == None: | 301 | if not self.bible_http_cache[bible] == None: |
843 | 241 | # check to see if book/chapter exists | 302 | # check to see if book/chapter exists |
844 | 242 | book= self.bible_db_cache[bible].get_bible_book(bookname) | 303 | book= self.bible_db_cache[bible].get_bible_book(bookname) |
845 | 243 | if book == None: | 304 | if book == None: |
846 | 244 | 305 | ||
847 | === modified file 'openlp/plugins/bibles/lib/mediaitem.py' | |||
848 | --- openlp/plugins/bibles/lib/mediaitem.py 2009-07-13 17:02:38 +0000 | |||
849 | +++ openlp/plugins/bibles/lib/mediaitem.py 2009-07-13 20:11:36 +0000 | |||
850 | @@ -2,7 +2,9 @@ | |||
851 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 |
852 | 3 | """ | 3 | """ |
853 | 4 | OpenLP - Open Source Lyrics Projection | 4 | OpenLP - Open Source Lyrics Projection |
854 | 5 | |||
855 | 5 | Copyright (c) 2008 Raoul Snyman | 6 | Copyright (c) 2008 Raoul Snyman |
856 | 7 | |||
857 | 6 | Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley | 8 | Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley |
858 | 7 | 9 | ||
859 | 8 | This program is free software; you can redistribute it and/or modify it under | 10 | This program is free software; you can redistribute it and/or modify it under |
860 | @@ -21,8 +23,10 @@ | |||
861 | 21 | 23 | ||
862 | 22 | from PyQt4 import QtCore, QtGui | 24 | from PyQt4 import QtCore, QtGui |
863 | 23 | 25 | ||
865 | 24 | from openlp.core.lib import ServiceItem, MediaManagerItem, Receiver, translate, contextMenuAction, contextMenuSeparator | 26 | from openlp.core.lib import translate, ServiceItem, MediaManagerItem, \ |
866 | 27 | Receiver, contextMenuAction, contextMenuSeparator | ||
867 | 25 | from openlp.plugins.bibles.forms import BibleImportForm | 28 | from openlp.plugins.bibles.forms import BibleImportForm |
868 | 29 | from openlp.plugins.bibles.lib.manager import BibleMode | ||
869 | 26 | 30 | ||
870 | 27 | class BibleList(QtGui.QListWidget): | 31 | class BibleList(QtGui.QListWidget): |
871 | 28 | 32 | ||
872 | @@ -255,12 +259,12 @@ | |||
873 | 255 | log.debug(u'Loading Bibles') | 259 | log.debug(u'Loading Bibles') |
874 | 256 | self.QuickVersionComboBox.clear() | 260 | self.QuickVersionComboBox.clear() |
875 | 257 | self.AdvancedVersionComboBox.clear() | 261 | self.AdvancedVersionComboBox.clear() |
877 | 258 | bibles = self.parent.biblemanager.get_bibles(u'full') | 262 | bibles = self.parent.biblemanager.get_bibles(BibleMode.Full) |
878 | 259 | # load bibles into the combo boxes | 263 | # load bibles into the combo boxes |
879 | 260 | for bible in bibles: | 264 | for bible in bibles: |
880 | 261 | self.QuickVersionComboBox.addItem(bible) | 265 | self.QuickVersionComboBox.addItem(bible) |
883 | 262 | # Without HTT | 266 | # Without HTTP |
884 | 263 | bibles = self.parent.biblemanager.get_bibles(u'partial') | 267 | bibles = self.parent.biblemanager.get_bibles(BibleMode.Partial) |
885 | 264 | first = True | 268 | first = True |
886 | 265 | # load bibles into the combo boxes | 269 | # load bibles into the combo boxes |
887 | 266 | for bible in bibles: | 270 | for bible in bibles: |
888 | @@ -287,8 +291,8 @@ | |||
889 | 287 | self.adjustComboBox(frm, self.verses, self.AdvancedToVerse) | 291 | self.adjustComboBox(frm, self.verses, self.AdvancedToVerse) |
890 | 288 | 292 | ||
891 | 289 | def onAdvancedToChapter(self): | 293 | def onAdvancedToChapter(self): |
894 | 290 | t1 = self.AdvancedFromChapter.currentText() | 294 | t1 = self.AdvancedFromChapter.currentText() |
895 | 291 | t2 = self.AdvancedToChapter.currentText() | 295 | t2 = self.AdvancedToChapter.currentText() |
896 | 292 | if t1 != t2: | 296 | if t1 != t2: |
897 | 293 | bible = unicode(self.AdvancedVersionComboBox.currentText()) | 297 | bible = unicode(self.AdvancedVersionComboBox.currentText()) |
898 | 294 | book = unicode(self.AdvancedBookComboBox.currentText()) | 298 | book = unicode(self.AdvancedBookComboBox.currentText()) |
899 | @@ -344,12 +348,12 @@ | |||
900 | 344 | bitem = self.ListView.item(item.row()) | 348 | bitem = self.ListView.item(item.row()) |
901 | 345 | text = unicode((bitem.data(QtCore.Qt.UserRole)).toString()) | 349 | text = unicode((bitem.data(QtCore.Qt.UserRole)).toString()) |
902 | 346 | verse = text[:text.find(u'(')] | 350 | verse = text[:text.find(u'(')] |
904 | 347 | bible = text[text.find(u'(') + 1:text.find(u')')] | 351 | bible = text[text.find(u'(') + 1:-1] |
905 | 348 | self.searchByReference(bible, verse) | 352 | self.searchByReference(bible, verse) |
910 | 349 | book = self.search_results[0][0] | 353 | book = self.search_results[0].book.name |
911 | 350 | chapter = unicode(self.search_results[0][1]) | 354 | chapter = unicode(self.search_results[0].chapter) |
912 | 351 | verse = unicode(self.search_results[0][2]) | 355 | verse = unicode(self.search_results[0].verse) |
913 | 352 | text = self.search_results[0][3] | 356 | text = self.search_results[0].text |
914 | 353 | #Paragraph style force new line per verse | 357 | #Paragraph style force new line per verse |
915 | 354 | if self.parent.bibles_tab.paragraph_style: | 358 | if self.parent.bibles_tab.paragraph_style: |
916 | 355 | text = text + u'\n\n' | 359 | text = text + u'\n\n' |
917 | @@ -406,8 +410,8 @@ | |||
918 | 406 | 410 | ||
919 | 407 | def initialiseChapterVerse(self, bible, book): | 411 | def initialiseChapterVerse(self, bible, book): |
920 | 408 | log.debug(u'initialiseChapterVerse %s , %s', bible, book) | 412 | log.debug(u'initialiseChapterVerse %s , %s', bible, book) |
923 | 409 | self.chapters_from = self.parent.biblemanager.get_book_chapter_count(bible, book)[0] | 413 | self.chapters_from = self.parent.biblemanager.get_book_chapter_count(bible, book) |
924 | 410 | self.verses = self.parent.biblemanager.get_book_verse_count(bible, book, 1)[0] | 414 | self.verses = self.parent.biblemanager.get_book_verse_count(bible, book, 1) |
925 | 411 | self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter) | 415 | self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter) |
926 | 412 | self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter) | 416 | self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter) |
927 | 413 | self.adjustComboBox(1, self.verses, self.AdvancedFromVerse) | 417 | self.adjustComboBox(1, self.verses, self.AdvancedFromVerse) |
928 | @@ -420,10 +424,16 @@ | |||
929 | 420 | combo.addItem(unicode(i)) | 424 | combo.addItem(unicode(i)) |
930 | 421 | 425 | ||
931 | 422 | def displayResults(self, bible): | 426 | def displayResults(self, bible): |
934 | 423 | for book, chap, vse , txt in self.search_results: | 427 | for verse in self.search_results: |
935 | 424 | bible_text = unicode(u' %s %d:%d (%s)'%(book , chap,vse, bible)) | 428 | #bible_text = unicode(u' %s %d:%d (%s)'%(book , chap,vse, bible)) |
936 | 429 | #bible_verse = QtGui.QListWidgetItem(bible_text) | ||
937 | 430 | #bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(bible_text)) | ||
938 | 431 | #self.ListView.addItem(bible_verse) | ||
939 | 432 | bible_text = u' %s %d:%d (%s)' % (verse.book.name, | ||
940 | 433 | verse.chapter, verse.verse, bible) | ||
941 | 425 | bible_verse = QtGui.QListWidgetItem(bible_text) | 434 | bible_verse = QtGui.QListWidgetItem(bible_text) |
943 | 426 | bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(bible_text)) | 435 | bible_verse.setData(QtCore.Qt.UserRole, |
944 | 436 | QtCore.QVariant(bible_text)) | ||
945 | 427 | self.ListView.addItem(bible_verse) | 437 | self.ListView.addItem(bible_verse) |
946 | 428 | 438 | ||
947 | 429 | def searchByReference(self, bible, search): | 439 | def searchByReference(self, bible, search): |
948 | 430 | 440 | ||
949 | === renamed file 'openlp/plugins/bibles/lib/tables.py' => 'openlp/plugins/bibles/lib/models.py' | |||
950 | --- openlp/plugins/bibles/lib/tables.py 2009-06-16 18:21:24 +0000 | |||
951 | +++ openlp/plugins/bibles/lib/models.py 2009-07-14 19:44:15 +0000 | |||
952 | @@ -1,7 +1,10 @@ | |||
953 | 1 | # -*- coding: utf-8 -*- | ||
954 | 1 | # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 |
955 | 2 | """ | 3 | """ |
956 | 3 | OpenLP - Open Source Lyrics Projection | 4 | OpenLP - Open Source Lyrics Projection |
957 | 5 | |||
958 | 4 | Copyright (c) 2008 Raoul Snyman | 6 | Copyright (c) 2008 Raoul Snyman |
959 | 7 | |||
960 | 5 | Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley | 8 | Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley |
961 | 6 | 9 | ||
962 | 7 | This program is free software; you can redistribute it and/or modify it under | 10 | This program is free software; you can redistribute it and/or modify it under |
963 | @@ -14,39 +17,95 @@ | |||
964 | 14 | 17 | ||
965 | 15 | You should have received a copy of the GNU General Public License along with | 18 | You should have received a copy of the GNU General Public License along with |
966 | 16 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | 19 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
968 | 17 | Place, Suite 330, Boston, MA 02111-1307 USA | 20 | Place, Suite 330, Boston, MA 02111-1307 USA |
969 | 18 | """ | 21 | """ |
973 | 19 | import string | 22 | import string |
974 | 20 | from sqlalchemy import * | 23 | |
975 | 21 | from sqlalchemy import Column, Table, MetaData, ForeignKey, schema | 24 | from sqlalchemy import Column, Table, MetaData, ForeignKey, types, \ |
976 | 25 | create_engine | ||
977 | 26 | from sqlalchemy.orm import mapper, relation, sessionmaker, scoped_session | ||
978 | 27 | |||
979 | 28 | class BaseModel(object): | ||
980 | 29 | """ | ||
981 | 30 | BaseModel provides a base object with a set of generic functions | ||
982 | 31 | """ | ||
983 | 32 | @classmethod | ||
984 | 33 | def populate(cls, **kwargs): | ||
985 | 34 | """ | ||
986 | 35 | Creates an instance of a class and populates it, returning the instance | ||
987 | 36 | """ | ||
988 | 37 | me = cls() | ||
989 | 38 | keys = kwargs.keys() | ||
990 | 39 | for key in keys: | ||
991 | 40 | me.__setattr__(key, kwargs[key]) | ||
992 | 41 | return me | ||
993 | 42 | |||
994 | 43 | |||
995 | 44 | class BibleMeta(BaseModel): | ||
996 | 45 | """ | ||
997 | 46 | Bible Meta Data | ||
998 | 47 | """ | ||
999 | 48 | pass | ||
1000 | 49 | |||
1001 | 50 | |||
1002 | 51 | class ONTestament(BaseModel): | ||
1003 | 52 | """ | ||
1004 | 53 | Bible Testaments | ||
1005 | 54 | """ | ||
1006 | 55 | pass | ||
1007 | 56 | |||
1008 | 57 | |||
1009 | 58 | class Book(BaseModel): | ||
1010 | 59 | """ | ||
1011 | 60 | Song model | ||
1012 | 61 | """ | ||
1013 | 62 | pass | ||
1014 | 63 | |||
1015 | 64 | |||
1016 | 65 | class Verse(BaseModel): | ||
1017 | 66 | """ | ||
1018 | 67 | Topic model | ||
1019 | 68 | """ | ||
1020 | 69 | pass | ||
1021 | 70 | |||
1022 | 71 | |||
1023 | 72 | def init_models(db_url): | ||
1024 | 73 | engine = create_engine(db_url) | ||
1025 | 74 | metadata.bind = engine | ||
1026 | 75 | session = scoped_session(sessionmaker(autoflush=True, | ||
1027 | 76 | autocommit=False, | ||
1028 | 77 | bind=engine)) | ||
1029 | 78 | # Don't think this is needed... | ||
1030 | 79 | #metadata.bind.echo = False | ||
1031 | 80 | #Define the tables and indexes | ||
1032 | 81 | return metadata, session | ||
1033 | 82 | |||
1034 | 22 | 83 | ||
1035 | 23 | metadata = MetaData() | 84 | metadata = MetaData() |
1036 | 24 | #Define the tables and indexes | ||
1037 | 25 | meta_table = Table(u'metadata', metadata, | ||
1038 | 26 | Column(u'key', String(255), primary_key=True), | ||
1039 | 27 | Column(u'value', String(255)), | ||
1040 | 28 | ) | ||
1041 | 29 | |||
1042 | 30 | testament_table = Table(u'testament', metadata, | ||
1043 | 31 | Column(u'id', Integer, primary_key=True), | ||
1044 | 32 | Column(u'name', String(30)), | ||
1045 | 33 | ) | ||
1046 | 34 | |||
1047 | 35 | book_table = Table(u'book', metadata, | ||
1048 | 36 | Column(u'id', Integer, primary_key=True), | ||
1049 | 37 | Column(u'testament_id', Integer, schema.ForeignKey(u'testament.id')), | ||
1050 | 38 | Column(u'name', String(30)), | ||
1051 | 39 | Column(u'abbreviation', String(5)), | ||
1052 | 40 | ) | ||
1053 | 41 | Index(u'idx_name', book_table.c.name, book_table.c.id) | ||
1054 | 42 | Index(u'idx_abbrev', book_table.c.abbreviation, book_table.c.id) | ||
1055 | 43 | |||
1056 | 44 | verse_table = Table(u'verse', metadata, | ||
1057 | 45 | Column(u'id', Integer, primary_key=True), | ||
1058 | 46 | Column(u'book_id', Integer , schema.ForeignKey(u'book.id')), | ||
1059 | 47 | Column(u'chapter', Integer), | ||
1060 | 48 | Column(u'verse', Integer), | ||
1061 | 49 | Column(u'text', Text), | ||
1062 | 50 | ) | ||
1063 | 51 | Index(u'idx_chapter_verse_book', verse_table.c.chapter, verse_table.c.verse, verse_table.c.book_id, verse_table.c.id) | ||
1064 | 52 | Index(u'idx_chapter_verse_text', verse_table.c.text, verse_table.c.verse, verse_table.c.book_id, verse_table.c.id) | ||
1065 | 53 | \ No newline at end of file | 85 | \ No newline at end of file |
1066 | 86 | meta_table = Table(u'metadata', metadata, | ||
1067 | 87 | Column(u'key', types.Unicode(255), primary_key=True, index=True), | ||
1068 | 88 | Column(u'value', types.Unicode(255)), | ||
1069 | 89 | ) | ||
1070 | 90 | testament_table = Table(u'testament', metadata, | ||
1071 | 91 | Column(u'id', types.Integer, primary_key=True), | ||
1072 | 92 | Column(u'name', types.Unicode(50)), | ||
1073 | 93 | ) | ||
1074 | 94 | book_table = Table(u'book', metadata, | ||
1075 | 95 | Column(u'id', types.Integer, primary_key=True), | ||
1076 | 96 | Column(u'testament_id', types.Integer, ForeignKey(u'testament.id')), | ||
1077 | 97 | Column(u'name', types.Unicode(50), index=True), | ||
1078 | 98 | Column(u'abbreviation', types.Unicode(5), index=True), | ||
1079 | 99 | ) | ||
1080 | 100 | verse_table = Table(u'verse', metadata, | ||
1081 | 101 | Column(u'id', types.Integer, primary_key=True, index=True), | ||
1082 | 102 | Column(u'book_id', types.Integer, ForeignKey(u'book.id'), index=True), | ||
1083 | 103 | Column(u'chapter', types.Integer, index=True), | ||
1084 | 104 | Column(u'verse', types.Integer, index=True), | ||
1085 | 105 | Column(u'text', types.UnicodeText, index=True), | ||
1086 | 106 | ) | ||
1087 | 107 | mapper(BibleMeta, meta_table) | ||
1088 | 108 | mapper(ONTestament, testament_table, | ||
1089 | 109 | properties={'books': relation(Book, backref='testament')}) | ||
1090 | 110 | mapper(Book, book_table, | ||
1091 | 111 | properties={'verses': relation(Verse, backref='book')}) | ||
1092 | 112 | mapper(Verse, verse_table) |
Some more fixes!