From: David G. <de...@gm...> - 2006-07-27 14:57:27
|
Hello! I'm writing a little script that takes an openoffice file as a template, opens it up, replaces all the tags it can find, and saves it under a different filename. For those that don't know, the format of the openoffice files is a zipped set of files, some of which are xml files, some of which are images, and some of which are folders that can be empty. So my script opens the zipfile, reads 'content.xml', and then saves the lot with the following function: def save(self,saveFileName="OO_Nota_converted.odt"): ###saves the modified file### savefile = zipfile.ZipFile(saveFileName,'w') for info in self.templateFile.infolist(): savefile.writestr(info,self.templateFile.read(info.filename)) savefile.writestr(zipfile.ZipInfo("content.xml"),self.content) My problem is that while this function works great with python, it produces corrupt zipfiles with jython. I suspect it's because some of the directories are empty, but I don't know why python can handle that and jython can't. Any thought are appreciated. David |
From: Josh J. <j.j...@mc...> - 2006-07-29 03:16:25
|
I haven't tried your example, but have you tried to use java.util.zip? I'm almost certain that would do the trick...even though you'd have to maintain the two different versions. - Josh ----- Original Message ----- From: "David Gibb" <de...@gm...> To: <jyt...@li...> Sent: Thursday, July 27, 2006 12:58 AM Subject: [Jython-users] zipfile produces corrupt files. > Hello! > > I'm writing a little script that takes an openoffice file as a > template, opens it up, replaces all the tags it can find, and saves it > under a different filename. > > For those that don't know, the format of the openoffice files is a > zipped set of files, some of which are xml files, some of which are > images, and some of which are folders that can be empty. > > So my script opens the zipfile, reads 'content.xml', and then saves > the lot with the following function: > > def save(self,saveFileName="OO_Nota_converted.odt"): > ###saves the modified file### > savefile = zipfile.ZipFile(saveFileName,'w') > > for info in self.templateFile.infolist(): > savefile.writestr(info,self.templateFile.read(info.filename)) > > savefile.writestr(zipfile.ZipInfo("content.xml"),self.content) > > My problem is that while this function works great with python, it > produces corrupt zipfiles with jython. I suspect it's because some of > the directories are empty, but I don't know why python can handle that > and jython can't. > > Any thought are appreciated. > David > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |
From: Frank W. <fwi...@gm...> - 2006-07-29 11:57:15
|
Jython-users, I accidentally replied to David only on this (the second time I've done that recently, don't know what's wrong with me lately) anyhow "solution" (or at least answer) below. > My problem is that while this function works great with python, it > produces corrupt zipfiles with jython. I suspect it's because some of > the directories are empty, but I don't know why python can handle that > and jython can't. It turns out that David was not closing his file. In Python that is not a problem, but Jython does not automatically close files. Getting Jython to automatically close files is a bit tricky and isn't likely to happen anytime soon... -Frank |