[pod] Changed the way pod results are re-zipped, in order to be compliant with section 17.4 of the OpenDocument format specification (bug https://bugs.launchpad.net/appy/+bug/1101237).

This commit is contained in:
Gaetan Delannay 2013-01-22 16:34:29 +01:00
parent cb77418dda
commit 5d31bc10db
2 changed files with 1791 additions and 1773 deletions

View file

@ -499,14 +499,27 @@ class Renderer:
resultOdt = zipfile.ZipFile(resultOdtName,'w', zipfile.ZIP_DEFLATED) resultOdt = zipfile.ZipFile(resultOdtName,'w', zipfile.ZIP_DEFLATED)
except RuntimeError: except RuntimeError:
resultOdt = zipfile.ZipFile(resultOdtName,'w') resultOdt = zipfile.ZipFile(resultOdtName,'w')
# Insert first the file "mimetype" (uncompressed), in order to be
# compliant with the OpenDocument Format specification, section 17.4,
# that has a restriction when it comes to zip containers: the file
# called "mimetype" must be at the beginning of the zip file, it must be
# uncompressed and it must be stored without any additional file
# attributes. Else, libraries like "magic", under Linux/Unix, are unable
# to detect the correct mimetype for POD results (it simply recognizes
# it as a "application/zip" and not a
# "application/vnd.oasis.opendocument.text)".
resultOdt.write(os.path.join(self.unzipFolder, 'mimetype'),
'mimetype', zipfile.ZIP_STORED)
for dir, dirnames, filenames in os.walk(self.unzipFolder): for dir, dirnames, filenames in os.walk(self.unzipFolder):
for f in filenames: for f in filenames:
folderName = dir[len(self.unzipFolder)+1:] folderName = dir[len(self.unzipFolder)+1:]
# Ignore file "mimetype" that was already inserted.
if (folderName == '') and (f == 'mimetype'): continue
resultOdt.write(os.path.join(dir, f), resultOdt.write(os.path.join(dir, f),
os.path.join(folderName, f)) os.path.join(folderName, f))
if not dirnames and not filenames: if not dirnames and not filenames:
# This is an empty leaf folder. We must create an entry in the # This is an empty leaf folder. We must create an entry in the
# zip for him # zip for him.
folderName = dir[len(self.unzipFolder):] folderName = dir[len(self.unzipFolder):]
zInfo = zipfile.ZipInfo("%s/" % folderName,time.localtime()[:6]) zInfo = zipfile.ZipInfo("%s/" % folderName,time.localtime()[:6])
zInfo.external_attr = 48 zInfo.external_attr = 48

File diff suppressed because it is too large Load diff