forked from openlp/openlp
Change upgrade of bibles: bibleupgradeform now trys to upgrade existing verses from webbibles.
bzr-revno: 1611
This commit is contained in:
commit
7e519464f6
@ -602,7 +602,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
handler = BSExtract(proxy_server)
|
handler = BSExtract(proxy_server)
|
||||||
books = handler.get_books_from_http(meta_data[u'download name'])
|
books = handler.get_books_from_http(meta_data[u'download name'])
|
||||||
if not books:
|
if not books:
|
||||||
log.exception(u'Upgrading books from %s - download '\
|
log.error(u'Upgrading books from %s - download '\
|
||||||
u'name: "%s" failed' % (
|
u'name: "%s" failed' % (
|
||||||
meta_data[u'download source'],
|
meta_data[u'download source'],
|
||||||
meta_data[u'download name']))
|
meta_data[u'download name']))
|
||||||
@ -633,7 +633,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
else:
|
else:
|
||||||
language_id = self.newbibles[number].get_language(name)
|
language_id = self.newbibles[number].get_language(name)
|
||||||
if not language_id:
|
if not language_id:
|
||||||
log.exception(u'Upgrading from "%s" failed' % filename[0])
|
log.warn(u'Upgrading from "%s" failed' % filename[0])
|
||||||
delete_database(self.path,
|
delete_database(self.path,
|
||||||
clean_filename(self.newbibles[number].get_name()))
|
clean_filename(self.newbibles[number].get_name()))
|
||||||
del self.newbibles[number]
|
del self.newbibles[number]
|
||||||
@ -657,7 +657,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
book_ref_id = self.newbibles[number].\
|
book_ref_id = self.newbibles[number].\
|
||||||
get_book_ref_id_by_name(book, len(books), language_id)
|
get_book_ref_id_by_name(book, len(books), language_id)
|
||||||
if not book_ref_id:
|
if not book_ref_id:
|
||||||
log.exception(u'Upgrading books from %s - download '\
|
log.warn(u'Upgrading books from %s - download '\
|
||||||
u'name: "%s" aborted by user' % (
|
u'name: "%s" aborted by user' % (
|
||||||
meta_data[u'download source'],
|
meta_data[u'download source'],
|
||||||
meta_data[u'download name']))
|
meta_data[u'download name']))
|
||||||
@ -667,15 +667,32 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
bible_failed = True
|
bible_failed = True
|
||||||
break
|
break
|
||||||
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
||||||
self.newbibles[number].create_book(book, book_ref_id,
|
db_book = self.newbibles[number].create_book(book,
|
||||||
book_details[u'testament_id'])
|
book_ref_id, book_details[u'testament_id'])
|
||||||
|
# Try to import still downloaded verses
|
||||||
|
oldbook = oldbible.get_book(book)
|
||||||
|
if oldbook:
|
||||||
|
verses = oldbible.get_verses(oldbook[u'id'])
|
||||||
|
if not verses:
|
||||||
|
log.warn(u'No verses found to import for book '
|
||||||
|
u'"%s"', book)
|
||||||
|
continue
|
||||||
|
for verse in verses:
|
||||||
|
if self.stop_import_flag:
|
||||||
|
bible_failed = True
|
||||||
|
break
|
||||||
|
self.newbibles[number].create_verse(db_book.id,
|
||||||
|
int(verse[u'chapter']),
|
||||||
|
int(verse[u'verse']), unicode(verse[u'text']))
|
||||||
|
Receiver.send_message(u'openlp_process_events')
|
||||||
|
self.newbibles[number].session.commit()
|
||||||
else:
|
else:
|
||||||
language_id = self.newbibles[number].get_object(BibleMeta,
|
language_id = self.newbibles[number].get_object(BibleMeta,
|
||||||
u'language_id')
|
u'language_id')
|
||||||
if not language_id:
|
if not language_id:
|
||||||
language_id = self.newbibles[number].get_language(name)
|
language_id = self.newbibles[number].get_language(name)
|
||||||
if not language_id:
|
if not language_id:
|
||||||
log.exception(u'Upgrading books from "%s" failed' % name)
|
log.warn(u'Upgrading books from "%s" failed' % name)
|
||||||
delete_database(self.path,
|
delete_database(self.path,
|
||||||
clean_filename(self.newbibles[number].get_name()))
|
clean_filename(self.newbibles[number].get_name()))
|
||||||
del self.newbibles[number]
|
del self.newbibles[number]
|
||||||
@ -701,7 +718,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
get_book_ref_id_by_name(book[u'name'], len(books),
|
get_book_ref_id_by_name(book[u'name'], len(books),
|
||||||
language_id)
|
language_id)
|
||||||
if not book_ref_id:
|
if not book_ref_id:
|
||||||
log.exception(u'Upgrading books from %s " '\
|
log.warn(u'Upgrading books from %s " '\
|
||||||
'failed - aborted by user' % name)
|
'failed - aborted by user' % name)
|
||||||
delete_database(self.path,
|
delete_database(self.path,
|
||||||
clean_filename(self.newbibles[number].get_name()))
|
clean_filename(self.newbibles[number].get_name()))
|
||||||
@ -713,7 +730,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||||||
book_ref_id, book_details[u'testament_id'])
|
book_ref_id, book_details[u'testament_id'])
|
||||||
verses = oldbible.get_verses(book[u'id'])
|
verses = oldbible.get_verses(book[u'id'])
|
||||||
if not verses:
|
if not verses:
|
||||||
log.exception(u'No verses found to import for book '
|
log.warn(u'No verses found to import for book '
|
||||||
u'"%s"', book[u'name'])
|
u'"%s"', book[u'name'])
|
||||||
self.newbibles[number].delete_book(db_book)
|
self.newbibles[number].delete_book(db_book)
|
||||||
continue
|
continue
|
||||||
|
@ -1045,6 +1045,28 @@ class OldBibleDB(QtCore.QObject, Manager):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_book(self, name):
|
||||||
|
"""
|
||||||
|
Return a book by name or abbreviation.
|
||||||
|
|
||||||
|
``name``
|
||||||
|
The name or abbreviation of the book.
|
||||||
|
"""
|
||||||
|
if not isinstance(name, unicode):
|
||||||
|
name = unicode(name)
|
||||||
|
books = self.run_sql(u'SELECT id, testament_id, name, '
|
||||||
|
u'abbreviation FROM book WHERE LOWER(name) = ? OR '
|
||||||
|
u'LOWER(abbreviation) = ?', (name.lower(), name.lower()))
|
||||||
|
if books:
|
||||||
|
return {
|
||||||
|
u'id': books[0][0],
|
||||||
|
u'testament_id': books[0][1],
|
||||||
|
u'name': unicode(books[0][2]),
|
||||||
|
u'abbreviation': unicode(books[0][3])
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_books(self):
|
def get_books(self):
|
||||||
"""
|
"""
|
||||||
Returns the books of the Bible.
|
Returns the books of the Bible.
|
||||||
|
Loading…
Reference in New Issue
Block a user