openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #07464
[Merge] lp:~googol-hush/openlp/trivial into lp:openlp
Andreas Preikschat has proposed merging lp:~googol-hush/openlp/trivial into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~googol-hush/openlp/trivial/+merge/54926
Hello,
- show a dialog when a corrupted service file is opened. http://support.openlp.org/issues/65
- removed the return from the except and attempt to remove service files when saving fails.
--
https://code.launchpad.net/~googol-hush/openlp/trivial/+merge/54926
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/trivial into lp:openlp.
=== modified file 'openlp/core/lib/__init__.py'
--- openlp/core/lib/__init__.py 2011-03-24 19:04:02 +0000
+++ openlp/core/lib/__init__.py 2011-03-25 20:37:25 +0000
@@ -316,8 +316,11 @@
Theme directory to make sure exists
"""
log.debug(u'check_directory_exists %s' % dir)
- if not os.path.exists(dir):
- os.makedirs(dir)
+ try:
+ if not os.path.exists(dir):
+ os.makedirs(dir)
+ except IOError:
+ pass
from listwidgetwithdnd import ListWidgetWithDnD
from displaytags import DisplayTags
=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py 2011-03-24 19:04:02 +0000
+++ openlp/core/ui/servicemanager.py 2011-03-25 20:37:25 +0000
@@ -481,28 +481,30 @@
# Usual Zip file cannot exceed 2GiB, file with Zip64 cannot be
# extracted using unzip in UNIX.
allow_zip_64 = (total_size > 2147483648 + len(service_content))
- log.debug(u'ServiceManager.saveFile - allowZip64 is %s' %
- allow_zip_64)
+ log.debug(u'ServiceManager.saveFile - allowZip64 is %s' % allow_zip_64)
zip = None
+ success = True
try:
zip = zipfile.ZipFile(path_file_name, 'w', zipfile.ZIP_STORED,
allow_zip_64)
# First we add service contents.
# We save ALL filenames into ZIP using UTF-8.
- zip.writestr(service_file_name.encode(u'utf-8'),
- service_content)
+ zip.writestr(service_file_name.encode(u'utf-8'), service_content)
# Finally add all the listed media files.
for path_from in write_list:
zip.write(path_from, path_from.encode(u'utf-8'))
except IOError:
log.exception(u'Failed to save service to disk')
- return False
+ success = False
finally:
if zip:
zip.close()
- self.mainwindow.addRecentFile(path_file_name)
- self.setModified(False)
- return True
+ if success:
+ self.mainwindow.addRecentFile(path_file_name)
+ self.setModified(False)
+ else:
+ delete_file(path_file_name)
+ return success
def saveFileAs(self):
"""
@@ -527,8 +529,9 @@
def loadFile(self, fileName):
if not fileName:
return False
- else:
- fileName = unicode(fileName)
+ fileName = unicode(fileName)
+ if not os.path.exists(fileName):
+ return False
zip = None
fileTo = None
try:
@@ -566,24 +569,27 @@
Receiver.send_message(u'%s_service_load' %
serviceItem.name.lower(), serviceItem)
delete_file(p_file)
+ self.setFileName(fileName)
+ self.mainwindow.addRecentFile(fileName)
+ self.setModified(False)
+ QtCore.QSettings().setValue(
+ 'service/last file', QtCore.QVariant(fileName))
Receiver.send_message(u'cursor_normal')
else:
critical_error_message_box(
message=translate('OpenLP.ServiceManager',
'File is not a valid service.'))
log.exception(u'File contains no service data')
- except (IOError, NameError):
+ except (IOError, NameError, zipfile.BadZipfile):
+ critical_error_message_box(
+ message=translate('OpenLP.ServiceManager',
+ 'File could not be opened because it is corrupt.'))
log.exception(u'Problem loading service file %s' % fileName)
finally:
if fileTo:
fileTo.close()
if zip:
zip.close()
- self.setFileName(fileName)
- self.mainwindow.addRecentFile(fileName)
- self.setModified(False)
- QtCore.QSettings(). \
- setValue(u'service/last file', QtCore.QVariant(fileName))
def loadLastFile(self):
"""
Follow ups