~raoul-snyman/openlp/python3

« back to all changes in this revision

Viewing changes to openlp/plugins/songs/lib/ewimport.py

  • Committer: Raoul Snyman
  • Date: 2013-04-03 06:51:39 UTC
  • Revision ID: raoul.snyman@saturnlaboratories.co.za-20130403065139-9qhs0xmlrcef4n2h
trying to migrate to py3k

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from openlp.core.lib import translate
39
39
from openlp.plugins.songs.lib import VerseType
40
40
from openlp.plugins.songs.lib import retrieve_windows_encoding, strip_rtf
41
 
from songimport import SongImport
 
41
from .songimport import SongImport
42
42
 
43
43
RTF_STRIPPING_REGEX = re.compile(r'\{\\tx[^}]*\}')
44
44
# regex: at least two newlines, can have spaces between them
81
81
            self.memoFile.close()
82
82
            return
83
83
        # Take a stab at how text is encoded
84
 
        self.encoding = u'cp1252'
 
84
        self.encoding = 'cp1252'
85
85
        db_file.seek(106)
86
86
        code_page, = struct.unpack('<h', db_file.read(2))
87
87
        if code_page == 852:
88
 
            self.encoding = u'cp1250'
 
88
            self.encoding = 'cp1250'
89
89
        # The following codepage to actual encoding mappings have not been
90
90
        # observed, but merely guessed. Actual example files are needed.
91
91
        elif code_page == 737:
92
 
            self.encoding = u'cp1253'
 
92
            self.encoding = 'cp1253'
93
93
        elif code_page == 775:
94
 
            self.encoding = u'cp1257'
 
94
            self.encoding = 'cp1257'
95
95
        elif code_page == 855:
96
 
            self.encoding = u'cp1251'
 
96
            self.encoding = 'cp1251'
97
97
        elif code_page == 857:
98
 
            self.encoding = u'cp1254'
 
98
            self.encoding = 'cp1254'
99
99
        elif code_page == 866:
100
 
            self.encoding = u'cp1251'
 
100
            self.encoding = 'cp1251'
101
101
        elif code_page == 869:
102
 
            self.encoding = u'cp1253'
 
102
            self.encoding = 'cp1253'
103
103
        elif code_page == 862:
104
 
            self.encoding = u'cp1255'
 
104
            self.encoding = 'cp1255'
105
105
        elif code_page == 874:
106
 
            self.encoding = u'cp874'
 
106
            self.encoding = 'cp874'
107
107
        self.encoding = retrieve_windows_encoding(self.encoding)
108
108
        if not self.encoding:
109
109
            return
125
125
        # Pick out the field description indexes we will need
126
126
        try:
127
127
            success = True
128
 
            fi_title = self.findField(u'Title')
129
 
            fi_author = self.findField(u'Author')
130
 
            fi_copy = self.findField(u'Copyright')
131
 
            fi_admin = self.findField(u'Administrator')
132
 
            fi_words = self.findField(u'Words')
133
 
            fi_ccli = self.findField(u'Song Number')
 
128
            fi_title = self.findField('Title')
 
129
            fi_author = self.findField('Author')
 
130
            fi_copy = self.findField('Copyright')
 
131
            fi_admin = self.findField('Administrator')
 
132
            fi_words = self.findField('Words')
 
133
            fi_ccli = self.findField('Song Number')
134
134
        except IndexError:
135
135
            # This is the wrong table
136
136
            success = False
159
159
                    self.copyright = copy
160
160
                if admin:
161
161
                    if copy:
162
 
                        self.copyright += u', '
 
162
                        self.copyright += ', '
163
163
                    self.copyright += translate('SongsPlugin.EasyWorshipSongImport', 'Administered by %s') % admin
164
164
                if ccli:
165
165
                    self.ccliNumber = ccli
166
166
                if authors:
167
167
                    # Split up the authors
168
 
                    author_list = authors.split(u'/')
169
 
                    if len(author_list) < 2:
170
 
                        author_list = authors.split(u';')
171
 
                    if len(author_list) < 2:
172
 
                        author_list = authors.split(u',')
 
168
                    author_list = authors.split('/')
 
169
                    if len(author_list) < 2:
 
170
                        author_list = authors.split(';')
 
171
                    if len(author_list) < 2:
 
172
                        author_list = authors.split(',')
173
173
                    for author_name in author_list:
174
174
                        self.addAuthor(author_name.strip())
175
175
                if words:
183
183
                        verse = verse.strip()
184
184
                        if not verse:
185
185
                            continue
186
 
                        verse_split = verse.split(u'\n', 1)
 
186
                        verse_split = verse.split('\n', 1)
187
187
                        first_line_is_tag = False
188
188
                        # EW tags: verse, chorus, pre-chorus, bridge, tag,
189
189
                        # intro, ending, slide
190
 
                        for type in VerseType.Names+[u'tag', u'slide']:
 
190
                        for type in VerseType.Names+['tag', 'slide']:
191
191
                            type = type.lower()
192
192
                            ew_tag = verse_split[0].strip().lower()
193
193
                            if ew_tag.startswith(type):
194
194
                                verse_type = type[0]
195
 
                                if type == u'tag' or type == u'slide':
 
195
                                if type == 'tag' or type == 'slide':
196
196
                                    verse_type = VerseType.Tags[VerseType.Other]
197
197
                                first_line_is_tag = True
198
198
                                number_found = False
205
205
                                        number_found = True
206
206
                                    match = NOTE_REGEX.search(ew_tag)
207
207
                                    if match:
208
 
                                        self.comments += ew_tag + u'\n'
 
208
                                        self.comments += ew_tag + '\n'
209
209
                                if not number_found:
210
 
                                    verse_type += u'1'
 
210
                                    verse_type += '1'
211
211
                                break
212
212
                        self.addVerse(
213
213
                            verse_split[-1].strip() \
214
214
                                if first_line_is_tag else verse,
215
215
                            verse_type)
216
216
                if len(self.comments) > 5:
217
 
                    self.comments += unicode(translate('SongsPlugin.EasyWorshipSongImport',
 
217
                    self.comments += str(translate('SongsPlugin.EasyWorshipSongImport',
218
218
                        '\n[above are Song Tags with notes imported from EasyWorship]'))
219
219
                if self.stopImportFlag:
220
220
                    break
290
290
                self.memoFile.seek(8, os.SEEK_CUR)
291
291
            elif memo_block_type == 3:
292
292
                if sub_block > 63:
293
 
                    return u''
 
293
                    return ''
294
294
                self.memoFile.seek(11 + (5 * sub_block), os.SEEK_CUR)
295
295
                sub_block_start, = struct.unpack('B', self.memoFile.read(1))
296
296
                self.memoFile.seek(block_start + (sub_block_start * 16))
297
297
            else:
298
 
                return u''
 
298
                return ''
299
299
            return self.memoFile.read(blob_size)
300
300
        else:
301
301
            return 0