From 757933c448480daa964e6944c42f996ee768adfc Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 18 Apr 2011 20:03:41 +0200 Subject: [PATCH] clean ups --- openlp/plugins/songs/forms/songimportform.py | 4 +--- openlp/plugins/songs/lib/ewimport.py | 14 +++++++------- openlp/plugins/songs/lib/olp1import.py | 10 ++++------ openlp/plugins/songs/lib/olpimport.py | 4 ++-- openlp/plugins/songs/lib/opensongimport.py | 4 ++-- openlp/plugins/songs/lib/songbeamerimport.py | 16 ++++++---------- openlp/plugins/songs/lib/songshowplusimport.py | 1 - openlp/plugins/songs/lib/wowimport.py | 2 +- 8 files changed, 23 insertions(+), 32 deletions(-) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 36fdf0181..73fa7c79d 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -740,9 +740,7 @@ class SongImportForm(OpenLPWizard): importer = self.plugin.importSongs(SongFormat.FoilPresenter, filenames=self.getListOfFiles(self.foilPresenterFileListWidget) ) - test = importer.do_import() - if isinstance(test, bool): - raise received_boolean + importer.do_import() if importer.stop_import_flag: self.progressLabel.setText(translate('SongsPlugin.SongImportForm', 'Song import has been cancelled.')) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 85a0b88c2..784558c5b 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -143,12 +143,12 @@ class EasyWorshipSongImport(SongImport): # 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): - return False + return if not os.path.isfile(import_source_mb): - return False + return db_size = os.path.getsize(self.import_source) if db_size < 0x800: - return False + return db_file = open(self.import_source, 'rb') self.memo_file = open(import_source_mb, 'rb') # Don't accept files that are clearly not paradox files @@ -157,7 +157,7 @@ class EasyWorshipSongImport(SongImport): if header_size != 0x800 or block_size < 1 or block_size > 4: db_file.close() self.memo_file.close() - return False + return # Take a stab at how text is encoded self.encoding = u'cp1252' db_file.seek(106) @@ -184,7 +184,7 @@ class EasyWorshipSongImport(SongImport): self.encoding = u'cp874' self.encoding = retrieve_windows_encoding(self.encoding) if not self.encoding: - return False + return # There does not appear to be a _reliable_ way of getting the number # of songs/records, so let's use file blocks for measuring progress. total_blocks = (db_size - header_size) / (block_size * 1024) @@ -242,7 +242,7 @@ class EasyWorshipSongImport(SongImport): if copy: self.copyright += u', ' self.copyright += \ - unicode(translate('SongsPlugin.ImportWizardForm', + unicode(translate('SongsPlugin.EasyWorshipSongImport', 'Administered by %s')) % admin if ccli: self.ccli_number = ccli @@ -269,7 +269,7 @@ class EasyWorshipSongImport(SongImport): self.memo_file.close() def find_field(self, field_name): - return [i for i, x in enumerate(self.field_descs) \ + return [i for i, x in enumerate(self.field_descs) if x.name == field_name][0] def set_record_struct(self, field_descs): diff --git a/openlp/plugins/songs/lib/olp1import.py b/openlp/plugins/songs/lib/olp1import.py index 26fdf19a9..b282a8dd7 100644 --- a/openlp/plugins/songs/lib/olp1import.py +++ b/openlp/plugins/songs/lib/olp1import.py @@ -64,16 +64,14 @@ class OpenLP1SongImport(SongImport): """ if not self.import_source.endswith(u'.olp'): self.log_error(self.import_source, - translate('SongsPlugin.OpenLP1SongImport', 'The file you ' - 'were trying to import is not a valid openlp.org 1.x song ' - 'database.')) + translate('SongsPlugin.OpenLP1SongImport', + 'Not a valid openlp.org 1.x song database.')) return encoding = self.get_encoding() if not encoding: self.log_error(self.import_source, - translate('SongsPlugin.OpenLP1SongImport', 'The file you ' - 'were trying to import is not a valid openlp.org 1.x song ' - 'database.')) + translate('SongsPlugin.OpenLP1SongImport', + 'Not a valid openlp.org 1.x song database.')) return # Connect to the database connection = sqlite.connect(self.import_source, mode=0444, diff --git a/openlp/plugins/songs/lib/olpimport.py b/openlp/plugins/songs/lib/olpimport.py index c69e5ded0..bbfabce3e 100644 --- a/openlp/plugins/songs/lib/olpimport.py +++ b/openlp/plugins/songs/lib/olpimport.py @@ -102,8 +102,8 @@ class OpenLPSongImport(SongImport): """ if not self.import_source.endswith(u'.sqlite'): self.log_error(self.import_source, - translate('SongsPlugin.OpenLPSongImport', 'The file you were ' - 'trying to import is not a valid OpenLP 2.0 song database.')) + translate('SongsPlugin.OpenLPSongImport', + 'Not a valid OpenLP 2.0 song database.')) return engine = create_engine(self.import_source) source_meta = MetaData() diff --git a/openlp/plugins/songs/lib/opensongimport.py b/openlp/plugins/songs/lib/opensongimport.py index 7cff1522f..acf672ca0 100644 --- a/openlp/plugins/songs/lib/opensongimport.py +++ b/openlp/plugins/songs/lib/opensongimport.py @@ -255,7 +255,7 @@ class OpenSongImport(SongImport): lines = u'\n'.join(verses[verse_tag][verse_num][inst]) self.add_verse(lines, verse_def) # figure out the presentation order, if present - if u'presentation' in fields and root.presentation != u'': + if u'presentation' in fields and root.presentation: order = unicode(root.presentation) # We make all the tags in the lyrics lower case, so match that here # and then split into a list on the whitespace @@ -266,7 +266,7 @@ class OpenSongImport(SongImport): verse_tag = match.group(1) verse_num = match.group(2) if not len(verse_tag): - verse_tag = u'v' + verse_tag = VerseType.Tags[VerseType.Verse] else: # Assume it's no.1 if there are no digits verse_tag = verse_def diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index 2813240a4..5a8ee9ca8 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -73,11 +73,6 @@ class SongBeamerImport(SongImport): Initialise the Song Beamer importer. """ SongImport.__init__(self, manager, **kwargs) - self.log_error(u'/home/andreas/1.sng', u'aaaa') - self.log_error(u'/home/andreas/4.sng', u'asdfsdfsadfds') - self.log_error(u'/home/andreas/3.sng', u'asdf3q4') - self.log_error(u'/home/andreas/2.sng', u'sadfasdf') - self.log_error(u'/home/andreas/รค.sng', u'kqwjw32w3') def do_import(self): """ @@ -238,11 +233,12 @@ class SongBeamerImport(SongImport): pass elif tag_val[0] == u'#Rights': song_book_pub = tag_val[1] - elif tag_val[0] == u'#Songbook': - book_num = tag_val[1].split(' / ') - self.song_book_name = book_num[0] - if len(book_num) == book_num[1]: - self.song_number = u'' + elif tag_val[0] == u'#Songbook' or tag_val[0] == u'#SongBook': + book_data = tag_val[1].split(u'/') + self.song_book_name = book_data[0].strip() + if len(book_data) == 2: + number = book_data[1].strip() + self.song_number = number if number.isdigit() else u'' elif tag_val[0] == u'#Speed': pass elif tag_val[0] == u'Tempo': diff --git a/openlp/plugins/songs/lib/songshowplusimport.py b/openlp/plugins/songs/lib/songshowplusimport.py index 27620d11a..9fdc5804a 100644 --- a/openlp/plugins/songs/lib/songshowplusimport.py +++ b/openlp/plugins/songs/lib/songshowplusimport.py @@ -101,7 +101,6 @@ class SongShowPlusImport(SongImport): return self.import_wizard.progressBar.setMaximum(len(self.import_source)) for file in self.import_source: - author = u'' self.sspVerseOrderList = [] otherCount = 0 otherList = {} diff --git a/openlp/plugins/songs/lib/wowimport.py b/openlp/plugins/songs/lib/wowimport.py index 661e6787d..f5293a53c 100644 --- a/openlp/plugins/songs/lib/wowimport.py +++ b/openlp/plugins/songs/lib/wowimport.py @@ -134,7 +134,7 @@ class WowImport(SongImport): songData.seek(3, os.SEEK_CUR) # Blocks are seperated by 2 bytes, skip them, but not if # this is the last block! - if (block + 1) < no_of_blocks: + if block + 1 < no_of_blocks: songData.seek(2, os.SEEK_CUR) self.add_verse(block_text, block_type) # Now to extract the author