zipfile + symlink..

A. Murat Eren meren at uludag.org.tr
Thu Jun 23 22:43:30 CEST 2005


 Hi,

 I have a problem about zipfile.

 I'm trying to add files from local file system into a zip file via zipfile 
module of python.. I have a function in my class which recursively adds files 
or dirs into zip:

 -------8<-------------------8<--------------------8<------------------8<-----
    def add_file(self, fileName):
        """add file or directory to a zip file"""
        if os.path.isdir(fileName):
            self.zip.writestr(fileName + '/', '')
            for f in os.listdir(fileName):
               self.add_file(fileName + '/' + f)
        else:
            if os.path.islink(fileName):
                dest = os.readlink(fileName)
                self.zip.writestr(fileName, dest)
                #do something here to set 'fileName's attributes
                #to write it as a symlink into the zip
            else:
                self.zip.write(fileName, fileName, zipfile.ZIP_DEFLATED)
 ------->8------------------->8-------------------->8------------------>8-----

 But here is a problem raising for symlinks (at the commented section of the 
code passage).. If i don't perform any special process for symlinks in the 
function, function produces zip files without symlinks, naturally; symlinks 
become regular files with the 'dest' content.. I have to set the attribute of 
the symlinks in the zip to make them a real symlink for the 'dest', how can i 
do that?

 Any help or idea would be great..


 Best regards,
-- 

- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
 A. Murat Eren
 meren at uludag.org.tr
 http://cekirdek.uludag.org.tr/~meren/
 0x527D7293, 
 7BCD A5A1 8101 0F6D 84A4  BD11 FE46 2B92 527D 7293
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -

--
 Alan Cox sounds as if he hasn't followed the
 development of programming languages
 and compilers for the last 10 years (exa).
-
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050623/cce2ca90/attachment.sig>


More information about the Python-list mailing list