~raoul-snyman/openlp/bug-1306950

« back to all changes in this revision

Viewing changes to openlp/plugins/songs/lib/importers/wordsofworship.py

  • Committer: Tim Bentley
  • Author(s): Tomas Groth
  • Date: 2014-11-07 21:44:09 UTC
  • mfrom: (2439.1.9 bugfixes4)
  • Revision ID: tim.bentley@gmail.com-20141107214409-j8ycof271bk601gq
Change duplicate check to pass int-string tuples to workers, to workaround bug #1388850, also added multiprocessing.freeze_support to __main__ to support multiprocessing in windows builds.
Try to fix DVD 0 track length by waiting. Fixes bug 1387293.
Fix for import of Words of Worship file, bug 1388768, added tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
        """
100
100
        Initialise the Words of Worship importer.
101
101
        """
102
 
        SongImport.__init__(self, manager, **kwargs)
 
102
        super(WordsOfWorshipImport, self).__init__(manager, **kwargs)
103
103
 
104
104
    def do_import(self):
105
105
        """
112
112
                    return
113
113
                self.set_defaults()
114
114
                song_data = open(source, 'rb')
115
 
                if song_data.read(19) != 'WoW File\nSong Words':
 
115
                if song_data.read(19).decode() != 'WoW File\nSong Words':
116
116
                    self.log_error(source,
117
117
                                   str(translate('SongsPlugin.WordsofWorshipSongImport',
118
 
                                                 'Invalid Words of Worship song file. Missing "Wow File\\nSong '
 
118
                                                 'Invalid Words of Worship song file. Missing "WoW File\\nSong '
119
119
                                                 'Words" header.')))
120
120
                    continue
121
121
                # Seek to byte which stores number of blocks in the song
122
122
                song_data.seek(56)
123
123
                no_of_blocks = ord(song_data.read(1))
124
124
                song_data.seek(66)
125
 
                if song_data.read(16) != 'CSongDoc::CBlock':
 
125
                if song_data.read(16).decode() != 'CSongDoc::CBlock':
126
126
                    self.log_error(source,
127
127
                                   str(translate('SongsPlugin.WordsofWorshipSongImport',
128
128
                                                 'Invalid Words of Worship song file. Missing "CSongDoc::CBlock" '
131
131
                # Seek to the beginning of the first block
132
132
                song_data.seek(82)
133
133
                for block in range(no_of_blocks):
 
134
                    skip_char_at_end = True
134
135
                    self.lines_to_read = ord(song_data.read(4)[:1])
135
136
                    block_text = ''
136
137
                    while self.lines_to_read:
137
138
                        self.line_text = str(song_data.read(ord(song_data.read(1))), 'cp1252')
138
 
                        song_data.seek(1, os.SEEK_CUR)
 
139
                        if skip_char_at_end:
 
140
                            skip_char = ord(song_data.read(1))
 
141
                            # Check if we really should skip a char. In some wsg files we shouldn't
 
142
                            if skip_char != 0:
 
143
                                song_data.seek(-1, os.SEEK_CUR)
 
144
                                skip_char_at_end = False
139
145
                        if block_text:
140
146
                            block_text += '\n'
141
147
                        block_text += self.line_text