forked from openlp/openlp
Coding standards clean up.
This commit is contained in:
parent
c9447edae8
commit
564c7e4a5a
|
@ -55,13 +55,13 @@ class CCLIFileImport(SongImport):
|
||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
Import either a ``.usr`` or a ``.txt`` SongSelect file.
|
Import either a ``.usr`` or a ``.txt`` SongSelect file.
|
||||||
"""
|
"""
|
||||||
log.debug(u'Starting CCLI File Import')
|
log.debug(u'Starting CCLI File Import')
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.importWizard.progressBar.setMaximum(len(self.importSource))
|
||||||
for filename in self.import_source:
|
for filename in self.importSource:
|
||||||
filename = unicode(filename)
|
filename = unicode(filename)
|
||||||
log.debug(u'Importing CCLI File: %s', filename)
|
log.debug(u'Importing CCLI File: %s', filename)
|
||||||
lines = []
|
lines = []
|
||||||
|
@ -80,23 +80,23 @@ class CCLIFileImport(SongImport):
|
||||||
ext = os.path.splitext(filename)[1]
|
ext = os.path.splitext(filename)[1]
|
||||||
if ext.lower() == u'.usr':
|
if ext.lower() == u'.usr':
|
||||||
log.info(u'SongSelect .usr format file found: %s', filename)
|
log.info(u'SongSelect .usr format file found: %s', filename)
|
||||||
if not self.do_import_usr_file(lines):
|
if not self.doImportUsrFile(lines):
|
||||||
self.log_error(filename)
|
self.logError(filename)
|
||||||
elif ext.lower() == u'.txt':
|
elif ext.lower() == u'.txt':
|
||||||
log.info(u'SongSelect .txt format file found: %s', filename)
|
log.info(u'SongSelect .txt format file found: %s', filename)
|
||||||
if not self.do_import_txt_file(lines):
|
if not self.doImportTxtFile(lines):
|
||||||
self.log_error(filename)
|
self.logError(filename)
|
||||||
else:
|
else:
|
||||||
self.log_error(filename,
|
self.logError(filename,
|
||||||
translate('SongsPlugin.CCLIFileImport',
|
translate('SongsPlugin.CCLIFileImport',
|
||||||
'The file does not have a valid extension.'))
|
'The file does not have a valid extension.'))
|
||||||
log.info(u'Extension %s is not valid', filename)
|
log.info(u'Extension %s is not valid', filename)
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
return
|
return
|
||||||
|
|
||||||
def do_import_usr_file(self, textList):
|
def doImportUsrFile(self, textList):
|
||||||
"""
|
"""
|
||||||
The :func:`do_import_usr_file` method provides OpenLP with the ability
|
The :func:`doImport_usr_file` method provides OpenLP with the ability
|
||||||
to import CCLI SongSelect songs in *USR* file format.
|
to import CCLI SongSelect songs in *USR* file format.
|
||||||
|
|
||||||
``textList``
|
``textList``
|
||||||
|
@ -219,9 +219,9 @@ class CCLIFileImport(SongImport):
|
||||||
self.topics = [topic.strip() for topic in song_topics.split(u'/t')]
|
self.topics = [topic.strip() for topic in song_topics.split(u'/t')]
|
||||||
return self.finish()
|
return self.finish()
|
||||||
|
|
||||||
def do_import_txt_file(self, textList):
|
def doImportTxtFile(self, textList):
|
||||||
"""
|
"""
|
||||||
The :func:`do_import_txt_file` method provides OpenLP with the ability
|
The :func:`doImport_txt_file` method provides OpenLP with the ability
|
||||||
to import CCLI SongSelect songs in *TXT* file format.
|
to import CCLI SongSelect songs in *TXT* file format.
|
||||||
|
|
||||||
``textList``
|
``textList``
|
||||||
|
|
|
@ -49,21 +49,21 @@ class EasiSlidesImport(SongImport):
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
self.commit = True
|
self.commit = True
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
Import either each of the files in self.import_sources - each element of
|
Import either each of the files in self.importSources - each element of
|
||||||
which can be either a single opensong file, or a zipfile containing
|
which can be either a single opensong file, or a zipfile containing
|
||||||
multiple opensong files. If `self.commit` is set False, the
|
multiple opensong files. If `self.commit` is set False, the
|
||||||
import will not be committed to the database (useful for test scripts).
|
import will not be committed to the database (useful for test scripts).
|
||||||
"""
|
"""
|
||||||
log.info(u'Importing EasiSlides XML file %s', self.import_source)
|
log.info(u'Importing EasiSlides XML file %s', self.importSource)
|
||||||
parser = etree.XMLParser(remove_blank_text=True)
|
parser = etree.XMLParser(remove_blank_text=True)
|
||||||
parsed_file = etree.parse(self.import_source, parser)
|
parsed_file = etree.parse(self.importSource, parser)
|
||||||
xml = unicode(etree.tostring(parsed_file))
|
xml = unicode(etree.tostring(parsed_file))
|
||||||
song_xml = objectify.fromstring(xml)
|
song_xml = objectify.fromstring(xml)
|
||||||
self.import_wizard.progressBar.setMaximum(len(song_xml.Item))
|
self.importWizard.progressBar.setMaximum(len(song_xml.Item))
|
||||||
for song in song_xml.Item:
|
for song in song_xml.Item:
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
return
|
return
|
||||||
self._parse_song(song)
|
self._parse_song(song)
|
||||||
|
|
||||||
|
@ -88,9 +88,9 @@ class EasiSlidesImport(SongImport):
|
||||||
self._parse_and_add_lyrics(song)
|
self._parse_and_add_lyrics(song)
|
||||||
if self._success:
|
if self._success:
|
||||||
if not self.finish():
|
if not self.finish():
|
||||||
self.log_error(song.Title1 if song.Title1 else u'')
|
self.logError(song.Title1 if song.Title1 else u'')
|
||||||
else:
|
else:
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
|
|
||||||
def _add_unicode_attribute(self, self_attribute, import_attribute,
|
def _add_unicode_attribute(self, self_attribute, import_attribute,
|
||||||
mandatory=False):
|
mandatory=False):
|
||||||
|
|
|
@ -155,17 +155,17 @@ class EasyWorshipSongImport(SongImport):
|
||||||
def __init__(self, manager, **kwargs):
|
def __init__(self, manager, **kwargs):
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
# Open the DB and MB files if they exist
|
# Open the DB and MB files if they exist
|
||||||
import_source_mb = self.import_source.replace('.DB', '.MB')
|
import_source_mb = self.importSource.replace('.DB', '.MB')
|
||||||
if not os.path.isfile(self.import_source):
|
if not os.path.isfile(self.importSource):
|
||||||
return
|
return
|
||||||
if not os.path.isfile(import_source_mb):
|
if not os.path.isfile(import_source_mb):
|
||||||
return
|
return
|
||||||
db_size = os.path.getsize(self.import_source)
|
db_size = os.path.getsize(self.importSource)
|
||||||
if db_size < 0x800:
|
if db_size < 0x800:
|
||||||
return
|
return
|
||||||
db_file = open(self.import_source, 'rb')
|
db_file = open(self.importSource, 'rb')
|
||||||
self.memo_file = open(import_source_mb, 'rb')
|
self.memo_file = open(import_source_mb, 'rb')
|
||||||
# Don't accept files that are clearly not paradox files
|
# Don't accept files that are clearly not paradox files
|
||||||
record_size, header_size, block_size, first_block, num_fields \
|
record_size, header_size, block_size, first_block, num_fields \
|
||||||
|
@ -204,7 +204,7 @@ class EasyWorshipSongImport(SongImport):
|
||||||
# There does not appear to be a _reliable_ way of getting the number
|
# 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.
|
# of songs/records, so let's use file blocks for measuring progress.
|
||||||
total_blocks = (db_size - header_size) / (block_size * 1024)
|
total_blocks = (db_size - header_size) / (block_size * 1024)
|
||||||
self.import_wizard.progressBar.setMaximum(total_blocks)
|
self.importWizard.progressBar.setMaximum(total_blocks)
|
||||||
# Read the field description information
|
# Read the field description information
|
||||||
db_file.seek(120)
|
db_file.seek(120)
|
||||||
field_info = db_file.read(num_fields * 2)
|
field_info = db_file.read(num_fields * 2)
|
||||||
|
@ -239,11 +239,11 @@ class EasyWorshipSongImport(SongImport):
|
||||||
rec_count = (rec_count + record_size) / record_size
|
rec_count = (rec_count + record_size) / record_size
|
||||||
# Loop through each record within the current block
|
# Loop through each record within the current block
|
||||||
for i in range(rec_count):
|
for i in range(rec_count):
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
break
|
break
|
||||||
raw_record = db_file.read(record_size)
|
raw_record = db_file.read(record_size)
|
||||||
self.fields = self.record_struct.unpack(raw_record)
|
self.fields = self.record_struct.unpack(raw_record)
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
self.title = self.get_field(fi_title)
|
self.title = self.get_field(fi_title)
|
||||||
# Get remaining fields.
|
# Get remaining fields.
|
||||||
copy = self.get_field(fi_copy)
|
copy = self.get_field(fi_copy)
|
||||||
|
@ -313,10 +313,10 @@ class EasyWorshipSongImport(SongImport):
|
||||||
translate('SongsPlugin.EasyWorshipSongImport',
|
translate('SongsPlugin.EasyWorshipSongImport',
|
||||||
'\n[above are Song Tags with notes imported from \
|
'\n[above are Song Tags with notes imported from \
|
||||||
EasyWorship]'))
|
EasyWorship]'))
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
break
|
break
|
||||||
if not self.finish():
|
if not self.finish():
|
||||||
self.log_error(self.import_source)
|
self.logError(self.importSource)
|
||||||
db_file.close()
|
db_file.close()
|
||||||
self.memo_file.close()
|
self.memo_file.close()
|
||||||
|
|
||||||
|
|
|
@ -115,23 +115,23 @@ class FoilPresenterImport(SongImport):
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
self.FoilPresenter = FoilPresenter(self.manager)
|
self.FoilPresenter = FoilPresenter(self.manager)
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
Imports the songs.
|
Imports the songs.
|
||||||
"""
|
"""
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.importWizard.progressBar.setMaximum(len(self.importSource))
|
||||||
parser = etree.XMLParser(remove_blank_text=True)
|
parser = etree.XMLParser(remove_blank_text=True)
|
||||||
for file_path in self.import_source:
|
for file_path in self.importSource:
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
return
|
return
|
||||||
self.import_wizard.incrementProgressBar(
|
self.importWizard.incrementProgressBar(
|
||||||
WizardStrings.ImportingType % os.path.basename(file_path))
|
WizardStrings.ImportingType % os.path.basename(file_path))
|
||||||
try:
|
try:
|
||||||
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))
|
||||||
self.FoilPresenter.xml_to_song(xml)
|
self.FoilPresenter.xml_to_song(xml)
|
||||||
except etree.XMLSyntaxError:
|
except etree.XMLSyntaxError:
|
||||||
self.log_error(file_path, SongStrings.XMLSyntaxError)
|
self.logError(file_path, SongStrings.XMLSyntaxError)
|
||||||
log.exception(u'XML syntax error in file %s' % file_path)
|
log.exception(u'XML syntax error in file %s' % file_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,11 +69,11 @@ class SongMediaItem(MediaManagerItem):
|
||||||
def __init__(self, parent, plugin, icon):
|
def __init__(self, parent, plugin, icon):
|
||||||
self.IconPath = u'songs/song'
|
self.IconPath = u'songs/song'
|
||||||
MediaManagerItem.__init__(self, parent, plugin, icon)
|
MediaManagerItem.__init__(self, parent, plugin, icon)
|
||||||
self.edit_song_form = EditSongForm(self, self.plugin.formparent,
|
self.editSongForm = EditSongForm(self, self.plugin.formparent,
|
||||||
self.plugin.manager)
|
self.plugin.manager)
|
||||||
self.openLyrics = OpenLyrics(self.plugin.manager)
|
self.openLyrics = OpenLyrics(self.plugin.manager)
|
||||||
self.singleServiceItem = False
|
self.singleServiceItem = False
|
||||||
self.song_maintenance_form = SongMaintenanceForm(
|
self.songMaintenanceForm = SongMaintenanceForm(
|
||||||
self.plugin.manager, self)
|
self.plugin.manager, self)
|
||||||
# Holds information about whether the edit is remotly triggered and
|
# Holds information about whether the edit is remotly triggered and
|
||||||
# which Song is required.
|
# which Song is required.
|
||||||
|
@ -316,25 +316,26 @@ class SongMediaItem(MediaManagerItem):
|
||||||
self.onClearTextButtonClick()
|
self.onClearTextButtonClick()
|
||||||
|
|
||||||
def onImportClick(self):
|
def onImportClick(self):
|
||||||
if not hasattr(self, u'import_wizard'):
|
if not hasattr(self, u'importWizard'):
|
||||||
self.import_wizard = SongImportForm(self, self.plugin)
|
self.importWizard = SongImportForm(self, self.plugin)
|
||||||
if self.import_wizard.exec_() == QtGui.QDialog.Accepted:
|
if self.importWizard.exec_() == QtGui.QDialog.Accepted:
|
||||||
Receiver.send_message(u'songs_load_list')
|
Receiver.send_message(u'songs_load_list')
|
||||||
|
|
||||||
def onExportClick(self):
|
def onExportClick(self):
|
||||||
export_wizard = SongExportForm(self, self.plugin)
|
if not hasattr(self, u'exportWizard'):
|
||||||
export_wizard.exec_()
|
self.exportWizard = SongExportForm(self, self.plugin)
|
||||||
|
self.exportWizard.exec_()
|
||||||
|
|
||||||
def onNewClick(self):
|
def onNewClick(self):
|
||||||
log.debug(u'onNewClick')
|
log.debug(u'onNewClick')
|
||||||
self.edit_song_form.newSong()
|
self.editSongForm.newSong()
|
||||||
self.edit_song_form.exec_()
|
self.editSongForm.exec_()
|
||||||
self.onClearTextButtonClick()
|
self.onClearTextButtonClick()
|
||||||
self.onSelectionChange()
|
self.onSelectionChange()
|
||||||
self.autoSelectId = -1
|
self.autoSelectId = -1
|
||||||
|
|
||||||
def onSongMaintenanceClick(self):
|
def onSongMaintenanceClick(self):
|
||||||
self.song_maintenance_form.exec_()
|
self.songMaintenanceForm.exec_()
|
||||||
|
|
||||||
def onRemoteEditClear(self):
|
def onRemoteEditClear(self):
|
||||||
log.debug(u'onRemoteEditClear')
|
log.debug(u'onRemoteEditClear')
|
||||||
|
@ -354,8 +355,8 @@ class SongMediaItem(MediaManagerItem):
|
||||||
if valid:
|
if valid:
|
||||||
self.remoteSong = song_id
|
self.remoteSong = song_id
|
||||||
self.remoteTriggered = remote_type
|
self.remoteTriggered = remote_type
|
||||||
self.edit_song_form.loadSong(song_id, remote_type == u'P')
|
self.editSongForm.loadSong(song_id, remote_type == u'P')
|
||||||
self.edit_song_form.exec_()
|
self.editSongForm.exec_()
|
||||||
self.autoSelectId = -1
|
self.autoSelectId = -1
|
||||||
self.onSongListLoad()
|
self.onSongListLoad()
|
||||||
|
|
||||||
|
@ -367,8 +368,8 @@ class SongMediaItem(MediaManagerItem):
|
||||||
if check_item_selected(self.listView, UiStrings().SelectEdit):
|
if check_item_selected(self.listView, UiStrings().SelectEdit):
|
||||||
self.editItem = self.listView.currentItem()
|
self.editItem = self.listView.currentItem()
|
||||||
item_id = (self.editItem.data(QtCore.Qt.UserRole)).toInt()[0]
|
item_id = (self.editItem.data(QtCore.Qt.UserRole)).toInt()[0]
|
||||||
self.edit_song_form.loadSong(item_id, False)
|
self.editSongForm.loadSong(item_id, False)
|
||||||
self.edit_song_form.exec_()
|
self.editSongForm.exec_()
|
||||||
self.autoSelectId = -1
|
self.autoSelectId = -1
|
||||||
self.onSongListLoad()
|
self.onSongListLoad()
|
||||||
self.editItem = None
|
self.editItem = None
|
||||||
|
|
|
@ -44,7 +44,7 @@ class OpenLP1SongImport(SongImport):
|
||||||
The :class:`OpenLP1SongImport` class provides OpenLP with the ability to
|
The :class:`OpenLP1SongImport` class provides OpenLP with the ability to
|
||||||
import song databases from installations of openlp.org 1.x.
|
import song databases from installations of openlp.org 1.x.
|
||||||
"""
|
"""
|
||||||
last_encoding = u'windows-1252'
|
lastEncoding = u'windows-1252'
|
||||||
|
|
||||||
def __init__(self, manager, **kwargs):
|
def __init__(self, manager, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -57,23 +57,23 @@ class OpenLP1SongImport(SongImport):
|
||||||
The database providing the data to import.
|
The database providing the data to import.
|
||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
self.available_themes = \
|
self.availableThemes = \
|
||||||
kwargs[u'plugin'].formparent.themeManagerContents.getThemes()
|
kwargs[u'plugin'].formparent.themeManagerContents.getThemes()
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
Run the import for an openlp.org 1.x song database.
|
Run the import for an openlp.org 1.x song database.
|
||||||
"""
|
"""
|
||||||
if not self.import_source.endswith(u'.olp'):
|
if not self.importSource.endswith(u'.olp'):
|
||||||
self.log_error(self.import_source,
|
self.logError(self.importSource,
|
||||||
translate('SongsPlugin.OpenLP1SongImport',
|
translate('SongsPlugin.OpenLP1SongImport',
|
||||||
'Not a valid openlp.org 1.x song database.'))
|
'Not a valid openlp.org 1.x song database.'))
|
||||||
return
|
return
|
||||||
encoding = self.get_encoding()
|
encoding = self.getEncoding()
|
||||||
if not encoding:
|
if not encoding:
|
||||||
return
|
return
|
||||||
# Connect to the database.
|
# Connect to the database.
|
||||||
connection = sqlite.connect(self.import_source, mode=0444,
|
connection = sqlite.connect(self.importSource, mode=0444,
|
||||||
encoding=(encoding, 'replace'))
|
encoding=(encoding, 'replace'))
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
# Determine if we're using a new or an old DB.
|
# Determine if we're using a new or an old DB.
|
||||||
|
@ -94,64 +94,64 @@ class OpenLP1SongImport(SongImport):
|
||||||
cursor.execute(u'SELECT settingsid, settingsname FROM settings')
|
cursor.execute(u'SELECT settingsid, settingsname FROM settings')
|
||||||
themes = {}
|
themes = {}
|
||||||
for theme_id, theme_name in cursor.fetchall():
|
for theme_id, theme_name in cursor.fetchall():
|
||||||
if theme_name in self.available_themes:
|
if theme_name in self.availableThemes:
|
||||||
themes[theme_id] = theme_name
|
themes[theme_id] = theme_name
|
||||||
# Import the songs.
|
# Import the songs.
|
||||||
cursor.execute(u'-- types int, unicode, unicode, unicode, int')
|
cursor.execute(u'-- types int, unicode, unicode, unicode, int')
|
||||||
cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, '
|
cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, '
|
||||||
u'copyrightinfo, settingsid FROM songs')
|
u'copyrightinfo, settingsid FROM songs')
|
||||||
songs = cursor.fetchall()
|
songs = cursor.fetchall()
|
||||||
self.import_wizard.progressBar.setMaximum(len(songs))
|
self.importWizard.progressBar.setMaximum(len(songs))
|
||||||
for song in songs:
|
for song in songs:
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
break
|
break
|
||||||
song_id = song[0]
|
song_id = song[0]
|
||||||
self.title = song[1]
|
self.title = song[1]
|
||||||
lyrics = song[2].replace(u'\r\n', u'\n')
|
lyrics = song[2].replace(u'\r\n', u'\n')
|
||||||
self.add_copyright(song[3])
|
self.addCopyright(song[3])
|
||||||
if themes.has_key(song[4]):
|
if themes.has_key(song[4]):
|
||||||
self.theme_name = themes[song[4]]
|
self.themeName = themes[song[4]]
|
||||||
verses = lyrics.split(u'\n\n')
|
verses = lyrics.split(u'\n\n')
|
||||||
for verse in verses:
|
for verse in verses:
|
||||||
if verse.strip():
|
if verse.strip():
|
||||||
self.add_verse(verse.strip())
|
self.addVerse(verse.strip())
|
||||||
cursor.execute(u'-- types int')
|
cursor.execute(u'-- types int')
|
||||||
cursor.execute(u'SELECT authorid FROM songauthors '
|
cursor.execute(u'SELECT authorid FROM songauthors '
|
||||||
u'WHERE songid = %s' % song_id)
|
u'WHERE songid = %s' % song_id)
|
||||||
author_ids = cursor.fetchall()
|
author_ids = cursor.fetchall()
|
||||||
for author_id in author_ids:
|
for author_id in author_ids:
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
break
|
break
|
||||||
for author in authors:
|
for author in authors:
|
||||||
if author[0] == author_id[0]:
|
if author[0] == author_id[0]:
|
||||||
self.parse_author(author[1])
|
self.parseAuthor(author[1])
|
||||||
break
|
break
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
break
|
break
|
||||||
if new_db:
|
if new_db:
|
||||||
cursor.execute(u'-- types int')
|
cursor.execute(u'-- types int, unicode, int')
|
||||||
cursor.execute(u'SELECT trackid FROM songtracks '
|
cursor.execute(u'SELECT trackid, fulltrackname, listindex FROM songtracks '
|
||||||
u'WHERE songid = %s ORDER BY listindex' % song_id)
|
u'WHERE songid = %s ORDER BY listindex' % song_id)
|
||||||
track_ids = cursor.fetchall()
|
track_ids = cursor.fetchall()
|
||||||
for track_id in track_ids:
|
for track_id, listindex in track_ids:
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
break
|
break
|
||||||
for track in tracks:
|
for track in tracks:
|
||||||
if track[0] == track_id[0]:
|
if track[0] == track_id:
|
||||||
self.add_media_file(track[1])
|
self.addMediaFile(track[1], listindex)
|
||||||
break
|
break
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
break
|
break
|
||||||
if not self.finish():
|
if not self.finish():
|
||||||
self.log_error(self.import_source)
|
self.logError(self.importSource)
|
||||||
|
|
||||||
def get_encoding(self):
|
def getEncoding(self):
|
||||||
"""
|
"""
|
||||||
Detect character encoding of an openlp.org 1.x song database.
|
Detect character encoding of an openlp.org 1.x song database.
|
||||||
"""
|
"""
|
||||||
# Connect to the database.
|
# Connect to the database.
|
||||||
connection = sqlite.connect(self.import_source, mode=0444)
|
connection = sqlite.connect(self.importSource, mode=0444)
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
detector = UniversalDetector()
|
detector = UniversalDetector()
|
||||||
|
|
|
@ -95,22 +95,22 @@ class OpenLPSongImport(SongImport):
|
||||||
The database providing the data to import.
|
The database providing the data to import.
|
||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
self.source_session = None
|
self.sourceSession = None
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
Run the import for an OpenLP version 2 song database.
|
Run the import for an OpenLP version 2 song database.
|
||||||
"""
|
"""
|
||||||
if not self.import_source.endswith(u'.sqlite'):
|
if not self.importSource.endswith(u'.sqlite'):
|
||||||
self.log_error(self.import_source,
|
self.logError(self.importSource,
|
||||||
translate('SongsPlugin.OpenLPSongImport',
|
translate('SongsPlugin.OpenLPSongImport',
|
||||||
'Not a valid OpenLP 2.0 song database.'))
|
'Not a valid OpenLP 2.0 song database.'))
|
||||||
return
|
return
|
||||||
self.import_source = u'sqlite:///%s' % self.import_source
|
self.importSource = u'sqlite:///%s' % self.importSource
|
||||||
engine = create_engine(self.import_source)
|
engine = create_engine(self.importSource)
|
||||||
source_meta = MetaData()
|
source_meta = MetaData()
|
||||||
source_meta.reflect(engine)
|
source_meta.reflect(engine)
|
||||||
self.source_session = scoped_session(sessionmaker(bind=engine))
|
self.sourceSession = scoped_session(sessionmaker(bind=engine))
|
||||||
if u'media_files' in source_meta.tables.keys():
|
if u'media_files' in source_meta.tables.keys():
|
||||||
has_media_files = True
|
has_media_files = True
|
||||||
else:
|
else:
|
||||||
|
@ -156,9 +156,9 @@ class OpenLPSongImport(SongImport):
|
||||||
except UnmappedClassError:
|
except UnmappedClassError:
|
||||||
mapper(OldTopic, source_topics_table)
|
mapper(OldTopic, source_topics_table)
|
||||||
|
|
||||||
source_songs = self.source_session.query(OldSong).all()
|
source_songs = self.sourceSession.query(OldSong).all()
|
||||||
if self.import_wizard:
|
if self.importWizard:
|
||||||
self.import_wizard.progressBar.setMaximum(len(source_songs))
|
self.importWizard.progressBar.setMaximum(len(source_songs))
|
||||||
for song in source_songs:
|
for song in source_songs:
|
||||||
new_song = Song()
|
new_song = Song()
|
||||||
new_song.title = song.title
|
new_song.title = song.title
|
||||||
|
@ -201,22 +201,22 @@ class OpenLPSongImport(SongImport):
|
||||||
if existing_topic is None:
|
if existing_topic is None:
|
||||||
existing_topic = Topic.populate(name=topic.name)
|
existing_topic = Topic.populate(name=topic.name)
|
||||||
new_song.topics.append(existing_topic)
|
new_song.topics.append(existing_topic)
|
||||||
# if has_media_files:
|
if has_media_files:
|
||||||
# if song.media_files:
|
if song.media_files:
|
||||||
# for media_file in song.media_files:
|
for media_file in song.media_files:
|
||||||
# existing_media_file = \
|
existing_media_file = \
|
||||||
# self.manager.get_object_filtered(MediaFile,
|
self.manager.get_object_filtered(MediaFile,
|
||||||
# MediaFile.file_name == media_file.file_name)
|
MediaFile.file_name == media_file.file_name)
|
||||||
# if existing_media_file:
|
if existing_media_file:
|
||||||
# new_song.media_files.append(existing_media_file)
|
new_song.media_files.append(existing_media_file)
|
||||||
# else:
|
else:
|
||||||
# new_song.media_files.append(MediaFile.populate(
|
new_song.media_files.append(MediaFile.populate(
|
||||||
# file_name=media_file.file_name))
|
file_name=media_file.file_name))
|
||||||
clean_song(self.manager, new_song)
|
clean_song(self.manager, new_song)
|
||||||
self.manager.save_object(new_song)
|
self.manager.save_object(new_song)
|
||||||
if self.import_wizard:
|
if self.importWizard:
|
||||||
self.import_wizard.incrementProgressBar(
|
self.importWizard.incrementProgressBar(
|
||||||
WizardStrings.ImportingType % new_song.title)
|
WizardStrings.ImportingType % new_song.title)
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
break
|
break
|
||||||
engine.dispose()
|
engine.dispose()
|
||||||
|
|
|
@ -61,21 +61,21 @@ class OooImport(SongImport):
|
||||||
self.document = None
|
self.document = None
|
||||||
self.process_started = False
|
self.process_started = False
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
if not isinstance(self.import_source, list):
|
if not isinstance(self.importSource, list):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.start_ooo()
|
self.start_ooo()
|
||||||
except NoConnectException as exc:
|
except NoConnectException as exc:
|
||||||
self.log_error(
|
self.logError(
|
||||||
self.import_source[0],
|
self.importSource[0],
|
||||||
translate('SongsPlugin.SongImport',
|
translate('SongsPlugin.SongImport',
|
||||||
'Cannot access OpenOffice or LibreOffice'))
|
'Cannot access OpenOffice or LibreOffice'))
|
||||||
log.error(exc)
|
log.error(exc)
|
||||||
return
|
return
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.importWizard.progressBar.setMaximum(len(self.importSource))
|
||||||
for filename in self.import_source:
|
for filename in self.importSource:
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
break
|
break
|
||||||
filename = unicode(filename)
|
filename = unicode(filename)
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
|
@ -84,11 +84,11 @@ class OooImport(SongImport):
|
||||||
self.process_ooo_document()
|
self.process_ooo_document()
|
||||||
self.close_ooo_file()
|
self.close_ooo_file()
|
||||||
else:
|
else:
|
||||||
self.log_error(self.filepath,
|
self.logError(self.filepath,
|
||||||
translate('SongsPlugin.SongImport',
|
translate('SongsPlugin.SongImport',
|
||||||
'Unable to open file'))
|
'Unable to open file'))
|
||||||
else:
|
else:
|
||||||
self.log_error(self.filepath,
|
self.logError(self.filepath,
|
||||||
translate('SongsPlugin.SongImport', 'File not found'))
|
translate('SongsPlugin.SongImport', 'File not found'))
|
||||||
self.close_ooo()
|
self.close_ooo()
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ class OooImport(SongImport):
|
||||||
self.document.supportsService("com.sun.star.text.TextDocument"):
|
self.document.supportsService("com.sun.star.text.TextDocument"):
|
||||||
self.close_ooo_file()
|
self.close_ooo_file()
|
||||||
else:
|
else:
|
||||||
self.import_wizard.incrementProgressBar(
|
self.importWizard.incrementProgressBar(
|
||||||
u'Processing file ' + filepath, 0)
|
u'Processing file ' + filepath, 0)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
log.exception("open_ooo_file failed: %s", url)
|
log.exception("open_ooo_file failed: %s", url)
|
||||||
|
@ -196,8 +196,8 @@ class OooImport(SongImport):
|
||||||
slides = doc.getDrawPages()
|
slides = doc.getDrawPages()
|
||||||
text = u''
|
text = u''
|
||||||
for slide_no in range(slides.getCount()):
|
for slide_no in range(slides.getCount()):
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
self.import_wizard.incrementProgressBar(u'Import cancelled', 0)
|
self.importWizard.incrementProgressBar(u'Import cancelled', 0)
|
||||||
return
|
return
|
||||||
slide = slides.getByIndex(slide_no)
|
slide = slides.getByIndex(slide_no)
|
||||||
slidetext = u''
|
slidetext = u''
|
||||||
|
@ -235,12 +235,12 @@ class OooImport(SongImport):
|
||||||
|
|
||||||
def process_songs_text(self, text):
|
def process_songs_text(self, text):
|
||||||
songtexts = self.tidy_text(text).split(u'\f')
|
songtexts = self.tidy_text(text).split(u'\f')
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
for songtext in songtexts:
|
for songtext in songtexts:
|
||||||
if songtext.strip():
|
if songtext.strip():
|
||||||
self.process_song_text(songtext.strip())
|
self.process_song_text(songtext.strip())
|
||||||
if self.check_complete():
|
if self.check_complete():
|
||||||
self.finish()
|
self.finish()
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
if self.check_complete():
|
if self.check_complete():
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|
|
@ -53,16 +53,16 @@ class OpenLyricsImport(SongImport):
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
self.openLyrics = OpenLyrics(self.manager)
|
self.openLyrics = OpenLyrics(self.manager)
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
Imports the songs.
|
Imports the songs.
|
||||||
"""
|
"""
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.importWizard.progressBar.setMaximum(len(self.importSource))
|
||||||
parser = etree.XMLParser(remove_blank_text=True)
|
parser = etree.XMLParser(remove_blank_text=True)
|
||||||
for file_path in self.import_source:
|
for file_path in self.importSource:
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
return
|
return
|
||||||
self.import_wizard.incrementProgressBar(
|
self.importWizard.incrementProgressBar(
|
||||||
WizardStrings.ImportingType % os.path.basename(file_path))
|
WizardStrings.ImportingType % os.path.basename(file_path))
|
||||||
try:
|
try:
|
||||||
# Pass a file object, because lxml does not cope with some
|
# Pass a file object, because lxml does not cope with some
|
||||||
|
@ -72,4 +72,4 @@ class OpenLyricsImport(SongImport):
|
||||||
self.openLyrics.xml_to_song(xml)
|
self.openLyrics.xml_to_song(xml)
|
||||||
except etree.XMLSyntaxError:
|
except etree.XMLSyntaxError:
|
||||||
log.exception(u'XML syntax error in file %s' % file_path)
|
log.exception(u'XML syntax error in file %s' % file_path)
|
||||||
self.log_error(file_path, SongStrings.XMLSyntaxError)
|
self.logError(file_path, SongStrings.XMLSyntaxError)
|
||||||
|
|
|
@ -107,24 +107,24 @@ class OpenSongImport(SongImport):
|
||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.importWizard.progressBar.setMaximum(len(self.importSource))
|
||||||
for filename in self.import_source:
|
for filename in self.importSource:
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
return
|
return
|
||||||
song_file = open(filename)
|
song_file = open(filename)
|
||||||
self.do_import_file(song_file)
|
self.doImportFile(song_file)
|
||||||
song_file.close()
|
song_file.close()
|
||||||
|
|
||||||
def do_import_file(self, file):
|
def doImportFile(self, file):
|
||||||
"""
|
"""
|
||||||
Process the OpenSong file - pass in a file-like object, not a file path.
|
Process the OpenSong file - pass in a file-like object, not a file path.
|
||||||
"""
|
"""
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
try:
|
try:
|
||||||
tree = objectify.parse(file)
|
tree = objectify.parse(file)
|
||||||
except (Error, LxmlError):
|
except (Error, LxmlError):
|
||||||
self.log_error(file.name, SongStrings.XMLSyntaxError)
|
self.logError(file.name, SongStrings.XMLSyntaxError)
|
||||||
log.exception(u'Error parsing XML')
|
log.exception(u'Error parsing XML')
|
||||||
return
|
return
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
@ -251,4 +251,4 @@ class OpenSongImport(SongImport):
|
||||||
log.info(u'Got order %s but not in verse tags, dropping'
|
log.info(u'Got order %s but not in verse tags, dropping'
|
||||||
u'this item from presentation order', verse_def)
|
u'this item from presentation order', verse_def)
|
||||||
if not self.finish():
|
if not self.finish():
|
||||||
self.log_error(file.name)
|
self.logError(file.name)
|
||||||
|
|
|
@ -98,7 +98,7 @@ class SofImport(OooImport):
|
||||||
try:
|
try:
|
||||||
paragraphs = self.document.getText().createEnumeration()
|
paragraphs = self.document.getText().createEnumeration()
|
||||||
while paragraphs.hasMoreElements():
|
while paragraphs.hasMoreElements():
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
return
|
return
|
||||||
paragraph = paragraphs.nextElement()
|
paragraph = paragraphs.nextElement()
|
||||||
if paragraph.supportsService("com.sun.star.text.Paragraph"):
|
if paragraph.supportsService("com.sun.star.text.Paragraph"):
|
||||||
|
@ -106,7 +106,7 @@ class SofImport(OooImport):
|
||||||
except RuntimeException as exc:
|
except RuntimeException as exc:
|
||||||
log.exception(u'Error processing file: %s', exc)
|
log.exception(u'Error processing file: %s', exc)
|
||||||
if not self.finish():
|
if not self.finish():
|
||||||
self.log_error(self.filepath)
|
self.logError(self.filepath)
|
||||||
|
|
||||||
def process_paragraph(self, paragraph):
|
def process_paragraph(self, paragraph):
|
||||||
"""
|
"""
|
||||||
|
@ -222,7 +222,7 @@ class SofImport(OooImport):
|
||||||
return
|
return
|
||||||
self.finish()
|
self.finish()
|
||||||
self.song = True
|
self.song = True
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
self.skip_to_close_bracket = False
|
self.skip_to_close_bracket = False
|
||||||
self.is_chorus = False
|
self.is_chorus = False
|
||||||
self.italics = False
|
self.italics = False
|
||||||
|
@ -256,7 +256,7 @@ class SofImport(OooImport):
|
||||||
if title.endswith(u','):
|
if title.endswith(u','):
|
||||||
title = title[:-1]
|
title = title[:-1]
|
||||||
self.title = title
|
self.title = title
|
||||||
self.import_wizard.incrementProgressBar(u'Processing song ' + title, 0)
|
self.importWizard.incrementProgressBar(u'Processing song ' + title, 0)
|
||||||
|
|
||||||
def add_sof_author(self, text):
|
def add_sof_author(self, text):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -98,18 +98,18 @@ class SongBeamerImport(SongImport):
|
||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
Receive a single file or a list of files to import.
|
Receive a single file or a list of files to import.
|
||||||
"""
|
"""
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.importWizard.progressBar.setMaximum(len(self.importSource))
|
||||||
if not isinstance(self.import_source, list):
|
if not isinstance(self.importSource, list):
|
||||||
return
|
return
|
||||||
for file in self.import_source:
|
for file in self.importSource:
|
||||||
# TODO: check that it is a valid SongBeamer file
|
# TODO: check that it is a valid SongBeamer file
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
return
|
return
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
self.current_verse = u''
|
self.current_verse = u''
|
||||||
self.current_verse_type = VerseType.Tags[VerseType.Verse]
|
self.current_verse_type = VerseType.Tags[VerseType.Verse]
|
||||||
read_verses = False
|
read_verses = False
|
||||||
|
@ -150,7 +150,7 @@ class SongBeamerImport(SongImport):
|
||||||
self.replace_html_tags()
|
self.replace_html_tags()
|
||||||
self.add_verse(self.current_verse, self.current_verse_type)
|
self.add_verse(self.current_verse, self.current_verse_type)
|
||||||
if not self.finish():
|
if not self.finish():
|
||||||
self.log_error(file)
|
self.logError(file)
|
||||||
|
|
||||||
def replace_html_tags(self):
|
def replace_html_tags(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -58,51 +58,51 @@ class SongImport(QtCore.QObject):
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
QtCore.QObject.__init__(self)
|
QtCore.QObject.__init__(self)
|
||||||
if kwargs.has_key(u'filename'):
|
if kwargs.has_key(u'filename'):
|
||||||
self.import_source = kwargs[u'filename']
|
self.importSource = kwargs[u'filename']
|
||||||
elif kwargs.has_key(u'filenames'):
|
elif kwargs.has_key(u'filenames'):
|
||||||
self.import_source = kwargs[u'filenames']
|
self.importSource = kwargs[u'filenames']
|
||||||
else:
|
else:
|
||||||
raise KeyError(u'Keyword arguments "filename[s]" not supplied.')
|
raise KeyError(u'Keyword arguments "filename[s]" not supplied.')
|
||||||
log.debug(self.import_source)
|
log.debug(self.importSource)
|
||||||
self.import_wizard = None
|
self.importWizard = None
|
||||||
self.song = None
|
self.song = None
|
||||||
self.stop_import_flag = False
|
self.stopImportFlag = False
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
self.error_log = []
|
self.errorLog = []
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import)
|
QtCore.SIGNAL(u'openlp_stop_wizard'), self.stopImport)
|
||||||
|
|
||||||
def set_defaults(self):
|
def setDefaults(self):
|
||||||
"""
|
"""
|
||||||
Create defaults for properties - call this before each song
|
Create defaults for properties - call this before each song
|
||||||
if importing many songs at once to ensure a clean beginning
|
if importing many songs at once to ensure a clean beginning
|
||||||
"""
|
"""
|
||||||
self.title = u''
|
self.title = u''
|
||||||
self.song_number = u''
|
self.songNumber = u''
|
||||||
self.alternate_title = u''
|
self.alternateTitle = u''
|
||||||
self.copyright = u''
|
self.copyright = u''
|
||||||
self.comments = u''
|
self.comments = u''
|
||||||
self.theme_name = u''
|
self.themeName = u''
|
||||||
self.ccli_number = u''
|
self.ccliNumber = u''
|
||||||
self.authors = []
|
self.authors = []
|
||||||
self.topics = []
|
self.topics = []
|
||||||
self.media_files = []
|
self.mediaFiles = []
|
||||||
self.song_book_name = u''
|
self.songBookName = u''
|
||||||
self.song_book_pub = u''
|
self.songBookPub = u''
|
||||||
self.verse_order_list_generated_useful = False
|
self.verseOrderListGeneratedUseful = False
|
||||||
self.verse_order_list_generated = []
|
self.verseOrderListGenerated = []
|
||||||
self.verse_order_list = []
|
self.verseOrderList = []
|
||||||
self.verses = []
|
self.verses = []
|
||||||
self.verse_counts = {}
|
self.verseCounts = {}
|
||||||
self.copyright_string = unicode(translate(
|
self.copyrightString = unicode(translate(
|
||||||
'SongsPlugin.SongImport', 'copyright'))
|
'SongsPlugin.SongImport', 'copyright'))
|
||||||
|
|
||||||
def log_error(self, filepath, reason=SongStrings.SongIncomplete):
|
def logError(self, filepath, reason=SongStrings.SongIncomplete):
|
||||||
"""
|
"""
|
||||||
This should be called, when a song could not be imported.
|
This should be called, when a song could not be imported.
|
||||||
|
|
||||||
``filepath``
|
``filepath``
|
||||||
This should be the file path if ``self.import_source`` is a list
|
This should be the file path if ``self.importSource`` is a list
|
||||||
with different files. If it is not a list, but a single file (for
|
with different files. If it is not a list, but a single file (for
|
||||||
instance a database), then this should be the song's title.
|
instance a database), then this should be the song's title.
|
||||||
|
|
||||||
|
@ -110,30 +110,30 @@ class SongImport(QtCore.QObject):
|
||||||
The reason, why the import failed. The string should be as
|
The reason, why the import failed. The string should be as
|
||||||
informative as possible.
|
informative as possible.
|
||||||
"""
|
"""
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
if self.import_wizard is None:
|
if self.importWizard is None:
|
||||||
return
|
return
|
||||||
if self.import_wizard.errorReportTextEdit.isHidden():
|
if self.importWizard.errorReportTextEdit.isHidden():
|
||||||
self.import_wizard.errorReportTextEdit.setText(
|
self.importWizard.errorReportTextEdit.setText(
|
||||||
translate('SongsPlugin.SongImport',
|
translate('SongsPlugin.SongImport',
|
||||||
'The following songs could not be imported:'))
|
'The following songs could not be imported:'))
|
||||||
self.import_wizard.errorReportTextEdit.setVisible(True)
|
self.importWizard.errorReportTextEdit.setVisible(True)
|
||||||
self.import_wizard.errorCopyToButton.setVisible(True)
|
self.importWizard.errorCopyToButton.setVisible(True)
|
||||||
self.import_wizard.errorSaveToButton.setVisible(True)
|
self.importWizard.errorSaveToButton.setVisible(True)
|
||||||
self.import_wizard.errorReportTextEdit.append(
|
self.importWizard.errorReportTextEdit.append(
|
||||||
u'- %s (%s)' % (filepath, reason))
|
u'- %s (%s)' % (filepath, reason))
|
||||||
|
|
||||||
def stop_import(self):
|
def stopImport(self):
|
||||||
"""
|
"""
|
||||||
Sets the flag for importers to stop their import
|
Sets the flag for importers to stop their import
|
||||||
"""
|
"""
|
||||||
log.debug(u'Stopping songs import')
|
log.debug(u'Stopping songs import')
|
||||||
self.stop_import_flag = True
|
self.stopImportFlag = True
|
||||||
|
|
||||||
def register(self, import_wizard):
|
def register(self, import_wizard):
|
||||||
self.import_wizard = import_wizard
|
self.importWizard = import_wizard
|
||||||
|
|
||||||
def tidy_text(self, text):
|
def tidyText(self, text):
|
||||||
"""
|
"""
|
||||||
Get rid of some dodgy unicode and formatting characters we're not
|
Get rid of some dodgy unicode and formatting characters we're not
|
||||||
interested in. Some can be converted to ascii.
|
interested in. Some can be converted to ascii.
|
||||||
|
@ -151,34 +151,34 @@ class SongImport(QtCore.QObject):
|
||||||
text = re.sub(r' ?(\n{5}|\f)+ ?', u'\f', text)
|
text = re.sub(r' ?(\n{5}|\f)+ ?', u'\f', text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def process_song_text(self, text):
|
def processSongText(self, text):
|
||||||
verse_texts = text.split(u'\n\n')
|
verse_texts = text.split(u'\n\n')
|
||||||
for verse_text in verse_texts:
|
for verse_text in verse_texts:
|
||||||
if verse_text.strip() != u'':
|
if verse_text.strip() != u'':
|
||||||
self.process_verse_text(verse_text.strip())
|
self.processVerseText(verse_text.strip())
|
||||||
|
|
||||||
def process_verse_text(self, text):
|
def processVerseText(self, text):
|
||||||
lines = text.split(u'\n')
|
lines = text.split(u'\n')
|
||||||
if text.lower().find(self.copyright_string) >= 0 \
|
if text.lower().find(self.copyrightString) >= 0 \
|
||||||
or text.find(unicode(SongStrings.CopyrightSymbol)) >= 0:
|
or text.find(unicode(SongStrings.CopyrightSymbol)) >= 0:
|
||||||
copyright_found = False
|
copyright_found = False
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if (copyright_found or
|
if (copyright_found or
|
||||||
line.lower().find(self.copyright_string) >= 0 or
|
line.lower().find(self.copyrightString) >= 0 or
|
||||||
line.find(unicode(SongStrings.CopyrightSymbol)) >= 0):
|
line.find(unicode(SongStrings.CopyrightSymbol)) >= 0):
|
||||||
copyright_found = True
|
copyright_found = True
|
||||||
self.add_copyright(line)
|
self.addCopyright(line)
|
||||||
else:
|
else:
|
||||||
self.parse_author(line)
|
self.parseAuthor(line)
|
||||||
return
|
return
|
||||||
if len(lines) == 1:
|
if len(lines) == 1:
|
||||||
self.parse_author(lines[0])
|
self.parseAuthor(lines[0])
|
||||||
return
|
return
|
||||||
if not self.title:
|
if not self.title:
|
||||||
self.title = lines[0]
|
self.title = lines[0]
|
||||||
self.add_verse(text)
|
self.addVerse(text)
|
||||||
|
|
||||||
def add_copyright(self, copyright):
|
def addCopyright(self, copyright):
|
||||||
"""
|
"""
|
||||||
Build the copyright field
|
Build the copyright field
|
||||||
"""
|
"""
|
||||||
|
@ -188,7 +188,7 @@ class SongImport(QtCore.QObject):
|
||||||
self.copyright += ' '
|
self.copyright += ' '
|
||||||
self.copyright += copyright
|
self.copyright += copyright
|
||||||
|
|
||||||
def parse_author(self, text):
|
def parseAuthor(self, text):
|
||||||
"""
|
"""
|
||||||
Add the author. OpenLP stores them individually so split by 'and', '&'
|
Add the author. OpenLP stores them individually so split by 'and', '&'
|
||||||
and comma. However need to check for 'Mr and Mrs Smith' and turn it to
|
and comma. However need to check for 'Mr and Mrs Smith' and turn it to
|
||||||
|
@ -204,9 +204,9 @@ class SongImport(QtCore.QObject):
|
||||||
if author2.endswith(u'.'):
|
if author2.endswith(u'.'):
|
||||||
author2 = author2[:-1]
|
author2 = author2[:-1]
|
||||||
if author2:
|
if author2:
|
||||||
self.add_author(author2)
|
self.addAuthor(author2)
|
||||||
|
|
||||||
def add_author(self, author):
|
def addAuthor(self, author):
|
||||||
"""
|
"""
|
||||||
Add an author to the list
|
Add an author to the list
|
||||||
"""
|
"""
|
||||||
|
@ -214,15 +214,15 @@ class SongImport(QtCore.QObject):
|
||||||
return
|
return
|
||||||
self.authors.append(author)
|
self.authors.append(author)
|
||||||
|
|
||||||
def add_media_file(self, filename):
|
def addMediaFile(self, filename, weight=0):
|
||||||
"""
|
"""
|
||||||
Add a media file to the list
|
Add a media file to the list
|
||||||
"""
|
"""
|
||||||
if filename in self.media_files:
|
if filename in map(lambda x: x[0], self.mediaFiles):
|
||||||
return
|
return
|
||||||
self.media_files.append(filename)
|
self.mediaFiles.append((filename, weight))
|
||||||
|
|
||||||
def add_verse(self, verse_text, verse_def=u'v', lang=None):
|
def addVerse(self, verse_text, verse_def=u'v', lang=None):
|
||||||
"""
|
"""
|
||||||
Add a verse. This is the whole verse, lines split by \\n. It will also
|
Add a verse. This is the whole verse, lines split by \\n. It will also
|
||||||
attempt to detect duplicates. In this case it will just add to the verse
|
attempt to detect duplicates. In this case it will just add to the verse
|
||||||
|
@ -241,29 +241,29 @@ class SongImport(QtCore.QObject):
|
||||||
"""
|
"""
|
||||||
for (old_verse_def, old_verse, old_lang) in self.verses:
|
for (old_verse_def, old_verse, old_lang) in self.verses:
|
||||||
if old_verse.strip() == verse_text.strip():
|
if old_verse.strip() == verse_text.strip():
|
||||||
self.verse_order_list_generated.append(old_verse_def)
|
self.verseOrderListGenerated.append(old_verse_def)
|
||||||
self.verse_order_list_generated_useful = True
|
self.verseOrderListGeneratedUseful = True
|
||||||
return
|
return
|
||||||
if verse_def[0] in self.verse_counts:
|
if verse_def[0] in self.verseCounts:
|
||||||
self.verse_counts[verse_def[0]] += 1
|
self.verseCounts[verse_def[0]] += 1
|
||||||
else:
|
else:
|
||||||
self.verse_counts[verse_def[0]] = 1
|
self.verseCounts[verse_def[0]] = 1
|
||||||
if len(verse_def) == 1:
|
if len(verse_def) == 1:
|
||||||
verse_def += unicode(self.verse_counts[verse_def[0]])
|
verse_def += unicode(self.verseCounts[verse_def[0]])
|
||||||
elif int(verse_def[1:]) > self.verse_counts[verse_def[0]]:
|
elif int(verse_def[1:]) > self.verseCounts[verse_def[0]]:
|
||||||
self.verse_counts[verse_def[0]] = int(verse_def[1:])
|
self.verseCounts[verse_def[0]] = int(verse_def[1:])
|
||||||
self.verses.append([verse_def, verse_text.rstrip(), lang])
|
self.verses.append([verse_def, verse_text.rstrip(), lang])
|
||||||
self.verse_order_list_generated.append(verse_def)
|
self.verseOrderListGenerated.append(verse_def)
|
||||||
|
|
||||||
def repeat_verse(self):
|
def repeatVerse(self):
|
||||||
"""
|
"""
|
||||||
Repeat the previous verse in the verse order
|
Repeat the previous verse in the verse order
|
||||||
"""
|
"""
|
||||||
self.verse_order_list_generated.append(
|
self.verseOrderListGenerated.append(
|
||||||
self.verse_order_list_generated[-1])
|
self.verseOrderListGenerated[-1])
|
||||||
self.verse_order_list_generated_useful = True
|
self.verseOrderListGeneratedUseful = True
|
||||||
|
|
||||||
def check_complete(self):
|
def checkComplete(self):
|
||||||
"""
|
"""
|
||||||
Check the mandatory fields are entered (i.e. title and a verse)
|
Check the mandatory fields are entered (i.e. title and a verse)
|
||||||
Author not checked here, if no author then "Author unknown" is
|
Author not checked here, if no author then "Author unknown" is
|
||||||
|
@ -278,21 +278,21 @@ class SongImport(QtCore.QObject):
|
||||||
"""
|
"""
|
||||||
All fields have been set to this song. Write the song to disk.
|
All fields have been set to this song. Write the song to disk.
|
||||||
"""
|
"""
|
||||||
if not self.check_complete():
|
if not self.checkComplete():
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
return False
|
return False
|
||||||
log.info(u'committing song %s to database', self.title)
|
log.info(u'committing song %s to database', self.title)
|
||||||
song = Song()
|
song = Song()
|
||||||
song.title = self.title
|
song.title = self.title
|
||||||
if self.import_wizard is not None:
|
if self.importWizard is not None:
|
||||||
self.import_wizard.incrementProgressBar(
|
self.importWizard.incrementProgressBar(
|
||||||
WizardStrings.ImportingType % song.title)
|
WizardStrings.ImportingType % song.title)
|
||||||
song.alternate_title = self.alternate_title
|
song.alternate_title = self.alternateTitle
|
||||||
# Values will be set when cleaning the song.
|
# Values will be set when cleaning the song.
|
||||||
song.search_title = u''
|
song.search_title = u''
|
||||||
song.search_lyrics = u''
|
song.search_lyrics = u''
|
||||||
song.verse_order = u''
|
song.verse_order = u''
|
||||||
song.song_number = self.song_number
|
song.song_number = self.songNumber
|
||||||
verses_changed_to_other = {}
|
verses_changed_to_other = {}
|
||||||
sxml = SongXML()
|
sxml = SongXML()
|
||||||
other_count = 1
|
other_count = 1
|
||||||
|
@ -310,18 +310,18 @@ class SongImport(QtCore.QObject):
|
||||||
verse_def = new_verse_def
|
verse_def = new_verse_def
|
||||||
sxml.add_verse_to_lyrics(verse_tag, verse_def[1:], verse_text, lang)
|
sxml.add_verse_to_lyrics(verse_tag, verse_def[1:], verse_text, lang)
|
||||||
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
||||||
if not len(self.verse_order_list) and \
|
if not len(self.verseOrderList) and \
|
||||||
self.verse_order_list_generated_useful:
|
self.verseOrderListGeneratedUseful:
|
||||||
self.verse_order_list = self.verse_order_list_generated
|
self.verseOrderList = self.verseOrderListGenerated
|
||||||
for i, current_verse_def in enumerate(self.verse_order_list):
|
for i, current_verse_def in enumerate(self.verseOrderList):
|
||||||
if verses_changed_to_other.has_key(current_verse_def):
|
if verses_changed_to_other.has_key(current_verse_def):
|
||||||
self.verse_order_list[i] = \
|
self.verseOrderList[i] = \
|
||||||
verses_changed_to_other[current_verse_def]
|
verses_changed_to_other[current_verse_def]
|
||||||
song.verse_order = u' '.join(self.verse_order_list)
|
song.verse_order = u' '.join(self.verseOrderList)
|
||||||
song.copyright = self.copyright
|
song.copyright = self.copyright
|
||||||
song.comments = self.comments
|
song.comments = self.comments
|
||||||
song.theme_name = self.theme_name
|
song.theme_name = self.themeName
|
||||||
song.ccli_number = self.ccli_number
|
song.ccli_number = self.ccliNumber
|
||||||
for authortext in self.authors:
|
for authortext in self.authors:
|
||||||
author = self.manager.get_object_filtered(Author,
|
author = self.manager.get_object_filtered(Author,
|
||||||
Author.display_name == authortext)
|
Author.display_name == authortext)
|
||||||
|
@ -330,17 +330,18 @@ class SongImport(QtCore.QObject):
|
||||||
last_name=authortext.split(u' ')[-1],
|
last_name=authortext.split(u' ')[-1],
|
||||||
first_name=u' '.join(authortext.split(u' ')[:-1]))
|
first_name=u' '.join(authortext.split(u' ')[:-1]))
|
||||||
song.authors.append(author)
|
song.authors.append(author)
|
||||||
for filename in self.media_files:
|
for filename, weight in self.mediaFiles:
|
||||||
media_file = self.manager.get_object_filtered(MediaFile,
|
media_file = self.manager.get_object_filtered(MediaFile,
|
||||||
MediaFile.file_name == filename)
|
MediaFile.file_name == filename)
|
||||||
if not media_file:
|
if not media_file:
|
||||||
song.media_files.append(MediaFile.populate(file_name=filename))
|
song.media_files.append(
|
||||||
if self.song_book_name:
|
MediaFile.populate(file_name=filename, weight=weight))
|
||||||
|
if self.songBookName:
|
||||||
song_book = self.manager.get_object_filtered(Book,
|
song_book = self.manager.get_object_filtered(Book,
|
||||||
Book.name == self.song_book_name)
|
Book.name == self.songBookName)
|
||||||
if song_book is None:
|
if song_book is None:
|
||||||
song_book = Book.populate(name=self.song_book_name,
|
song_book = Book.populate(name=self.songBookName,
|
||||||
publisher=self.song_book_pub)
|
publisher=self.songBookPub)
|
||||||
song.book = song_book
|
song.book = song_book
|
||||||
for topictext in self.topics:
|
for topictext in self.topics:
|
||||||
if not topictext:
|
if not topictext:
|
||||||
|
@ -352,36 +353,5 @@ class SongImport(QtCore.QObject):
|
||||||
song.topics.append(topic)
|
song.topics.append(topic)
|
||||||
clean_song(self.manager, song)
|
clean_song(self.manager, song)
|
||||||
self.manager.save_object(song)
|
self.manager.save_object(song)
|
||||||
self.set_defaults()
|
self.setDefaults()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def print_song(self):
|
|
||||||
"""
|
|
||||||
For debugging
|
|
||||||
"""
|
|
||||||
print u'========================================' \
|
|
||||||
+ u'========================================'
|
|
||||||
print u'TITLE: ' + self.title
|
|
||||||
print u'ALT TITLE: ' + self.alternate_title
|
|
||||||
for (verse_def, verse_text, lang) in self.verses:
|
|
||||||
print u'VERSE ' + verse_def + u': ' + verse_text
|
|
||||||
print u'ORDER: ' + u' '.join(self.verse_order_list)
|
|
||||||
print u'GENERATED ORDER: ' + u' '.join(self.verse_order_list_generated)
|
|
||||||
for author in self.authors:
|
|
||||||
print u'AUTHOR: ' + author
|
|
||||||
if self.copyright:
|
|
||||||
print u'COPYRIGHT: ' + self.copyright
|
|
||||||
if self.song_book_name:
|
|
||||||
print u'BOOK: ' + self.song_book_name
|
|
||||||
if self.song_book_pub:
|
|
||||||
print u'BOOK PUBLISHER: ' + self.song_book_pub
|
|
||||||
if self.song_number:
|
|
||||||
print u'NUMBER: ' + self.song_number
|
|
||||||
for topictext in self.topics:
|
|
||||||
print u'TOPIC: ' + topictext
|
|
||||||
if self.comments:
|
|
||||||
print u'COMMENTS: ' + self.comments
|
|
||||||
if self.theme_name:
|
|
||||||
print u'THEME: ' + self.theme_name
|
|
||||||
if self.ccli_number:
|
|
||||||
print u'CCLI: ' + self.ccli_number
|
|
||||||
|
|
|
@ -95,120 +95,120 @@ class SongShowPlusImport(SongImport):
|
||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
Receive a single file or a list of files to import.
|
Receive a single file or a list of files to import.
|
||||||
"""
|
"""
|
||||||
if not isinstance(self.import_source, list):
|
if not isinstance(self.importSource, list):
|
||||||
return
|
return
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.importWizard.progressBar.setMaximum(len(self.importSource))
|
||||||
for file in self.import_source:
|
for file in self.importSource:
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
return
|
return
|
||||||
self.sspVerseOrderList = []
|
self.sspVerseOrderList = []
|
||||||
otherCount = 0
|
other_count = 0
|
||||||
otherList = {}
|
other_list = {}
|
||||||
file_name = os.path.split(file)[1]
|
file_name = os.path.split(file)[1]
|
||||||
self.import_wizard.incrementProgressBar(
|
self.importWizard.incrementProgressBar(
|
||||||
WizardStrings.ImportingType % file_name, 0)
|
WizardStrings.ImportingType % file_name, 0)
|
||||||
songData = open(file, 'rb')
|
song_data = open(file, 'rb')
|
||||||
while True:
|
while True:
|
||||||
blockKey, = struct.unpack("I", songData.read(4))
|
block_key, = struct.unpack("I", song_data.read(4))
|
||||||
# The file ends with 4 NUL's
|
# The file ends with 4 NUL's
|
||||||
if blockKey == 0:
|
if block_key == 0:
|
||||||
break
|
break
|
||||||
nextBlockStarts, = struct.unpack("I", songData.read(4))
|
next_block_starts, = struct.unpack("I", song_data.read(4))
|
||||||
nextBlockStarts += songData.tell()
|
next_block_starts += song_data.tell()
|
||||||
if blockKey in (VERSE, CHORUS, BRIDGE):
|
if block_key in (VERSE, CHORUS, BRIDGE):
|
||||||
null, verseNo, = struct.unpack("BB", songData.read(2))
|
null, verse_no, = struct.unpack("BB", song_data.read(2))
|
||||||
elif blockKey == CUSTOM_VERSE:
|
elif block_key == CUSTOM_VERSE:
|
||||||
null, verseNameLength, = struct.unpack("BB",
|
null, verse_name_length, = struct.unpack("BB",
|
||||||
songData.read(2))
|
song_data.read(2))
|
||||||
verseName = songData.read(verseNameLength)
|
verse_name = song_data.read(verse_name_length)
|
||||||
lengthDescriptorSize, = struct.unpack("B", songData.read(1))
|
length_descriptor_size, = struct.unpack("B", song_data.read(1))
|
||||||
log.debug(lengthDescriptorSize)
|
log.debug(length_descriptor_size)
|
||||||
# Detect if/how long the length descriptor is
|
# Detect if/how long the length descriptor is
|
||||||
if lengthDescriptorSize == 12 or lengthDescriptorSize == 20:
|
if length_descriptor_size == 12 or length_descriptor_size == 20:
|
||||||
lengthDescriptor, = struct.unpack("I", songData.read(4))
|
length_descriptor, = struct.unpack("I", song_data.read(4))
|
||||||
elif lengthDescriptorSize == 2:
|
elif length_descriptor_size == 2:
|
||||||
lengthDescriptor = 1
|
length_descriptor = 1
|
||||||
elif lengthDescriptorSize == 9:
|
elif length_descriptor_size == 9:
|
||||||
lengthDescriptor = 0
|
length_descriptor = 0
|
||||||
else:
|
else:
|
||||||
lengthDescriptor, = struct.unpack("B", songData.read(1))
|
length_descriptor, = struct.unpack("B", song_data.read(1))
|
||||||
log.debug(lengthDescriptorSize)
|
log.debug(length_descriptor_size)
|
||||||
data = songData.read(lengthDescriptor)
|
data = song_data.read(length_descriptor)
|
||||||
if blockKey == TITLE:
|
if block_key == TITLE:
|
||||||
self.title = unicode(data, u'cp1252')
|
self.title = unicode(data, u'cp1252')
|
||||||
elif blockKey == AUTHOR:
|
elif block_key == AUTHOR:
|
||||||
authors = data.split(" / ")
|
authors = data.split(" / ")
|
||||||
for author in authors:
|
for author in authors:
|
||||||
if author.find(",") !=-1:
|
if author.find(",") !=-1:
|
||||||
authorParts = author.split(", ")
|
authorParts = author.split(", ")
|
||||||
author = authorParts[1] + " " + authorParts[0]
|
author = authorParts[1] + " " + authorParts[0]
|
||||||
self.parse_author(unicode(author, u'cp1252'))
|
self.parseAuthor(unicode(author, u'cp1252'))
|
||||||
elif blockKey == COPYRIGHT:
|
elif block_key == COPYRIGHT:
|
||||||
self.add_copyright(unicode(data, u'cp1252'))
|
self.addCopyright(unicode(data, u'cp1252'))
|
||||||
elif blockKey == CCLI_NO:
|
elif block_key == CCLI_NO:
|
||||||
self.ccli_number = int(data)
|
self.ccliNumber = int(data)
|
||||||
elif blockKey == VERSE:
|
elif block_key == VERSE:
|
||||||
self.add_verse(unicode(data, u'cp1252'),
|
self.addVerse(unicode(data, u'cp1252'),
|
||||||
"%s%s" % (VerseType.Tags[VerseType.Verse], verseNo))
|
"%s%s" % (VerseType.Tags[VerseType.Verse], verse_no))
|
||||||
elif blockKey == CHORUS:
|
elif block_key == CHORUS:
|
||||||
self.add_verse(unicode(data, u'cp1252'),
|
self.addVerse(unicode(data, u'cp1252'),
|
||||||
"%s%s" % (VerseType.Tags[VerseType.Chorus], verseNo))
|
"%s%s" % (VerseType.Tags[VerseType.Chorus], verse_no))
|
||||||
elif blockKey == BRIDGE:
|
elif block_key == BRIDGE:
|
||||||
self.add_verse(unicode(data, u'cp1252'),
|
self.addVerse(unicode(data, u'cp1252'),
|
||||||
"%s%s" % (VerseType.Tags[VerseType.Bridge], verseNo))
|
"%s%s" % (VerseType.Tags[VerseType.Bridge], verse_no))
|
||||||
elif blockKey == TOPIC:
|
elif block_key == TOPIC:
|
||||||
self.topics.append(unicode(data, u'cp1252'))
|
self.topics.append(unicode(data, u'cp1252'))
|
||||||
elif blockKey == COMMENTS:
|
elif block_key == COMMENTS:
|
||||||
self.comments = unicode(data, u'cp1252')
|
self.comments = unicode(data, u'cp1252')
|
||||||
elif blockKey == VERSE_ORDER:
|
elif block_key == VERSE_ORDER:
|
||||||
verseTag = self.toOpenLPVerseTag(data, True)
|
verse_tag = self.toOpenLPVerseTag(data, True)
|
||||||
if verseTag:
|
if verse_tag:
|
||||||
if not isinstance(verseTag, unicode):
|
if not isinstance(verse_tag, unicode):
|
||||||
verseTag = unicode(verseTag, u'cp1252')
|
verse_tag = unicode(verse_tag, u'cp1252')
|
||||||
self.sspVerseOrderList.append(verseTag)
|
self.sspVerseOrderList.append(verse_tag)
|
||||||
elif blockKey == SONG_BOOK:
|
elif block_key == SONG_BOOK:
|
||||||
self.song_book_name = unicode(data, u'cp1252')
|
self.songBookName = unicode(data, u'cp1252')
|
||||||
elif blockKey == SONG_NUMBER:
|
elif block_key == SONG_NUMBER:
|
||||||
self.song_number = ord(data)
|
self.songNumber = ord(data)
|
||||||
elif blockKey == CUSTOM_VERSE:
|
elif block_key == CUSTOM_VERSE:
|
||||||
verseTag = self.toOpenLPVerseTag(verseName)
|
verse_tag = self.toOpenLPVerseTag(verse_name)
|
||||||
self.add_verse(unicode(data, u'cp1252'), verseTag)
|
self.addVerse(unicode(data, u'cp1252'), verse_tag)
|
||||||
else:
|
else:
|
||||||
log.debug("Unrecognised blockKey: %s, data: %s"
|
log.debug("Unrecognised blockKey: %s, data: %s"
|
||||||
% (blockKey, data))
|
% (block_key, data))
|
||||||
songData.seek(nextBlockStarts)
|
song_data.seek(next_block_starts)
|
||||||
self.verse_order_list = self.sspVerseOrderList
|
self.verseOrderList = self.sspVerseOrderList
|
||||||
songData.close()
|
song_data.close()
|
||||||
if not self.finish():
|
if not self.finish():
|
||||||
self.log_error(file)
|
self.logError(file)
|
||||||
|
|
||||||
def toOpenLPVerseTag(self, verseName, ignoreUnique=False):
|
def toOpenLPVerseTag(self, verse_name, ignore_unique=False):
|
||||||
if verseName.find(" ") != -1:
|
if verse_name.find(" ") != -1:
|
||||||
verseParts = verseName.split(" ")
|
verse_parts = verse_name.split(" ")
|
||||||
verseType = verseParts[0]
|
verse_type = verse_parts[0]
|
||||||
verseNumber = verseParts[1]
|
verse_number = verse_parts[1]
|
||||||
else:
|
else:
|
||||||
verseType = verseName
|
verse_type = verse_name
|
||||||
verseNumber = "1"
|
verse_number = "1"
|
||||||
verseType = verseType.lower()
|
verse_type = verse_type.lower()
|
||||||
if verseType == "verse":
|
if verse_type == "verse":
|
||||||
verseTag = VerseType.Tags[VerseType.Verse]
|
verse_tag = VerseType.Tags[VerseType.Verse]
|
||||||
elif verseType == "chorus":
|
elif verse_type == "chorus":
|
||||||
verseTag = VerseType.Tags[VerseType.Chorus]
|
verse_tag = VerseType.Tags[VerseType.Chorus]
|
||||||
elif verseType == "bridge":
|
elif verse_type == "bridge":
|
||||||
verseTag = VerseType.Tags[VerseType.Bridge]
|
verse_tag = VerseType.Tags[VerseType.Bridge]
|
||||||
elif verseType == "pre-chorus":
|
elif verse_type == "pre-chorus":
|
||||||
verseTag = VerseType.Tags[VerseType.PreChorus]
|
verse_tag = VerseType.Tags[VerseType.PreChorus]
|
||||||
else:
|
else:
|
||||||
if not self.otherList.has_key(verseName):
|
if not self.otherList.has_key(verse_name):
|
||||||
if ignoreUnique:
|
if ignore_unique:
|
||||||
return None
|
return None
|
||||||
self.otherCount = self.otherCount + 1
|
self.otherCount = self.otherCount + 1
|
||||||
self.otherList[verseName] = str(self.otherCount)
|
self.otherList[verse_name] = str(self.otherCount)
|
||||||
verseTag = VerseType.Tags[VerseType.Other]
|
verse_tag = VerseType.Tags[VerseType.Other]
|
||||||
verseNumber = self.otherList[verseName]
|
verse_number = self.otherList[verse_name]
|
||||||
return verseTag + verseNumber
|
return verse_tag + verse_number
|
||||||
|
|
|
@ -98,58 +98,58 @@ class WowImport(SongImport):
|
||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
SongImport.__init__(self, manager, **kwargs)
|
||||||
|
|
||||||
def do_import(self):
|
def doImport(self):
|
||||||
"""
|
"""
|
||||||
Receive a single file or a list of files to import.
|
Receive a single file or a list of files to import.
|
||||||
"""
|
"""
|
||||||
if isinstance(self.import_source, list):
|
if isinstance(self.importSource, list):
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.importWizard.progressBar.setMaximum(len(self.importSource))
|
||||||
for file in self.import_source:
|
for file in self.importSource:
|
||||||
if self.stop_import_flag:
|
if self.stopImportFlag:
|
||||||
return
|
return
|
||||||
file_name = os.path.split(file)[1]
|
file_name = os.path.split(file)[1]
|
||||||
# Get the song title
|
# Get the song title
|
||||||
self.title = file_name.rpartition(u'.')[0]
|
self.title = file_name.rpartition(u'.')[0]
|
||||||
songData = open(file, 'rb')
|
song_data = open(file, 'rb')
|
||||||
if songData.read(19) != u'WoW File\nSong Words':
|
if song_data.read(19) != u'WoW File\nSong Words':
|
||||||
self.log_error(file)
|
self.logError(file)
|
||||||
continue
|
continue
|
||||||
# Seek to byte which stores number of blocks in the song
|
# Seek to byte which stores number of blocks in the song
|
||||||
songData.seek(56)
|
song_data.seek(56)
|
||||||
no_of_blocks = ord(songData.read(1))
|
no_of_blocks = ord(song_data.read(1))
|
||||||
# Seek to the beging of the first block
|
# Seek to the beging of the first block
|
||||||
songData.seek(82)
|
song_data.seek(82)
|
||||||
for block in range(no_of_blocks):
|
for block in range(no_of_blocks):
|
||||||
self.lines_to_read = ord(songData.read(1))
|
self.linesToRead = ord(song_data.read(1))
|
||||||
# Skip 3 nulls to the beginnig of the 1st line
|
# Skip 3 nulls to the beginnig of the 1st line
|
||||||
songData.seek(3, os.SEEK_CUR)
|
song_data.seek(3, os.SEEK_CUR)
|
||||||
block_text = u''
|
block_text = u''
|
||||||
while self.lines_to_read:
|
while self.linesToRead:
|
||||||
self.line_text = unicode(
|
self.lineText = unicode(
|
||||||
songData.read(ord(songData.read(1))), u'cp1252')
|
song_data.read(ord(song_data.read(1))), u'cp1252')
|
||||||
songData.seek(1, os.SEEK_CUR)
|
song_data.seek(1, os.SEEK_CUR)
|
||||||
if block_text:
|
if block_text:
|
||||||
block_text += u'\n'
|
block_text += u'\n'
|
||||||
block_text += self.line_text
|
block_text += self.lineText
|
||||||
self.lines_to_read -= 1
|
self.linesToRead -= 1
|
||||||
block_type = BLOCK_TYPES[ord(songData.read(1))]
|
block_type = BLOCK_TYPES[ord(song_data.read(1))]
|
||||||
# Skip 3 nulls at the end of the block
|
# Skip 3 nulls at the end of the block
|
||||||
songData.seek(3, os.SEEK_CUR)
|
song_data.seek(3, os.SEEK_CUR)
|
||||||
# Blocks are seperated by 2 bytes, skip them, but not if
|
# Blocks are seperated by 2 bytes, skip them, but not if
|
||||||
# this is the last block!
|
# this is the last block!
|
||||||
if block + 1 < no_of_blocks:
|
if block + 1 < no_of_blocks:
|
||||||
songData.seek(2, os.SEEK_CUR)
|
song_data.seek(2, os.SEEK_CUR)
|
||||||
self.add_verse(block_text, block_type)
|
self.addVerse(block_text, block_type)
|
||||||
# Now to extract the author
|
# Now to extract the author
|
||||||
author_length = ord(songData.read(1))
|
author_length = ord(song_data.read(1))
|
||||||
if author_length:
|
if author_length:
|
||||||
self.parse_author(
|
self.parseAuthor(
|
||||||
unicode(songData.read(author_length), u'cp1252'))
|
unicode(song_data.read(author_length), u'cp1252'))
|
||||||
# Finally the copyright
|
# Finally the copyright
|
||||||
copyright_length = ord(songData.read(1))
|
copyright_length = ord(song_data.read(1))
|
||||||
if copyright_length:
|
if copyright_length:
|
||||||
self.add_copyright(unicode(
|
self.addCopyright(unicode(
|
||||||
songData.read(copyright_length), u'cp1252'))
|
song_data.read(copyright_length), u'cp1252'))
|
||||||
songData.close()
|
song_data.close()
|
||||||
if not self.finish():
|
if not self.finish():
|
||||||
self.log_error(file)
|
self.logError(file)
|
||||||
|
|
Loading…
Reference in New Issue