forked from openlp/openlp
A few fixes for mediamanager file handling and service file saving, most notably for #730459, also >2GiB service files are possible, but user is asked if he wants to include >50Mib files.
bzr-revno: 1367
This commit is contained in:
commit
c6b28c61cf
@ -349,11 +349,11 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
Validates whether an image still exists and, if it does, is the
|
Validates whether an image still exists and, if it does, is the
|
||||||
thumbnail representation of the image up to date.
|
thumbnail representation of the image up to date.
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(image):
|
if not os.path.exists(unicode(image)):
|
||||||
return False
|
return False
|
||||||
if os.path.exists(thumb):
|
if os.path.exists(thumb):
|
||||||
imageDate = os.stat(image).st_mtime
|
imageDate = os.stat(unicode(image)).st_mtime
|
||||||
thumbDate = os.stat(thumb).st_mtime
|
thumbDate = os.stat(unicode(thumb)).st_mtime
|
||||||
# If image has been updated rebuild icon
|
# If image has been updated rebuild icon
|
||||||
if imageDate > thumbDate:
|
if imageDate > thumbDate:
|
||||||
self.iconFromFile(image, thumb)
|
self.iconFromFile(image, thumb)
|
||||||
|
@ -415,46 +415,74 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
"""
|
"""
|
||||||
if not self.fileName():
|
if not self.fileName():
|
||||||
return self.saveFileAs()
|
return self.saveFileAs()
|
||||||
else:
|
path_file_name = unicode(self.fileName())
|
||||||
fileName = self.fileName()
|
(path, file_name) = os.path.split(path_file_name)
|
||||||
log.debug(u'ServiceManager.saveFile - %s' % fileName)
|
(basename, extension) = os.path.splitext(file_name)
|
||||||
|
service_file_name = basename + '.osd'
|
||||||
|
log.debug(u'ServiceManager.saveFile - %s' % path_file_name)
|
||||||
SettingsManager.set_last_dir(self.mainwindow.serviceSettingsSection,
|
SettingsManager.set_last_dir(self.mainwindow.serviceSettingsSection,
|
||||||
split_filename(fileName)[0])
|
path)
|
||||||
service = []
|
service = []
|
||||||
serviceFileName = fileName.replace(u'.osz', u'.osd')
|
|
||||||
zip = None
|
|
||||||
file = None
|
|
||||||
try:
|
|
||||||
write_list = []
|
write_list = []
|
||||||
zip = zipfile.ZipFile(unicode(fileName), 'w')
|
total_size = 0
|
||||||
for item in self.serviceItems:
|
for item in self.serviceItems:
|
||||||
service.append({u'serviceitem': \
|
service.append({u'serviceitem':
|
||||||
item[u'service_item'].get_service_repr()})
|
item[u'service_item'].get_service_repr()})
|
||||||
if item[u'service_item'].uses_file():
|
if not item[u'service_item'].uses_file():
|
||||||
|
continue
|
||||||
for frame in item[u'service_item'].get_frames():
|
for frame in item[u'service_item'].get_frames():
|
||||||
if item[u'service_item'].is_image():
|
if item[u'service_item'].is_image():
|
||||||
path_from = frame[u'path']
|
path_from = frame[u'path']
|
||||||
else:
|
else:
|
||||||
path_from = unicode(os.path.join(
|
path_from = os.path.join(frame[u'path'], frame[u'title'])
|
||||||
frame[u'path'],
|
# Only write a file once
|
||||||
frame[u'title']))
|
if path_from in write_list:
|
||||||
# On write a file once
|
continue
|
||||||
if not path_from in write_list:
|
file_size = os.path.getsize(path_from)
|
||||||
|
size_limit = 52428800 # 50MiB
|
||||||
|
#if file_size > size_limit:
|
||||||
|
# # File exeeds size_limit bytes, ask user
|
||||||
|
# message = unicode(translate('OpenLP.ServiceManager',
|
||||||
|
# 'Do you want to include \n%.1f MB file "%s"\n'
|
||||||
|
# 'into the service file?\nThis may take some time.\n\n'
|
||||||
|
# 'Please note that you need to\ntake care of that file'
|
||||||
|
# ' yourself,\nif you leave it out.')) % \
|
||||||
|
# (file_size/1048576, os.path.split(path_from)[1])
|
||||||
|
# ans = QtGui.QMessageBox.question(self.mainwindow,
|
||||||
|
# translate('OpenLP.ServiceManager', 'Including Large '
|
||||||
|
# 'File'), message, QtGui.QMessageBox.StandardButtons(
|
||||||
|
# QtGui.QMessageBox.Ok|QtGui.QMessageBox.Cancel),
|
||||||
|
# QtGui.QMessageBox.Ok)
|
||||||
|
# if ans == QtGui.QMessageBox.Cancel:
|
||||||
|
# continue
|
||||||
write_list.append(path_from)
|
write_list.append(path_from)
|
||||||
zip.write(path_from.encode(u'utf-8'))
|
total_size += file_size
|
||||||
file = open(serviceFileName, u'wb')
|
log.debug(u'ServiceManager.saveFile - ZIP contents size is %i bytes' %
|
||||||
cPickle.dump(service, file)
|
total_size)
|
||||||
file.close()
|
service_content = cPickle.dumps(service)
|
||||||
zip.write(serviceFileName.encode(u'utf-8'))
|
# 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)
|
||||||
|
zip = None
|
||||||
|
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)
|
||||||
|
# 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:
|
except IOError:
|
||||||
log.exception(u'Failed to save service to disk')
|
log.exception(u'Failed to save service to disk')
|
||||||
|
return False
|
||||||
finally:
|
finally:
|
||||||
if file:
|
|
||||||
file.close()
|
|
||||||
if zip:
|
if zip:
|
||||||
zip.close()
|
zip.close()
|
||||||
delete_file(serviceFileName)
|
self.mainwindow.addRecentFile(path_file_name)
|
||||||
self.mainwindow.addRecentFile(fileName)
|
|
||||||
self.setModified(False)
|
self.setModified(False)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user