foilpresenterimport - some changes

This commit is contained in:
Armin Köhler 2011-02-19 22:34:51 +01:00
parent 4e6b967fc8
commit 6208587b93
3 changed files with 20 additions and 29 deletions

View File

@ -54,6 +54,7 @@ class WizardStrings(object):
SoF = u'Songs of Fellowship' SoF = u'Songs of Fellowship'
SSP = u'SongShow Plus' SSP = u'SongShow Plus'
WoW = u'Words of Worship' WoW = u'Words of Worship'
FP = u'Foilpresenter'
# These strings should need a good reason to be retranslated elsewhere. # These strings should need a good reason to be retranslated elsewhere.
FinishedImport = translate('OpenLP.Ui', 'Finished import.') FinishedImport = translate('OpenLP.Ui', 'Finished import.')
FormatLabel = translate('OpenLP.Ui', 'Format:') FormatLabel = translate('OpenLP.Ui', 'Format:')

View File

@ -410,12 +410,8 @@ class SongImportForm(OpenLPWizard):
return False return False
elif source_format == SongFormat.FoilPresenter: elif source_format == SongFormat.FoilPresenter:
if self.foilPresenterFileListWidget.count() == 0: if self.foilPresenterFileListWidget.count() == 0:
criticalErrorMessageBox( critical_error_message_box(UiStrings.NFSp,
translate('SongsPlugin.ImportWizardForm', WizardStrings.YouSpecifyFile % WizardStrings.FP)
'No Foilpresenter Files Selected'),
translate('SongsPlugin.ImportWizardForm',
'You need to add at least one Foilpresenter '
'song file to import from.'))
self.foilPresenterAddButton.setFocus() self.foilPresenterAddButton.setFocus()
return False return False
return True return True
@ -613,9 +609,7 @@ class SongImportForm(OpenLPWizard):
""" """
Get FoilPresenter song database files Get FoilPresenter song database files
""" """
self.getFiles( self.getFiles(WizardStrings.OpenTypeFile % WizardStrings.FP,
translate('SongsPlugin.ImportWizardForm',
'Select FoilPresenter Files'),
self.foilPresenterFileListWidget, u'%s (*.foil)' self.foilPresenterFileListWidget, u'%s (*.foil)'
% translate('SongsPlugin.ImportWizardForm', % translate('SongsPlugin.ImportWizardForm',
'Foilpresenter Song Files') 'Foilpresenter Song Files')

View File

@ -94,6 +94,7 @@ import os
from lxml import etree, objectify from lxml import etree, objectify
from openlp.core.lib import translate 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 import VerseType
from openlp.plugins.songs.lib.songimport import SongImport from openlp.plugins.songs.lib.songimport import SongImport
from openlp.plugins.songs.lib.db import Author, Book, Song, Topic from openlp.plugins.songs.lib.db import Author, Book, Song, Topic
@ -110,32 +111,27 @@ class FoilPresenterImport(SongImport):
Initialise the import. Initialise the import.
""" """
log.debug(u'initialise FoilPresenterImport') log.debug(u'initialise FoilPresenterImport')
SongImport.__init__(self, master_manager) SongImport.__init__(self, master_manager, **kwargs)
self.master_manager = master_manager self.FoilPresenter = FoilPresenter(self.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']
def do_import(self): def do_import(self):
""" """
Imports the songs. Imports the songs.
""" """
self.import_wizard.progressBar.setMaximum(len(self.import_source)) self.import_wizard.progressBar.setMaximum(len(self.import_source))
parser = etree.XMLParser(remove_blank_text=True)
for file_path in self.import_source: for file_path in self.import_source:
if self.stop_import_flag: if self.stop_import_flag:
return False return False
self.import_wizard.incrementProgressBar(unicode(translate( self.import_wizard.incrementProgressBar(
'SongsPlugin.FoilPresenterImport', 'Importing %s...')) % WizardStrings.ImportingType % os.path.basename(file_path))
os.path.basename(file_path)) try:
parser = etree.XMLParser(remove_blank_text=True) parsed_file = etree.parse(file_path, parser)
parsed_file = etree.parse(file_path, parser) xml = unicode(etree.tostring(parsed_file))
xml = unicode(etree.tostring(parsed_file)) if self.FoilPresenter.xml_to_song(xml) is None:
if self.FoilPresenter.xml_to_song(xml) is None: log.debug(u'File could not be imported: %s' % file_path)
log.debug(u'File could not be imported: %s' % file_path) except etree.XMLSyntaxError:
# Importing this song failed! For now we stop import. log.exception(u'XML syntax error in file %s' % file_path)
return False
return True return True
class FoilPresenter(object): class FoilPresenter(object):
@ -325,9 +321,9 @@ class FoilPresenter(object):
for test_temp in test: for test_temp in test:
author_temp.append(test_temp) author_temp.append(test_temp)
for author in author_temp: for author in author_temp:
author = re.compile( regex = u'^[\/,;\-\s]+|[\/,;\-\s]+$|'\
u'^[\/,;\-\s]+|[\/,;\-\s]+$|\s*[0-9]{4}\s*[\-\/]?\s*([0-9]{4})?[\/,;\-\s]*$' '\s*[0-9]{4}\s*[\-\/]?\s*([0-9]{4})?[\/,;\-\s]*$'
).sub(u'', author) author = re.compile(regex).sub(u'', author)
author = re.compile( author = re.compile(
u'[0-9]{1,2}\.\s?J(ahr)?h\.|um\s*$|vor\s*$').sub(u'', u'[0-9]{1,2}\.\s?J(ahr)?h\.|um\s*$|vor\s*$').sub(u'',
author) author)