← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~mahfiaz/openlp/v1db_import_nonascii into lp:openlp

 

mahfiaz has proposed merging lp:~mahfiaz/openlp/v1db_import_nonascii into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~mahfiaz/openlp/v1db_import_nonascii/+merge/86475

Fixes error when trying to import non-ascii file of openlp.org songs or bibles database. Also some in-code notes about error handling.
-- 
https://code.launchpad.net/~mahfiaz/openlp/v1db_import_nonascii/+merge/86475
Your team OpenLP Core is requested to review the proposed merge of lp:~mahfiaz/openlp/v1db_import_nonascii into lp:openlp.
=== modified file 'openlp/plugins/bibles/lib/openlp1.py'
--- openlp/plugins/bibles/lib/openlp1.py	2011-06-12 16:02:52 +0000
+++ openlp/plugins/bibles/lib/openlp1.py	2011-12-20 22:50:32 +0000
@@ -27,6 +27,7 @@
 
 import logging
 import sqlite
+import sys
 
 from openlp.core.lib import Receiver
 from openlp.core.ui.wizard import WizardStrings
@@ -53,9 +54,14 @@
         connection = None
         cursor = None
         try:
-            connection = sqlite.connect(self.filename)
+            connection = sqlite.connect(
+                self.filename.encode(sys.getfilesystemencoding()))
             cursor = connection.cursor()
-        except:
+        except sqlite.DatabaseError:
+            log.exception(u'File "%s" is encrypted or not a sqlite database, '
+            'therefore not an openlp.org 1.x database either' % self.filename)
+            # Please add an user error here!
+            # This file is not an openlp.org 1.x bible database.
             return False
         #Create the bible language
         language_id = self.get_language(bible_name)
@@ -63,7 +69,17 @@
             log.exception(u'Importing books from "%s" failed' % self.filename)
             return False
         # Create all books.
-        cursor.execute(u'SELECT id, testament_id, name, abbreviation FROM book')
+        try:
+            cursor.execute(
+                u'SELECT id, testament_id, name, abbreviation FROM book')
+        except sqlite.DatabaseError as error:
+            log.exception(u'DatabaseError: %s' % error)
+            if error == 'no such table: book':
+                # Please add an user error here!
+                # This file is not an openlp.org 1.x bible database.
+                return False
+            else:
+                raise sqlite.DatabaseError(error)
         books = cursor.fetchall()
         self.wizard.progressBar.setMaximum(len(books) + 1)
         for book in books:

=== modified file 'openlp/plugins/songs/lib/olp1import.py'
--- openlp/plugins/songs/lib/olp1import.py	2011-10-31 14:18:22 +0000
+++ openlp/plugins/songs/lib/olp1import.py	2011-12-20 22:50:32 +0000
@@ -165,7 +165,8 @@
         Detect character encoding of an openlp.org 1.x song database.
         """
         # Connect to the database.
-        connection = sqlite.connect(self.importSource, mode=0444)
+        connection = sqlite.connect(self.importSource.encode(
+            sys.getfilesystemencoding()), mode=0444)
         cursor = connection.cursor()
 
         detector = UniversalDetector()


Follow ups