Refactor exception handling

This commit is contained in:
Samuel Findlay 2012-06-06 00:12:19 +10:00
parent 2fb09b2462
commit 34de12040f
1 changed files with 37 additions and 42 deletions

View File

@ -88,11 +88,10 @@ class ZionWorxImport(SongImport):
'Error reading CSV file.')),
unicode(translate('SongsPlugin.ZionWorxImport',
'Line %d: %s' % (songs_reader.line_num, e))))
else:
return
num_records = len(records)
log.info(u'%s records found in CSV file' % num_records)
self.importWizard.progressBar.setMaximum(num_records)
try:
for index, record in enumerate(records, 1):
if self.stopImportFlag:
return
@ -100,19 +99,21 @@ class ZionWorxImport(SongImport):
try:
self.title = self._decode(record[u'Title1'])
if record[u'Title2']:
self.alternateTitle = self._decode(
record[u'Title2'])
self.alternateTitle = self._decode(record[u'Title2'])
self.parseAuthor(self._decode(record[u'Writer']))
self.addCopyright(self._decode(
record[u'Copyright']))
self.addCopyright(self._decode(record[u'Copyright']))
lyrics = self._decode(record[u'Lyrics'])
except UnicodeDecodeError, e:
self.logError(unicode(translate(
'SongsPlugin.ZionWorxImport',
'Decoding error.')),
'SongsPlugin.ZionWorxImport', 'Record %d' % index)),
unicode(translate('SongsPlugin.ZionWorxImport',
'Record %d: %s' % (index, e))))
else:
'Decoding error: %s' % e)))
continue
except TypeError, e:
self.logError(unicode(translate(
'SongsPlugin.ZionWorxImport', 'File not valid ZionWorx '
'CSV format.')), u'TypeError: %s' % e)
return
verse = u''
for line in lyrics.splitlines():
if line and not line.isspace():
@ -125,14 +126,8 @@ class ZionWorxImport(SongImport):
title = self.title
if not self.finish():
self.logError(unicode(translate(
'SongsPlugin.ZionWorxImport',
'Record %d' % index))
'SongsPlugin.ZionWorxImport', 'Record %d' % index))
+ (u': "' + title + u'"' if title else u''))
except TypeError, e:
self.logError(unicode(translate(
'SongsPlugin.ZionWorxImport',
'File not valid ZionWorx CSV format.')),
u'TypeError: %s' % e)
def _decode(self, str):
"""