← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/songs into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol-hush/openlp/songs into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~googol-hush/openlp/songs/+merge/57904

Hello,

- attempt to improve the song importers by allowing them to give feedback to the user.

My thoughts:
- a import fails for a generic reasons -> return False (so the default message "Your song import failed" is displayed)
- the reasons why the import failed is known (e. g. somebody tried to import a v1 bible with the v2 importer) -> return a messages to be displayed in the wizard
- import is successful -> return nothing

Once this is merged, I would write to the mailing list and ask people to look at the importers again and adapt them where possible.
-- 
https://code.launchpad.net/~googol-hush/openlp/songs/+merge/57904
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/songs into lp:openlp.
=== modified file 'openlp/core/ui/wizard.py'
--- openlp/core/ui/wizard.py	2011-03-24 19:04:02 +0000
+++ openlp/core/ui/wizard.py	2011-04-15 16:39:31 +0000
@@ -132,6 +132,7 @@
         self.progressLayout.addWidget(self.progressLabel)
         self.progressBar = QtGui.QProgressBar(self.progressPage)
         self.progressBar.setObjectName(u'progressBar')
+        self.progressLabel.setWordWrap(True)
         self.progressLayout.addWidget(self.progressBar)
         self.addPage(self.progressPage)
 

=== modified file 'openlp/plugins/songs/forms/songimportform.py'
--- openlp/plugins/songs/forms/songimportform.py	2011-04-11 14:34:14 +0000
+++ openlp/plugins/songs/forms/songimportform.py	2011-04-15 16:39:31 +0000
@@ -459,10 +459,7 @@
         """
         Return a list of file from the listbox
         """
-        files = []
-        for row in range(0, listbox.count()):
-            files.append(unicode(listbox.item(row).text()))
-        return files
+        return [unicode(listbox.item(i).text()) for i in range(listbox.count())]
 
     def removeSelectedItems(self, listbox):
         """
@@ -743,12 +740,15 @@
             importer = self.plugin.importSongs(SongFormat.FoilPresenter,
                 filenames=self.getListOfFiles(self.foilPresenterFileListWidget)
             )
-        if importer.do_import():
+        message = importer.do_import()
+        if isinstance(message, bool) and not message:
+            self.progressLabel.setText(self.progressLabel.setText(
+                translate('SongsPlugin.SongImportForm',
+                'Your song import failed.')))
+        elif not isinstance(message, bool) and message:
+            self.progressLabel.setText(message)
+        else:
             self.progressLabel.setText(WizardStrings.FinishedImport)
-        else:
-            self.progressLabel.setText(
-                translate('SongsPlugin.SongImportForm',
-                'Your song import failed.'))
 
     def addFileSelectItem(self, prefix, obj_prefix=None, can_disable=False,
         single_select=False):

=== modified file 'openlp/plugins/songs/lib/cclifileimport.py'
--- openlp/plugins/songs/lib/cclifileimport.py	2011-04-03 13:35:58 +0000
+++ openlp/plugins/songs/lib/cclifileimport.py	2011-04-15 16:39:31 +0000
@@ -93,7 +93,6 @@
                 song_count += 1
             if self.stop_import_flag:
                 return False
-        return True
 
     def do_import_usr_file(self, textList):
         """

=== modified file 'openlp/plugins/songs/lib/easislidesimport.py'
--- openlp/plugins/songs/lib/easislidesimport.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/easislidesimport.py	2011-04-15 16:39:31 +0000
@@ -75,7 +75,6 @@
                 return False
             elif self.commit:
                 self.finish()
-        return True
 
     def _parse_song(self, song):
         self._success = True

=== modified file 'openlp/plugins/songs/lib/ewimport.py'
--- openlp/plugins/songs/lib/ewimport.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/ewimport.py	2011-04-15 16:39:31 +0000
@@ -273,7 +273,8 @@
                 self.import_wizard.incrementProgressBar(u'')
         db_file.close()
         self.memo_file.close()
-        return success
+        if not success:
+            return False
 
     def find_field(self, field_name):
         return [i for i, x in enumerate(self.field_descs) \

=== modified file 'openlp/plugins/songs/lib/foilpresenterimport.py'
--- openlp/plugins/songs/lib/foilpresenterimport.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/foilpresenterimport.py	2011-04-15 16:39:31 +0000
@@ -131,7 +131,6 @@
                     log.debug(u'File could not be imported: %s' % file_path)
             except etree.XMLSyntaxError:
                 log.exception(u'XML syntax error in file %s' % file_path)
-        return True
 
 
 class FoilPresenter(object):
@@ -235,7 +234,6 @@
         self._process_topics(foilpresenterfolie, song)
         clean_song(self.manager, song)
         self.manager.save_object(song)
-        return song.id
 
     def _child(self, element):
         """

=== modified file 'openlp/plugins/songs/lib/olp1import.py'
--- openlp/plugins/songs/lib/olp1import.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/olp1import.py	2011-04-15 16:39:31 +0000
@@ -32,6 +32,7 @@
 from chardet.universaldetector import UniversalDetector
 import sqlite
 
+from openlp.core.lib import translate
 from openlp.core.ui.wizard import WizardStrings
 from openlp.plugins.songs.lib import retrieve_windows_encoding
 from songimport import SongImport
@@ -61,10 +62,14 @@
         """
         Run the import for an openlp.org 1.x song database.
         """
-        # Connect to the database
+        if not self.import_source.endswith(u'.olp'):
+            return translate('SongsPlugin.OpenLP1SongImport', 'The file you '
+                'were trying to import is not a valid openlp.org 1.x song '
+                'database.')
         encoding = self.get_encoding()
         if not encoding:
             return False
+        # Connect to the database
         connection = sqlite.connect(self.import_source, mode=0444,
             encoding=(encoding, 'replace'))
         cursor = connection.cursor()

=== modified file 'openlp/plugins/songs/lib/olpimport.py'
--- openlp/plugins/songs/lib/olpimport.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/olpimport.py	2011-04-15 16:39:31 +0000
@@ -100,6 +100,9 @@
         """
         Run the import for an OpenLP version 2 song database.
         """
+        if not self.import_source.endswith(u'.sqlite'):
+            return translate('SongsPlugin.OpenLPSongImport', 'The file you were'
+            ' trying to import is not a valid OpenLP 2.0 song database.')
         engine = create_engine(self.import_source)
         source_meta = MetaData()
         source_meta.reflect(engine)
@@ -217,4 +220,3 @@
             if self.stop_import_flag:
                 return False
         engine.dispose()
-        return True

=== modified file 'openlp/plugins/songs/lib/oooimport.py'
--- openlp/plugins/songs/lib/oooimport.py	2011-04-11 14:17:43 +0000
+++ openlp/plugins/songs/lib/oooimport.py	2011-04-15 16:39:31 +0000
@@ -56,13 +56,11 @@
         self.process_started = False
 
     def do_import(self):
-        self.stop_import_flag = False
-        self.import_wizard.progressBar.setMaximum(0)
         self.start_ooo()
+        self.import_wizard.progressBar.setMaximum(self.import_source)
         for filename in self.import_source:
             if self.stop_import_flag:
-                self.import_wizard.incrementProgressBar(u'Import cancelled', 0)
-                return
+                return False
             filename = unicode(filename)
             if os.path.isfile(filename):
                 self.open_ooo_file(filename)
@@ -70,9 +68,6 @@
                     self.process_ooo_document()
                     self.close_ooo_file()
         self.close_ooo()
-        self.import_wizard.progressBar.setMaximum(1)
-        self.import_wizard.incrementProgressBar(u'', 1)
-        return True
 
     def process_ooo_document(self):
         """

=== modified file 'openlp/plugins/songs/lib/openlyricsimport.py'
--- openlp/plugins/songs/lib/openlyricsimport.py	2011-04-12 09:55:02 +0000
+++ openlp/plugins/songs/lib/openlyricsimport.py	2011-04-15 16:39:31 +0000
@@ -71,4 +71,3 @@
                     log.debug(u'File could not be imported: %s' % file_path)
             except etree.XMLSyntaxError:
                 log.exception(u'XML syntax error in file %s' % file_path)
-        return True

=== modified file 'openlp/plugins/songs/lib/opensongimport.py'
--- openlp/plugins/songs/lib/opensongimport.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/opensongimport.py	2011-04-15 16:39:31 +0000
@@ -163,7 +163,8 @@
                 else:
                     success = False
                     break
-        return success
+        if not success:
+            return False
 
     def do_import_file(self, file):
         """

=== modified file 'openlp/plugins/songs/lib/sofimport.py'
--- openlp/plugins/songs/lib/sofimport.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/sofimport.py	2011-04-15 16:39:31 +0000
@@ -89,7 +89,7 @@
         while paragraphs.hasMoreElements():
             if self.stop_import_flag:
                 self.import_wizard.incrementProgressBar(u'Import cancelled', 0)
-                return
+                return False
             paragraph = paragraphs.nextElement()
             if paragraph.supportsService("com.sun.star.text.Paragraph"):
                 self.process_paragraph(paragraph)

=== modified file 'openlp/plugins/songs/lib/songbeamerimport.py'
--- openlp/plugins/songs/lib/songbeamerimport.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/songbeamerimport.py	2011-04-15 16:39:31 +0000
@@ -78,58 +78,59 @@
         """
         Receive a single file or a list of files to import.
         """
-        if isinstance(self.import_source, list):
-            self.import_wizard.progressBar.setMaximum(
-                len(self.import_source))
-            for file in self.import_source:
-                # TODO: check that it is a valid SongBeamer file
-                self.set_defaults()
-                self.current_verse = u''
-                self.current_verse_type = VerseType.Tags[VerseType.Verse]
-                read_verses = False
-                file_name = os.path.split(file)[1]
-                self.import_wizard.incrementProgressBar(
-                    WizardStrings.ImportingType % file_name, 0)
-                if os.path.isfile(file):
-                    detect_file = open(file, u'r')
-                    details = chardet.detect(detect_file.read(2048))
-                    detect_file.close()
-                    infile = codecs.open(file, u'r', details['encoding'])
-                    songData = infile.readlines()
-                    infile.close()
-                else:
-                    return False
-                self.title = file_name.split('.sng')[0]
-                read_verses = False
-                for line in songData:
-                    # Just make sure that the line is of the type 'Unicode'.
-                    line = unicode(line).strip()
-                    if line.startswith(u'#') and not read_verses:
-                        self.parse_tags(line)
-                    elif line.startswith(u'---'):
-                        if self.current_verse:
-                            self.replace_html_tags()
-                            self.add_verse(self.current_verse,
-                                self.current_verse_type)
-                            self.current_verse = u''
-                            self.current_verse_type = VerseType.Tags[VerseType.Verse]
-                        read_verses = True
-                        verse_start = True
-                    elif read_verses:
-                        if verse_start:
-                            verse_start = False
-                            if not self.check_verse_marks(line):
-                                self.current_verse = line + u'\n'
-                        else:
-                            self.current_verse += line + u'\n'
-                if self.current_verse:
-                    self.replace_html_tags()
-                    self.add_verse(self.current_verse, self.current_verse_type)
-                if self.check_complete():
-                    self.finish()
-                self.import_wizard.incrementProgressBar(
-                    WizardStrings.ImportingType % file_name)
-            return True
+        self.import_wizard.progressBar.setMaximum(len(self.import_source))
+        if not isinstance(self.import_source, list):
+            return False
+        for file in self.import_source:
+            # TODO: check that it is a valid SongBeamer file
+            if self.stop_import_flag:
+                return False
+            self.set_defaults()
+            self.current_verse = u''
+            self.current_verse_type = VerseType.Tags[VerseType.Verse]
+            read_verses = False
+            file_name = os.path.split(file)[1]
+            self.import_wizard.incrementProgressBar(
+                WizardStrings.ImportingType % file_name, 0)
+            if os.path.isfile(file):
+                detect_file = open(file, u'r')
+                details = chardet.detect(detect_file.read(2048))
+                detect_file.close()
+                infile = codecs.open(file, u'r', details['encoding'])
+                songData = infile.readlines()
+                infile.close()
+            else:
+                return False
+            self.title = file_name.split('.sng')[0]
+            read_verses = False
+            for line in songData:
+                # Just make sure that the line is of the type 'Unicode'.
+                line = unicode(line).strip()
+                if line.startswith(u'#') and not read_verses:
+                    self.parse_tags(line)
+                elif line.startswith(u'---'):
+                    if self.current_verse:
+                        self.replace_html_tags()
+                        self.add_verse(self.current_verse,
+                            self.current_verse_type)
+                        self.current_verse = u''
+                        self.current_verse_type = VerseType.Tags[VerseType.Verse]
+                    read_verses = True
+                    verse_start = True
+                elif read_verses:
+                    if verse_start:
+                        verse_start = False
+                        if not self.check_verse_marks(line):
+                            self.current_verse = line + u'\n'
+                    else:
+                        self.current_verse += line + u'\n'
+            if self.current_verse:
+                self.replace_html_tags()
+                self.add_verse(self.current_verse, self.current_verse_type)
+            if self.check_complete():
+                self.finish()
+            self.import_wizard.incrementProgressBar(
+                WizardStrings.ImportingType % file_name)
 
     def replace_html_tags(self):
         """

=== modified file 'openlp/plugins/songs/lib/songshowplusimport.py'
--- openlp/plugins/songs/lib/songshowplusimport.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/songshowplusimport.py	2011-04-15 16:39:31 +0000
@@ -107,7 +107,7 @@
                 self.import_wizard.incrementProgressBar(
                     WizardStrings.ImportingType % file_name, 0)
                 songData = open(file, 'rb')
-                while (1):
+                while True:
                     blockKey, = struct.unpack("I", songData.read(4))
                     # The file ends with 4 NUL's
                     if blockKey == 0:
@@ -173,7 +173,6 @@
                 self.finish()
                 self.import_wizard.incrementProgressBar(
                     WizardStrings.ImportingType % file_name)
-            return True
 
     def toOpenLPVerseTag(self, verseName, ignoreUnique=False):
         if verseName.find(" ") != -1:

=== modified file 'openlp/plugins/songs/lib/wowimport.py'
--- openlp/plugins/songs/lib/wowimport.py	2011-03-24 19:04:02 +0000
+++ openlp/plugins/songs/lib/wowimport.py	2011-04-15 16:39:31 +0000
@@ -156,4 +156,3 @@
                 self.finish()
                 self.import_wizard.incrementProgressBar(
                     WizardStrings.ImportingType % file_name)
-            return True


Follow ups