- Fix Bug #792811 - Traceback UnicodeEncodeError while importing a webbible

- If upgrade fails new bible databases which are failed now should be deleted always. If upgrade was successfull the old database is deleted immediately. So never should stay an old and a new version from one bible.
- changed behaviour if the user cancel the import so that after a traceback it is possible to cancel the dialog.
- Fix Bug #792831 - now the right parent is used for dialogs and error messages
- Biblegateway.com has changed it's Bible-Book-List Layout. Addapt the regex for importing the booklist of a bible from biblegateway to the new html layout.
- changed log usage
- remove unnecessary code
- small fixes

bzr-revno: 1614
Fixes: https://launchpad.net/bugs/792811, https://launchpad.net/bugs/792831
This commit is contained in:
Armin Köhler 2011-06-05 20:17:09 +01:00 committed by Tim Bentley
commit d89b60a96f
3 changed files with 43 additions and 45 deletions

View File

@ -115,6 +115,8 @@ class BibleUpgradeForm(OpenLPWizard):
self.stop_import_flag = True
if not self.currentPage() == self.progressPage:
self.done(QtGui.QDialog.Rejected)
else:
self.postWizard()
def onCurrentIdChanged(self, pageId):
"""
@ -127,14 +129,6 @@ class BibleUpgradeForm(OpenLPWizard):
elif self.page(pageId) == self.selectPage and self.maxBibles == 0:
self.next()
def onFinishButton(self):
"""
Some cleanup while finishing
"""
for number, filename in enumerate(self.files):
if number in self.success and self.success[number] == True:
delete_file(os.path.join(self.path, filename[0]))
def onBackupBrowseButtonClicked(self):
"""
Show the file open dialog for the OSIS file.
@ -180,8 +174,6 @@ class BibleUpgradeForm(OpenLPWizard):
"""
Set up the signals used in the bible importer.
"""
QtCore.QObject.connect(self.finishButton,
QtCore.SIGNAL(u'clicked()'), self.onFinishButton)
QtCore.QObject.connect(self.backupBrowseButton,
QtCore.SIGNAL(u'clicked()'), self.onBackupBrowseButtonClicked)
QtCore.QObject.connect(self.noBackupCheckBox,
@ -536,7 +528,7 @@ class BibleUpgradeForm(OpenLPWizard):
"""
Perform the actual upgrade.
"""
include_webbible = False
self.include_webbible = False
proxy_server = None
if self.maxBibles == 0:
self.progressLabel.setText(
@ -578,19 +570,19 @@ class BibleUpgradeForm(OpenLPWizard):
name = unicode(self.versionNameEdit[biblenumber].text())
self.newbibles[number] = BibleDB(self.mediaItem, path=self.path,
name=name)
self.newbibles[number].register(self.plugin.upgrade_wizard)
metadata = oldbible.get_metadata()
webbible = False
meta_data = {}
for meta in metadata:
meta_data[meta[u'key']] = meta[u'value']
if not meta[u'key'] == u'Version':
if not meta[u'key'] == u'Version' and not meta[u'key'] == \
u'dbversion':
self.newbibles[number].create_meta(meta[u'key'],
meta[u'value'])
else:
self.newbibles[number].create_meta(meta[u'key'], name)
if meta[u'key'] == u'download source':
webbible = True
include_webbible = True
self.include_webbible = True
if meta.has_key(u'proxy server'):
proxy_server = meta[u'proxy server']
if webbible:
@ -606,8 +598,7 @@ class BibleUpgradeForm(OpenLPWizard):
u'name: "%s" failed' % (
meta_data[u'download source'],
meta_data[u'download name']))
delete_database(self.path,
clean_filename(self.newbibles[number].get_name()))
delete_database(self.path, clean_filename(name))
del self.newbibles[number]
critical_error_message_box(
translate('BiblesPlugin.UpgradeWizardForm',
@ -626,7 +617,7 @@ class BibleUpgradeForm(OpenLPWizard):
bible = BiblesResourcesDB.get_webbible(
meta_data[u'download name'],
meta_data[u'download source'].lower())
if bible[u'language_id']:
if bible and bible[u'language_id']:
language_id = bible[u'language_id']
self.newbibles[number].create_meta(u'language_id',
language_id)
@ -634,8 +625,7 @@ class BibleUpgradeForm(OpenLPWizard):
language_id = self.newbibles[number].get_language(name)
if not language_id:
log.warn(u'Upgrading from "%s" failed' % filename[0])
delete_database(self.path,
clean_filename(self.newbibles[number].get_name()))
delete_database(self.path, clean_filename(name))
del self.newbibles[number]
self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm',
@ -661,8 +651,7 @@ class BibleUpgradeForm(OpenLPWizard):
u'name: "%s" aborted by user' % (
meta_data[u'download source'],
meta_data[u'download name']))
delete_database(self.path,
clean_filename(self.newbibles[number].get_name()))
delete_database(self.path, clean_filename(name))
del self.newbibles[number]
bible_failed = True
break
@ -693,8 +682,7 @@ class BibleUpgradeForm(OpenLPWizard):
language_id = self.newbibles[number].get_language(name)
if not language_id:
log.warn(u'Upgrading books from "%s" failed' % name)
delete_database(self.path,
clean_filename(self.newbibles[number].get_name()))
delete_database(self.path, clean_filename(name))
del self.newbibles[number]
self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm',
@ -720,8 +708,7 @@ class BibleUpgradeForm(OpenLPWizard):
if not book_ref_id:
log.warn(u'Upgrading books from %s " '\
'failed - aborted by user' % name)
delete_database(self.path,
clean_filename(self.newbibles[number].get_name()))
delete_database(self.path, clean_filename(name))
del self.newbibles[number]
bible_failed = True
break
@ -744,6 +731,8 @@ class BibleUpgradeForm(OpenLPWizard):
Receiver.send_message(u'openlp_process_events')
self.newbibles[number].session.commit()
if not bible_failed:
self.newbibles[number].create_meta(u'Version', name)
delete_file(os.path.join(self.path, filename[0]))
self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\n'
@ -756,10 +745,13 @@ class BibleUpgradeForm(OpenLPWizard):
'Upgrading Bible %s of %s: "%s"\nFailed')) %
(number + 1, self.maxBibles, name),
self.progressBar.maximum() - self.progressBar.value())
delete_database(self.path,
clean_filename(name))
delete_database(self.path, clean_filename(name))
number += 1
self.mediaItem.reloadBibles()
def postWizard(self):
"""
Clean up the UI after the import has finished.
"""
successful_import = 0
failed_import = 0
for number, filename in enumerate(self.files):
@ -774,7 +766,7 @@ class BibleUpgradeForm(OpenLPWizard):
else:
failed_import_text = u''
if successful_import > 0:
if include_webbible:
if self.include_webbible:
self.progressLabel.setText(unicode(
translate('BiblesPlugin.UpgradeWizardForm', 'Upgrading '
'Bible(s): %s successful%s\nPlease note, that verses from '
@ -790,3 +782,4 @@ class BibleUpgradeForm(OpenLPWizard):
self.progressLabel.setText(
translate('BiblesPlugin.UpgradeWizardForm', 'Upgrade '
'failed.'))
OpenLPWizard.postWizard(self)

View File

@ -109,7 +109,7 @@ class BGExtract(object):
try:
clean_verse_num = int(str(raw_verse_num))
except ValueError:
log.exception(u'Illegal verse number in %s %s %s:%s',
log.warn(u'Illegal verse number in %s %s %s:%s',
version, bookname, chapter, unicode(raw_verse_num))
if clean_verse_num:
verse_text = raw_verse_num.next
@ -139,16 +139,17 @@ class BGExtract(object):
"""
log.debug(u'BGExtract.get_books_from_http("%s")', version)
url_params = urllib.urlencode(
{u'search': 'Bible-List', u'version': u'%s' % version})
reference_url = u'http://www.biblegateway.com/passage/?%s' % url_params
{u'action': 'getVersionInfo', u'vid': u'%s' % version})
reference_url = u'http://www.biblegateway.com/versions/?%s#books' % \
url_params
page = get_web_page(reference_url)
if not page:
send_error_message(u'download')
return None
page_source = page.read()
page_source = unicode(page_source, 'utf8')
page_source_temp = re.search(u'<table id="booklist".*?>.*?</table>', \
page_source, re.DOTALL)
page_source_temp = re.search(u'<table .*?class="infotable".*?>.*?'\
u'</table>', page_source, re.DOTALL)
if page_source_temp:
soup = page_source_temp.group(0)
else:
@ -156,15 +157,17 @@ class BGExtract(object):
try:
soup = BeautifulSoup(soup)
except HTMLParseError:
log.exception(u'BeautifulSoup could not parse the Bible page.')
log.error(u'BeautifulSoup could not parse the Bible page.')
send_error_message(u'parse')
return None
if not soup:
send_error_message(u'parse')
return None
Receiver.send_message(u'openlp_process_events')
content = soup.find(u'table', {u'id': u'booklist'})
content = soup.find(u'table', {u'class': u'infotable'})
content = content.findAll(u'tr')
if not content:
log.exception(u'No books found in the Biblegateway response.')
log.error(u'No books found in the Biblegateway response.')
send_error_message(u'parse')
return None
books = []
@ -199,9 +202,10 @@ class BSExtract(object):
"""
log.debug(u'BSExtract.get_bible_chapter("%s", "%s", "%s")', version,
bookname, chapter)
urlversion = urllib.quote(version.encode("utf-8"))
urlbookname = urllib.quote(bookname.encode("utf-8"))
chapter_url = u'http://m.bibleserver.com/text/%s/%s%s' % \
(version, urlbookname, chapter)
chapter_url = u'http://m.bibleserver.com/text/%s/%s%d' % \
(urlversion, urlbookname, chapter)
header = (u'Accept-Language', u'en')
soup = get_soup_for_bible_ref(chapter_url, header)
if not soup:
@ -209,7 +213,7 @@ class BSExtract(object):
Receiver.send_message(u'openlp_process_events')
content = soup.find(u'div', u'content')
if not content:
log.exception(u'No verses found in the Bibleserver response.')
log.error(u'No verses found in the Bibleserver response.')
send_error_message(u'parse')
return None
content = content.find(u'div').findAll(u'div')
@ -230,14 +234,15 @@ class BSExtract(object):
The version of the Bible like NIV for New International Version
"""
log.debug(u'BSExtract.get_books_from_http("%s")', version)
urlversion = urllib.quote(version.encode("utf-8"))
chapter_url = u'http://m.bibleserver.com/overlay/selectBook?'\
'translation=%s' % (version)
'translation=%s' % (urlversion)
soup = get_soup_for_bible_ref(chapter_url)
if not soup:
return None
content = soup.find(u'ul')
if not content:
log.exception(u'No books found in the Bibleserver response.')
log.error(u'No books found in the Bibleserver response.')
send_error_message(u'parse')
return None
content = content.findAll(u'li')
@ -281,7 +286,7 @@ class CWExtract(object):
Receiver.send_message(u'openlp_process_events')
htmlverses = soup.findAll(u'span', u'versetext')
if not htmlverses:
log.debug(u'No verses found in the CrossWalk response.')
log.error(u'No verses found in the CrossWalk response.')
send_error_message(u'parse')
return None
verses = {}
@ -333,7 +338,7 @@ class CWExtract(object):
content = soup.find(u'div', {u'class': u'Body'})
content = content.find(u'ul', {u'class': u'parent'})
if not content:
log.exception(u'No books found in the Crosswalk response.')
log.error(u'No books found in the Crosswalk response.')
send_error_message(u'parse')
return None
content = content.findAll(u'li')