Fix DB unit of work for updates

Fix Bible identification code for BibleGateway

bzr-revno: 2109
This commit is contained in:
Raoul Snyman 2012-11-11 17:25:09 +00:00 committed by Tim Bentley
commit e919c53434
2 changed files with 12 additions and 14 deletions

View File

@ -85,11 +85,13 @@ def upgrade_db(url, upgrade):
Provides a class for the metadata table.
"""
pass
load_changes = True
load_changes = False
tables = []
try:
tables = upgrade.upgrade_setup(metadata)
load_changes = True
except (SQLAlchemyError, DBAPIError):
load_changes = False
pass
metadata_table = Table(u'metadata', metadata,
Column(u'key', types.Unicode(64), primary_key=True),
Column(u'value', types.UnicodeText(), default=None)
@ -99,6 +101,7 @@ def upgrade_db(url, upgrade):
version_meta = session.query(Metadata).get(u'version')
if version_meta is None:
version_meta = Metadata.populate(key=u'version', value=u'0')
session.add(version_meta)
version = 0
else:
version = int(version_meta.value)
@ -111,17 +114,17 @@ def upgrade_db(url, upgrade):
try:
getattr(upgrade, u'upgrade_%d' % version) \
(session, metadata, tables)
version_meta.value = unicode(version)
except (SQLAlchemyError, DBAPIError):
log.exception(u'Could not run database upgrade script '
'"upgrade_%s", upgrade process has been halted.', version)
break
version_meta.value = unicode(version)
session.commit()
version += 1
else:
version_meta = Metadata.populate(key=u'version',
value=int(upgrade.__version__))
session.add(version_meta)
session.commit()
session.commit()
return int(version_meta.value), upgrade.__version__

View File

@ -279,14 +279,8 @@ class BGExtract(object):
page_source = unicode(page_source, u'utf8')
except UnicodeDecodeError:
page_source = unicode(page_source, u'cp1251')
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:
soup = None
try:
soup = BeautifulSoup(soup)
soup = BeautifulSoup(page_source)
except HTMLParseError:
log.error(u'BeautifulSoup could not parse the Bible page.')
send_error_message(u'parse')
@ -295,8 +289,9 @@ class BGExtract(object):
send_error_message(u'parse')
return None
Receiver.send_message(u'openlp_process_events')
content = soup.find(u'table', {u'class': u'infotable'})
content = content.findAll(u'tr')
content = soup.find(u'table', u'infotable')
if content:
content = content.findAll(u'tr')
if not content:
log.error(u'No books found in the Biblegateway response.')
send_error_message(u'parse')