From e9c56b6cc53cf60f0552d2cf2cef27b59471bdad Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 28 Jun 2013 22:16:44 +0100 Subject: [PATCH] Corrected if statment and added enumeration class. --- openlp/plugins/songs/lib/ewimport.py | 51 ++++++++++--------- .../openlp_plugins/songs/test_ewimport.py | 12 +++-- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 287310cb3..2f7681b7e 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -54,6 +54,19 @@ class FieldDescEntry: self.size = size +class FieldType(object): + """ + An enumeration class for different field types that can be expected in an EasyWorship song file. + """ + String = 1 + Int16 = 3 + Int32 = 4 + Logical = 9 + Memo = 0x0c + Blob = 0x0d + Timestamp = 0x15 + + class EasyWorshipSongImport(SongImport): """ The :class:`EasyWorshipSongImport` class provides OpenLP with the @@ -65,7 +78,7 @@ class EasyWorshipSongImport(SongImport): def doImport(self): # Open the DB and MB files if they exist import_source_mb = self.import_source.replace('.DB', '.MB') - if not (os.path.isfile(self.import_source) or os.path.isfile(import_source_mb)): + if not (os.path.isfile(self.import_source) or not os.path.isfile(import_source_mb)): return db_size = os.path.getsize(self.import_source) if db_size < 0x800: @@ -231,26 +244,19 @@ class EasyWorshipSongImport(SongImport): # Begin with empty field struct list fsl = ['>'] for field_desc in field_descs: - if field_desc.field_type == 1: - # string + if field_desc.field_type == FieldType.String: fsl.append('%ds' % field_desc.size) - elif field_desc.field_type == 3: - # 16-bit int + elif field_desc.field_type == FieldType.Int16: fsl.append('H') - elif field_desc.field_type == 4: - # 32-bit int + elif field_desc.field_type == FieldType.Int32: fsl.append('I') - elif field_desc.field_type == 9: - # Logical + elif field_desc.field_type == FieldType.Logical: fsl.append('B') - elif field_desc.field_type == 0x0c: - # Memo + elif field_desc.field_type == FieldType.Memo: fsl.append('%ds' % field_desc.size) - elif field_desc.field_type == 0x0d: - # Blob + elif field_desc.field_type == FieldType.Blob: fsl.append('%ds' % field_desc.size) - elif field_desc.field_type == 0x15: - # Timestamp + elif field_desc.field_type == FieldType.Timestamp: fsl.append('Q') else: fsl.append('%ds' % field_desc.size) @@ -267,20 +273,15 @@ class EasyWorshipSongImport(SongImport): elif field == 0: return None # Format the field depending on the field type - if field_desc.field_type == 1: - # string + if field_desc.field_type == FieldType.String: return field.rstrip('\0').decode(self.encoding) - elif field_desc.field_type == 3: - # 16-bit int + elif field_desc.field_type == FieldType.Int16: return field ^ 0x8000 - elif field_desc.field_type == 4: - # 32-bit int + elif field_desc.field_type == FieldType.Int32: return field ^ 0x80000000 - elif field_desc.field_type == 9: - # Logical + elif field_desc.field_type == FieldType.Logical: return (field ^ 0x80 == 1) - elif field_desc.field_type == 0x0c or field_desc.field_type == 0x0d: - # Memo or Blob + elif field_desc.field_type == FieldType.Memo or field_desc.field_type == FieldType.Blob: block_start, blob_size = struct.unpack_from('