← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/bug-1077654 into lp:openlp

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/bug-1077654 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #1077654 in OpenLP: "Error when importing Bibles from BibleGateway"
  https://bugs.launchpad.net/openlp/+bug/1077654

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/bug-1077654/+merge/133824

Fixed bug #1077654 where there were more classes in the CSS, but we were specifically looking for only one class. Made the code less brittle.
-- 
https://code.launchpad.net/~raoul-snyman/openlp/bug-1077654/+merge/133824
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/bug-1077654 into lp:openlp.
=== modified file 'openlp/core/lib/db.py'
--- openlp/core/lib/db.py	2012-11-07 21:37:01 +0000
+++ openlp/core/lib/db.py	2012-11-11 16:15:24 +0000
@@ -85,11 +85,13 @@
         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 @@
     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 @@
             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__
 
 

=== modified file 'openlp/plugins/bibles/lib/http.py'
--- openlp/plugins/bibles/lib/http.py	2012-11-07 21:37:01 +0000
+++ openlp/plugins/bibles/lib/http.py	2012-11-11 16:15:24 +0000
@@ -279,14 +279,8 @@
             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 @@
             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')


Follow ups