From 6208587b939333766412500d6552f2394598ed99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Sat, 19 Feb 2011 22:34:51 +0100 Subject: [PATCH] foilpresenterimport - some changes --- openlp/core/ui/wizard.py | 1 + openlp/plugins/songs/forms/songimportform.py | 12 ++----- .../plugins/songs/lib/foilpresenterimport.py | 36 +++++++++---------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index 2960607e4..fc1edeecb 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -54,6 +54,7 @@ class WizardStrings(object): SoF = u'Songs of Fellowship' SSP = u'SongShow Plus' WoW = u'Words of Worship' + FP = u'Foilpresenter' # These strings should need a good reason to be retranslated elsewhere. FinishedImport = translate('OpenLP.Ui', 'Finished import.') FormatLabel = translate('OpenLP.Ui', 'Format:') diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index bc3e28a33..06de08a93 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -410,12 +410,8 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.FoilPresenter: if self.foilPresenterFileListWidget.count() == 0: - criticalErrorMessageBox( - translate('SongsPlugin.ImportWizardForm', - 'No Foilpresenter Files Selected'), - translate('SongsPlugin.ImportWizardForm', - 'You need to add at least one Foilpresenter ' - 'song file to import from.')) + critical_error_message_box(UiStrings.NFSp, + WizardStrings.YouSpecifyFile % WizardStrings.FP) self.foilPresenterAddButton.setFocus() return False return True @@ -613,9 +609,7 @@ class SongImportForm(OpenLPWizard): """ Get FoilPresenter song database files """ - self.getFiles( - translate('SongsPlugin.ImportWizardForm', - 'Select FoilPresenter Files'), + self.getFiles(WizardStrings.OpenTypeFile % WizardStrings.FP, self.foilPresenterFileListWidget, u'%s (*.foil)' % translate('SongsPlugin.ImportWizardForm', 'Foilpresenter Song Files') diff --git a/openlp/plugins/songs/lib/foilpresenterimport.py b/openlp/plugins/songs/lib/foilpresenterimport.py index 919901694..635137b00 100644 --- a/openlp/plugins/songs/lib/foilpresenterimport.py +++ b/openlp/plugins/songs/lib/foilpresenterimport.py @@ -94,6 +94,7 @@ import os from lxml import etree, objectify from openlp.core.lib import translate +from openlp.core.ui.wizard import WizardStrings from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib.songimport import SongImport from openlp.plugins.songs.lib.db import Author, Book, Song, Topic @@ -110,32 +111,27 @@ class FoilPresenterImport(SongImport): Initialise the import. """ log.debug(u'initialise FoilPresenterImport') - SongImport.__init__(self, master_manager) - self.master_manager = master_manager - self.FoilPresenter = FoilPresenter(master_manager) - if kwargs.has_key(u'filename'): - self.import_source = kwargs[u'filename'] - if kwargs.has_key(u'filenames'): - self.import_source = kwargs[u'filenames'] + SongImport.__init__(self, master_manager, **kwargs) + self.FoilPresenter = FoilPresenter(self.manager) def do_import(self): """ Imports the songs. """ self.import_wizard.progressBar.setMaximum(len(self.import_source)) + parser = etree.XMLParser(remove_blank_text=True) for file_path in self.import_source: if self.stop_import_flag: return False - self.import_wizard.incrementProgressBar(unicode(translate( - 'SongsPlugin.FoilPresenterImport', 'Importing %s...')) % - os.path.basename(file_path)) - parser = etree.XMLParser(remove_blank_text=True) - parsed_file = etree.parse(file_path, parser) - xml = unicode(etree.tostring(parsed_file)) - if self.FoilPresenter.xml_to_song(xml) is None: - log.debug(u'File could not be imported: %s' % file_path) - # Importing this song failed! For now we stop import. - return False + self.import_wizard.incrementProgressBar( + WizardStrings.ImportingType % os.path.basename(file_path)) + try: + parsed_file = etree.parse(file_path, parser) + xml = unicode(etree.tostring(parsed_file)) + if self.FoilPresenter.xml_to_song(xml) is None: + log.debug(u'File could not be imported: %s' % file_path) + except etree.XMLSyntaxError: + log.exception(u'XML syntax error in file %s' % file_path) return True class FoilPresenter(object): @@ -325,9 +321,9 @@ class FoilPresenter(object): for test_temp in test: author_temp.append(test_temp) for author in author_temp: - author = re.compile( - u'^[\/,;\-\s]+|[\/,;\-\s]+$|\s*[0-9]{4}\s*[\-\/]?\s*([0-9]{4})?[\/,;\-\s]*$' - ).sub(u'', author) + regex = u'^[\/,;\-\s]+|[\/,;\-\s]+$|'\ + '\s*[0-9]{4}\s*[\-\/]?\s*([0-9]{4})?[\/,;\-\s]*$' + author = re.compile(regex).sub(u'', author) author = re.compile( u'[0-9]{1,2}\.\s?J(ahr)?h\.|um\s*$|vor\s*$').sub(u'', author)