~raoul-snyman/openlp/python3

« back to all changes in this revision

Viewing changes to openlp/plugins/songs/lib/sundayplusimport.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:
35
35
from openlp.plugins.songs.lib.songimport import SongImport
36
36
 
37
37
HOTKEY_TO_VERSE_TYPE = {
38
 
    u'1': u'v1',
39
 
    u'2': u'v2',
40
 
    u'3': u'v3',
41
 
    u'4': u'v4',
42
 
    u'5': u'v5',
43
 
    u'6': u'v6',
44
 
    u'7': u'v7',
45
 
    u'8': u'v8',
46
 
    u'9': u'v9',
47
 
    u'C': u'c',
48
 
    u'+': u'b',
49
 
    u'Z': u'o'}
 
38
    '1': 'v1',
 
39
    '2': 'v2',
 
40
    '3': 'v3',
 
41
    '4': 'v4',
 
42
    '5': 'v5',
 
43
    '6': 'v6',
 
44
    '7': 'v7',
 
45
    '8': 'v8',
 
46
    '9': 'v9',
 
47
    'C': 'c',
 
48
    '+': 'b',
 
49
    'Z': 'o'}
50
50
 
51
51
class SundayPlusImport(SongImport):
52
52
    """
61
61
        Initialise the class.
62
62
        """
63
63
        SongImport.__init__(self, manager, **kwargs)
64
 
        self.encoding = u'us-ascii'
 
64
        self.encoding = 'us-ascii'
65
65
 
66
66
    def doImport(self):
67
67
        self.importWizard.progressBar.setMaximum(len(self.importSource))
87
87
 
88
88
    def parse(self, data, cell=False):
89
89
        if len(data) == 0 or data[0:1] != '[' or data[-1] != ']':
90
 
            self.logError(u'File is malformed')
 
90
            self.logError('File is malformed')
91
91
            return False
92
92
        i = 1
93
93
        verse_type = VerseType.Tags[VerseType.Verse]
144
144
                    elif name == 'Hotkey':
145
145
                        # Hotkey always appears after MARKER_NAME, so it
146
146
                        # effectively overrides MARKER_NAME, if present.
147
 
                        if len(value) and value in HOTKEY_TO_VERSE_TYPE.keys():
 
147
                        if len(value) and value in list(HOTKEY_TO_VERSE_TYPE.keys()):
148
148
                            verse_type = HOTKEY_TO_VERSE_TYPE[value]
149
149
                    if name == 'rtf':
150
150
                        value = self.unescape(value)
157
157
                        # only Public Domain, we treat this as special data:
158
158
                        # we remove that line and add data to specific field.
159
159
                        processed_lines = []
160
 
                        for i in xrange(len(lines)):
 
160
                        for i in range(len(lines)):
161
161
                            line = lines[i].strip()
162
 
                            if line[:3].lower() == u'ccl':
 
162
                            if line[:3].lower() == 'ccl':
163
163
                                m = re.search(r'[0-9]+', line)
164
164
                                if m:
165
165
                                    self.ccliNumber = int(m.group(0))
166
166
                                    continue
167
 
                            elif line.lower() == u'public domain':
168
 
                                self.copyright = u'Public Domain'
 
167
                            elif line.lower() == 'public domain':
 
168
                                self.copyright = 'Public Domain'
169
169
                                continue
170
170
                            processed_lines.append(line)
171
171
                        self.addVerse('\n'.join(processed_lines).strip(),
178
178
 
179
179
    def titleFromFilename(self, filename):
180
180
        title = os.path.split(filename)[1]
181
 
        if title.endswith(u'.ptf'):
 
181
        if title.endswith('.ptf'):
182
182
            title = title[:-4]
183
183
        # For some strange reason all example files names ended with 1-7.
184
 
        if title.endswith(u'1-7'):
 
184
        if title.endswith('1-7'):
185
185
            title = title[:-3]
186
 
        return title.replace(u'_', u' ')
 
186
        return title.replace('_', ' ')
187
187
 
188
188
    def decode(self, blob):
189
189
        while True:
190
190
            try:
191
 
                return unicode(blob, self.encoding)
 
191
                return str(blob, self.encoding)
192
192
            except:
193
193
                self.encoding = retrieve_windows_encoding()
194
194