Sort out song importer initialisation

This commit is contained in:
Jon Tibble 2011-02-18 17:34:43 +00:00
parent cb37a8bc17
commit bcf35bf54e
13 changed files with 34 additions and 63 deletions

View File

@ -51,22 +51,17 @@ class CCLIFileImport(SongImport):
``filenames``
The files to be imported.
"""
SongImport.__init__(self, manager)
if u'filenames' in kwargs:
self.filenames = kwargs[u'filenames']
log.debug(self.filenames)
else:
raise KeyError(u'Keyword argument "filenames" not supplied.')
SongImport.__init__(self, manager, **kwargs)
def do_import(self):
"""
Import either a .usr or a .txt SongSelect file
"""
log.debug(u'Starting CCLI File Import')
song_total = len(self.filenames)
song_total = len(self.import_source)
self.import_wizard.progressBar.setMaximum(song_total)
song_count = 1
for filename in self.filenames:
for filename in self.import_source:
self.import_wizard.incrementProgressBar(unicode(translate(
'SongsPlugin.CCLIFileImport', 'Importing song %d of %d')) %
(song_count, song_total))

View File

@ -46,32 +46,30 @@ class EasiSlidesImport(SongImport):
"""
Initialise the class.
"""
SongImport.__init__(self, manager)
self.filename = kwargs[u'filename']
self.song = None
SongImport.__init__(self, manager, **kwargs)
self.commit = True
def do_import(self):
"""
Import either each of the files in self.filenames - each element of
Import either each of the files in self.import_sources - each element of
which can be either a single opensong file, or a zipfile containing
multiple opensong files. If `self.commit` is set False, the
import will not be committed to the database (useful for test scripts).
"""
self.import_wizard.progressBar.setMaximum(1)
log.info(u'Importing EasiSlides XML file %s', self.filename)
log.info(u'Importing EasiSlides XML file %s', self.import_source)
parser = etree.XMLParser(remove_blank_text=True)
file = etree.parse(self.filename, parser)
file = etree.parse(self.import_source, parser)
xml = unicode(etree.tostring(file))
song_xml = objectify.fromstring(xml)
self.import_wizard.incrementProgressBar(
WizardStrings.ImportingType % os.path.split(self.filename)[-1])
WizardStrings.ImportingType % os.path.split(self.import_source)[-1])
self.import_wizard.progressBar.setMaximum(len(song_xml.Item))
for song in song_xml.Item:
self.import_wizard.incrementProgressBar(
unicode(translate('SongsPlugin.ImportWizardForm',
u'Importing %s, song %s...')) %
(os.path.split(self.filename)[-1], song.Title1))
(os.path.split(self.import_source)[-1], song.Title1))
success = self._parse_song(song)
if not success or self.stop_import_flag:
return False

View File

@ -135,8 +135,7 @@ class EasyWorshipSongImport(SongImport):
ability to import EasyWorship song files.
"""
def __init__(self, manager, **kwargs):
self.import_source = kwargs[u'filename']
SongImport.__init__(self, manager)
SongImport.__init__(self, manager, **kwargs)
def do_import(self):
# Open the DB and MB files if they exist

View File

@ -55,8 +55,7 @@ class OpenLP1SongImport(SongImport):
``filename``
The database providing the data to import.
"""
SongImport.__init__(self, manager)
self.import_source = kwargs[u'filename']
SongImport.__init__(self, manager, **kwargs)
def do_import(self):
"""

View File

@ -86,9 +86,8 @@ class OpenLPSongImport(SongImport):
``source_db``
The database providing the data to import.
"""
SongImport.__init__(self, manager)
self.import_source = u'sqlite:///%s' % kwargs[u'filename']
log.debug(self.import_source)
SongImport.__init__(self, manager, **kwargs)
self.import_source = u'sqlite:///%s' % self.import_source
self.source_session = None
def do_import(self):

View File

@ -56,20 +56,15 @@ class OooImport(SongImport):
Initialise the class. Requires a songmanager class which is passed
to SongImport for writing song to disk
"""
SongImport.__init__(self, master_manager)
self.song = None
self.master_manager = master_manager
SongImport.__init__(self, master_manager, **kwargs)
self.document = None
self.process_started = False
self.filenames = kwargs[u'filenames']
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import)
def do_import(self):
self.stop_import_flag = False
self.import_wizard.progressBar.setMaximum(0)
self.start_ooo()
for filename in self.filenames:
for filename in self.import_source:
if self.stop_import_flag:
self.import_wizard.incrementProgressBar(u'Import cancelled', 0)
return

0
openlp/plugins/songs/lib/openlyricsexport.py Executable file → Normal file
View File

View File

@ -48,13 +48,8 @@ class OpenLyricsImport(SongImport):
Initialise the import.
"""
log.debug(u'initialise OpenLyricsImport')
SongImport.__init__(self, master_manager)
self.master_manager = master_manager
self.openLyrics = OpenLyrics(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.openLyrics = OpenLyrics(self.manager)
def do_import(self):
"""

View File

@ -105,21 +105,19 @@ class OpenSongImport(SongImport):
"""
Initialise the class.
"""
SongImport.__init__(self, manager)
self.filenames = kwargs[u'filenames']
self.song = None
SongImport.__init__(self, manager, **kwargs)
self.commit = True
def do_import(self):
"""
Import either each of the files in self.filenames - each element of
Import either each of the files in self.import_source - each element of
which can be either a single opensong file, or a zipfile containing
multiple opensong files. If `self.commit` is set False, the
import will not be committed to the database (useful for test scripts).
"""
success = True
numfiles = 0
for filename in self.filenames:
for filename in self.import_source:
ext = os.path.splitext(filename)[1]
if ext.lower() == u'.zip':
z = ZipFile(filename, u'r')
@ -128,7 +126,7 @@ class OpenSongImport(SongImport):
numfiles += 1
log.debug(u'Total number of files: %d', numfiles)
self.import_wizard.progressBar.setMaximum(numfiles)
for filename in self.filenames:
for filename in self.import_source:
if self.stop_import_flag:
success = False
break

View File

@ -74,12 +74,7 @@ class SongBeamerImport(SongImport):
``master_manager``
The song manager for the running OpenLP installation.
"""
SongImport.__init__(self, 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']
log.debug(self.import_source)
SongImport.__init__(self, master_manager, **kwargs)
def do_import(self):
"""

View File

@ -44,7 +44,7 @@ class SongImport(QtCore.QObject):
whether the authors etc already exist and add them or refer to them
as necessary
"""
def __init__(self, manager):
def __init__(self, manager, **kwargs):
"""
Initialise and create defaults for properties
@ -54,6 +54,14 @@ class SongImport(QtCore.QObject):
"""
self.manager = manager
if kwargs.has_key(u'filename'):
self.import_source = kwargs[u'filename']
elif kwargs.has_key(u'filenames'):
self.import_source = kwargs[u'filenames']
else:
raise KeyError(u'Keyword arguments "filename[s]" not supplied.')
log.debug(self.import_source)
self.song = None
self.stop_import_flag = False
self.set_defaults()
QtCore.QObject.connect(Receiver.get_receiver(),
@ -263,7 +271,7 @@ class SongImport(QtCore.QObject):
"""
if not self.authors:
self.authors.append(SongStrings.AuthorUnknownUnT)
log.info(u'commiting song %s to database', self.title)
log.info(u'committing song %s to database', self.title)
song = Song()
song.title = self.title
song.alternate_title = self.alternate_title

View File

@ -93,12 +93,7 @@ class SongShowPlusImport(SongImport):
``master_manager``
The song manager for the running OpenLP installation.
"""
SongImport.__init__(self, 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']
log.debug(self.import_source)
SongImport.__init__(self, master_manager, **kwargs)
def do_import(self):
"""

View File

@ -99,12 +99,7 @@ class WowImport(SongImport):
``master_manager``
The song manager for the running OpenLP installation.
"""
SongImport.__init__(self, 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']
log.debug(self.import_source)
SongImport.__init__(self, master_manager, **kwargs)
def do_import(self):
"""