From 877ea4e13d7d840fd5de5a58b05587a5a4de770a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Thu, 2 Jun 2011 12:42:42 +0200 Subject: [PATCH 1/3] Change upgrade of bibles: bibleupgradeform now trys to upgrade existing verses from webbibles. --- .../plugins/bibles/forms/bibleupgradeform.py | 21 ++++++++++++++++-- openlp/plugins/bibles/lib/db.py | 22 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index 0fdcdfd11..3d25d6092 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -671,8 +671,25 @@ class BibleUpgradeForm(OpenLPWizard): bible_failed = True break book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) - self.newbibles[number].create_book(book, book_ref_id, - book_details[u'testament_id']) + db_book = self.newbibles[number].create_book(book, + 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.exception(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: language_id = self.newbibles[number].get_object(BibleMeta, u'language_id') diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 776521aa6..975b4093d 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -1043,6 +1043,28 @@ class OldBibleDB(QtCore.QObject, Manager): else: 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): """ Returns the books of the Bible. From eda3e9ebe00d3aec754d719734e0f6f40d31bace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Thu, 2 Jun 2011 13:52:06 +0200 Subject: [PATCH 2/3] change log usage --- openlp/plugins/bibles/forms/bibleupgradeform.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index 3d25d6092..ecfb676f6 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -606,7 +606,7 @@ class BibleUpgradeForm(OpenLPWizard): handler = BSExtract(proxy_server) books = handler.get_books_from_http(meta_data[u'download name']) if not books: - log.exception(u'Upgrading books from %s - download '\ + log.error(u'Upgrading books from %s - download '\ u'name: "%s" failed' % ( meta_data[u'download source'], meta_data[u'download name'])) @@ -637,7 +637,7 @@ class BibleUpgradeForm(OpenLPWizard): else: language_id = self.newbibles[number].get_language(name) if not language_id: - log.exception(u'Upgrading from "%s" failed' % filename[0]) + log.error(u'Upgrading from "%s" failed' % filename[0]) delete_database(self.path, clean_filename(self.newbibles[number].get_name())) del self.newbibles[number] @@ -661,7 +661,7 @@ class BibleUpgradeForm(OpenLPWizard): book_ref_id = self.newbibles[number].\ get_book_ref_id_by_name(book, len(books), language_id) if not book_ref_id: - log.exception(u'Upgrading books from %s - download '\ + log.error(u'Upgrading books from %s - download '\ u'name: "%s" aborted by user' % ( meta_data[u'download source'], meta_data[u'download name'])) @@ -678,7 +678,7 @@ class BibleUpgradeForm(OpenLPWizard): if oldbook: verses = oldbible.get_verses(oldbook[u'id']) 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) continue for verse in verses: @@ -696,7 +696,7 @@ class BibleUpgradeForm(OpenLPWizard): if not language_id: language_id = self.newbibles[number].get_language(name) if not language_id: - log.exception(u'Upgrading books from "%s" failed' % name) + log.error(u'Upgrading books from "%s" failed' % name) delete_database(self.path, clean_filename(self.newbibles[number].get_name())) del self.newbibles[number] @@ -722,7 +722,7 @@ class BibleUpgradeForm(OpenLPWizard): get_book_ref_id_by_name(book[u'name'], len(books), language_id) if not book_ref_id: - log.exception(u'Upgrading books from %s " '\ + log.error(u'Upgrading books from %s " '\ 'failed - aborted by user' % name) delete_database(self.path, clean_filename(self.newbibles[number].get_name())) @@ -734,7 +734,7 @@ class BibleUpgradeForm(OpenLPWizard): book_ref_id, book_details[u'testament_id']) verses = oldbible.get_verses(book[u'id']) if not verses: - log.exception(u'No verses found to import for book ' + log.error(u'No verses found to import for book ' u'"%s"', book[u'name']) self.newbibles[number].delete_book(db_book) continue From c4e6e91c81f10b510173d5ae051b22814057be7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Fri, 3 Jun 2011 14:43:54 +0200 Subject: [PATCH 3/3] change log usage --- openlp/plugins/bibles/forms/bibleupgradeform.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index ecfb676f6..0b1556f07 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -637,7 +637,7 @@ class BibleUpgradeForm(OpenLPWizard): else: language_id = self.newbibles[number].get_language(name) if not language_id: - log.error(u'Upgrading from "%s" failed' % filename[0]) + log.warn(u'Upgrading from "%s" failed' % filename[0]) delete_database(self.path, clean_filename(self.newbibles[number].get_name())) del self.newbibles[number] @@ -661,7 +661,7 @@ class BibleUpgradeForm(OpenLPWizard): book_ref_id = self.newbibles[number].\ get_book_ref_id_by_name(book, len(books), language_id) if not book_ref_id: - log.error(u'Upgrading books from %s - download '\ + log.warn(u'Upgrading books from %s - download '\ u'name: "%s" aborted by user' % ( meta_data[u'download source'], meta_data[u'download name'])) @@ -696,7 +696,7 @@ class BibleUpgradeForm(OpenLPWizard): if not language_id: language_id = self.newbibles[number].get_language(name) if not language_id: - log.error(u'Upgrading books from "%s" failed' % name) + log.warn(u'Upgrading books from "%s" failed' % name) delete_database(self.path, clean_filename(self.newbibles[number].get_name())) del self.newbibles[number] @@ -722,7 +722,7 @@ class BibleUpgradeForm(OpenLPWizard): get_book_ref_id_by_name(book[u'name'], len(books), language_id) if not book_ref_id: - log.error(u'Upgrading books from %s " '\ + log.warn(u'Upgrading books from %s " '\ 'failed - aborted by user' % name) delete_database(self.path, clean_filename(self.newbibles[number].get_name())) @@ -734,7 +734,7 @@ class BibleUpgradeForm(OpenLPWizard): book_ref_id, book_details[u'testament_id']) verses = oldbible.get_verses(book[u'id']) if not verses: - log.error(u'No verses found to import for book ' + log.warn(u'No verses found to import for book ' u'"%s"', book[u'name']) self.newbibles[number].delete_book(db_book) continue