From 237cabfeff8744971b7dd877cd6073025ccd9df1 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 15 Apr 2011 16:10:31 +0200 Subject: [PATCH] only try to import a database when it is a v1 database, clean ups --- openlp/plugins/songs/forms/songimportform.py | 5 +- openlp/plugins/songs/lib/olp1import.py | 4 +- openlp/plugins/songs/lib/songbeamerimport.py | 106 ++++++++++--------- 3 files changed, 58 insertions(+), 57 deletions(-) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 468d2f341..7666d8f52 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -459,10 +459,7 @@ class SongImportForm(OpenLPWizard): """ Return a list of file from the listbox """ - files = [] - for row in range(0, listbox.count()): - files.append(unicode(listbox.item(row).text())) - return files + return [unicode(listbox.item(i).text()) for i in range(listbox.count())] def removeSelectedItems(self, listbox): """ diff --git a/openlp/plugins/songs/lib/olp1import.py b/openlp/plugins/songs/lib/olp1import.py index 232b17db0..61cdcbe06 100644 --- a/openlp/plugins/songs/lib/olp1import.py +++ b/openlp/plugins/songs/lib/olp1import.py @@ -61,10 +61,12 @@ class OpenLP1SongImport(SongImport): """ Run the import for an openlp.org 1.x song database. """ - # Connect to the database + if not self.import_source.endswith(u'.olp'): + return False encoding = self.get_encoding() if not encoding: return False + # Connect to the database connection = sqlite.connect(self.import_source, mode=0444, encoding=(encoding, 'replace')) cursor = connection.cursor() diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index 5cd2c4329..f90c05965 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -78,58 +78,60 @@ class SongBeamerImport(SongImport): """ Receive a single file or a list of files to import. """ - if isinstance(self.import_source, list): - self.import_wizard.progressBar.setMaximum( - len(self.import_source)) - for file in self.import_source: - # TODO: check that it is a valid SongBeamer file - self.set_defaults() - self.current_verse = u'' - self.current_verse_type = VerseType.Tags[VerseType.Verse] - read_verses = False - file_name = os.path.split(file)[1] - self.import_wizard.incrementProgressBar( - WizardStrings.ImportingType % file_name, 0) - if os.path.isfile(file): - detect_file = open(file, u'r') - details = chardet.detect(detect_file.read(2048)) - detect_file.close() - infile = codecs.open(file, u'r', details['encoding']) - songData = infile.readlines() - infile.close() - else: - return False - self.title = file_name.split('.sng')[0] - read_verses = False - for line in songData: - # Just make sure that the line is of the type 'Unicode'. - line = unicode(line).strip() - if line.startswith(u'#') and not read_verses: - self.parse_tags(line) - elif line.startswith(u'---'): - if self.current_verse: - self.replace_html_tags() - self.add_verse(self.current_verse, - self.current_verse_type) - self.current_verse = u'' - self.current_verse_type = VerseType.Tags[VerseType.Verse] - read_verses = True - verse_start = True - elif read_verses: - if verse_start: - verse_start = False - if not self.check_verse_marks(line): - self.current_verse = line + u'\n' - else: - self.current_verse += line + u'\n' - if self.current_verse: - self.replace_html_tags() - self.add_verse(self.current_verse, self.current_verse_type) - if self.check_complete(): - self.finish() - self.import_wizard.incrementProgressBar( - WizardStrings.ImportingType % file_name) - return True + self.import_wizard.progressBar.setMaximum(len(self.import_source)) + if not isinstance(self.import_source, list): + return False + for file in self.import_source: + # TODO: check that it is a valid SongBeamer file + if self.stop_import_flag: + return False + self.set_defaults() + self.current_verse = u'' + self.current_verse_type = VerseType.Tags[VerseType.Verse] + read_verses = False + file_name = os.path.split(file)[1] + self.import_wizard.incrementProgressBar( + WizardStrings.ImportingType % file_name, 0) + if os.path.isfile(file): + detect_file = open(file, u'r') + details = chardet.detect(detect_file.read(2048)) + detect_file.close() + infile = codecs.open(file, u'r', details['encoding']) + songData = infile.readlines() + infile.close() + else: + return False + self.title = file_name.split('.sng')[0] + read_verses = False + for line in songData: + # Just make sure that the line is of the type 'Unicode'. + line = unicode(line).strip() + if line.startswith(u'#') and not read_verses: + self.parse_tags(line) + elif line.startswith(u'---'): + if self.current_verse: + self.replace_html_tags() + self.add_verse(self.current_verse, + self.current_verse_type) + self.current_verse = u'' + self.current_verse_type = VerseType.Tags[VerseType.Verse] + read_verses = True + verse_start = True + elif read_verses: + if verse_start: + verse_start = False + if not self.check_verse_marks(line): + self.current_verse = line + u'\n' + else: + self.current_verse += line + u'\n' + if self.current_verse: + self.replace_html_tags() + self.add_verse(self.current_verse, self.current_verse_type) + if self.check_complete(): + self.finish() + self.import_wizard.incrementProgressBar( + WizardStrings.ImportingType % file_name) + return True def replace_html_tags(self): """