← Back to team overview

openlp-core team mailing list archive

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

 

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

    Requested reviews:
    OpenLP Core (openlp-core)


Canceling of Imports implemented, with a bit of cancel and failure handling included. More to follow.
-- 
https://code.launchpad.net/~raoul-snyman/openlp/biblesplugin/+merge/16610
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/bibles/forms/importwizardform.py'
--- openlp/plugins/bibles/forms/importwizardform.py	2009-12-24 18:01:39 +0000
+++ openlp/plugins/bibles/forms/importwizardform.py	2009-12-27 22:35:23 +0000
@@ -66,13 +66,13 @@
         QtGui.QWizard.__init__(self, parent)
         self.setupUi(self)
         self.registerFields()
-        self.web_bible_list = {}
         self.finishButton = self.button(QtGui.QWizard.FinishButton)
         self.cancelButton = self.button(QtGui.QWizard.CancelButton)
         self.biblemanager = biblemanager
         self.config = config
         self.bibleplugin = bibleplugin
-        self.biblemanager.process_dialog(self)
+        self.biblemanager.set_process_dialog(self)
+        self.web_bible_list = {}
         self.loadWebBibles()
         QtCore.QObject.connect(self.LocationComboBox,
             QtCore.SIGNAL(u'currentIndexChanged(int)'),
@@ -89,6 +89,9 @@
         QtCore.QObject.connect(self.OpenSongBrowseButton,
             QtCore.SIGNAL(u'clicked()'),
             self.onOpenSongBrowseButtonClicked)
+        QtCore.QObject.connect(self.cancelButton,
+            QtCore.SIGNAL(u'clicked(bool)'),
+            self.onCancelButtonClicked)
         QtCore.QObject.connect(self,
             QtCore.SIGNAL(u'currentIdChanged(int)'),
             self.onCurrentIdChanged)
@@ -192,6 +195,11 @@
         self.getFileName(self.trUtf8('Open OpenSong Bible'),
             self.OpenSongFileEdit)
 
+    def onCancelButtonClicked(self, checked):
+        log.debug('Cancel button pressed!')
+        if self.currentId() == 3:
+            Receiver.send_message(u'openlpstopimport')
+
     def onCurrentIdChanged(self, id):
         if id == 3:
             self.preImport()
@@ -237,11 +245,11 @@
         self.setField(u'opensong_file', u'')
         self.setField(u'web_location', 0)
         self.setField(u'web_biblename', self.BibleComboBox)
-        self.setField(u'proxy_server', 
+        self.setField(u'proxy_server',
             self.config.get_config(u'proxy address', u''))
-        self.setField(u'proxy_username', 
+        self.setField(u'proxy_username',
             self.config.get_config(u'proxy username',u''))
-        self.setField(u'proxy_password', 
+        self.setField(u'proxy_password',
             self.config.get_config(u'proxy password',u''))
         self.setField(u'license_version', self.VersionNameEdit)
         self.setField(u'license_copyright', self.CopyrightEdit)
@@ -297,8 +305,7 @@
         Receiver.send_message(u'process_events')
 
     def preImport(self):
-        self.finishButton.setEnabled(False)
-        self.cancelButton.setVisible(False)
+        self.finishButton.setVisible(False)
         self.ImportProgressBar.setMinimum(0)
         self.ImportProgressBar.setMaximum(1188)
         self.ImportProgressBar.setValue(0)
@@ -352,13 +359,14 @@
                 unicode(self.field(u'license_copyright').toString()),
                 unicode(self.field(u'license_permission').toString())
             )
+            self.ImportProgressLabel.setText(self.trUtf8('Finished import.'))
         else:
             self.ImportProgressLabel.setText(
                 self.trUtf8('Your Bible import failed.'))
-            self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())
 
     def postImport(self):
-        self.ImportProgressLabel.setText(self.trUtf8('Finished import.'))
-        self.finishButton.setEnabled(True)
+        self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())
+        self.finishButton.setVisible(True)
+        self.cancelButton.setVisible(False)
         Receiver.send_message(u'process_events')
 

=== modified file 'openlp/plugins/bibles/lib/bibleCSVimpl.py'
--- openlp/plugins/bibles/lib/bibleCSVimpl.py	2009-12-21 20:58:00 +0000
+++ openlp/plugins/bibles/lib/bibleCSVimpl.py	2009-12-27 22:35:24 +0000
@@ -49,6 +49,7 @@
 
     def load_data(self, booksfile, versesfile, dialogobject):
         #Populate the Tables
+        success = True
         fbooks = None
         try:
             fbooks = open(booksfile, 'r')
@@ -71,10 +72,12 @@
                     count = 0
         except:
             log.exception(u'Loading books from file failed')
+            success = False
         finally:
             if fbooks:
                 fbooks.close()
-
+        if not success:
+            return False
         fverse = None
         try:
             fverse = open(versesfile, 'r')
@@ -104,6 +107,14 @@
             self.bibledb.save_verses()
         except:
             log.exception(u'Loading verses from file failed')
+            success = False
         finally:
             if fverse:
                 fverse.close()
+        if not self.loadbible:
+            dialogobject.incrementProgressBar(u'Import canceled!')
+            dialogobject.ImportProgressBar.setValue(
+                dialogobject.ImportProgressBar.maximum())
+            return False
+        else:
+            return success

=== modified file 'openlp/plugins/bibles/lib/bibleOSISimpl.py'
--- openlp/plugins/bibles/lib/bibleOSISimpl.py	2009-12-24 18:03:49 +0000
+++ openlp/plugins/bibles/lib/bibleOSISimpl.py	2009-12-27 22:35:24 +0000
@@ -91,6 +91,7 @@
         """
         Stops the import of the Bible.
         """
+        log.debug('Stopping import!')
         self.loadbible = False
 
     def load_data(self, osisfile_record, dialogobject=None):
@@ -116,19 +117,23 @@
             if detect_file:
                 detect_file.close()
         osis = None
+        success = True
         try:
             osis = codecs.open(osisfile_record, u'r', details['encoding'])
             last_chapter = 0
             testament = 1
             db_book = None
             for file_record in osis:
+                if not self.loadbible:
+                    break
                 match = self.verse_regex.search(file_record)
                 if match:
                     book = match.group(1)
                     chapter = int(match.group(2))
                     verse = int(match.group(3))
                     verse_text = match.group(4)
-                    if not db_book or db_book.name != book:
+                    if not db_book or db_book.name != self.books[book][0]:
+                        log.debug('New book: "%s"', self.books[book][0])
                         if book == u'Matt':
                             testament += 1
                         db_book = self.bibledb.create_book(
@@ -166,11 +171,19 @@
                         .replace(u'</div>', u'')
                     verse_text = self.spaces_regex.sub(u' ', verse_text)
                     self.bibledb.add_verse(db_book.id, chapter, verse, verse_text)
+                    Receiver.send_message(u'process_events')
             self.bibledb.save_verses()
             dialogobject.incrementProgressBar(u'Finishing import...')
         except:
             log.exception(u'Loading bible from OSIS file failed')
+            success = False
         finally:
             if osis:
                 osis.close()
-
+        if not self.loadbible:
+            dialogobject.incrementProgressBar(u'Import canceled!')
+            dialogobject.ImportProgressBar.setValue(
+                dialogobject.ImportProgressBar.maximum())
+            return False
+        else:
+            return success

=== modified file 'openlp/plugins/bibles/lib/bibleOpenSongimpl.py'
--- openlp/plugins/bibles/lib/bibleOpenSongimpl.py	2009-12-21 20:58:00 +0000
+++ openlp/plugins/bibles/lib/bibleOpenSongimpl.py	2009-12-27 22:35:24 +0000
@@ -89,15 +89,22 @@
             if detect_file:
                 detect_file.close()
         opensong_bible = None
+        success = True
         try:
             opensong_bible = codecs.open(bible_file, u'r', details['encoding'])
             opensong = objectify.parse(opensong_bible)
             bible = opensong.getroot()
             for book in bible.b:
+                if not self.loadbible:
+                    break
                 dbbook = self.bibledb.create_book(book.attrib[u'n'],
                     book.attrib[u'n'][:4])
                 for chapter in book.c:
+                    if not self.loadbible:
+                        break
                     for verse in chapter.v:
+                        if not self.loadbible:
+                            break
                         self.bibledb.add_verse(dbbook.id, chapter.attrib[u'n'],
                             verse.attrib[u'n'], verse.text)
                         Receiver.send_message(u'process_events')
@@ -106,7 +113,15 @@
                     self.bibledb.save_verses()
         except:
             log.exception(u'Loading bible from OpenSong file failed')
+            success = False
         finally:
             if opensong_bible:
                 opensong_bible.close()
+        if not self.loadbible:
+            dialogobject.incrementProgressBar(u'Import canceled!')
+            dialogobject.ImportProgressBar.setValue(
+                dialogobject.ImportProgressBar.maximum())
+            return False
+        else:
+            return success
 

=== modified file 'openlp/plugins/bibles/lib/manager.py'
--- openlp/plugins/bibles/lib/manager.py	2009-12-21 20:58:00 +0000
+++ openlp/plugins/bibles/lib/manager.py	2009-12-27 22:35:24 +0000
@@ -155,7 +155,7 @@
                         fbibles.close()
         log.debug(u'Bible Initialised')
 
-    def process_dialog(self, dialogobject):
+    def set_process_dialog(self, dialogobject):
         """
         Sets the reference to the dialog with the progress bar on it.
 
@@ -246,8 +246,7 @@
             self.bible_db_cache[biblename] = nbible
             # Create the loader and pass in the database
             bcsv = BibleCSVImpl(nbible)
-            bcsv.load_data(booksfile, versefile, self.dialogobject)
-            return True
+            return bcsv.load_data(booksfile, versefile, self.dialogobject)
         else:
             log.debug(u'register_csv_file_bible %s not created already exists',
                 biblename)
@@ -268,9 +267,8 @@
             # Cache the database for use later
             self.bible_db_cache[biblename] = nbible
             # Create the loader and pass in the database
-            bcsv = BibleOSISImpl(self.biblePath, nbible)
-            bcsv.load_data(osisfile, self.dialogobject)
-            return True
+            bosis = BibleOSISImpl(self.biblePath, nbible)
+            return bosis.load_data(osisfile, self.dialogobject)
         else:
             log.debug(
                 u'register_OSIS_file_bible %s, %s not created already exists',


Follow ups