forked from openlp/openlp
ask before creating an error report
copy not imported files to a folder
This commit is contained in:
parent
d45f93b594
commit
48d0d39a17
@ -742,12 +742,19 @@ class SongImportForm(OpenLPWizard):
|
|||||||
)
|
)
|
||||||
importer.do_import()
|
importer.do_import()
|
||||||
if importer.error_log:
|
if importer.error_log:
|
||||||
error_path = importer.write_error_report()
|
|
||||||
self.progressLabel.setTextInteractionFlags(
|
self.progressLabel.setTextInteractionFlags(
|
||||||
QtCore.Qt.TextSelectableByMouse)
|
QtCore.Qt.TextSelectableByMouse)
|
||||||
|
self.progressLabel.setText(translate(
|
||||||
|
'SongsPlugin.SongImportForm', 'Your song import failed.'))
|
||||||
|
if critical_error_message_box(translate('SongsPlugin.SongImportForm',
|
||||||
|
'Song import failed.'), translate('SongsPlugin.SongImportForm',
|
||||||
|
'Your song import failed. Do you want to create an error '
|
||||||
|
'report?'), self, True) == QtGui.QMessageBox.No:
|
||||||
|
return
|
||||||
|
error_path = importer.write_error_report()
|
||||||
self.progressLabel.setText(unicode(translate(
|
self.progressLabel.setText(unicode(translate(
|
||||||
'SongsPlugin.SongImportForm', 'Your song import failed. See '
|
'SongsPlugin.SongImportForm', 'Your song import failed. '
|
||||||
'the error report for more details:\n%s')) % error_path)
|
'For more details see the error report:\n%s')) % error_path)
|
||||||
else:
|
else:
|
||||||
self.progressLabel.setText(WizardStrings.FinishedImport)
|
self.progressLabel.setText(WizardStrings.FinishedImport)
|
||||||
|
|
||||||
|
@ -94,7 +94,6 @@ 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.import_source = u'sqlite:///%s' % self.import_source
|
|
||||||
self.source_session = None
|
self.source_session = None
|
||||||
|
|
||||||
def do_import(self):
|
def do_import(self):
|
||||||
@ -106,6 +105,7 @@ class OpenLPSongImport(SongImport):
|
|||||||
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
|
||||||
engine = create_engine(self.import_source)
|
engine = create_engine(self.import_source)
|
||||||
source_meta = MetaData()
|
source_meta = MetaData()
|
||||||
source_meta.reflect(engine)
|
source_meta.reflect(engine)
|
||||||
|
@ -28,10 +28,11 @@ import datetime
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
|
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
from openlp.core.lib import Receiver, translate
|
from openlp.core.lib import Receiver, translate, check_directory_exists
|
||||||
from openlp.core.ui.wizard import WizardStrings
|
from openlp.core.ui.wizard import WizardStrings
|
||||||
from openlp.core.utils import AppLocation
|
from openlp.core.utils import AppLocation
|
||||||
from openlp.plugins.songs.lib import clean_song, VerseType
|
from openlp.plugins.songs.lib import clean_song, VerseType
|
||||||
@ -121,12 +122,19 @@ class SongImport(QtCore.QObject):
|
|||||||
"""
|
"""
|
||||||
report_path = os.path.join(AppLocation.get_data_path(), unicode(translate(
|
report_path = os.path.join(AppLocation.get_data_path(), unicode(translate(
|
||||||
'SongsPlugin.SongImport','song_import_report (%s).txt')) %
|
'SongsPlugin.SongImport','song_import_report (%s).txt')) %
|
||||||
datetime.datetime.now().strftime(u'%Y-%m-%dT%H:%M:%S'))
|
datetime.datetime.now().strftime(u'%Y-%m-%d %H:%M:%S'))
|
||||||
report_file = codecs.open(report_path, u'w', u'utf-8')
|
report_file = codecs.open(report_path, u'w', u'utf-8')
|
||||||
report_file.write(translate('SongsPlugin.SongImport',
|
report_file.write(translate('SongsPlugin.SongImport',
|
||||||
'The following songs could not be imported:\n'))
|
'The following songs could not be imported:\n'))
|
||||||
for filepath, reason in self.error_log:
|
for filepath, reason in self.error_log:
|
||||||
report_file.write(u'- %s (%s)\n' % (filepath, reason))
|
report_file.write(u'- %s (%s)\n' % (filepath, reason))
|
||||||
|
if not os.path.isfile(filepath):
|
||||||
|
continue
|
||||||
|
check_directory_exists(report_path[:-4])
|
||||||
|
new_song_path = \
|
||||||
|
os.path.join(report_path[:-4], os.path.basename(filepath))
|
||||||
|
if not os.path.exists(new_song_path):
|
||||||
|
shutil.copyfile(filepath, new_song_path)
|
||||||
report_file.close()
|
report_file.close()
|
||||||
return report_path
|
return report_path
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user