zipfile + symlink..

A

A. Murat Eren

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).
-

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCux71/kYrklJ9cpMRAiBjAKC7ckNKc2stHI2w8c9aIWAE9DDWEACfcGHj
eEo0EK+ueCZ1FsL60BahYTc=
=hCiJ
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top