From 48d0d39a17d80911460ba579f53ed21073b400bf Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 19 Apr 2011 17:55:36 +0200 Subject: [PATCH] ask before creating an error report copy not imported files to a folder --- openlp/plugins/songs/forms/songimportform.py | 13 ++++++++++--- openlp/plugins/songs/lib/olpimport.py | 2 +- openlp/plugins/songs/lib/songimport.py | 12 ++++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 3d3421d8b..05de6c8a1 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -742,12 +742,19 @@ class SongImportForm(OpenLPWizard): ) importer.do_import() if importer.error_log: - error_path = importer.write_error_report() self.progressLabel.setTextInteractionFlags( 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( - 'SongsPlugin.SongImportForm', 'Your song import failed. See ' - 'the error report for more details:\n%s')) % error_path) + 'SongsPlugin.SongImportForm', 'Your song import failed. ' + 'For more details see the error report:\n%s')) % error_path) else: self.progressLabel.setText(WizardStrings.FinishedImport) diff --git a/openlp/plugins/songs/lib/olpimport.py b/openlp/plugins/songs/lib/olpimport.py index f17ac188b..a201c1783 100644 --- a/openlp/plugins/songs/lib/olpimport.py +++ b/openlp/plugins/songs/lib/olpimport.py @@ -94,7 +94,6 @@ class OpenLPSongImport(SongImport): The database providing the data to import. """ SongImport.__init__(self, manager, **kwargs) - self.import_source = u'sqlite:///%s' % self.import_source self.source_session = None def do_import(self): @@ -106,6 +105,7 @@ class OpenLPSongImport(SongImport): translate('SongsPlugin.OpenLPSongImport', 'Not a valid OpenLP 2.0 song database.')) return + self.import_source = u'sqlite:///%s' % self.import_source engine = create_engine(self.import_source) source_meta = MetaData() source_meta.reflect(engine) diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 80eebde43..b8163fab6 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -28,10 +28,11 @@ import datetime import logging import os import re +import shutil 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.utils import AppLocation 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( '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.write(translate('SongsPlugin.SongImport', 'The following songs could not be imported:\n')) for filepath, reason in self.error_log: 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() return report_path